├── .gitignore ├── LICENSE ├── README.md ├── requirements.txt └── srs ├── 0din.py ├── database.py ├── entry.sh ├── indexer.py ├── peer_discovery.py ├── previews.py ├── scheduler.py ├── search.py ├── settings.py ├── static ├── css │ └── tailwind.css ├── js │ └── theme.js └── logo │ ├── favicon.ico │ ├── logo.png │ └── logo.svg ├── templates ├── admin.html ├── index.html ├── layout.html ├── login.html ├── md5_results.html ├── results.html └── setup.html └── trigger.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Virtual environment 2 | .venv/ 3 | venv/ 4 | 5 | # Python cache 6 | __pycache__/ 7 | *.pyc 8 | *.pyo 9 | 10 | # Logs and database 11 | *.log 12 | *.sqlite3 13 | 14 | # OS specific files 15 | .DS_Store 16 | Thumbs.db 17 | 18 | # IDE specific files 19 | .vscode/ 20 | .idea/ 21 | 22 | # Environment variables 23 | .env 24 | 25 | # Odin related files 26 | credentials.json 27 | settings.json 28 | database.db -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 0din 2 | 3 | Decentralized Federated File Hosting Platform 4 | ## Overview 5 | 6 | 0din is a decentralized, federated file hosting platform that aims to provide a scalable and user-friendly solution for sharing and accessing files across a distributed network. By combining the strengths of decentralization and federation, 0din creates a dynamic, resilient ecosystem for file-sharing. 7 | 8 | ## Installation 9 | 10 | 1. **Clone the repository**: 11 | ```bash 12 | git clone https://github.com/4rtemis-4rrow/0din.git 13 | 14 | cd 0din 15 | 16 | 2. **Create and activate a virtual environment**: 17 | 18 | Run the following command in your project directory to create a virtual environment: 19 | ```bash 20 | python3 -m venv .venv 21 | ``` 22 | 23 | To activate the virtual environment, execute one of the following commands: 24 | 25 | On macOS and Linux: 26 | ```bash 27 | source .venv/bin/activate 28 | ``` 29 | 30 | On Windows: 31 | ```bash 32 | .venv\Scripts\activate 33 | ``` 34 | 4. **Install dependencies**: 35 | ```bash 36 | pip install -r requirements.txt 37 | 38 | 5. **Run the application:**: 39 | ```bash 40 | python srs/0din.py 41 | ## Key Features 42 | 43 | Decentralized Hosting: Operates on a distributed network of nodes, each contributing to the overall system, ensuring robustness and redundancy. 44 | 45 | Federated Architecture: Nodes communicate and interact seamlessly, enabling users to access files hosted on any participating node. 46 | 47 | Admin-Only Uploads: File uploads are restricted to administrators. Uploads are done by manually placing files into designated directories rather than through a web interface. 48 | 49 | Automatic Categorization: Files are automatically categorized based on their path and file extension, simplifying file organization and retrieval. 50 | 51 | HTTP Access: Files can be accessed via standard HTTP, allowing users to browse and download files using any web browser without the need for specialized clients, unlike torrents. 52 | 53 | Ease of Setup: Designed for simplicity, 0din is extremely easy to set up, requiring minimal configuration and maintenance. 54 | 55 | ## How It Works 56 | 57 | Setup: Configure 0din by pointing it to a specific directory on your system. 0din will begin hosting files from this directory immediately. 58 | 59 | File Access: Users can search and download files from any node in the network using a standard web browser. The federated design ensures that files are available across the network. 60 | 61 | File Management: Administrators manage file uploads by manually placing files into the appropriate directories on their node. 62 | 63 | Network Expansion: As more users establish 0din nodes, the network grows, increasing the availability and distribution of files across a broader range. 64 | 65 | ## Advantages of 0din Over Other Decentralized Solutions 66 | 67 | 1. Decentralized File Hosting with Federated Search 68 | - 0din: Each node operates independently, hosting its own files and handling its own search queries. The federated search system aggregates results from multiple nodes, ensuring a comprehensive search experience without relying on a central tracker or indexer. 69 | 70 | - BitTorrent/IPFS: Typically rely on centralized or semi-centralized trackers (BitTorrent) or distributed hash tables (IPFS) for indexing and search. 71 | 72 | 2. Simple Node Operation 73 | - 0din: Nodes are lightweight and easy to set up, requiring only a simple configuration and basic file placement. No complex software or additional components are needed for hosting files or participating in the network. 74 | - BitTorrent/IPFS: Can involve more complex setup processes and require additional software or configurations to function effectively. 75 | 76 | 3. No Need for Specialized Clients 77 | - 0din: Operates over standard HTTP, allowing users to access and download files using any modern web browser. This eliminates the need for specialized clients or software. 78 | - BitTorrent: Requires specific torrent clients to download files. IPFS requires IPFS clients or gateways for accessing content. 79 | 80 | 4. Rapidly Growing Network with Minimal Overhead 81 | - 0din: Designed to scale effortlessly with the number of nodes, leveraging federated search to distribute query load and minimize individual node responsibilities. 82 | - BitTorrent/IPFS: May experience performance issues with high numbers of peers or files, especially if nodes become heavily loaded with both data and queries. 83 | 84 | 5. Flexible File Access and Distribution 85 | - 0din: Provides unrestricted access to files, with users able to download from any node hosting the desired content. There are no built-in restrictions on file availability. 86 | - BitTorrent/IPFS: Often involve mechanisms for rate-limiting, seeding requirements, or access controls, which can restrict file availability and download speeds. 87 | 88 | 6. Admin-Controlled Content Compliance 89 | - 0din: Content compliance is managed by individual node admins, who are responsible for handling copyright and DMCA issues according to their local regulations. This decentralized approach allows flexibility in content management. 90 | - BitTorrent/IPFS: Content management is less flexible, with issues often handled by central entities or through network-wide policies. 91 | 92 | 7. Autocategorization Based on Path and Extension 93 | - 0din: Automatically categorizes files based on their directory path and file extension, simplifying the organization and searchability of large datasets. 94 | - BitTorrent/IPFS: Generally do not include built-in categorization features, relying on external metadata or user-added tags. 95 | 96 | 8. Efficient Peer Discovery 97 | - 0din: Utilizes gossip-based peer discovery with a constant heartbeat ping to maintain an up-to-date list of active nodes, ensuring efficient network operation and node management. 98 | - BitTorrent: Depends on trackers or DHT for peer discovery, which can be subject to central points of failure or inefficiencies. IPFS uses a similar DHT-based approach. 99 | 100 | 9. Community-Driven Expansion 101 | - 0din: Leverages the contributions of data hoarders who bring substantial storage capacities to the network, creating a massive, distributed archive of information. 102 | - BitTorrent/IPFS: Expansion often depends on broader adoption and community support, with no specific focus on data hoarders or large-scale individual contributions. 103 | 104 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | Pillow 2 | colorlog 3 | cryptography 4 | ebooklib 5 | flask 6 | gunicorn 7 | matplotlib 8 | psycopg2-binary 9 | pydub 10 | pymupdf 11 | python-docx 12 | python-dotenv 13 | python-pptx 14 | requests 15 | schedule 16 | -------------------------------------------------------------------------------- /srs/0din.py: -------------------------------------------------------------------------------- 1 | import os 2 | import json 3 | import logging 4 | import secrets 5 | import search 6 | import indexer 7 | import sqlite3 8 | import settings 9 | import datetime 10 | from flask import Flask, render_template, redirect, request, jsonify, flash, send_file, abort, session, url_for 11 | from werkzeug.security import generate_password_hash, check_password_hash 12 | from colorlog import ColoredFormatter 13 | from dotenv import load_dotenv 14 | from database import get_db_connection 15 | from scheduler import start_scheduler, schedule_tasks 16 | from threading import Thread 17 | 18 | 19 | load_dotenv() 20 | 21 | # Logging configuration 22 | log_format = "%(asctime)s - %(name)s - %(levelname)s - %(message)s" 23 | formatter = ColoredFormatter( 24 | "%(asctime)s - %(name)s - %(log_color)s%(levelname)s%(reset)s - %(message)s", 25 | datefmt="%Y-%m-%d %H:%M:%S", 26 | log_colors={ 27 | 'DEBUG': 'cyan', 28 | 'INFO': 'green', 29 | 'WARNING': 'yellow', 30 | 'ERROR': 'red', 31 | 'CRITICAL': 'bold_red', 32 | } 33 | ) 34 | 35 | console_handler = logging.StreamHandler() 36 | console_handler.setFormatter(formatter) 37 | logger = logging.getLogger() 38 | logger.setLevel(logging.DEBUG) 39 | logger.addHandler(console_handler) 40 | 41 | def setup_jinja_filters(app): 42 | @app.template_filter('date') 43 | def format_date(value): 44 | if not value: 45 | return "" 46 | try: 47 | if isinstance(value, str): 48 | dt = datetime.datetime.fromisoformat(value.replace('Z', '+00:00')) 49 | else: 50 | dt = value 51 | return dt.strftime('%b %d, %Y') 52 | except: 53 | return value 54 | 55 | @app.template_filter('filesizeformat') 56 | def filesizeformat(bytes, precision=2): 57 | """Format the value like a 'human-readable' file size (i.e. 13 KB, 4.1 MB, 102 bytes, etc).""" 58 | if bytes is None or bytes == '': 59 | return '0 bytes' 60 | 61 | bytes = float(bytes) 62 | 63 | if bytes == 0: 64 | return '0 bytes' 65 | elif bytes == 1: 66 | return '1 byte' 67 | 68 | abbrevs = ( 69 | (1<<50, 'PB'), 70 | (1<<40, 'TB'), 71 | (1<<30, 'GB'), 72 | (1<<20, 'MB'), 73 | (1<<10, 'KB'), 74 | (1, 'bytes') 75 | ) 76 | 77 | for factor, suffix in abbrevs: 78 | if bytes >= factor: 79 | break 80 | 81 | if suffix == 'bytes': 82 | precision = 0 83 | 84 | return '%.*f %s' % (precision, bytes / factor, suffix) 85 | 86 | # Add this to your existing Flask app initialization 87 | def configure_app(app): 88 | setup_jinja_filters(app) 89 | 90 | # Add static folder configuration if needed 91 | app.static_folder = 'static' 92 | app.static_url_path = '/static' 93 | 94 | return app 95 | 96 | app = Flask(__name__) 97 | app = configure_app(app) 98 | app.secret_key = secrets.token_hex(16) 99 | 100 | def setup_admin_credentials(username, password): 101 | hashed_password = generate_password_hash(password) 102 | with open('credentials.json', 'w') as f: 103 | json.dump({'username': username, 'password': hashed_password}, f) 104 | 105 | def load_credentials(): 106 | if os.path.exists('credentials.json'): 107 | with open('credentials.json') as f: 108 | return json.load(f) 109 | return {'username': 'admin', 'password': generate_password_hash('admin')} 110 | 111 | @app.before_request 112 | def check_setup(): 113 | ssl_enabled = os.getenv("ENABLE_SSL") == "true" 114 | https_redirect_enabled = os.getenv("ENABLE_HTTPS_REDIRECT") == "true" 115 | 116 | if ssl_enabled: 117 | if not request.is_secure: 118 | url = request.url.replace("http://", "https://", 1) 119 | return redirect(url, code=301) 120 | return 121 | 122 | if https_redirect_enabled: 123 | if not request.is_secure and request.headers.get('X-Forwarded-Proto', 'http') != 'https': 124 | url = request.url.replace("http://", "https://", 1) 125 | return redirect(url, code=301) 126 | 127 | if request.path.startswith('/static') or request.endpoint in ['setup', 'login']: 128 | return 129 | 130 | if not os.path.exists('credentials.json'): 131 | return redirect(url_for('setup')) 132 | 133 | @app.route('/setup', methods=['GET', 'POST']) 134 | def setup(): 135 | if os.path.exists('credentials.json'): 136 | return redirect(url_for('login')) 137 | 138 | if request.method == 'POST': 139 | username = request.form['username'] 140 | password = request.form['password'] 141 | password_confirmation = request.form['password_confirmation'] 142 | 143 | if (password_confirmation != password): 144 | flash("Passwords do not match", 'error') 145 | return redirect(url_for('setup')) 146 | 147 | setup_admin_credentials(username, password) 148 | return redirect(url_for('login')) 149 | 150 | return render_template('setup.html') 151 | 152 | @app.route('/login', methods=['GET', 'POST']) 153 | def login(): 154 | if request.method == 'POST': 155 | username = request.form['username'] 156 | password = request.form['password'] 157 | credentials = load_credentials() 158 | if username == credentials['username'] and check_password_hash(credentials['password'], password): 159 | session['logged_in'] = True 160 | return redirect(url_for('admin')) 161 | else: 162 | return 'Invalid credentials', 401 163 | return render_template('login.html') 164 | 165 | @app.route('/admin', methods=['GET', 'POST']) 166 | def admin(): 167 | if not session.get('logged_in'): 168 | return redirect(url_for('login')) 169 | 170 | config = settings.return_all() 171 | 172 | if request.method == 'POST': 173 | for key in config: 174 | if key in request.form: 175 | try: 176 | config[key] = json.loads(request.form[key]) 177 | except ValueError: 178 | config[key] = request.form[key] 179 | 180 | return render_template('admin.html', config=config) 181 | 182 | @app.route('/shutdown', methods=['POST']) 183 | def shutdown(): 184 | if not session.get('logged_in'): 185 | return redirect(url_for('login')) 186 | func = request.environ.get('werkzeug.server.shutdown') 187 | if func is None: 188 | raise RuntimeError('Not running with the Werkzeug Server') 189 | func() 190 | return 'Server shutting down...' 191 | 192 | @app.route('/restart', methods=['POST']) 193 | def restart(): 194 | if not session.get('logged_in'): 195 | return redirect(url_for('login')) 196 | func = request.environ.get('werkzeug.server.shutdown') 197 | if func is None: 198 | raise RuntimeError('Not running with the Werkzeug Server') 199 | func() 200 | os.execv(__file__, ['python'] + [__file__]) 201 | return 'Server restarting...' 202 | 203 | @app.route('/indexer', methods=['POST']) 204 | def trigger_indexer(): 205 | if not session.get('logged_in'): 206 | return "Unauthorized", 401 207 | 208 | conn = get_db_connection() 209 | path = request.json.get('path') 210 | if not path: 211 | return "Path is required", 400 212 | 213 | try: 214 | indexer.indexer(path, conn) 215 | return "Indexer run successfully", 200 216 | except Exception as e: 217 | return f"An error occurred: {str(e)}", 500 218 | finally: 219 | conn.close() 220 | 221 | @app.route('/') 222 | def home(): 223 | return render_template('index.html') 224 | 225 | @app.route('/global_search', methods=['POST']) 226 | def global_search_route(): 227 | conn = get_db_connection() 228 | query = request.form.get('query') 229 | category = request.form.get('category') 230 | if category == 'all': 231 | category = None 232 | 233 | results = search.global_search(query, settings.get_setting("known_nodes"), settings.get_setting("NODE_ID"), conn, "name", category) 234 | conn.close() 235 | return render_template('results.html', query=query, category=category, results=results) 236 | 237 | @app.route('/json/global_search', methods=['POST']) 238 | def global_search_json(): 239 | conn = get_db_connection() 240 | query = request.form.get('query') 241 | category = request.form.get('category') 242 | if category == 'all': 243 | category = None 244 | 245 | results = search.global_search(query, settings.get_setting("known_nodes"), settings.get_setting("NODE_ID"), conn, "name", category) 246 | conn.close() 247 | return jsonify(results) 248 | 249 | @app.route('/localsearch', methods=['POST']) 250 | def localsearch_endpoint(): 251 | conn = get_db_connection() 252 | data = request.get_json() 253 | search_term = data.get('search_term') 254 | search_type = data.get('search_type', 'name') 255 | category = data.get('category') 256 | 257 | logger.debug(f"Received request for local search: search_term={search_term}, search_type={search_type}, category={category}") 258 | 259 | matches = search.local_search(search_term, settings.get_setting("NODE_ID"), conn, search_type, category) 260 | conn.close() 261 | return jsonify(matches), 200 262 | 263 | @app.route('/md5_search/') 264 | def md5_search(md5_hash): 265 | try: 266 | conn = get_db_connection() 267 | results = search.global_search(md5_hash, settings.get_setting("known_nodes"), settings.get_setting("NODE_ID"), conn, "md5") 268 | return render_template('md5_results.html', md5_hash=md5_hash, results=results) 269 | except Exception as e: 270 | logger.error(f"Error during MD5 search: {e}") 271 | return "An error occurred during the search." 272 | finally: 273 | conn.close() 274 | 275 | @app.route('/json/md5_search/') 276 | def md5_search_json(md5_hash): 277 | conn = get_db_connection() 278 | results = search.global_search(md5_hash, settings.get_setting("known_nodes"), settings.get_setting("NODE_ID"), conn, "md5") 279 | conn.close() 280 | return jsonify(results) 281 | 282 | @app.route('/download/') 283 | def download_file(md5_hash): 284 | conn = get_db_connection() 285 | cursor = conn.cursor() 286 | 287 | try: 288 | cursor.execute("SELECT path FROM files WHERE md5_hash = ?;", (md5_hash,)) 289 | result = cursor.fetchone() 290 | 291 | if result: 292 | path = result[0] 293 | cursor.execute("UPDATE files SET download_count = download_count + 1 WHERE md5_hash = ?;", (md5_hash,)) 294 | conn.commit() 295 | return send_file(path) 296 | else: 297 | abort(404, description="File not found") 298 | finally: 299 | cursor.close() 300 | conn.close() 301 | 302 | @app.route('/json/nodes') 303 | def nodes(): 304 | return jsonify(list(settings.get_setting("known_nodes"))) 305 | 306 | @app.route('/total_file_size', methods=['GET']) 307 | def total_file_size(): 308 | conn = get_db_connection() 309 | try: 310 | cursor = conn.cursor() 311 | cursor.execute("SELECT SUM(file_size) FROM files;") 312 | result = cursor.fetchone() 313 | total_size = result[0] if result and result[0] is not None else 0 314 | return jsonify({'total_file_size': total_size}) 315 | except sqlite3.Error as e: 316 | return jsonify({'error': str(e)}), 500 317 | finally: 318 | conn.close() 319 | 320 | @app.route('/preview/', methods=['GET']) 321 | def serve_preview(filename): 322 | try: 323 | shared_directory = settings.get_setting("DIRECTORY") 324 | hidden_directory = os.path.join(shared_directory, '.previews') 325 | preview_file_path = os.path.join(hidden_directory, f"{filename}") 326 | 327 | if not os.path.exists(preview_file_path): 328 | logger.warning(f"Preview file not found: {preview_file_path}") 329 | abort(404) 330 | 331 | return send_file(preview_file_path, mimetype='image/webp') 332 | except Exception as e: 333 | logger.error(f"Error serving preview for {filename}: {e}") 334 | abort(500) 335 | 336 | @app.route('/announce', methods=['POST']) 337 | def announce_endpoint(): 338 | data = request.json 339 | node_id = data.get("node_id") 340 | response_url = data.get("response_url") 341 | received_known_nodes = data.get("known_nodes", []) 342 | logger.debug(f"Handling Announcement From {node_id}") 343 | known_nodes = settings.get_setting("known_nodes") 344 | known_nodes.add(node_id) 345 | known_nodes.update(received_known_nodes) 346 | settings.set_setting("known_nodes", known_nodes) 347 | return jsonify({"known_nodes": list(known_nodes)}), 200 348 | 349 | @app.route('/heartbeat', methods=['GET']) 350 | def heartbeat(): 351 | return jsonify({"status": "alive", "message": "Heartbeat response from the node"}), 200 352 | 353 | @app.route('/total_files', methods=['GET']) 354 | def total_files(): 355 | conn = get_db_connection() 356 | try: 357 | cursor = conn.cursor() 358 | cursor.execute("SELECT COUNT(*) FROM files;") 359 | result = cursor.fetchone() 360 | total_files = result[0] if result and result[0] is not None else 0 361 | return jsonify({'total_files': total_files}) 362 | except sqlite3.Error as e: 363 | return jsonify({'error': str(e)}), 500 364 | finally: 365 | conn.close() 366 | 367 | @app.route('/total_files_all', methods=['GET']) 368 | def total_files_all(): 369 | conn = get_db_connection() 370 | try: 371 | cursor = conn.cursor() 372 | cursor.execute("SELECT COUNT(*) FROM files;") 373 | result = cursor.fetchone() 374 | total_files = result[0] if result and result[0] is not None else 0 375 | known_nodes = settings.get_setting("known_nodes") 376 | for node in known_nodes: 377 | node_url = f"http://{node}:{os.getenv('NODE_PORT', 5000)}/total_files" 378 | response = requests.get(node_url) 379 | if response.status_code == 200: 380 | total_files += response.json()['total_files'] 381 | return jsonify({'total_files': total_files}) 382 | except sqlite3.Error as e: 383 | return jsonify({'error': str(e)}), 500 384 | finally: 385 | conn.close() 386 | 387 | def run_background_tasks(): 388 | start_scheduler() 389 | schedule_tasks() 390 | # You can also call indexing and peer discovery here if you want 391 | 392 | def start_background_tasks(): 393 | Thread(target=run_background_tasks, daemon=True).start() 394 | 395 | if __name__ == '__main__': 396 | start_background_tasks() 397 | app.run(host='0.0.0.0', port=int(os.getenv("NODE_PORT", 5000))) 398 | 399 | -------------------------------------------------------------------------------- /srs/database.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sqlite3 3 | import logging 4 | from colorlog import ColoredFormatter 5 | 6 | # Logging setup 7 | log_format = "%(asctime)s - %(name)s - %(levelname)s - %(message)s" 8 | formatter = ColoredFormatter( 9 | "%(asctime)s - %(name)s - %(log_color)s%(levelname)s%(reset)s - %(message)s", 10 | datefmt="%Y-%m-%d %H:%M:%S", 11 | log_colors={ 12 | 'DEBUG': 'cyan', 13 | 'INFO': 'green', 14 | 'WARNING': 'yellow', 15 | 'ERROR': 'red', 16 | 'CRITICAL': 'bold_red', 17 | } 18 | ) 19 | console_handler = logging.StreamHandler() 20 | console_handler.setFormatter(formatter) 21 | logger = logging.getLogger() 22 | logger.setLevel(logging.DEBUG) 23 | logger.addHandler(console_handler) 24 | 25 | # Path to SQLite database file 26 | DB_PATH = os.getenv('SQLITE_DB_PATH', 'database.db') 27 | 28 | def get_db_connection(): 29 | try: 30 | conn = sqlite3.connect(DB_PATH) 31 | conn.row_factory = sqlite3.Row 32 | logger.info("SQLite database connection established.") 33 | return conn 34 | except sqlite3.Error as e: 35 | logger.error(f"SQLite connection failed: {e}") 36 | raise 37 | 38 | def put_connection(conn): 39 | conn.close() 40 | -------------------------------------------------------------------------------- /srs/entry.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ "${ENABLE_SSL}" = "true" ]; then 4 | gunicorn -w 4 -b 0.0.0.0:${NODE_PORT:-5000} 0din:app \ 5 | --certfile=cert.pem --keyfile=key.pem \ 6 | --log-level debug --access-logfile - --error-logfile - 7 | else 8 | gunicorn -w 4 -b 0.0.0.0:${NODE_PORT:-5000} 0din:app \ 9 | --log-level debug --access-logfile - --error-logfile - 10 | fi 11 | 12 | -------------------------------------------------------------------------------- /srs/indexer.py: -------------------------------------------------------------------------------- 1 | import os 2 | import hashlib 3 | import sqlite3 4 | import re 5 | import logging 6 | import colorlog 7 | 8 | # Configure logger with colorlog 9 | logger = colorlog.getLogger(__name__) 10 | handler = colorlog.StreamHandler() 11 | handler.setFormatter( 12 | colorlog.ColoredFormatter( 13 | "%(log_color)s%(levelname)s:%(name)s:%(message)s", 14 | log_colors={ 15 | "DEBUG": "cyan", 16 | "INFO": "green", 17 | "WARNING": "yellow", 18 | "ERROR": "red", 19 | "CRITICAL": "bold_red", 20 | }, 21 | ) 22 | ) 23 | logger.addHandler(handler) 24 | logger.setLevel(logging.DEBUG) 25 | 26 | def _calculate_md5(file_path, connection): 27 | logger.debug(f"Checking MD5 for {file_path}") 28 | cursor = connection.cursor() 29 | cursor.execute("SELECT md5_hash FROM files WHERE path = ?", (file_path,)) 30 | result = cursor.fetchone() 31 | if result: 32 | logger.info(f"Reusing existing MD5 for {file_path}: {result[0]}") 33 | return result[0] 34 | logger.debug(f"Calculating MD5 for {file_path}") 35 | md5_hash = hashlib.md5() 36 | try: 37 | with open(file_path, "rb") as f: 38 | for chunk in iter(lambda: f.read(4096), b""): 39 | md5_hash.update(chunk) 40 | return md5_hash.hexdigest() 41 | except Exception as e: 42 | logger.error(f"Error calculating MD5 for {file_path}: {e}") 43 | return None 44 | 45 | def _detect_category(file_path, file_extension): 46 | logger.debug(f"Detecting category for {file_path}") 47 | categories = { 48 | "movie": ["movie", "movies", "film", "cinema", "flick"], 49 | "tv show": ["tv", "show", "shows", "series", "episode", "season"], 50 | "book": ["book", "books", "novel", "textbook", "literature"], 51 | "audiobook": ["audiobook", "audiobooks", "audio book", "narration"], 52 | "podcast": ["podcast", "podcasts", "episode", "broadcast"], 53 | "music": ["music", "album", "track", "song"], 54 | "image": ["image", "picture", "photo", "snapshot", "gallery"], 55 | "ebook": ["ebook", "e-book", "electronic book", "kindle", "pdf"], 56 | "compressed": ["zip", "archive", "compressed", "rar", "tar"], 57 | } 58 | for category, keywords in categories.items(): 59 | if any(keyword in file_path.lower() for keyword in keywords): 60 | logger.info(f"Category detected from path: {category}") 61 | return category 62 | extension_categories = { 63 | "audio": [".mp3", ".wav", ".flac", ".aac", ".ogg", ".m4a"], 64 | "video": [".mp4", ".avi", ".mkv", ".mov", ".wmv", ".flv"], 65 | "image": [".jpg", ".jpeg", ".png", ".gif", ".bmp", ".tiff", ".svg"], 66 | "plaintext": [".txt", ".md", ".log", ".csv", ".json"], 67 | "document": [".pdf", ".doc", ".docx", ".xls", ".xlsx", ".ppt", ".pptx", ".odt"], 68 | "ebook": [".epub", ".mobi", ".azw"], 69 | "compressed": [".zip", ".rar", ".tar", ".gz", ".7z"], 70 | } 71 | for category, extensions in extension_categories.items(): 72 | if file_extension.lower() in extensions: 73 | logger.info(f"Category detected from file extension: {category}") 74 | return category 75 | logger.warning(f"No category matched for {file_path}. Categorized as 'other'") 76 | return "other" 77 | 78 | def _load_exclusion_patterns(directory): 79 | logger.debug(f"Loading exclusion patterns from {directory}") 80 | exclude_file_path = os.path.join(directory, ".exclude_patterns") 81 | if os.path.exists(exclude_file_path): 82 | try: 83 | with open(exclude_file_path, "r") as f: 84 | logger.info(f"Exclusion patterns loaded from {exclude_file_path}") 85 | return [re.compile(line.strip()) for line in f.readlines() if line.strip()] 86 | except Exception as e: 87 | logger.error(f"Error loading exclusion patterns: {e}") 88 | return [] 89 | 90 | def _should_exclude(file_path, exclude_patterns): 91 | for pattern in exclude_patterns: 92 | if pattern.search(file_path): 93 | logger.info(f"File {file_path} excluded by pattern {pattern.pattern}") 94 | return True 95 | return False 96 | 97 | def _create_database(connection): 98 | logger.debug("Creating database table if not exists") 99 | try: 100 | cursor = connection.cursor() 101 | cursor.execute(""" 102 | CREATE TABLE IF NOT EXISTS files ( 103 | id INTEGER PRIMARY KEY AUTOINCREMENT, 104 | file_name TEXT, 105 | path TEXT, 106 | md5_hash TEXT UNIQUE, 107 | file_size INTEGER, 108 | category TEXT, 109 | date_indexed TIMESTAMP DEFAULT CURRENT_TIMESTAMP, 110 | download_count INTEGER DEFAULT 0 111 | ); 112 | """) 113 | connection.commit() 114 | logger.info("Database table created or already exists.") 115 | except Exception as e: 116 | logger.critical(f"Error creating database table: {e}") 117 | 118 | def _index_directory(directory, exclude_patterns, connection): 119 | logger.debug(f"Indexing directory: {directory}") 120 | file_index = [] 121 | 122 | for root, _, files in os.walk(directory): 123 | for file_name in files: 124 | if file_name == ".exclude_patterns": 125 | continue 126 | 127 | file_path = os.path.join(root, file_name) 128 | if _should_exclude(file_path, exclude_patterns): 129 | continue 130 | 131 | file_size = os.path.getsize(file_path) 132 | file_extension = os.path.splitext(file_name)[1] 133 | file_hash = _calculate_md5(file_path, connection) 134 | if file_hash is None: 135 | logger.error(f"Skipping {file_path} due to MD5 error") 136 | continue 137 | 138 | cursor = connection.cursor() 139 | cursor.execute("SELECT * FROM files WHERE md5_hash = ?", (file_hash,)) 140 | existing_file = cursor.fetchone() 141 | 142 | if existing_file: 143 | logger.info(f"File already indexed: {file_name} (MD5: {file_hash})") 144 | continue 145 | 146 | file_category = _detect_category(file_path, file_extension) 147 | 148 | cursor.execute(""" 149 | INSERT INTO files (file_name, path, md5_hash, file_size, category) 150 | VALUES (?, ?, ?, ?, ?); 151 | """, (file_name, file_path, file_hash, file_size, file_category)) 152 | connection.commit() 153 | 154 | file_index.append({ 155 | "file_name": file_name, 156 | "path": file_path, 157 | "md5_hash": file_hash, 158 | "file_size": file_size, 159 | "category": file_category, 160 | }) 161 | logger.info(f"Indexed {file_name} with category {file_category}") 162 | 163 | return file_index 164 | 165 | def indexer(directory, connection): 166 | logger.debug(f"Starting indexing for directory {directory}") 167 | _create_database(connection) 168 | exclude_patterns = _load_exclusion_patterns(directory) 169 | file_index = _index_directory(directory, exclude_patterns, connection) 170 | logger.info(f"Indexing complete. {len(file_index)} files indexed.") 171 | connection.close() 172 | logger.debug("Database connection closed.") 173 | -------------------------------------------------------------------------------- /srs/peer_discovery.py: -------------------------------------------------------------------------------- 1 | import requests 2 | import time 3 | import logging 4 | import colorlog 5 | 6 | # Configure logging 7 | handler = colorlog.StreamHandler() 8 | handler.setFormatter(colorlog.ColoredFormatter( 9 | '%(log_color)s%(asctime)s - %(levelname)s - %(message)s', 10 | log_colors={ 11 | 'DEBUG': 'cyan', 12 | 'INFO': 'green', 13 | 'WARNING': 'yellow', 14 | 'ERROR': 'red', 15 | 'CRITICAL': 'bold_red', 16 | } 17 | )) 18 | 19 | logger = colorlog.getLogger(__name__) 20 | logger.addHandler(handler) 21 | logger.setLevel(logging.DEBUG) 22 | 23 | 24 | def _check_internet_connection(test_url="http://www.google.com", timeout=5): 25 | """ 26 | Check if there is an active internet connection by making a request to a reliable URL. 27 | 28 | Args: 29 | test_url (str): URL to test internet connectivity. 30 | timeout (int): Timeout for the request in seconds. 31 | 32 | Returns: 33 | bool: True if internet connection is available, False otherwise. 34 | """ 35 | try: 36 | response = requests.get(test_url, timeout=timeout) 37 | logger.info(f"Internet connection check: {response.status_code == 200}") 38 | return response.status_code == 200 39 | except requests.RequestException as e: 40 | logger.error(f"Internet connection check failed: {e}") 41 | return False 42 | 43 | 44 | def announce(announce_url, node_id, known_nodes, max_retries=3, timeout=5): 45 | """ 46 | Announce the node to a known node and update the known nodes list with the received list. 47 | 48 | Args: 49 | announce_url (str): URL of the known node to announce to. 50 | node_id (str): The ID of the announcing node (e.g., 'ip:port'). 51 | known_nodes (set): Set of known nodes to be updated. 52 | max_retries (int): Maximum number of retries for the announcement. 53 | timeout (int): Timeout for the request in seconds. 54 | 55 | Returns: 56 | set: The list of known nodes received from the other node. 57 | """ 58 | payload = {"node_id": node_id} 59 | for attempt in range(max_retries): 60 | try: 61 | logger.debug(f"Announcing to {announce_url}, attempt {attempt + 1}") 62 | response = requests.post(announce_url, json=payload, timeout=timeout) 63 | response.raise_for_status() 64 | response_data = response.json() 65 | received_nodes = response_data.get("known_nodes", []) 66 | known_nodes.update(received_nodes) 67 | logger.info(f"Announcement successful, known nodes received: {received_nodes}") 68 | return set(received_nodes) 69 | except requests.RequestException as e: 70 | logger.warning(f"Attempt {attempt + 1} failed: {e}") 71 | time.sleep(2 ** attempt) 72 | 73 | logger.error(f"Failed to announce to {announce_url} after {max_retries} attempts") 74 | return set() 75 | 76 | def heartbeat_ping(node_url, timeout=5): 77 | """ 78 | Send a heartbeat ping to a node to check if it is still alive. 79 | 80 | Args: 81 | node_url (str): URL of the node to ping. 82 | timeout (int): Timeout for the request in seconds. 83 | 84 | Returns: 85 | int: 0 if the heartbeat page is valid, 1 if it is invalid, 2 if there is no internet connection. 86 | """ 87 | if not _check_internet_connection(): 88 | logger.warning("No internet connection available.") 89 | return 2 90 | 91 | try: 92 | logger.debug(f"Pinging node at {node_url}") 93 | response = requests.get(f"{node_url}/heartbeat", timeout=timeout) 94 | if response.status_code == 200 and 'heartbeat' in response.text: 95 | logger.info(f"Heartbeat valid from {node_url}") 96 | return 0 97 | else: 98 | logger.warning(f"Invalid or unreachable node at {node_url}") 99 | return 1 100 | except requests.RequestException as e: 101 | logger.error(f"Node {node_url} unreachable: {e}") 102 | return 1 103 | 104 | -------------------------------------------------------------------------------- /srs/previews.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import subprocess 4 | import zipfile 5 | import tarfile 6 | from PIL import Image, ImageDraw, ImageFont 7 | import fitz # PyMuPDF 8 | from docx import Document 9 | from pptx import Presentation 10 | import ebooklib 11 | from ebooklib import epub 12 | import matplotlib.pyplot as plt 13 | from pydub import AudioSegment 14 | import tempfile 15 | 16 | def generate_image_preview(input_file, output_file): 17 | try: 18 | # Identify the file type based on extension 19 | file_ext = os.path.splitext(input_file)[1].lower() 20 | 21 | if file_ext in ['.jpg', '.jpeg', '.png', '.bmp', '.gif', '.tiff']: 22 | # Process image files 23 | process_image(input_file, output_file) 24 | elif file_ext in ['.mp4', '.mkv', '.avi', '.mov', '.webm']: 25 | # Process video files 26 | process_video(input_file, output_file) 27 | elif file_ext in ['.mp3', '.wav', '.ogg', '.flac']: 28 | # Process audio files 29 | process_audio(input_file, output_file) 30 | elif file_ext == '.pdf': 31 | # Process PDF files 32 | process_pdf(input_file, output_file) 33 | elif file_ext == '.docx': 34 | # Process DOCX files 35 | process_docx(input_file, output_file) 36 | elif file_ext == '.pptx': 37 | # Process PPTX files 38 | process_pptx(input_file, output_file) 39 | elif file_ext == '.epub': 40 | # Process EPUB files 41 | process_epub(input_file, output_file) 42 | elif file_ext in ['.txt', '.md', '.py', '.html', '.css', '.js']: 43 | # Process text and code files 44 | process_text(input_file, output_file) 45 | elif file_ext in ['.zip', '.tar', '.gz']: 46 | # Process archive files 47 | process_archive(input_file, output_file) 48 | else: 49 | # Fallback for unsupported file types 50 | process_generic_placeholder(output_file) 51 | except Exception as e: 52 | print(f"Error processing file: {e}") 53 | 54 | # ------------------- Helper functions for each format ------------------- # 55 | 56 | def process_image(input_file, output_file): 57 | """Downscale image and save as webp""" 58 | try: 59 | with Image.open(input_file) as img: 60 | img.thumbnail((512, 512)) # Resize to 512x512 max 61 | img.save(output_file, "WEBP") 62 | print(f"Image preview saved at {output_file}") 63 | except Exception as e: 64 | print(f"Failed to process image: {e}") 65 | 66 | def process_video(input_file, output_file): 67 | """Generate a video thumbnail using ffmpegthumbnailer""" 68 | try: 69 | command = ['ffmpegthumbnailer', '-i', input_file, '-o', output_file, '-s', '512', '-f'] 70 | subprocess.run(command, check=True) 71 | print(f"Video preview saved at {output_file}") 72 | except Exception as e: 73 | print(f"Failed to process video: {e}") 74 | 75 | def process_audio(input_file, output_file): 76 | """Generate a waveform image from an audio file""" 77 | try: 78 | # Load audio file 79 | audio = AudioSegment.from_file(input_file) 80 | data = audio.get_array_of_samples() 81 | 82 | # Plot waveform 83 | plt.figure(figsize=(8, 4)) 84 | plt.plot(data[:10000]) # Only plot first 10k samples for preview 85 | plt.axis('off') 86 | 87 | # Save the waveform as an image 88 | plt.savefig(output_file, format="webp", bbox_inches='tight', pad_inches=0) 89 | plt.close() 90 | print(f"Audio preview saved at {output_file}") 91 | except Exception as e: 92 | print(f"Failed to process audio: {e}") 93 | 94 | def process_pdf(input_file, output_file): 95 | """Generate a thumbnail from the first page of a PDF""" 96 | try: 97 | pdf_document = fitz.open(input_file) 98 | page = pdf_document.load_page(0) # Get the first page 99 | pix = page.get_pixmap() 100 | img = Image.frombytes("RGB", [pix.width, pix.height], pix.samples) 101 | img.thumbnail((512, 512)) 102 | img.save(output_file, "WEBP") 103 | print(f"PDF preview saved at {output_file}") 104 | except Exception as e: 105 | print(f"Failed to process PDF: {e}") 106 | 107 | def process_docx(input_file, output_file): 108 | """Generate a thumbnail from the first page of a DOCX document""" 109 | try: 110 | doc = Document(input_file) 111 | if doc.paragraphs: 112 | text = doc.paragraphs[0].text 113 | else: 114 | text = "No content" 115 | 116 | # Create a blank image and draw text 117 | img = Image.new("RGB", (512, 512), (255, 255, 255)) 118 | d = ImageDraw.Draw(img) 119 | d.text((10, 10), text[:200], fill=(0, 0, 0)) # Show the first 200 characters 120 | img.save(output_file, "WEBP") 121 | print(f"DOCX preview saved at {output_file}") 122 | except Exception as e: 123 | print(f"Failed to process DOCX: {e}") 124 | 125 | def process_pptx(input_file, output_file): 126 | """Generate a thumbnail from the first slide of a PPTX presentation""" 127 | try: 128 | prs = Presentation(input_file) 129 | first_slide = prs.slides[0] 130 | 131 | # Create an image with the title text 132 | if first_slide.shapes.title: 133 | title = first_slide.shapes.title.text 134 | else: 135 | title = "No Title" 136 | 137 | img = Image.new("RGB", (512, 512), (255, 255, 255)) 138 | d = ImageDraw.Draw(img) 139 | d.text((10, 10), title[:200], fill=(0, 0, 0)) # Show the first 200 characters 140 | img.save(output_file, "WEBP") 141 | print(f"PPTX preview saved at {output_file}") 142 | except Exception as e: 143 | print(f"Failed to process PPTX: {e}") 144 | 145 | def process_epub(input_file, output_file): 146 | """Generate a thumbnail from an EPUB ebook""" 147 | try: 148 | book = epub.read_epub(input_file) 149 | cover = None 150 | 151 | for item in book.get_items(): 152 | if item.get_type() == ebooklib.ITEM_COVER: 153 | cover = item.content 154 | break 155 | 156 | if cover: 157 | with open(tempfile.mktemp(suffix=".jpg"), 'wb') as f: 158 | f.write(cover) 159 | img = Image.open(f.name) 160 | img.thumbnail((512, 512)) 161 | img.save(output_file, "WEBP") 162 | else: 163 | process_generic_placeholder(output_file) 164 | print(f"EPUB preview saved at {output_file}") 165 | except Exception as e: 166 | print(f"Failed to process EPUB: {e}") 167 | 168 | def process_text(input_file, output_file): 169 | """Generate a preview from text or code file""" 170 | try: 171 | with open(input_file, 'r') as f: 172 | text = f.read(200) # Read the first 200 characters 173 | 174 | img = Image.new("RGB", (512, 512), (255, 255, 255)) 175 | d = ImageDraw.Draw(img) 176 | d.text((10, 10), text, fill=(0, 0, 0)) 177 | img.save(output_file, "WEBP") 178 | print(f"Text preview saved at {output_file}") 179 | except Exception as e: 180 | print(f"Failed to process text file: {e}") 181 | 182 | def process_archive(input_file, output_file): 183 | """Generate a preview of archive contents""" 184 | try: 185 | if zipfile.is_zipfile(input_file): 186 | with zipfile.ZipFile(input_file, 'r') as archive: 187 | file_list = archive.namelist()[:10] # Show first 10 files 188 | elif tarfile.is_tarfile(input_file): 189 | with tarfile.open(input_file, 'r') as archive: 190 | file_list = [tarinfo.name for tarinfo in archive.getmembers()][:10] 191 | else: 192 | file_list = [] 193 | 194 | img = Image.new("RGB", (512, 512), (255, 255, 255)) 195 | d = ImageDraw.Draw(img) 196 | d.text((10, 10), "\n".join(file_list), fill=(0, 0, 0)) # Display file names 197 | img.save(output_file, "WEBP") 198 | print(f"Archive preview saved at {output_file}") 199 | except Exception as e: 200 | print(f"Failed to process archive: {e}") 201 | 202 | def process_generic_placeholder(output_file): 203 | """Generate a placeholder preview for unsupported file types""" 204 | try: 205 | img = Image.new("RGB", (512, 512), (200, 200, 200)) 206 | d = ImageDraw.Draw(img) 207 | d.text((100, 250), "Preview Not Available", fill=(0, 0, 0)) 208 | img.save(output_file, "WEBP") 209 | print(f"Generic placeholder saved at {output_file}") 210 | except Exception as e: 211 | print(f"Failed to create placeholder: {e}") 212 | 213 | # ---------------------------- Main Execution ---------------------------- # 214 | 215 | if __name__ == "__main__": 216 | if len(sys.argv) < 3: 217 | print("Usage: python generate_preview.py ") 218 | sys.exit(1) 219 | 220 | input_file = sys.argv[1] 221 | output_file = sys.argv[2] 222 | 223 | generate_image_preview(input_file, output_file) 224 | 225 | -------------------------------------------------------------------------------- /srs/scheduler.py: -------------------------------------------------------------------------------- 1 | import schedule 2 | import time 3 | import threading 4 | import logging 5 | import requests 6 | from datetime import datetime, timedelta 7 | from settings import get_setting, return_all, set_setting 8 | from database import get_db_connection 9 | import peer_discovery 10 | import indexer 11 | from colorlog import ColoredFormatter 12 | 13 | # Logging configuration 14 | log_format = "%(asctime)s - %(name)s - %(levelname)s - %(message)s" 15 | formatter = ColoredFormatter( 16 | "%(asctime)s - %(name)s - %(log_color)s%(levelname)s%(reset)s - %(message)s", 17 | datefmt="%Y-%m-%d %H:%M:%S", 18 | log_colors={ 19 | 'DEBUG': 'cyan', 20 | 'INFO': 'green', 21 | 'WARNING': 'yellow', 22 | 'ERROR': 'red', 23 | 'CRITICAL': 'bold_red', 24 | } 25 | ) 26 | console_handler = logging.StreamHandler() 27 | console_handler.setFormatter(formatter) 28 | logger = logging.getLogger() 29 | logger.setLevel(logging.DEBUG) 30 | logger.addHandler(console_handler) 31 | 32 | def run_indexer(): 33 | """Runs the indexer task.""" 34 | logger.info("Running indexer...") 35 | conn = get_db_connection() 36 | 37 | # Run your actual indexing logic here 38 | indexer.indexer(get_setting('DIRECTORY'), conn) 39 | 40 | logger.info("Indexer completed successfully.") 41 | 42 | # Schedule the next run after 24 hours 43 | schedule.every(24).hours.do(run_indexer) 44 | logger.info("Scheduled indexer for the next run in 24 hours") 45 | 46 | def run_announcer(): 47 | """Runs the announcer task.""" 48 | logger.info("Running announcer...") 49 | known_nodes = get_setting("known_nodes") 50 | announced_nodes = set() 51 | new_nodes_discovered = False 52 | 53 | for node in known_nodes: 54 | if node not in announced_nodes: 55 | logger.info(f"Announcing to {node}...") 56 | new_nodes = peer_discovery.announce(f"http://{node}/announce", get_setting('NODE_ID'), known_nodes) 57 | announced_nodes.add(node) 58 | if new_nodes: 59 | new_nodes_discovered = True 60 | known_nodes.update(new_nodes) 61 | set_setting("known_nodes", known_nodes) 62 | 63 | logger.info(f"Known nodes: {known_nodes}") 64 | logger.info(f"Announced nodes: {announced_nodes}") 65 | 66 | if not new_nodes_discovered: 67 | logger.info("No new nodes discovered, stopping announcer.") 68 | 69 | # Schedule the next run based on the interval set in settings 70 | interval = get_setting('PEER_DISCOVER_INTERVAL') 71 | schedule.every(interval).hours.do(run_announcer) 72 | logger.info(f"Scheduled announcer for the next run in {interval} hours") 73 | 74 | def run_heartbeat_checker(): 75 | """Runs the heartbeat checker.""" 76 | logger.info("Running heartbeat checker...") 77 | known_nodes = return_all()['known_nodes'] 78 | nodes_to_remove = set() 79 | 80 | for node in known_nodes: 81 | result = peer_discovery.heartbeat_ping(f"http://{node}/heartbeat") 82 | if result == 1: 83 | logger.info(f"Node {node} is unreachable or invalid, removing from known_nodes.") 84 | nodes_to_remove.add(node) 85 | elif result == 2: 86 | logger.error("No internet connection, cannot perform heartbeat check.") 87 | break 88 | 89 | # Update known nodes 90 | known_nodes.difference_update(nodes_to_remove) 91 | logger.info(f"Updated known nodes: {known_nodes}") 92 | 93 | # Schedule the next run based on the interval set in settings 94 | interval = get_setting('HEARTBEAT_INTERVAL') 95 | schedule.every(interval).minutes.do(run_heartbeat_checker) 96 | logger.info(f"Scheduled heartbeat checker for the next run in {interval} minutes") 97 | 98 | def schedule_tasks(): 99 | """Schedules all tasks.""" 100 | # Schedule the indexer for the first time 101 | index_time = get_setting('INDEX_FILES_TIME') 102 | next_index_run = datetime.now().replace(hour=index_time, minute=0, second=0, microsecond=0) 103 | if datetime.now() > next_index_run: 104 | next_index_run += timedelta(days=1) 105 | 106 | delay_index = (next_index_run - datetime.now()).total_seconds() 107 | logger.info(f"Scheduled indexer for {next_index_run} (in {delay_index // 3600} hours and {(delay_index % 3600) // 60} minutes)") 108 | 109 | # Run the indexer immediately 110 | run_indexer() 111 | 112 | # Fetch known nodes from the URL and update settings 113 | response = requests.get(get_setting('URL')) 114 | if response.status_code == 200: 115 | data = response.json() 116 | current_known_nodes = return_all()['known_nodes'] 117 | current_known_nodes.update(data) 118 | logger.info(f"Updated known nodes from the URL: {current_known_nodes}") 119 | else: 120 | logger.error(f"Failed to download node list, status code {response.status_code}") 121 | 122 | # Run announcer and heartbeat checker immediately 123 | run_announcer() 124 | run_heartbeat_checker() 125 | 126 | def _run_scheduler(): 127 | """Internal function to run the scheduler.""" 128 | while True: 129 | schedule.run_pending() 130 | time.sleep(1) 131 | 132 | def start_scheduler(): 133 | """Start the task scheduler in a background thread.""" 134 | scheduler_thread = threading.Thread(target=_run_scheduler, daemon=True) 135 | scheduler_thread.start() 136 | 137 | -------------------------------------------------------------------------------- /srs/search.py: -------------------------------------------------------------------------------- 1 | import sqlite3 2 | import os 3 | import requests 4 | import logging 5 | from colorlog import ColoredFormatter 6 | from concurrent.futures import ThreadPoolExecutor, as_completed 7 | from previews import generate_image_preview 8 | from settings import get_setting 9 | 10 | # Logging configuration 11 | log_format = "%(asctime)s - %(name)s - %(levelname)s - %(message)s" 12 | formatter = ColoredFormatter( 13 | "%(asctime)s - %(name)s - %(log_color)s%(levelname)s%(reset)s - %(message)s", 14 | datefmt="%Y-%m-%d %H:%M:%S", 15 | log_colors={ 16 | 'DEBUG': 'cyan', 17 | 'INFO': 'green', 18 | 'WARNING': 'yellow', 19 | 'ERROR': 'red', 20 | 'CRITICAL': 'bold_red', 21 | } 22 | ) 23 | 24 | console_handler = logging.StreamHandler() 25 | console_handler.setFormatter(formatter) 26 | logger = logging.getLogger() 27 | logger.setLevel(logging.DEBUG) 28 | logger.addHandler(console_handler) 29 | 30 | def local_search(search_term, node_id, conn, search_type='name', category=None): 31 | """ 32 | Perform a local search in the SQLite database for a specific search term. 33 | """ 34 | matches = [] 35 | cursor = conn.cursor() 36 | 37 | try: 38 | logger.debug(f"Starting local search: search_term={search_term}, search_type={search_type}, category={category}") 39 | 40 | # Create the SQL query to include download_count 41 | query = "SELECT file_name, path, md5_hash, file_size, category, download_count FROM files WHERE" 42 | conditions = [] 43 | params = [] 44 | 45 | if category: 46 | conditions.append(" category = ?") 47 | params.append(category) 48 | if search_type == 'name': 49 | conditions.append(" LOWER(file_name) LIKE LOWER(?)") 50 | params.append(f"%{search_term}%") 51 | elif search_type == 'md5': 52 | conditions.append(" md5_hash = ?") 53 | params.append(search_term) 54 | 55 | query += " AND".join(conditions) 56 | 57 | # Execute the query 58 | cursor.execute(query, tuple(params)) 59 | results = cursor.fetchall() 60 | 61 | # Determine the protocol for download URLs 62 | if os.getenv("ENABLE_SSL") == "true" or os.getenv("ENABLE_HTTPS_REDIRECT") == "true": 63 | protocol = "https" 64 | else: 65 | protocol = "http" 66 | 67 | # Create a hidden directory for previews 68 | shared_directory = get_setting("DIRECTORY") 69 | hidden_directory = os.path.join(shared_directory, '.previews') 70 | 71 | os.makedirs(hidden_directory, exist_ok=True) # Create the hidden directory if it doesn't exist 72 | 73 | for row in results: 74 | file_name = row[0] 75 | file_path = row[1] 76 | md5_hash = row[2] 77 | 78 | # Generate the preview file name 79 | preview_file_name = f"{os.path.splitext(file_name)[0]} - preview.webp" 80 | output_file_path = os.path.join(hidden_directory, preview_file_name) 81 | 82 | # Generate the image preview 83 | try: 84 | generate_image_preview(file_path, output_file_path) 85 | except Exception as e: 86 | logger.error(f"Failed to generate preview for {file_name}: {e}") 87 | 88 | match = { 89 | 'file_name': file_name, 90 | 'path': file_path, 91 | 'md5_hash': md5_hash, 92 | 'file_size': row[3], 93 | 'category': row[4], 94 | 'download_count': row[5], # Added download_count to the result 95 | 'node_id': node_id, 96 | 'download_url': f"{protocol}://{node_id}/download/{md5_hash}", 97 | 'preview_url': f"{protocol}://{node_id}/previews/.previews/{preview_file_name}" # Assuming you have a way to serve these previews 98 | } 99 | matches.append(match) 100 | 101 | logger.info(f"Local search completed. Found {len(matches)} matches.") 102 | except Exception as e: 103 | logger.error(f"Error during local search: {e}") 104 | finally: 105 | cursor.close() 106 | 107 | return matches 108 | 109 | def global_search(search_term, known_nodes, current_node_id, conn, search_type='name', category=None): 110 | """ 111 | Perform a global search across all known nodes and the local index in the SQLite database. 112 | """ 113 | global_matches = [] 114 | 115 | logger.debug(f"Initiating global search for term '{search_term}' on node '{current_node_id}'") 116 | 117 | # Perform local search 118 | local_matches = local_search(search_term, current_node_id, conn, search_type, category) 119 | global_matches.extend(local_matches) 120 | 121 | def remote_search(node_id): 122 | """Performs the remote search request.""" 123 | if node_id == current_node_id: 124 | return [] # Skip the current node 125 | try: 126 | search_url = f"http://{node_id}/localsearch" 127 | logger.debug(f"Sending remote search request to {search_url}") 128 | response = requests.post(search_url, json={ 129 | "search_term": search_term, 130 | "search_type": search_type, 131 | "category": category 132 | }, verify=False) 133 | response.raise_for_status() 134 | remote_matches = response.json() 135 | for match in remote_matches: 136 | match['node_id'] = node_id 137 | logger.info(f"Received {len(remote_matches)} matches from node {node_id}") 138 | return remote_matches 139 | except requests.RequestException as e: 140 | logger.error(f"Error during global search on node {node_id}: {e}") 141 | return [] 142 | 143 | # Use ThreadPoolExecutor to perform remote searches concurrently 144 | with ThreadPoolExecutor() as executor: 145 | futures = {executor.submit(remote_search, node_id): node_id for node_id in known_nodes if node_id != current_node_id} 146 | 147 | for future in as_completed(futures): 148 | remote_matches = future.result() 149 | global_matches.extend(remote_matches) 150 | 151 | # Sort global matches by download_count in descending order 152 | global_matches = sorted(global_matches, key=lambda x: x.get('download_count', 0), reverse=True) 153 | 154 | logger.info(f"Global search completed. Total matches found: {len(global_matches)}") 155 | return global_matches 156 | 157 | # Example of opening an SQLite connection 158 | def get_sqlite_connection(): 159 | # Assuming your SQLite DB file is `database.db` 160 | conn = sqlite3.connect("database.db") 161 | return conn 162 | -------------------------------------------------------------------------------- /srs/settings.py: -------------------------------------------------------------------------------- 1 | import json 2 | import os 3 | 4 | # Define the path to the settings JSON file 5 | SETTINGS_FILE = 'settings.json' 6 | 7 | # This dictionary will hold the settings in memory 8 | settings = {} 9 | 10 | def load_settings(): 11 | """Load settings from the JSON file.""" 12 | global settings 13 | if os.path.exists(SETTINGS_FILE): 14 | with open(SETTINGS_FILE, 'r') as f: 15 | settings = json.load(f) 16 | # Convert 'known_nodes' back to a set if it exists 17 | if 'known_nodes' in settings: 18 | settings['known_nodes'] = set(settings['known_nodes']) 19 | else: 20 | # If the file doesn't exist, initialize with default settings 21 | settings = get_default_settings() 22 | _save_settings() 23 | 24 | def get_default_settings(): 25 | """Return default settings.""" 26 | return { 27 | 'NODE_ID': os.getenv('NODE_ID', '127.0.0.1:5000'), 28 | 'LAST_EXECUTION_FILE': 'last_execution.txt', 29 | 'INDEX_FILES_TIME': 1, 30 | 'PEER_DISCOVER_INTERVAL': 1, 31 | 'DIRECTORY': os.getenv("SHARED_DIRECTORY"), 32 | 'URL': 'https://raw.githubusercontent.com/username/repository/branch/path/to/file.json', 33 | 'HEARTBEAT_INTERVAL': 10, 34 | 'known_nodes': set(os.getenv('KNOWN_NODES', '').split(', ')), 35 | } 36 | 37 | def _save_settings(): 38 | """Save the current settings to the JSON file.""" 39 | # Convert 'known_nodes' from set to list before saving 40 | settings_to_save = settings.copy() 41 | if 'known_nodes' in settings_to_save: 42 | settings_to_save['known_nodes'] = list(settings_to_save['known_nodes']) 43 | 44 | with open(SETTINGS_FILE, 'w') as f: 45 | json.dump(settings_to_save, f, indent=4) 46 | 47 | def get_setting(key, default=None): 48 | """Retrieve a setting value by key.""" 49 | return settings.get(key, default) 50 | 51 | def set_setting(key, value): 52 | """Set a setting value and save the updated settings to the file.""" 53 | settings[key] = value 54 | _save_settings() 55 | 56 | def return_all(): 57 | return settings 58 | 59 | # Automatically load settings when the module is imported 60 | load_settings() 61 | 62 | -------------------------------------------------------------------------------- /srs/static/css/tailwind.css: -------------------------------------------------------------------------------- 1 | /*! tailwindcss v3.3.3 | MIT License | https://tailwindcss.com */ 2 | /* 3 | 1. Prevent padding and border from affecting element width. (https://github.com/mozdevs/cssremedy/issues/4) 4 | 2. Allow adding a border to an element by just adding a border-width. (https://github.com/tailwindcss/tailwindcss/pull/116) 5 | */ 6 | 7 | *, 8 | ::before, 9 | ::after { 10 | box-sizing: border-box; /* 1 */ 11 | border-width: 0; /* 2 */ 12 | border-style: solid; /* 2 */ 13 | border-color: #e5e7eb; /* 2 */ 14 | } 15 | 16 | ::before, 17 | ::after { 18 | --tw-content: ""; 19 | } 20 | 21 | /* 22 | 1. Use a consistent sensible line-height in all browsers. 23 | 2. Prevent adjustments of font size after orientation changes in iOS. 24 | 3. Use a more readable tab size. 25 | 4. Use the user's configured `sans` font-family by default. 26 | 5. Use the user's configured `sans` font-feature-settings by default. 27 | 6. Use the user's configured `sans` font-variation-settings by default. 28 | */ 29 | 30 | html { 31 | line-height: 1.5; /* 1 */ 32 | -webkit-text-size-adjust: 100%; /* 2 */ 33 | -moz-tab-size: 4; /* 3 */ 34 | tab-size: 4; /* 3 */ 35 | font-family: 36 | ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"; /* 4 */ 37 | font-feature-settings: normal; /* 5 */ 38 | font-variation-settings: normal; /* 6 */ 39 | } 40 | 41 | /* 42 | 1. Remove the margin in all browsers. 43 | 2. Inherit line-height from `html` so users can set them as a class directly on the `html` element. 44 | */ 45 | 46 | body { 47 | margin: 0; /* 1 */ 48 | line-height: inherit; /* 2 */ 49 | } 50 | 51 | /* 52 | 1. Add the correct height in Firefox. 53 | 2. Correct the inheritance of border color in Firefox. (https://bugzilla.mozilla.org/show_bug.cgi?id=190655) 54 | 3. Ensure horizontal rules are visible by default. 55 | */ 56 | 57 | hr { 58 | height: 0; /* 1 */ 59 | color: inherit; /* 2 */ 60 | border-top-width: 1px; /* 3 */ 61 | } 62 | 63 | /* 64 | Add the correct text decoration in Chrome, Edge, and Safari. 65 | */ 66 | 67 | abbr:where([title]) { 68 | text-decoration: underline dotted; 69 | } 70 | 71 | /* 72 | Remove the default font size and weight for headings. 73 | */ 74 | 75 | h1, 76 | h2, 77 | h3, 78 | h4, 79 | h5, 80 | h6 { 81 | font-size: inherit; 82 | font-weight: inherit; 83 | } 84 | 85 | /* 86 | Reset links to optimize for opt-in styling instead of opt-out. 87 | */ 88 | 89 | a { 90 | color: inherit; 91 | text-decoration: inherit; 92 | } 93 | 94 | /* 95 | Add the correct font weight in Edge and Safari. 96 | */ 97 | 98 | b, 99 | strong { 100 | font-weight: bolder; 101 | } 102 | 103 | /* 104 | 1. Use the user's configured `mono` font family by default. 105 | 2. Correct the odd `em` font sizing in all browsers. 106 | */ 107 | 108 | code, 109 | kbd, 110 | samp, 111 | pre { 112 | font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; /* 1 */ 113 | font-size: 1em; /* 2 */ 114 | } 115 | 116 | /* 117 | Add the correct font size in all browsers. 118 | */ 119 | 120 | small { 121 | font-size: 80%; 122 | } 123 | 124 | /* 125 | Prevent `sub` and `sup` elements from affecting the line height in all browsers. 126 | */ 127 | 128 | sub, 129 | sup { 130 | font-size: 75%; 131 | line-height: 0; 132 | position: relative; 133 | vertical-align: baseline; 134 | } 135 | 136 | sub { 137 | bottom: -0.25em; 138 | } 139 | 140 | sup { 141 | top: -0.5em; 142 | } 143 | 144 | /* 145 | 1. Remove text indentation from table contents in Chrome and Safari. (https://bugs.chromium.org/p/chromium/issues/detail?id=999088, https://bugs.webkit.org/show_bug.cgi?id=201297) 146 | 2. Correct table border color inheritance in all Chrome and Safari. (https://bugs.chromium.org/p/chromium/issues/detail?id=935729, https://bugs.webkit.org/show_bug.cgi?id=195016) 147 | 3. Remove gaps between table borders by default. 148 | */ 149 | 150 | table { 151 | text-indent: 0; /* 1 */ 152 | border-color: inherit; /* 2 */ 153 | border-collapse: collapse; /* 3 */ 154 | } 155 | 156 | /* 157 | 1. Change the font styles in all browsers. 158 | 2. Remove the margin in Firefox and Safari. 159 | 3. Remove default padding in all browsers. 160 | */ 161 | 162 | button, 163 | input, 164 | optgroup, 165 | select, 166 | textarea { 167 | font-family: inherit; /* 1 */ 168 | font-feature-settings: inherit; /* 1 */ 169 | font-variation-settings: inherit; /* 1 */ 170 | font-size: 100%; /* 1 */ 171 | font-weight: inherit; /* 1 */ 172 | line-height: inherit; /* 1 */ 173 | color: inherit; /* 1 */ 174 | margin: 0; /* 2 */ 175 | padding: 0; /* 3 */ 176 | } 177 | 178 | /* 179 | Remove the inheritance of text transform in Edge and Firefox. 180 | */ 181 | 182 | button, 183 | select { 184 | text-transform: none; 185 | } 186 | 187 | /* 188 | 1. Correct the inability to style clickable types in iOS and Safari. 189 | 2. Remove default button styles. 190 | */ 191 | 192 | button, 193 | [type="button"], 194 | [type="reset"], 195 | [type="submit"] { 196 | -webkit-appearance: button; /* 1 */ 197 | background-color: transparent; /* 2 */ 198 | background-image: none; /* 2 */ 199 | } 200 | 201 | /* 202 | Use the modern Firefox focus style for all focusable elements. 203 | */ 204 | 205 | :-moz-focusring { 206 | outline: auto; 207 | } 208 | 209 | /* 210 | Remove the additional `:invalid` styles in Firefox. (https://github.com/mozilla/gecko-dev/blob/2f9eacd9d3d995c937b4251a5557d95d494c9be1/layout/style/res/forms.css#L728-L737) 211 | */ 212 | 213 | :-moz-ui-invalid { 214 | box-shadow: none; 215 | } 216 | 217 | /* 218 | Add the correct vertical alignment in Chrome and Firefox. 219 | */ 220 | 221 | progress { 222 | vertical-align: baseline; 223 | } 224 | 225 | /* 226 | Correct the cursor style of increment and decrement buttons in Safari. 227 | */ 228 | 229 | ::-webkit-inner-spin-button, 230 | ::-webkit-outer-spin-button { 231 | height: auto; 232 | } 233 | 234 | /* 235 | 1. Correct the odd appearance in Chrome and Safari. 236 | 2. Correct the outline style in Safari. 237 | */ 238 | 239 | [type="search"] { 240 | -webkit-appearance: textfield; /* 1 */ 241 | outline-offset: -2px; /* 2 */ 242 | } 243 | 244 | /* 245 | Remove the inner padding in Chrome and Safari on macOS. 246 | */ 247 | 248 | ::-webkit-search-decoration { 249 | -webkit-appearance: none; 250 | } 251 | 252 | /* 253 | 1. Correct the inability to style clickable types in iOS and Safari. 254 | 2. Change font properties to `inherit` in Safari. 255 | */ 256 | 257 | ::-webkit-file-upload-button { 258 | -webkit-appearance: button; /* 1 */ 259 | font: inherit; /* 2 */ 260 | } 261 | 262 | /* 263 | Add the correct display in Chrome and Safari. 264 | */ 265 | 266 | summary { 267 | display: list-item; 268 | } 269 | 270 | /* 271 | Removes the default spacing and border for appropriate elements. 272 | */ 273 | 274 | blockquote, 275 | dl, 276 | dd, 277 | h1, 278 | h2, 279 | h3, 280 | h4, 281 | h5, 282 | h6, 283 | hr, 284 | figure, 285 | p, 286 | pre { 287 | margin: 0; 288 | } 289 | 290 | fieldset { 291 | margin: 0; 292 | padding: 0; 293 | } 294 | 295 | legend { 296 | padding: 0; 297 | } 298 | 299 | ol, 300 | ul, 301 | menu { 302 | list-style: none; 303 | margin: 0; 304 | padding: 0; 305 | } 306 | 307 | /* 308 | Reset default styling for dialogs. 309 | */ 310 | dialog { 311 | padding: 0; 312 | } 313 | 314 | /* 315 | Prevent resizing textareas horizontally by default. 316 | */ 317 | 318 | textarea { 319 | resize: vertical; 320 | } 321 | 322 | /* 323 | 1. Reset the default placeholder opacity in Firefox. (https://github.com/tailwindlabs/tailwindcss/issues/3300) 324 | 2. Set the default placeholder color to the user's configured gray 400 color. 325 | */ 326 | 327 | input::placeholder, 328 | textarea::placeholder { 329 | opacity: 1; /* 1 */ 330 | color: #9ca3af; /* 2 */ 331 | } 332 | 333 | /* 334 | Set the default cursor for buttons. 335 | */ 336 | 337 | button, 338 | [role="button"] { 339 | cursor: pointer; 340 | } 341 | 342 | /* 343 | Make sure disabled buttons don't get the pointer cursor. 344 | */ 345 | :disabled { 346 | cursor: default; 347 | } 348 | 349 | /* 350 | 1. Make replaced elements `display: block` by default. (https://github.com/mozdevs/cssremedy/issues/14) 351 | 2. Add `vertical-align: middle` to align replaced elements more sensibly by default. (https://github.com/jensimmons/cssremedy/issues/14#issuecomment-634934210) 352 | This can trigger a poorly considered lint error in some tools but is included by design. 353 | */ 354 | 355 | img, 356 | svg, 357 | video, 358 | canvas, 359 | audio, 360 | iframe, 361 | embed, 362 | object { 363 | display: block; /* 1 */ 364 | vertical-align: middle; /* 2 */ 365 | } 366 | 367 | /* 368 | Constrain images and videos to the parent width and preserve their intrinsic aspect ratio. (https://github.com/mozdevs/cssremedy/issues/14) 369 | */ 370 | 371 | img, 372 | video { 373 | max-width: 100%; 374 | height: auto; 375 | } 376 | 377 | /* Make elements with the HTML hidden attribute stay hidden by default */ 378 | [hidden] { 379 | display: none; 380 | } 381 | 382 | /* Tailwind utility classes */ 383 | .container { 384 | width: 100%; 385 | } 386 | @media (min-width: 640px) { 387 | .container { 388 | max-width: 640px; 389 | } 390 | } 391 | @media (min-width: 768px) { 392 | .container { 393 | max-width: 768px; 394 | } 395 | } 396 | @media (min-width: 1024px) { 397 | .container { 398 | max-width: 1024px; 399 | } 400 | } 401 | @media (min-width: 1280px) { 402 | .container { 403 | max-width: 1280px; 404 | } 405 | } 406 | @media (min-width: 1536px) { 407 | .container { 408 | max-width: 1536px; 409 | } 410 | } 411 | 412 | .sr-only { 413 | position: absolute; 414 | width: 1px; 415 | height: 1px; 416 | padding: 0; 417 | margin: -1px; 418 | overflow: hidden; 419 | clip: rect(0, 0, 0, 0); 420 | white-space: nowrap; 421 | border-width: 0; 422 | } 423 | 424 | .mx-auto { 425 | margin-left: auto; 426 | margin-right: auto; 427 | } 428 | 429 | .mt-1 { 430 | margin-top: 0.25rem; 431 | } 432 | 433 | .mt-2 { 434 | margin-top: 0.5rem; 435 | } 436 | 437 | .mt-4 { 438 | margin-top: 1rem; 439 | } 440 | 441 | .mb-4 { 442 | margin-bottom: 1rem; 443 | } 444 | 445 | .mb-6 { 446 | margin-bottom: 1.5rem; 447 | } 448 | 449 | .mr-2 { 450 | margin-right: 0.5rem; 451 | } 452 | 453 | .ml-2 { 454 | margin-left: 0.5rem; 455 | } 456 | 457 | .flex { 458 | display: flex; 459 | } 460 | 461 | .inline-flex { 462 | display: inline-flex; 463 | } 464 | 465 | .grid { 466 | display: grid; 467 | } 468 | 469 | .hidden { 470 | display: none; 471 | } 472 | 473 | .h-4 { 474 | height: 1rem; 475 | } 476 | 477 | .h-5 { 478 | height: 1.25rem; 479 | } 480 | 481 | .h-6 { 482 | height: 1.5rem; 483 | } 484 | 485 | .h-10 { 486 | height: 2.5rem; 487 | } 488 | 489 | .h-16 { 490 | height: 4rem; 491 | } 492 | 493 | .min-h-screen { 494 | min-height: 100vh; 495 | } 496 | 497 | .w-4 { 498 | width: 1rem; 499 | } 500 | 501 | .w-5 { 502 | width: 1.25rem; 503 | } 504 | 505 | .w-6 { 506 | width: 1.5rem; 507 | } 508 | 509 | .w-10 { 510 | width: 2.5rem; 511 | } 512 | 513 | .w-full { 514 | width: 100%; 515 | } 516 | 517 | .max-w-md { 518 | max-width: 28rem; 519 | } 520 | 521 | .max-w-3xl { 522 | max-width: 48rem; 523 | } 524 | 525 | .max-w-5xl { 526 | max-width: 64rem; 527 | } 528 | 529 | .max-w-6xl { 530 | max-width: 72rem; 531 | } 532 | 533 | .flex-1 { 534 | flex: 1 1 0%; 535 | } 536 | 537 | .animate-spin { 538 | animation: spin 1s linear infinite; 539 | } 540 | 541 | @keyframes spin { 542 | from { 543 | transform: rotate(0deg); 544 | } 545 | to { 546 | transform: rotate(360deg); 547 | } 548 | } 549 | 550 | .grid-cols-2 { 551 | grid-template-columns: repeat(2, minmax(0, 1fr)); 552 | } 553 | 554 | .flex-col { 555 | flex-direction: column; 556 | } 557 | 558 | .flex-wrap { 559 | flex-wrap: wrap; 560 | } 561 | 562 | .items-start { 563 | align-items: flex-start; 564 | } 565 | 566 | .items-center { 567 | align-items: center; 568 | } 569 | 570 | .justify-center { 571 | justify-content: center; 572 | } 573 | 574 | .justify-between { 575 | justify-content: space-between; 576 | } 577 | 578 | .justify-end { 579 | justify-content: flex-end; 580 | } 581 | 582 | .gap-1 { 583 | gap: 0.25rem; 584 | } 585 | 586 | .gap-2 { 587 | gap: 0.5rem; 588 | } 589 | 590 | .gap-3 { 591 | gap: 0.75rem; 592 | } 593 | 594 | .gap-4 { 595 | gap: 1rem; 596 | } 597 | 598 | .gap-8 { 599 | gap: 2rem; 600 | } 601 | 602 | .gap-x-4 { 603 | column-gap: 1rem; 604 | } 605 | 606 | .gap-y-1 { 607 | row-gap: 0.25rem; 608 | } 609 | 610 | .space-y-2 > :not([hidden]) ~ :not([hidden]) { 611 | --tw-space-y-reverse: 0; 612 | margin-top: calc(0.5rem * calc(1 - var(--tw-space-y-reverse))); 613 | margin-bottom: calc(0.5rem * var(--tw-space-y-reverse)); 614 | } 615 | 616 | .space-y-4 > :not([hidden]) ~ :not([hidden]) { 617 | --tw-space-y-reverse: 0; 618 | margin-top: calc(1rem * calc(1 - var(--tw-space-y-reverse))); 619 | margin-bottom: calc(1rem * var(--tw-space-y-reverse)); 620 | } 621 | 622 | .space-y-6 > :not([hidden]) ~ :not([hidden]) { 623 | --tw-space-y-reverse: 0; 624 | margin-top: calc(1.5rem * calc(1 - var(--tw-space-y-reverse))); 625 | margin-bottom: calc(1.5rem * var(--tw-space-y-reverse)); 626 | } 627 | 628 | .space-y-8 > :not([hidden]) ~ :not([hidden]) { 629 | --tw-space-y-reverse: 0; 630 | margin-top: calc(2rem * calc(1 - var(--tw-space-y-reverse))); 631 | margin-bottom: calc(2rem * var(--tw-space-y-reverse)); 632 | } 633 | 634 | .space-x-8 > :not([hidden]) ~ :not([hidden]) { 635 | --tw-space-x-reverse: 0; 636 | margin-right: calc(2rem * var(--tw-space-x-reverse)); 637 | margin-left: calc(2rem * calc(1 - var(--tw-space-x-reverse))); 638 | } 639 | 640 | .overflow-hidden { 641 | overflow: hidden; 642 | } 643 | 644 | .rounded-md { 645 | border-radius: 0.375rem; 646 | } 647 | 648 | .rounded-lg { 649 | border-radius: 0.5rem; 650 | } 651 | 652 | .rounded-full { 653 | border-radius: 9999px; 654 | } 655 | 656 | .border { 657 | border-width: 1px; 658 | } 659 | 660 | .border-b { 661 | border-bottom-width: 1px; 662 | } 663 | 664 | .border-b-2 { 665 | border-bottom-width: 2px; 666 | } 667 | 668 | .border-t { 669 | border-top-width: 1px; 670 | } 671 | 672 | .border-transparent { 673 | border-color: transparent; 674 | } 675 | 676 | .border-gray-200 { 677 | --tw-border-opacity: 1; 678 | border-color: rgb(229 231 235 / var(--tw-border-opacity)); 679 | } 680 | 681 | .border-gray-300 { 682 | --tw-border-opacity: 1; 683 | border-color: rgb(209 213 219 / var(--tw-border-opacity)); 684 | } 685 | 686 | .border-blue-500 { 687 | --tw-border-opacity: 1; 688 | border-color: rgb(59 130 246 / var(--tw-border-opacity)); 689 | } 690 | 691 | .border-red-200 { 692 | --tw-border-opacity: 1; 693 | border-color: rgb(254 202 202 / var(--tw-border-opacity)); 694 | } 695 | 696 | .dark\:border-gray-700 { 697 | --tw-border-opacity: 1; 698 | border-color: rgb(55 65 81 / var(--tw-border-opacity)); 699 | } 700 | 701 | .dark\:border-gray-800 { 702 | --tw-border-opacity: 1; 703 | border-color: rgb(31 41 55 / var(--tw-border-opacity)); 704 | } 705 | 706 | .dark\:border-blue-400 { 707 | --tw-border-opacity: 1; 708 | border-color: rgb(96 165 250 / var(--tw-border-opacity)); 709 | } 710 | 711 | .dark\:border-red-800 { 712 | --tw-border-opacity: 1; 713 | border-color: rgb(153 27 27 / var(--tw-border-opacity)); 714 | } 715 | 716 | .bg-white { 717 | --tw-bg-opacity: 1; 718 | background-color: rgb(255 255 255 / var(--tw-bg-opacity)); 719 | } 720 | 721 | .bg-blue-600 { 722 | --tw-bg-opacity: 1; 723 | background-color: rgb(37 99 235 / var(--tw-bg-opacity)); 724 | } 725 | 726 | .bg-gray-100 { 727 | --tw-bg-opacity: 1; 728 | background-color: rgb(243 244 246 / var(--tw-bg-opacity)); 729 | } 730 | 731 | .bg-green-100 { 732 | --tw-bg-opacity: 1; 733 | background-color: rgb(220 252 231 / var(--tw-bg-opacity)); 734 | } 735 | 736 | .bg-red-100 { 737 | --tw-bg-opacity: 1; 738 | background-color: rgb(254 226 226 / var(--tw-bg-opacity)); 739 | } 740 | 741 | .dark\:bg-gray-800 { 742 | --tw-bg-opacity: 1; 743 | background-color: rgb(31 41 55 / var(--tw-bg-opacity)); 744 | } 745 | 746 | .dark\:bg-gray-900 { 747 | --tw-bg-opacity: 1; 748 | background-color: rgb(17 24 39 / var(--tw-bg-opacity)); 749 | } 750 | 751 | .dark\:bg-red-900\/30 { 752 | background-color: rgb(127 29 29 / 0.3); 753 | } 754 | 755 | .dark\:bg-green-900\/30 { 756 | background-color: rgb(20 83 45 / 0.3); 757 | } 758 | 759 | .p-1 { 760 | padding: 0.25rem; 761 | } 762 | 763 | .p-2 { 764 | padding: 0.5rem; 765 | } 766 | 767 | .p-3 { 768 | padding: 0.75rem; 769 | } 770 | 771 | .p-4 { 772 | padding: 1rem; 773 | } 774 | 775 | .p-6 { 776 | padding: 1.5rem; 777 | } 778 | 779 | .p-8 { 780 | padding: 2rem; 781 | } 782 | 783 | .px-1 { 784 | padding-left: 0.25rem; 785 | padding-right: 0.25rem; 786 | } 787 | 788 | .px-2\.5 { 789 | padding-left: 0.625rem; 790 | padding-right: 0.625rem; 791 | } 792 | 793 | .px-2 { 794 | padding-left: 0.5rem; 795 | padding-right: 0.5rem; 796 | } 797 | 798 | .px-3 { 799 | padding-left: 0.75rem; 800 | padding-right: 0.75rem; 801 | } 802 | 803 | .px-4 { 804 | padding-left: 1rem; 805 | padding-right: 1rem; 806 | } 807 | 808 | .py-1 { 809 | padding-top: 0.25rem; 810 | padding-bottom: 0.25rem; 811 | } 812 | 813 | .py-2 { 814 | padding-top: 0.5rem; 815 | padding-bottom: 0.5rem; 816 | } 817 | 818 | .py-4 { 819 | padding-top: 1rem; 820 | padding-bottom: 1rem; 821 | } 822 | 823 | .py-0\.5 { 824 | padding-top: 0.125rem; 825 | padding-bottom: 0.125rem; 826 | } 827 | 828 | .py-0 { 829 | padding-top: 0px; 830 | padding-bottom: 0px; 831 | } 832 | 833 | .py-8 { 834 | padding-top: 2rem; 835 | padding-bottom: 2rem; 836 | } 837 | 838 | .text-center { 839 | text-align: center; 840 | } 841 | 842 | .text-xs { 843 | font-size: 0.75rem; 844 | line-height: 1rem; 845 | } 846 | 847 | .text-sm { 848 | font-size: 0.875rem; 849 | line-height: 1.25rem; 850 | } 851 | 852 | .text-lg { 853 | font-size: 1.125rem; 854 | line-height: 1.75rem; 855 | } 856 | 857 | .text-xl { 858 | font-size: 1.25rem; 859 | line-height: 1.75rem; 860 | } 861 | 862 | .text-2xl { 863 | font-size: 1.5rem; 864 | line-height: 2rem; 865 | } 866 | 867 | .text-3xl { 868 | font-size: 1.875rem; 869 | line-height: 2.25rem; 870 | } 871 | 872 | .font-medium { 873 | font-weight: 500; 874 | } 875 | 876 | .font-semibold { 877 | font-weight: 600; 878 | } 879 | 880 | .font-bold { 881 | font-weight: 700; 882 | } 883 | 884 | .tracking-tight { 885 | letter-spacing: -0.025em; 886 | } 887 | 888 | .text-white { 889 | --tw-text-opacity: 1; 890 | color: rgb(255 255 255 / var(--tw-text-opacity)); 891 | } 892 | 893 | .text-gray-100 { 894 | --tw-text-opacity: 1; 895 | color: rgb(243 244 246 / var(--tw-text-opacity)); 896 | } 897 | 898 | .text-gray-400 { 899 | --tw-text-opacity: 1; 900 | color: rgb(156 163 175 / var(--tw-text-opacity)); 901 | } 902 | 903 | .text-gray-500 { 904 | --tw-text-opacity: 1; 905 | color: rgb(107 114 128 / var(--tw-text-opacity)); 906 | } 907 | 908 | .text-gray-600 { 909 | --tw-text-opacity: 1; 910 | color: rgb(75 85 99 / var(--tw-text-opacity)); 911 | } 912 | 913 | .text-gray-700 { 914 | --tw-text-opacity: 1; 915 | color: rgb(55 65 81 / var(--tw-text-opacity)); 916 | } 917 | 918 | .text-gray-800 { 919 | --tw-text-opacity: 1; 920 | color: rgb(31 41 55 / var(--tw-text-opacity)); 921 | } 922 | 923 | .text-gray-900 { 924 | --tw-text-opacity: 1; 925 | color: rgb(17 24 39 / var(--tw-text-opacity)); 926 | } 927 | 928 | .text-blue-600 { 929 | --tw-text-opacity: 1; 930 | color: rgb(37 99 235 / var(--tw-text-opacity)); 931 | } 932 | 933 | .text-green-700 { 934 | --tw-text-opacity: 1; 935 | color: rgb(21 128 61 / var(--tw-text-opacity)); 936 | } 937 | 938 | .text-green-800 { 939 | --tw-text-opacity: 1; 940 | color: rgb(22 101 52 / var(--tw-text-opacity)); 941 | } 942 | 943 | .text-red-700 { 944 | --tw-text-opacity: 1; 945 | color: rgb(185 28 28 / var(--tw-text-opacity)); 946 | } 947 | 948 | .dark\:text-white { 949 | --tw-text-opacity: 1; 950 | color: rgb(255 255 255 / var(--tw-text-opacity)); 951 | } 952 | 953 | .dark\:text-gray-100 { 954 | --tw-text-opacity: 1; 955 | color: rgb(243 244 246 / var(--tw-text-opacity)); 956 | } 957 | 958 | .dark\:text-gray-200 { 959 | --tw-text-opacity: 1; 960 | color: rgb(229 231 235 / var(--tw-text-opacity)); 961 | } 962 | 963 | .dark\:text-gray-300 { 964 | --tw-text-opacity: 1; 965 | color: rgb(209 213 219 / var(--tw-text-opacity)); 966 | } 967 | 968 | .dark\:text-gray-400 { 969 | --tw-text-opacity: 1; 970 | color: rgb(156 163 175 / var(--tw-text-opacity)); 971 | } 972 | 973 | .dark\:text-blue-400 { 974 | --tw-text-opacity: 1; 975 | color: rgb(96 165 250 / var(--tw-text-opacity)); 976 | } 977 | 978 | .dark\:text-green-400 { 979 | --tw-text-opacity: 1; 980 | color: rgb(74 222 128 / var(--tw-text-opacity)); 981 | } 982 | 983 | .dark\:text-red-400 { 984 | --tw-text-opacity: 1; 985 | color: rgb(248 113 113 / var(--tw-text-opacity)); 986 | } 987 | 988 | .transition-colors { 989 | transition-property: color, background-color, border-color, text-decoration-color, fill, stroke; 990 | transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1); 991 | transition-duration: 150ms; 992 | } 993 | 994 | .duration-200 { 995 | transition-duration: 200ms; 996 | } 997 | 998 | .focus\:outline-none:focus { 999 | outline: 2px solid transparent; 1000 | outline-offset: 2px; 1001 | } 1002 | 1003 | .focus\:ring-2:focus { 1004 | --tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color); 1005 | --tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color); 1006 | box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000); 1007 | } 1008 | 1009 | .focus\:ring-blue-500:focus { 1010 | --tw-ring-opacity: 1; 1011 | --tw-ring-color: rgb(59 130 246 / var(--tw-ring-opacity)); 1012 | } 1013 | 1014 | .focus\:ring-red-500:focus { 1015 | --tw-ring-opacity: 1; 1016 | --tw-ring-color: rgb(239 68 68 / var(--tw-ring-opacity)); 1017 | } 1018 | 1019 | .focus\:ring-offset-2:focus { 1020 | --tw-ring-offset-width: 2px; 1021 | } 1022 | 1023 | .hover\:bg-gray-50:hover { 1024 | --tw-bg-opacity: 1; 1025 | background-color: rgb(249 250 251 / var(--tw-bg-opacity)); 1026 | } 1027 | 1028 | .hover\:bg-gray-100:hover { 1029 | --tw-bg-opacity: 1; 1030 | background-color: rgb(243 244 246 / var(--tw-bg-opacity)); 1031 | } 1032 | 1033 | .hover\:bg-blue-700:hover { 1034 | --tw-bg-opacity: 1; 1035 | background-color: rgb(29 78 216 / var(--tw-bg-opacity)); 1036 | } 1037 | 1038 | .hover\:bg-red-700:hover { 1039 | --tw-bg-opacity: 1; 1040 | background-color: rgb(185 28 28 / var(--tw-bg-opacity)); 1041 | } 1042 | 1043 | .hover\:text-gray-700:hover { 1044 | --tw-text-opacity: 1; 1045 | color: rgb(55 65 81 / var(--tw-text-opacity)); 1046 | } 1047 | 1048 | .hover\:border-gray-300:hover { 1049 | --tw-border-opacity: 1; 1050 | border-color: rgb(209 213 219 / var(--tw-border-opacity)); 1051 | } 1052 | 1053 | .dark\:hover\:bg-gray-700:hover { 1054 | --tw-bg-opacity: 1; 1055 | background-color: rgb(55 65 81 / var(--tw-bg-opacity)); 1056 | } 1057 | 1058 | .dark\:hover\:bg-gray-800:hover { 1059 | --tw-bg-opacity: 1; 1060 | background-color: rgb(31 41 55 / var(--tw-bg-opacity)); 1061 | } 1062 | 1063 | .dark\:hover\:text-gray-300:hover { 1064 | --tw-text-opacity: 1; 1065 | color: rgb(209 213 219 / var(--tw-text-opacity)); 1066 | } 1067 | 1068 | .dark\:hover\:border-gray-700:hover { 1069 | --tw-border-opacity: 1; 1070 | border-color: rgb(55 65 81 / var(--tw-border-opacity)); 1071 | } 1072 | 1073 | @media (min-width: 640px) { 1074 | .sm\:flex-row { 1075 | flex-direction: row; 1076 | } 1077 | 1078 | .sm\:grid-cols-2 { 1079 | grid-template-columns: repeat(2, minmax(0, 1fr)); 1080 | } 1081 | 1082 | .sm\:w-\[180px\] { 1083 | width: 180px; 1084 | } 1085 | } 1086 | -------------------------------------------------------------------------------- /srs/static/js/theme.js: -------------------------------------------------------------------------------- 1 | // Theme toggle functionality 2 | document.addEventListener("DOMContentLoaded", () => { 3 | const themeToggle = document.getElementById("theme-toggle") 4 | 5 | // Check for saved theme preference or use the system preference 6 | const savedTheme = localStorage.getItem("theme") 7 | const systemPrefersDark = window.matchMedia("(prefers-color-scheme: dark)").matches 8 | 9 | // Apply the theme 10 | if (savedTheme === "dark" || (!savedTheme && systemPrefersDark)) { 11 | document.body.classList.add("dark") 12 | } 13 | 14 | // Toggle theme when button is clicked 15 | themeToggle.addEventListener("click", () => { 16 | document.body.classList.toggle("dark") 17 | 18 | // Save the preference 19 | if (document.body.classList.contains("dark")) { 20 | localStorage.setItem("theme", "dark") 21 | } else { 22 | localStorage.setItem("theme", "light") 23 | } 24 | }) 25 | }) 26 | -------------------------------------------------------------------------------- /srs/static/logo/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/4rtemis-4rrow/0din/8ac3663d632ebb5195e0900781df1a5a2fafc76d/srs/static/logo/favicon.ico -------------------------------------------------------------------------------- /srs/static/logo/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/4rtemis-4rrow/0din/8ac3663d632ebb5195e0900781df1a5a2fafc76d/srs/static/logo/logo.png -------------------------------------------------------------------------------- /srs/static/logo/logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 285 | -------------------------------------------------------------------------------- /srs/templates/admin.html: -------------------------------------------------------------------------------- 1 | {% extends "layout.html" %} 2 | 3 | {% block title %}Admin Dashboard - 0din{% endblock %} 4 | 5 | {% block content %} 6 |
7 |
8 |

Admin Dashboard

9 |

Manage your file indexing system settings and operations

10 |
11 | 12 |
13 | 24 |
25 | 26 | 27 |
28 |
29 |
30 |

File Indexer

31 |

Index files in a specific directory to make them searchable

32 |
33 |
34 | 35 | 36 |
37 |
38 | 40 | 47 |
48 |
49 |
50 |
51 |
52 | 53 | 54 | 105 | 106 | 107 | 132 | 133 |
134 | 136 | 137 | 138 | 139 | 140 | Back to Home 141 | 142 |
143 | 147 |
148 |
149 |
150 | 151 | 387 | {% endblock %} 388 | -------------------------------------------------------------------------------- /srs/templates/index.html: -------------------------------------------------------------------------------- 1 | {% extends "layout.html" %} 2 | 3 | {% block title %}0din - Home{% endblock %} 4 | 5 | {% block content %} 6 |
7 |
8 |

0din File Search System

9 |

Search for files across all connected nodes

10 |
11 | 12 |
13 |
14 | 15 |
16 | 19 | 26 |
27 | 37 |
38 | 46 |
47 | 48 |
49 |
50 |
51 |

Total Files

52 | 53 | 54 | 55 | 56 | 57 | 58 |
59 |
Loading...
60 |
61 | 62 |
63 |
64 |

Total Size

65 | 66 | 67 | 68 | 69 | 70 |
71 |
Loading...
72 |
73 |
74 |
75 | 76 | 123 | {% endblock %} 124 | -------------------------------------------------------------------------------- /srs/templates/layout.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | {% block title %}0din{% endblock %} 7 | 8 | 9 | 10 | 11 | {% block head %}{% endblock %} 12 | 13 | 14 |
15 |
16 | 17 | 0din Logo 18 |

0din

19 |
20 |
21 | {% block header_actions %} 22 | 23 | 24 | 25 | 26 | 27 | Settings 28 | 29 | {% endblock %} 30 | 46 |
47 |
48 |
49 | 50 |
51 | {% block content %}{% endblock %} 52 |
53 | 54 | {% block scripts %}{% endblock %} 55 | 56 | 57 | -------------------------------------------------------------------------------- /srs/templates/login.html: -------------------------------------------------------------------------------- 1 | {% extends "layout.html" %} 2 | 3 | {% block title %}Login - 0din{% endblock %} 4 | 5 | {% block header_actions %} 6 | 7 | 8 | 9 | 10 | 11 | Home 12 | 13 | {% endblock %} 14 | 15 | {% block content %} 16 |
17 |
18 |
19 |
20 | 0din Logo 21 |

Admin Login

22 |
23 |
24 |

Enter your credentials to access the admin dashboard

25 | 26 | {% with messages = get_flashed_messages(with_categories=true) %} 27 | {% if messages %} 28 | {% for category, message in messages %} 29 |
30 | {{ message }} 31 |
32 | {% endfor %} 33 | {% endif %} 34 | {% endwith %} 35 | 36 |
37 |
38 | 40 |
41 |
42 | 44 |
45 |
46 | 48 | 49 | 50 | 51 | 52 | Back to Home 53 | 54 | 58 |
59 |
60 |
61 |
62 | {% endblock %} 63 | -------------------------------------------------------------------------------- /srs/templates/md5_results.html: -------------------------------------------------------------------------------- 1 | {% extends "layout.html" %} 2 | 3 | {% block title %}MD5 Search - 0din{% endblock %} 4 | 5 | {% block content %} 6 |
7 |
8 |

MD5 Search Results

9 |

10 | Results for MD5 hash: {{ md5_hash }} 11 |

12 |
13 | 14 |
15 | {% if results|length == 0 %} 16 |
17 | 18 | 19 | 20 | 21 |

No files found

22 |

23 | No files with the MD5 hash "{{ md5_hash }}" were found. 24 |

25 |
26 | {% else %} 27 | {% for file in results %} 28 |
29 |
30 | 31 |
32 | {% if file.file_name %} 33 | Preview of {{ file.file_name }} 37 | {% else %} 38 |
39 | {% if file.category == 'document' %} 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | {% elif file.category == 'image' %} 48 | 49 | 50 | 51 | 52 | 53 | {% else %} 54 | 55 | 56 | 57 | 58 | {% endif %} 59 |
60 | {% endif %} 61 |
62 | 63 | 64 |
65 |

{{ file.file_name }}

66 |
67 |
Size: {{ file.file_size|filesizeformat }}
68 |
Node: {{ file.node_id }}
69 |
Category: {{ file.category|capitalize }}
70 |
Modified: {{ file.last_modified|date }}
71 | {% if file.download_count is defined %} 72 |
Downloads: {{ file.download_count }}
73 | {% endif %} 74 |
MD5 Hash: {{ file.md5_hash }}
75 |
76 | 77 | 88 |
89 |
90 |
91 | {% endfor %} 92 | {% endif %} 93 |
94 |
95 | {% endblock %} 96 | 97 | -------------------------------------------------------------------------------- /srs/templates/results.html: -------------------------------------------------------------------------------- 1 | {% extends "layout.html" %} 2 | 3 | {% block title %}Search Results - 0din{% endblock %} 4 | 5 | {% block content %} 6 |
7 |
8 |

Search Results

9 |

10 | Results for "{{ query }}" 11 | {% if category and category != 'all' %} 12 | in {{ category }} 13 | {% endif %} 14 |

15 |
16 | 17 |
18 |
19 | 22 | 32 |
33 | 41 |
42 | 43 |
44 | {% if results|length == 0 %} 45 |
46 | 47 | 48 | 49 | 50 |

No files found

51 |

52 | Try adjusting your search or category to find what you're looking for. 53 |

54 |
55 | {% else %} 56 | {% for file in results %} 57 |
58 |
59 | 60 |
61 | {% if file.file_name %} 62 | Preview of {{ file.file_name }} 66 | {% else %} 67 |
68 | {% if file.category == 'document' %} 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | {% elif file.category == 'image' %} 77 | 78 | 79 | 80 | 81 | 82 | {% elif file.category == 'video' %} 83 | 84 | 85 | 86 | 87 | 88 | {% elif file.category == 'audio' %} 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | {% elif file.category == 'archive' %} 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | {% else %} 106 | 107 | 108 | 109 | 110 | {% endif %} 111 |
112 | {% endif %} 113 |
114 | 115 | 116 |
117 |

{{ file.file_name }}

118 |
119 |
Size: {{ file.file_size|filesizeformat }}
120 |
Node: {{ file.node_id }}
121 |
Category: {{ file.category|capitalize }}
122 |
Modified: {{ file.last_modified|date }}
123 | {% if file.download_count is defined %} 124 |
Downloads: {{ file.download_count }}
125 | {% endif %} 126 |
127 | 128 | 147 |
148 |
149 |
150 | {% endfor %} 151 | {% endif %} 152 |
153 |
154 | {% endblock %} 155 | 156 | -------------------------------------------------------------------------------- /srs/templates/setup.html: -------------------------------------------------------------------------------- 1 | {% extends "layout.html" %} 2 | 3 | {% block title %}Setup - 0din{% endblock %} 4 | 5 | {% block content %} 6 |
7 |
8 |
9 |
10 | 0din Logo 11 |

Initial Setup

12 |
13 |
14 |

Create your admin account to get started

15 | 16 | {% with messages = get_flashed_messages(with_categories=true) %} 17 | {% if messages %} 18 | {% for category, message in messages %} 19 |
20 | {{ message }} 21 |
22 | {% endfor %} 23 | {% endif %} 24 | {% endwith %} 25 | 26 |
27 |
28 | 29 | 31 |
32 |
33 | 34 | 36 |
37 |
38 | 39 | 41 |
42 | 46 |
47 |
48 |
49 | {% endblock %} 50 | -------------------------------------------------------------------------------- /srs/trigger.py: -------------------------------------------------------------------------------- 1 | import indexer 2 | import database 3 | import sys 4 | 5 | path = sys.argv[1] 6 | 7 | conn = database.get_db_connection() 8 | 9 | indexer.indexer(path, conn) 10 | --------------------------------------------------------------------------------