--- /dev/null
+ GNU AFFERO GENERAL PUBLIC LICENSE\r
+ Version 3, 19 November 2007\r
+\r
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>\r
+ Everyone is permitted to copy and distribute verbatim copies\r
+ of this license document, but changing it is not allowed.\r
+\r
+ Preamble\r
+\r
+ The GNU Affero General Public License is a free, copyleft license for\r
+software and other kinds of works, specifically designed to ensure\r
+cooperation with the community in the case of network server software.\r
+\r
+ The licenses for most software and other practical works are designed\r
+to take away your freedom to share and change the works. By contrast,\r
+our General Public Licenses are intended to guarantee your freedom to\r
+share and change all versions of a program--to make sure it remains free\r
+software for all its users.\r
+\r
+ When we speak of free software, we are referring to freedom, not\r
+price. Our General Public Licenses are designed to make sure that you\r
+have the freedom to distribute copies of free software (and charge for\r
+them if you wish), that you receive source code or can get it if you\r
+want it, that you can change the software or use pieces of it in new\r
+free programs, and that you know you can do these things.\r
+\r
+ Developers that use our General Public Licenses protect your rights\r
+with two steps: (1) assert copyright on the software, and (2) offer\r
+you this License which gives you legal permission to copy, distribute\r
+and/or modify the software.\r
+\r
+ A secondary benefit of defending all users' freedom is that\r
+improvements made in alternate versions of the program, if they\r
+receive widespread use, become available for other developers to\r
+incorporate. Many developers of free software are heartened and\r
+encouraged by the resulting cooperation. However, in the case of\r
+software used on network servers, this result may fail to come about.\r
+The GNU General Public License permits making a modified version and\r
+letting the public access it on a server without ever releasing its\r
+source code to the public.\r
+\r
+ The GNU Affero General Public License is designed specifically to\r
+ensure that, in such cases, the modified source code becomes available\r
+to the community. It requires the operator of a network server to\r
+provide the source code of the modified version running there to the\r
+users of that server. Therefore, public use of a modified version, on\r
+a publicly accessible server, gives the public access to the source\r
+code of the modified version.\r
+\r
+ An older license, called the Affero General Public License and\r
+published by Affero, was designed to accomplish similar goals. This is\r
+a different license, not a version of the Affero GPL, but Affero has\r
+released a new version of the Affero GPL which permits relicensing under\r
+this license.\r
+\r
+ The precise terms and conditions for copying, distribution and\r
+modification follow.\r
+\r
+ TERMS AND CONDITIONS\r
+\r
+ 0. Definitions.\r
+\r
+ "This License" refers to version 3 of the GNU Affero General Public License.\r
+\r
+ "Copyright" also means copyright-like laws that apply to other kinds of\r
+works, such as semiconductor masks.\r
+\r
+ "The Program" refers to any copyrightable work licensed under this\r
+License. Each licensee is addressed as "you". "Licensees" and\r
+"recipients" may be individuals or organizations.\r
+\r
+ To "modify" a work means to copy from or adapt all or part of the work\r
+in a fashion requiring copyright permission, other than the making of an\r
+exact copy. The resulting work is called a "modified version" of the\r
+earlier work or a work "based on" the earlier work.\r
+\r
+ A "covered work" means either the unmodified Program or a work based\r
+on the Program.\r
+\r
+ To "propagate" a work means to do anything with it that, without\r
+permission, would make you directly or secondarily liable for\r
+infringement under applicable copyright law, except executing it on a\r
+computer or modifying a private copy. Propagation includes copying,\r
+distribution (with or without modification), making available to the\r
+public, and in some countries other activities as well.\r
+\r
+ To "convey" a work means any kind of propagation that enables other\r
+parties to make or receive copies. Mere interaction with a user through\r
+a computer network, with no transfer of a copy, is not conveying.\r
+\r
+ An interactive user interface displays "Appropriate Legal Notices"\r
+to the extent that it includes a convenient and prominently visible\r
+feature that (1) displays an appropriate copyright notice, and (2)\r
+tells the user that there is no warranty for the work (except to the\r
+extent that warranties are provided), that licensees may convey the\r
+work under this License, and how to view a copy of this License. If\r
+the interface presents a list of user commands or options, such as a\r
+menu, a prominent item in the list meets this criterion.\r
+\r
+ 1. Source Code.\r
+\r
+ The "source code" for a work means the preferred form of the work\r
+for making modifications to it. "Object code" means any non-source\r
+form of a work.\r
+\r
+ A "Standard Interface" means an interface that either is an official\r
+standard defined by a recognized standards body, or, in the case of\r
+interfaces specified for a particular programming language, one that\r
+is widely used among developers working in that language.\r
+\r
+ The "System Libraries" of an executable work include anything, other\r
+than the work as a whole, that (a) is included in the normal form of\r
+packaging a Major Component, but which is not part of that Major\r
+Component, and (b) serves only to enable use of the work with that\r
+Major Component, or to implement a Standard Interface for which an\r
+implementation is available to the public in source code form. A\r
+"Major Component", in this context, means a major essential component\r
+(kernel, window system, and so on) of the specific operating system\r
+(if any) on which the executable work runs, or a compiler used to\r
+produce the work, or an object code interpreter used to run it.\r
+\r
+ The "Corresponding Source" for a work in object code form means all\r
+the source code needed to generate, install, and (for an executable\r
+work) run the object code and to modify the work, including scripts to\r
+control those activities. However, it does not include the work's\r
+System Libraries, or general-purpose tools or generally available free\r
+programs which are used unmodified in performing those activities but\r
+which are not part of the work. For example, Corresponding Source\r
+includes interface definition files associated with source files for\r
+the work, and the source code for shared libraries and dynamically\r
+linked subprograms that the work is specifically designed to require,\r
+such as by intimate data communication or control flow between those\r
+subprograms and other parts of the work.\r
+\r
+ The Corresponding Source need not include anything that users\r
+can regenerate automatically from other parts of the Corresponding\r
+Source.\r
+\r
+ The Corresponding Source for a work in source code form is that\r
+same work.\r
+\r
+ 2. Basic Permissions.\r
+\r
+ All rights granted under this License are granted for the term of\r
+copyright on the Program, and are irrevocable provided the stated\r
+conditions are met. This License explicitly affirms your unlimited\r
+permission to run the unmodified Program. The output from running a\r
+covered work is covered by this License only if the output, given its\r
+content, constitutes a covered work. This License acknowledges your\r
+rights of fair use or other equivalent, as provided by copyright law.\r
+\r
+ You may make, run and propagate covered works that you do not\r
+convey, without conditions so long as your license otherwise remains\r
+in force. You may convey covered works to others for the sole purpose\r
+of having them make modifications exclusively for you, or provide you\r
+with facilities for running those works, provided that you comply with\r
+the terms of this License in conveying all material for which you do\r
+not control copyright. Those thus making or running the covered works\r
+for you must do so exclusively on your behalf, under your direction\r
+and control, on terms that prohibit them from making any copies of\r
+your copyrighted material outside their relationship with you.\r
+\r
+ Conveying under any other circumstances is permitted solely under\r
+the conditions stated below. Sublicensing is not allowed; section 10\r
+makes it unnecessary.\r
+\r
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.\r
+\r
+ No covered work shall be deemed part of an effective technological\r
+measure under any applicable law fulfilling obligations under article\r
+11 of the WIPO copyright treaty adopted on 20 December 1996, or\r
+similar laws prohibiting or restricting circumvention of such\r
+measures.\r
+\r
+ When you convey a covered work, you waive any legal power to forbid\r
+circumvention of technological measures to the extent such circumvention\r
+is effected by exercising rights under this License with respect to\r
+the covered work, and you disclaim any intention to limit operation or\r
+modification of the work as a means of enforcing, against the work's\r
+users, your or third parties' legal rights to forbid circumvention of\r
+technological measures.\r
+\r
+ 4. Conveying Verbatim Copies.\r
+\r
+ You may convey verbatim copies of the Program's source code as you\r
+receive it, in any medium, provided that you conspicuously and\r
+appropriately publish on each copy an appropriate copyright notice;\r
+keep intact all notices stating that this License and any\r
+non-permissive terms added in accord with section 7 apply to the code;\r
+keep intact all notices of the absence of any warranty; and give all\r
+recipients a copy of this License along with the Program.\r
+\r
+ You may charge any price or no price for each copy that you convey,\r
+and you may offer support or warranty protection for a fee.\r
+\r
+ 5. Conveying Modified Source Versions.\r
+\r
+ You may convey a work based on the Program, or the modifications to\r
+produce it from the Program, in the form of source code under the\r
+terms of section 4, provided that you also meet all of these conditions:\r
+\r
+ a) The work must carry prominent notices stating that you modified\r
+ it, and giving a relevant date.\r
+\r
+ b) The work must carry prominent notices stating that it is\r
+ released under this License and any conditions added under section\r
+ 7. This requirement modifies the requirement in section 4 to\r
+ "keep intact all notices".\r
+\r
+ c) You must license the entire work, as a whole, under this\r
+ License to anyone who comes into possession of a copy. This\r
+ License will therefore apply, along with any applicable section 7\r
+ additional terms, to the whole of the work, and all its parts,\r
+ regardless of how they are packaged. This License gives no\r
+ permission to license the work in any other way, but it does not\r
+ invalidate such permission if you have separately received it.\r
+\r
+ d) If the work has interactive user interfaces, each must display\r
+ Appropriate Legal Notices; however, if the Program has interactive\r
+ interfaces that do not display Appropriate Legal Notices, your\r
+ work need not make them do so.\r
+\r
+ A compilation of a covered work with other separate and independent\r
+works, which are not by their nature extensions of the covered work,\r
+and which are not combined with it such as to form a larger program,\r
+in or on a volume of a storage or distribution medium, is called an\r
+"aggregate" if the compilation and its resulting copyright are not\r
+used to limit the access or legal rights of the compilation's users\r
+beyond what the individual works permit. Inclusion of a covered work\r
+in an aggregate does not cause this License to apply to the other\r
+parts of the aggregate.\r
+\r
+ 6. Conveying Non-Source Forms.\r
+\r
+ You may convey a covered work in object code form under the terms\r
+of sections 4 and 5, provided that you also convey the\r
+machine-readable Corresponding Source under the terms of this License,\r
+in one of these ways:\r
+\r
+ a) Convey the object code in, or embodied in, a physical product\r
+ (including a physical distribution medium), accompanied by the\r
+ Corresponding Source fixed on a durable physical medium\r
+ customarily used for software interchange.\r
+\r
+ b) Convey the object code in, or embodied in, a physical product\r
+ (including a physical distribution medium), accompanied by a\r
+ written offer, valid for at least three years and valid for as\r
+ long as you offer spare parts or customer support for that product\r
+ model, to give anyone who possesses the object code either (1) a\r
+ copy of the Corresponding Source for all the software in the\r
+ product that is covered by this License, on a durable physical\r
+ medium customarily used for software interchange, for a price no\r
+ more than your reasonable cost of physically performing this\r
+ conveying of source, or (2) access to copy the\r
+ Corresponding Source from a network server at no charge.\r
+\r
+ c) Convey individual copies of the object code with a copy of the\r
+ written offer to provide the Corresponding Source. This\r
+ alternative is allowed only occasionally and noncommercially, and\r
+ only if you received the object code with such an offer, in accord\r
+ with subsection 6b.\r
+\r
+ d) Convey the object code by offering access from a designated\r
+ place (gratis or for a charge), and offer equivalent access to the\r
+ Corresponding Source in the same way through the same place at no\r
+ further charge. You need not require recipients to copy the\r
+ Corresponding Source along with the object code. If the place to\r
+ copy the object code is a network server, the Corresponding Source\r
+ may be on a different server (operated by you or a third party)\r
+ that supports equivalent copying facilities, provided you maintain\r
+ clear directions next to the object code saying where to find the\r
+ Corresponding Source. Regardless of what server hosts the\r
+ Corresponding Source, you remain obligated to ensure that it is\r
+ available for as long as needed to satisfy these requirements.\r
+\r
+ e) Convey the object code using peer-to-peer transmission, provided\r
+ you inform other peers where the object code and Corresponding\r
+ Source of the work are being offered to the general public at no\r
+ charge under subsection 6d.\r
+\r
+ A separable portion of the object code, whose source code is excluded\r
+from the Corresponding Source as a System Library, need not be\r
+included in conveying the object code work.\r
+\r
+ A "User Product" is either (1) a "consumer product", which means any\r
+tangible personal property which is normally used for personal, family,\r
+or household purposes, or (2) anything designed or sold for incorporation\r
+into a dwelling. In determining whether a product is a consumer product,\r
+doubtful cases shall be resolved in favor of coverage. For a particular\r
+product received by a particular user, "normally used" refers to a\r
+typical or common use of that class of product, regardless of the status\r
+of the particular user or of the way in which the particular user\r
+actually uses, or expects or is expected to use, the product. A product\r
+is a consumer product regardless of whether the product has substantial\r
+commercial, industrial or non-consumer uses, unless such uses represent\r
+the only significant mode of use of the product.\r
+\r
+ "Installation Information" for a User Product means any methods,\r
+procedures, authorization keys, or other information required to install\r
+and execute modified versions of a covered work in that User Product from\r
+a modified version of its Corresponding Source. The information must\r
+suffice to ensure that the continued functioning of the modified object\r
+code is in no case prevented or interfered with solely because\r
+modification has been made.\r
+\r
+ If you convey an object code work under this section in, or with, or\r
+specifically for use in, a User Product, and the conveying occurs as\r
+part of a transaction in which the right of possession and use of the\r
+User Product is transferred to the recipient in perpetuity or for a\r
+fixed term (regardless of how the transaction is characterized), the\r
+Corresponding Source conveyed under this section must be accompanied\r
+by the Installation Information. But this requirement does not apply\r
+if neither you nor any third party retains the ability to install\r
+modified object code on the User Product (for example, the work has\r
+been installed in ROM).\r
+\r
+ The requirement to provide Installation Information does not include a\r
+requirement to continue to provide support service, warranty, or updates\r
+for a work that has been modified or installed by the recipient, or for\r
+the User Product in which it has been modified or installed. Access to a\r
+network may be denied when the modification itself materially and\r
+adversely affects the operation of the network or violates the rules and\r
+protocols for communication across the network.\r
+\r
+ Corresponding Source conveyed, and Installation Information provided,\r
+in accord with this section must be in a format that is publicly\r
+documented (and with an implementation available to the public in\r
+source code form), and must require no special password or key for\r
+unpacking, reading or copying.\r
+\r
+ 7. Additional Terms.\r
+\r
+ "Additional permissions" are terms that supplement the terms of this\r
+License by making exceptions from one or more of its conditions.\r
+Additional permissions that are applicable to the entire Program shall\r
+be treated as though they were included in this License, to the extent\r
+that they are valid under applicable law. If additional permissions\r
+apply only to part of the Program, that part may be used separately\r
+under those permissions, but the entire Program remains governed by\r
+this License without regard to the additional permissions.\r
+\r
+ When you convey a copy of a covered work, you may at your option\r
+remove any additional permissions from that copy, or from any part of\r
+it. (Additional permissions may be written to require their own\r
+removal in certain cases when you modify the work.) You may place\r
+additional permissions on material, added by you to a covered work,\r
+for which you have or can give appropriate copyright permission.\r
+\r
+ Notwithstanding any other provision of this License, for material you\r
+add to a covered work, you may (if authorized by the copyright holders of\r
+that material) supplement the terms of this License with terms:\r
+\r
+ a) Disclaiming warranty or limiting liability differently from the\r
+ terms of sections 15 and 16 of this License; or\r
+\r
+ b) Requiring preservation of specified reasonable legal notices or\r
+ author attributions in that material or in the Appropriate Legal\r
+ Notices displayed by works containing it; or\r
+\r
+ c) Prohibiting misrepresentation of the origin of that material, or\r
+ requiring that modified versions of such material be marked in\r
+ reasonable ways as different from the original version; or\r
+\r
+ d) Limiting the use for publicity purposes of names of licensors or\r
+ authors of the material; or\r
+\r
+ e) Declining to grant rights under trademark law for use of some\r
+ trade names, trademarks, or service marks; or\r
+\r
+ f) Requiring indemnification of licensors and authors of that\r
+ material by anyone who conveys the material (or modified versions of\r
+ it) with contractual assumptions of liability to the recipient, for\r
+ any liability that these contractual assumptions directly impose on\r
+ those licensors and authors.\r
+\r
+ All other non-permissive additional terms are considered "further\r
+restrictions" within the meaning of section 10. If the Program as you\r
+received it, or any part of it, contains a notice stating that it is\r
+governed by this License along with a term that is a further\r
+restriction, you may remove that term. If a license document contains\r
+a further restriction but permits relicensing or conveying under this\r
+License, you may add to a covered work material governed by the terms\r
+of that license document, provided that the further restriction does\r
+not survive such relicensing or conveying.\r
+\r
+ If you add terms to a covered work in accord with this section, you\r
+must place, in the relevant source files, a statement of the\r
+additional terms that apply to those files, or a notice indicating\r
+where to find the applicable terms.\r
+\r
+ Additional terms, permissive or non-permissive, may be stated in the\r
+form of a separately written license, or stated as exceptions;\r
+the above requirements apply either way.\r
+\r
+ 8. Termination.\r
+\r
+ You may not propagate or modify a covered work except as expressly\r
+provided under this License. Any attempt otherwise to propagate or\r
+modify it is void, and will automatically terminate your rights under\r
+this License (including any patent licenses granted under the third\r
+paragraph of section 11).\r
+\r
+ However, if you cease all violation of this License, then your\r
+license from a particular copyright holder is reinstated (a)\r
+provisionally, unless and until the copyright holder explicitly and\r
+finally terminates your license, and (b) permanently, if the copyright\r
+holder fails to notify you of the violation by some reasonable means\r
+prior to 60 days after the cessation.\r
+\r
+ Moreover, your license from a particular copyright holder is\r
+reinstated permanently if the copyright holder notifies you of the\r
+violation by some reasonable means, this is the first time you have\r
+received notice of violation of this License (for any work) from that\r
+copyright holder, and you cure the violation prior to 30 days after\r
+your receipt of the notice.\r
+\r
+ Termination of your rights under this section does not terminate the\r
+licenses of parties who have received copies or rights from you under\r
+this License. If your rights have been terminated and not permanently\r
+reinstated, you do not qualify to receive new licenses for the same\r
+material under section 10.\r
+\r
+ 9. Acceptance Not Required for Having Copies.\r
+\r
+ You are not required to accept this License in order to receive or\r
+run a copy of the Program. Ancillary propagation of a covered work\r
+occurring solely as a consequence of using peer-to-peer transmission\r
+to receive a copy likewise does not require acceptance. However,\r
+nothing other than this License grants you permission to propagate or\r
+modify any covered work. These actions infringe copyright if you do\r
+not accept this License. Therefore, by modifying or propagating a\r
+covered work, you indicate your acceptance of this License to do so.\r
+\r
+ 10. Automatic Licensing of Downstream Recipients.\r
+\r
+ Each time you convey a covered work, the recipient automatically\r
+receives a license from the original licensors, to run, modify and\r
+propagate that work, subject to this License. You are not responsible\r
+for enforcing compliance by third parties with this License.\r
+\r
+ An "entity transaction" is a transaction transferring control of an\r
+organization, or substantially all assets of one, or subdividing an\r
+organization, or merging organizations. If propagation of a covered\r
+work results from an entity transaction, each party to that\r
+transaction who receives a copy of the work also receives whatever\r
+licenses to the work the party's predecessor in interest had or could\r
+give under the previous paragraph, plus a right to possession of the\r
+Corresponding Source of the work from the predecessor in interest, if\r
+the predecessor has it or can get it with reasonable efforts.\r
+\r
+ You may not impose any further restrictions on the exercise of the\r
+rights granted or affirmed under this License. For example, you may\r
+not impose a license fee, royalty, or other charge for exercise of\r
+rights granted under this License, and you may not initiate litigation\r
+(including a cross-claim or counterclaim in a lawsuit) alleging that\r
+any patent claim is infringed by making, using, selling, offering for\r
+sale, or importing the Program or any portion of it.\r
+\r
+ 11. Patents.\r
+\r
+ A "contributor" is a copyright holder who authorizes use under this\r
+License of the Program or a work on which the Program is based. The\r
+work thus licensed is called the contributor's "contributor version".\r
+\r
+ A contributor's "essential patent claims" are all patent claims\r
+owned or controlled by the contributor, whether already acquired or\r
+hereafter acquired, that would be infringed by some manner, permitted\r
+by this License, of making, using, or selling its contributor version,\r
+but do not include claims that would be infringed only as a\r
+consequence of further modification of the contributor version. For\r
+purposes of this definition, "control" includes the right to grant\r
+patent sublicenses in a manner consistent with the requirements of\r
+this License.\r
+\r
+ Each contributor grants you a non-exclusive, worldwide, royalty-free\r
+patent license under the contributor's essential patent claims, to\r
+make, use, sell, offer for sale, import and otherwise run, modify and\r
+propagate the contents of its contributor version.\r
+\r
+ In the following three paragraphs, a "patent license" is any express\r
+agreement or commitment, however denominated, not to enforce a patent\r
+(such as an express permission to practice a patent or covenant not to\r
+sue for patent infringement). To "grant" such a patent license to a\r
+party means to make such an agreement or commitment not to enforce a\r
+patent against the party.\r
+\r
+ If you convey a covered work, knowingly relying on a patent license,\r
+and the Corresponding Source of the work is not available for anyone\r
+to copy, free of charge and under the terms of this License, through a\r
+publicly available network server or other readily accessible means,\r
+then you must either (1) cause the Corresponding Source to be so\r
+available, or (2) arrange to deprive yourself of the benefit of the\r
+patent license for this particular work, or (3) arrange, in a manner\r
+consistent with the requirements of this License, to extend the patent\r
+license to downstream recipients. "Knowingly relying" means you have\r
+actual knowledge that, but for the patent license, your conveying the\r
+covered work in a country, or your recipient's use of the covered work\r
+in a country, would infringe one or more identifiable patents in that\r
+country that you have reason to believe are valid.\r
+\r
+ If, pursuant to or in connection with a single transaction or\r
+arrangement, you convey, or propagate by procuring conveyance of, a\r
+covered work, and grant a patent license to some of the parties\r
+receiving the covered work authorizing them to use, propagate, modify\r
+or convey a specific copy of the covered work, then the patent license\r
+you grant is automatically extended to all recipients of the covered\r
+work and works based on it.\r
+\r
+ A patent license is "discriminatory" if it does not include within\r
+the scope of its coverage, prohibits the exercise of, or is\r
+conditioned on the non-exercise of one or more of the rights that are\r
+specifically granted under this License. You may not convey a covered\r
+work if you are a party to an arrangement with a third party that is\r
+in the business of distributing software, under which you make payment\r
+to the third party based on the extent of your activity of conveying\r
+the work, and under which the third party grants, to any of the\r
+parties who would receive the covered work from you, a discriminatory\r
+patent license (a) in connection with copies of the covered work\r
+conveyed by you (or copies made from those copies), or (b) primarily\r
+for and in connection with specific products or compilations that\r
+contain the covered work, unless you entered into that arrangement,\r
+or that patent license was granted, prior to 28 March 2007.\r
+\r
+ Nothing in this License shall be construed as excluding or limiting\r
+any implied license or other defenses to infringement that may\r
+otherwise be available to you under applicable patent law.\r
+\r
+ 12. No Surrender of Others' Freedom.\r
+\r
+ If conditions are imposed on you (whether by court order, agreement or\r
+otherwise) that contradict the conditions of this License, they do not\r
+excuse you from the conditions of this License. If you cannot convey a\r
+covered work so as to satisfy simultaneously your obligations under this\r
+License and any other pertinent obligations, then as a consequence you may\r
+not convey it at all. For example, if you agree to terms that obligate you\r
+to collect a royalty for further conveying from those to whom you convey\r
+the Program, the only way you could satisfy both those terms and this\r
+License would be to refrain entirely from conveying the Program.\r
+\r
+ 13. Remote Network Interaction; Use with the GNU General Public License.\r
+\r
+ Notwithstanding any other provision of this License, if you modify the\r
+Program, your modified version must prominently offer all users\r
+interacting with it remotely through a computer network (if your version\r
+supports such interaction) an opportunity to receive the Corresponding\r
+Source of your version by providing access to the Corresponding Source\r
+from a network server at no charge, through some standard or customary\r
+means of facilitating copying of software. This Corresponding Source\r
+shall include the Corresponding Source for any work covered by version 3\r
+of the GNU General Public License that is incorporated pursuant to the\r
+following paragraph.\r
+\r
+ Notwithstanding any other provision of this License, you have\r
+permission to link or combine any covered work with a work licensed\r
+under version 3 of the GNU General Public License into a single\r
+combined work, and to convey the resulting work. The terms of this\r
+License will continue to apply to the part which is the covered work,\r
+but the work with which it is combined will remain governed by version\r
+3 of the GNU General Public License.\r
+\r
+ 14. Revised Versions of this License.\r
+\r
+ The Free Software Foundation may publish revised and/or new versions of\r
+the GNU Affero General Public License from time to time. Such new versions\r
+will be similar in spirit to the present version, but may differ in detail to\r
+address new problems or concerns.\r
+\r
+ Each version is given a distinguishing version number. If the\r
+Program specifies that a certain numbered version of the GNU Affero General\r
+Public License "or any later version" applies to it, you have the\r
+option of following the terms and conditions either of that numbered\r
+version or of any later version published by the Free Software\r
+Foundation. If the Program does not specify a version number of the\r
+GNU Affero General Public License, you may choose any version ever published\r
+by the Free Software Foundation.\r
+\r
+ If the Program specifies that a proxy can decide which future\r
+versions of the GNU Affero General Public License can be used, that proxy's\r
+public statement of acceptance of a version permanently authorizes you\r
+to choose that version for the Program.\r
+\r
+ Later license versions may give you additional or different\r
+permissions. However, no additional obligations are imposed on any\r
+author or copyright holder as a result of your choosing to follow a\r
+later version.\r
+\r
+ 15. Disclaimer of Warranty.\r
+\r
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY\r
+APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT\r
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY\r
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,\r
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\r
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM\r
+IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF\r
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.\r
+\r
+ 16. Limitation of Liability.\r
+\r
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\r
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS\r
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY\r
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE\r
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF\r
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD\r
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),\r
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF\r
+SUCH DAMAGES.\r
+\r
+ 17. Interpretation of Sections 15 and 16.\r
+\r
+ If the disclaimer of warranty and limitation of liability provided\r
+above cannot be given local legal effect according to their terms,\r
+reviewing courts shall apply local law that most closely approximates\r
+an absolute waiver of all civil liability in connection with the\r
+Program, unless a warranty or assumption of liability accompanies a\r
+copy of the Program in return for a fee.\r
+\r
+ END OF TERMS AND CONDITIONS\r
+\r
+ How to Apply These Terms to Your New Programs\r
+\r
+ If you develop a new program, and you want it to be of the greatest\r
+possible use to the public, the best way to achieve this is to make it\r
+free software which everyone can redistribute and change under these terms.\r
+\r
+ To do so, attach the following notices to the program. It is safest\r
+to attach them to the start of each source file to most effectively\r
+state the exclusion of warranty; and each file should have at least\r
+the "copyright" line and a pointer to where the full notice is found.\r
+\r
+ <one line to give the program's name and a brief idea of what it does.>\r
+ Copyright (C) <year> <name of author>\r
+\r
+ This program is free software: you can redistribute it and/or modify\r
+ it under the terms of the GNU Affero General Public License as published by\r
+ the Free Software Foundation, either version 3 of the License, or\r
+ (at your option) any later version.\r
+\r
+ This program is distributed in the hope that it will be useful,\r
+ but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ GNU Affero General Public License for more details.\r
+\r
+ You should have received a copy of the GNU Affero General Public License\r
+ along with this program. If not, see <http://www.gnu.org/licenses/>.\r
+\r
+Also add information on how to contact you by electronic and paper mail.\r
+\r
+ If your software can interact with users remotely through a computer\r
+network, you should also make sure that it provides a way for users to\r
+get its source. For example, if your program is a web application, its\r
+interface could display a "Source" link that leads users to an archive\r
+of the code. There are many ways you could offer source, and different\r
+solutions will be better for different programs; see section 13 for the\r
+specific requirements.\r
+\r
+ You should also get your employer (if you work as a programmer) or school,\r
+if any, to sign a "copyright disclaimer" for the program, if necessary.\r
+For more information on this, and how to apply and follow the GNU AGPL, see\r
+<http://www.gnu.org/licenses/>.\r
###PERL;
# bot is generated from bot.1.pl
+# 02.01.2016
#
# This is the facebook bot. It depends on the proxy.
# It reads pages from m.facebook.com archived on the proxy, extracts threads,
# posts, images, etc. from a facebook group and saves them.
+#
+# Copyright (C) 2015-2016 Balthasar SzczepaĆski
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
use strict;
use Fcntl;
###PROXY_LIB;
###FACEBUG_LIB;
use proxy_lib qw(url2path urldiv2path path2urldiv getcgi divideurl joinurl readconfigfile entitydecode entityencode urldecode readheaderfile);
-use facebug_lib qw(key readdatafile writedatafile);
-use POSIX qw(strftime);
+use facebug_lib qw(key readdatafile writedatafile gettimenumber);
+use POSIX qw(strftime locale_h);
###ARCH_PATH;
###GROUPSETTINGS_PATH;
my $time = time();
srand ($time-$$);
+unless (setlocale (LC_TIME, "C")) {
+ print "Can't set time locale!\n\n";
+ exit;
+}
print strftime("%d.%m.%Y %H:%M:%S", gmtime($time))."\n";
# If there are commandline arguments the bot will only process the facebook
my $pagetype; #type of page: 'group', 'thread' or 'post'
+
# Argument must be HEADER path.
if ($headerpath =~ /^((.+)\@h)$/) {
$headerpath = $1;
my $mode; # the state of the main state machine
my $level; # keeps track in how many <div> levels the bot went
my $level2; # same as above used in different state (previous must be kept)
+
+ my $level3;
+ my $level4;
+ my $shared;
+ my $attnumber2;
+
my $closetag=0;# if there is a tag to close
my $ignoretext;# if text should be ignored and not added to post/thread content
my $link; # if bot is inside a link
my $incomplete;# if thread firstpost's content is incomplete
my $firstpost; # if the bot is in the firstpost (important if pagetype='post')
+ my $content;
+
# Set initial values depending on page type.
if ($pagetype eq 'thread') {
print "Thread $threadid\n";
$thread{'id'}=$threadid;
$thread{'groupid'}=$$settings{'id'};
$thread{'timenumber'}=$timenumber;
- $mode = 'thread';
- $level=0;
- $attnumber=0;
- $incomplete=0;
+ $mode = 'threads';
+ # $level=0;
+ # $attnumber=0;
+ # $incomplete=0;
+ # $shared=0;
}
elsif ($pagetype eq 'post'){
print "Post $postid ($threadid)\n";
if ($mode eq 'threads'){
# Thread found. Id not known yet!
if (($tag{'<'} eq 'div') and ($tag{'id'} =~ /^([a-zA-Z0-9]_[a-zA-Z0-9]_[a-zA-Z0-9])$/)) {
- print "Thread [$1]\n";
$mode = 'thread';
+ $content=0;
# set initial values
- %thread = ();
- $thread{'groupid'}=$$settings{'id'};
- $thread{'timenumber2'}=$timenumber;
+ if($pagetype ne 'thread') {
+ print "Thread [$1]\n";
+ %thread = ();
+ $thread{'groupid'}=$$settings{'id'};
+ $thread{'timenumber2'}=$timenumber;
+ }
$level = 0;
$attnumber=0;
$incomplete=0;
+ $shared=0;
}
}
# one thread
elsif ($mode eq 'thread'){
# thread author is in first <h3>
- if ($tag{'<'} eq 'h3') {
+ if (($tag{'<'} eq 'h3') and ($thread{($shared?'shared-':'').'author'} eq '')) {
$mode = 'thread-author';
}
- elsif (($tag{'<'} eq 'div')and($tag{'id'} !~ /^ufi_/)) {
+ # elsif (($tag{'<'} eq 'div')and($tag{'id'} !~ /^ufi_/)) {
+ elsif ($tag{'<'} eq 'div') {
# Post content is (always?) in the first <div> with a 2 letter class name after author
- if (($tag{'class'} =~ /^[a-z]{2}$/) and (!defined($thread{'postcontent'})) and (defined($thread{'author'}))) {
+ if (($tag{'class'} =~ /^[a-z]{2}$/) and (!defined($thread{($shared?'shared-':'').'postcontent'})) and (defined($thread{($shared?'shared-':'').'author'}))) {
$mode='thread-content';
+ $content=1;
$level2=0;
$ignoretext=1; # text in firstposts only inside <p>
$hidename=0;
$link=0;
}
+ # The thread contains "shared" content
+ elsif (($tag{'id'} =~ /^([a-zA-Z0-9]_[a-zA-Z0-9]_[a-zA-Z0-9])$/) and !$shared and ($thread{'shared'} eq '')) {
+ $shared=1;
+ $attnumber2=$attnumber;
+ $level3=$level;
+ $level4=$level2;
+ $attnumber=0;
+ $level=0;
+ $thread{'shared'}=1;
+ }
else {
++$level;
}
}
elsif ($tag{'<'} eq 'a') {
+ if (lc($tag{'aria-label'})eq 'likes') {
+ $mode='thread-likes';
+ }
+ ###DUPLICADED!
# there is an image attached
- if ($tag{'href'} =~ /^\/photo\.php\?(.*&)?fbid=([0-9]+)(&.*)?$/) {
+ elsif ($tag{'href'} =~ /^\/photo\.php\?(.*&)?fbid=([0-9]+)(&.*)?$/) {
+ my $imgnum=$2;
+ my $imgid='a_';
+
+ while(length($imgnum)>240) {
+ $imgid.=substr($imgnum,0,120).'-/';
+ $imgnum=substr($imgnum,120);
+ }
+ $imgid.=$imgnum;
+
++$attnumber;
- $thread{'img-'.$attnumber}='a_'.$2;
+ $thread{($shared?'shared-':'').'img-'.$attnumber}=$imgid;
$mode = 'thread-attachment-img';
}
+ elsif ($tag{'href'} =~ /^\/[A-Za-z0-9\.]+\/photos\/([^\?]+)(\?.*)?$/) {
+ my $imgurl = urldecode($1);
+ my $imgid = 's_';
+ $imgurl =~ s/([^A-Za-z0-9_\.])/sprintf ("@%02X",ord($1))/eg;
+
+ while(length($imgurl)>240) {
+ $imgid.=substr($imgurl,0,120).'-/';
+ $imgurl=substr($imgurl,120);
+ }
+ $imgid.=$imgurl;
+
+ ++$attnumber;
+ $thread{($shared?'shared-':'').'img-'.$attnumber}=$imgid;
+ $mode = 'thread-attachment-img';
+ }
+ elsif ($tag{'href'} =~ /^\/video_redirect\/?\?(.*)$/) {
+ my %linkcgi = getcgi($1);
+ my $imgurl;
+ my $imgid='v_';
+ if ($linkcgi{'src'} =~ /^https?:\/\/([a-z0-9\.\-]+)?fbcdn\.net\/(hvideo[^\?]+)(\?.*)?$/) {
+ $imgurl= $2;
+ $imgurl =~ s/([^A-Za-z0-9_\.])/sprintf ("@%02X",ord($1))/eg;
+
+ while(length($imgurl)>240) {
+ $imgid.=substr($imgurl,0,120).'-/';
+ $imgurl=substr($imgurl,120);
+ }
+ $imgid.=$imgurl;
+ ++$attnumber;
+ $thread{($shared?'shared-':'').'img-'.$attnumber}=$imgid;
+ $mode = 'thread-attachment-img';
+ }
+ }
+ ###END OF DUPLICATED
# there is a link attached
elsif ($tag{'href'} =~ /^https?:\/\/([a-z0-9\.\-]+)?facebook\.com\/l\.php\?(.*&)?u=([^&]+)(&.*)?$/) {
++$attnumber;
- $thread{'link-'.$attnumber}=urldecode($3);
+ $thread{($shared?'shared-':'').'link-'.$attnumber}=urldecode($3);
$mode = 'thread-attachment-link';
}
# if thread id is not known it can be determined from this link.
# whose id starts with "ufi_". When page type is 'group' it ends when
# leaving the thread-related div
#
- elsif ((($tag{'<'} eq 'div') and ($tag{'id'} =~ /^ufi_/))or(($tag{'<'} eq '/div') and ($level ==0))) {
- # depending on page type the rest of the page contains posts or other
- # threads.
- if ($pagetype eq 'thread') {
- $mode='posts';
+ # elsif ((($tag{'<'} eq 'div') and ($tag{'id'} =~ /^ufi_/))or(($tag{'<'} eq '/div') and ($level ==0))) {
+ elsif (($tag{'<'} eq '/div') and ($level ==0)) {
+ if($shared){
+ $shared=0;
+ $attnumber=$attnumber2;
+ $level=$level3;
+ $level2=$level4;
}
else {
- $mode='threads';
- }
-
- # Now prepare to save the file
- my $threadfile;
- my $threadpath = ARCH_PATH.$$settings{'id'}.'/';
- unless (-d $threadpath) {
- unless (mkdir $threadpath) {
- print "Can't mkdir $threadpath.\n";
+ # depending on page type the rest of the page contains posts or other
+ # threads.
+ if ($pagetype eq 'thread') {
+ $mode='posts';
}
- }
- $threadpath.='thread/';
- unless (-d $threadpath) {
- unless (mkdir $threadpath) {
- print "Can't mkdir $threadpath.\n";
+ else {
+ $mode='threads';
}
- }
- $threadpath.=$thread{'id'};
-
- if (sysopen ($threadfile, $threadpath, O_RDWR | O_CREAT)) {
- if (flock ($threadfile, 2)) {
- # read the data already saved in file
- %thread2 = readdatafile($threadfile);
-
- # in 'threads' page type the firstpost's content may be incomplete.
- # in that case it should not be written to file if there is already
- # one. Even if the file has an older version.
- # but in this page type there is information about the number of
- # replies, not found in 'thread' page type. This information should
- # be written even when the post contnet shouldn't.
- #
- # That's why a thread has the timenumber and timenumber2.
- # timenumber defines the time of the post content. in pagetype
- # 'thread' only timenumber is checked and only timenumber is
- # updated.
- # timenumber2 defines the time of information only available in the
- # 'group' page type. In this pagetype the post content is only
- # updated if complete and timenumber allows it. Other information is
- # updated if timenumber2 allows it
-
- # Don't overwrite newer information with older.
- if ((($pagetype eq 'thread')and($thread2{'timenumber'} ne '')and($thread2{'timenumber'}>=$thread{'timenumber'}))or(($pagetype ne 'thread')and($thread2{'timenumber2'} ne '')and($thread2{'timenumber2'}>=$thread{'timenumber2'}))) {
- print ("Newer version already saved.\n\n");
+
+ # Now prepare to save the file
+ my $threadfile;
+ my $threadpath = ARCH_PATH.$$settings{'id'}.'/';
+ unless (-d $threadpath) {
+ unless (mkdir $threadpath) {
+ print "Can't mkdir $threadpath.\n";
}
- else {
- if($pagetype ne 'thread'){
- # Don't overwrite newer post content with older.
- if(($thread2{'timenumber'} ne '')and($thread2{'timenumber'} > $thread{'timenumber2'})) {
- print ("Newer version of post content already saved.\n");
- delete $thread{'postcontent'};
- }
- elsif($incomplete) {
- # Don't overwrite complete post content with incomplete one.
- # Write incomplete content if nothing was archived before,
- # better this than nothing.
- print ("Post content incomplete.\n");
- if(defined($thread2{'postcontent'})){
+ }
+ $threadpath.='thread/';
+ unless (-d $threadpath) {
+ unless (mkdir $threadpath) {
+ print "Can't mkdir $threadpath.\n";
+ }
+ }
+ $threadpath.=$thread{'id'};
+
+ if (sysopen ($threadfile, $threadpath, O_RDWR | O_CREAT)) {
+ if (flock ($threadfile, 2)) {
+ # read the data already saved in file
+ %thread2 = readdatafile($threadfile);
+
+ # in 'threads' page type the firstpost's content may be incomplete.
+ # in that case it should not be written to file if there is already
+ # one. Even if the file has an older version.
+ # but in this page type there is information about the number of
+ # replies, not found in 'thread' page type. This information should
+ # be written even when the post contnet shouldn't.
+ #
+ # That's why a thread has the timenumber and timenumber2.
+ # timenumber defines the time of the post content. in pagetype
+ # 'thread' only timenumber is checked and only timenumber is
+ # updated.
+ # timenumber2 defines the time of information only available in the
+ # 'group' page type. In this pagetype the post content is only
+ # updated if complete and timenumber allows it. Other information is
+ # updated if timenumber2 allows it
+
+ # Don't overwrite newer information with older.
+ if ((($pagetype eq 'thread')and($thread2{'timenumber'} ne '')and($thread2{'timenumber'}>=$thread{'timenumber'}))or(($pagetype ne 'thread')and($thread2{'timenumber2'} ne '')and($thread2{'timenumber2'}>=$thread{'timenumber2'}))) {
+ print ("Newer version already saved.\n\n");
+ }
+ else {
+ if($pagetype ne 'thread'){
+ # Don't overwrite newer post content with older.
+ if(($thread2{'timenumber'} ne '')and($thread2{'timenumber'} > $thread{'timenumber2'})) {
+ print ("Newer version of post content already saved.\n");
delete $thread{'postcontent'};
}
+ elsif($incomplete) {
+ # Don't overwrite complete post content with incomplete one.
+ # Write incomplete content if nothing was archived before,
+ # better this than nothing.
+ print ("Post content incomplete.\n");
+ if(defined($thread2{'postcontent'})){
+ delete $thread{'postcontent'};
+ }
+ }
+ else {
+ $thread{'timenumber'}=$thread{'timenumber2'};
+ }
}
- else {
- $thread{'timenumber'}=$thread{'timenumber2'};
+ # delete previous information about attachments - the numbers
+ # could have changed.
+ foreach my $ind (keys %thread2) {
+ if($ind =~ /^(shared-)?((img(key)?)|(link(text|title)?))-[0-9]+$/) {
+ delete $thread2{$ind};
+ }
}
- }
- # delete previous information about attachments - the numbers
- # could have changed.
- foreach my $ind (keys %thread2) {
- if($ind =~ /^((img(key)?)|(link(text|title)?))-[0-9]+$/) {
- delete $thread2{$ind};
+
+ # overwrite previous information with new one
+ foreach my $ind (keys %thread) {
+ $thread2{$ind}=$thread{$ind};
+ }
+ if ($thread2{'key'} eq '') {
+ $thread2{'key'} = key(KEY_BITS);
}
- }
-
- # overwrite previous information with new one
- foreach my $ind (keys %thread) {
- $thread2{$ind}=$thread{$ind};
- }
- if ($thread2{'key'} eq '') {
- $thread2{'key'} = key(KEY_BITS);
- }
-
- # write data to file
- if (seek($threadfile, 0, 0)) {
- writedatafile($threadfile,%thread2);
- truncate ($threadfile , tell($threadfile));
- foreach my $ind (keys %thread2) {
- print "$ind: $thread2{$ind}\n"; ####
+ # write data to file
+ if (seek($threadfile, 0, 0)) {
+ writedatafile($threadfile,%thread2);
+ truncate ($threadfile , tell($threadfile));
+
+ foreach my $ind (keys %thread2) {
+ print "$ind: $thread2{$ind}\n"; ####
+ }
+ print "saved.\n\n";
+ }
+ else {
+ print "Can't seek $threadfile.\n\n";
}
- print "saved.\n\n";
- }
- else {
- print "Can't seek $threadfile.\n\n";
}
}
+ else {
+ print "Can't lock $threadfile.\n\n";
+ }
+ close ($threadfile);
}
- else {
- print "Can't lock $threadfile.\n\n";
+ else
+ {
+ print "Can't open $threadpath.\n\n";
}
- close ($threadfile);
- }
- else
- {
- print "Can't open $threadpath.\n\n";
}
}
}
# name can be found in hyperlinks
if ($tag{'<'} eq 'a') {
# there are two types of facebook user IDs
- if ($tag{'href'} =~ /^\/([A-Za-z0-9\.]+)(\?.*)?$/) {
+ if ($tag{'href'} =~ /^\/([A-Za-z0-9\.]+)\/?(\?.*)?$/) {
my $author = $1;
if ($tag{'href'} =~ /^\/profile\.php\?(.*&)?id=([^&]+)(&.*)?$/) {
$author = urldecode($2);
}
- if ($thread{'author'} eq '') {
- $thread{'author'} = $author;
- $thread{'name'} = ($$names{$author} ne '')?$$names{$author}:$$names{'default'};
+ if ($thread{($shared?'shared-':'').'author'} eq '') {
+ $thread{($shared?'shared-':'').'author'} = $author;
+ $thread{($shared?'shared-':'').'name'} = ($$names{$author} ne '')?$$names{$author}:$$names{'default'};
}
}
}
elsif ($mode eq 'thread-content') {
# There should not be any sub<div>s. Ignore everything inside.
if ($tag{'<'} eq 'div') {
- ++$level2;
- $ignoretext=1;
+ # if($tag{'class'} ne '') {
+ # $level+=$level2+1;
+ # $mode='thread';
+ # }
+ # else{
+ ++$level2;
+ $ignoretext=1;
+ # }
}
elsif ($tag{'<'} eq '/div') {
if($level2){
}
else {
$mode = 'thread';
+ $content = 0;
}
}
elsif ($tag{'<'} eq 'br') {
- $thread{'postcontent'}.='<br>';
+ $thread{($shared?'shared-':'').'postcontent'}.='<br>';
$ignoretext=0;
}
elsif ($tag{'<'} eq 'p') {
- $thread{'postcontent'}.='<p>';
+ $thread{($shared?'shared-':'').'postcontent'}.='<p>';
$ignoretext=0;
}
elsif ($tag{'<'} eq '/p') {
- $thread{'postcontent'}.='</p>';
+ $thread{($shared?'shared-':'').'postcontent'}.='</p>';
$ignoretext=1;
}
elsif (!$ignoretext) {
my $imgkey = saveimg($tag{'src'},$imgid,$$settings{'id'});
if ($imgkey ne '') {
- $thread{'postcontent'}.='<img src="&img@i'.$imgid.'@k'.$imgkey.';" alt="'.$tag{'alt'}.'">';
+ $thread{($shared?'shared-':'').'postcontent'}.='<img src="&img@i'.$imgid.'@k'.$imgkey.';" alt="'.$tag{'alt'}.'">';
}
else {
- $thread{'postcontent'}.='<img src="" alt="'.$tag{'alt'}.'">';
+ $thread{($shared?'shared-':'').'postcontent'}.='<img src="" alt="'.$tag{'alt'}.'">';
}
}
elsif ($tag{'<'} eq 'a') {
# a link to an external page
if ($tag{'href'} =~ /^https?:\/\/([a-z0-9\.\-]+)?facebook\.com\/l\.php\?(.*&)?u=([^&]+)(&.*)?$/) {
- $thread{'postcontent'}.='<a href="'.entityencode(urldecode($3)).'">';
+ $thread{($shared?'shared-':'').'postcontent'}.='<a href="'.entityencode(urldecode($3)).'">';
$link=1;
}
# a link to a user
- elsif ($tag{'href'} =~ /^\/([A-Za-z0-9\.]+)(\?.*)$/) {
+ elsif ($tag{'href'} =~ /^\/([A-Za-z0-9\.]+)\/?(\?.*)$/) {
my $person=$1;
if ($tag{'href'} =~ /^\/profile\.php\?(.*&)?id=([^&]+)(&.*)?$/) {
$person = urldecode($2);
}
- $thread{'postcontent'}.='<a href="#">'.(($$names{$person} ne '')?$$names{$person}:$$names{'default'});
+ $thread{($shared?'shared-':'').'postcontent'}.='<a href="#">'.(($$names{$person} ne '')?$$names{$person}:$$names{'default'});
$link=1;
$hidename=1;
}
}
elsif ($tag{'<'} eq '/a') {
if($link) {
- $thread{'postcontent'}.='</a>';
+ $thread{($shared?'shared-':'').'postcontent'}.='</a>';
$link=0;
$hidename=0;
}
}
}
# a link for "more..." outside the <p>s = past incomplete!
- elsif(($tag{'<'} eq 'a') and ($tag{'href'}=~/^\/groups\/$$settings{'id'}\/?\?(.*&)?id=([^&]+)(&.*)?$/) and ($pagetype ne 'thread')) {
- unless($incomplete) {
- $thread{'postcontent'}.='<p><b>Post not completely archived.</b></p>';
+ elsif ($tag{'<'} eq 'a') {
+ if (($tag{'href'}=~/^\/groups\/$$settings{'id'}\/?\?(.*&)?id=([^&]+)(&.*)?$/) and ($pagetype ne 'thread')) {
+ unless($incomplete) {
+ $thread{($shared?'shared-':'').'postcontent'}.='<p><b>Post not completely archived.</b></p>';
+ }
+ $incomplete=1;
}
- $incomplete=1;
+
+ ### HAD TO BE DUPLICATED :(
+
+
+ # there is an image attached
+ elsif ($tag{'href'} =~ /^\/photo\.php\?(.*&)?fbid=([0-9]+)(&.*)?$/) {
+ my $imgnum=$2;
+ my $imgid='a_';
+
+ while(length($imgnum)>240) {
+ $imgid.=substr($imgnum,0,120).'-/';
+ $imgnum=substr($imgnum,120);
+ }
+ $imgid.=$imgnum;
+
+ ++$attnumber;
+ $thread{($shared?'shared-':'').'img-'.$attnumber}=$imgid;
+ $mode = 'thread-attachment-img';
+ }
+ elsif ($tag{'href'} =~ /^\/[A-Za-z0-9\.]+\/photos\/([^\?]+)(\?.*)?$/) {
+ my $imgurl = urldecode($1);
+ my $imgid = 's_';
+ $imgurl =~ s/([^A-Za-z0-9_\.])/sprintf ("@%02X",ord($1))/eg;
+
+ while(length($imgurl)>240) {
+ $imgid.=substr($imgurl,0,120).'-/';
+ $imgurl=substr($imgurl,120);
+ }
+ $imgid.=$imgurl;
+
+ ++$attnumber;
+ $thread{($shared?'shared-':'').'img-'.$attnumber}=$imgid;
+ $mode = 'thread-attachment-img';
+ }
+ elsif ($tag{'href'} =~ /^\/video_redirect\/?\?(.*)$/) {
+ my %linkcgi = getcgi($1);
+ my $imgurl;
+ my $imgid='v_';
+ if ($linkcgi{'src'} =~ /^https?:\/\/([a-z0-9\.\-]+)?fbcdn\.net\/(hvideo[^\?]+)(\?.*)?$/) {
+ $imgurl= $2;
+ $imgurl =~ s/([^A-Za-z0-9_\.])/sprintf ("@%02X",ord($1))/eg;
+
+ while(length($imgurl)>240) {
+ $imgid.=substr($imgurl,0,120).'-/';
+ $imgurl=substr($imgurl,120);
+ }
+ $imgid.=$imgurl;
+ ++$attnumber;
+ $thread{($shared?'shared-':'').'img-'.$attnumber}=$imgid;
+ $mode = 'thread-attachment-img';
+ }
+ }
+ # there is a link attached
+ elsif ($tag{'href'} =~ /^https?:\/\/([a-z0-9\.\-]+)?facebook\.com\/l\.php\?(.*&)?u=([^&]+)(&.*)?$/) {
+ ++$attnumber;
+ $thread{($shared?'shared-':'').'link-'.$attnumber}=urldecode($3);
+ $mode = 'thread-attachment-link';
+ }
+ # # if thread id is not known it can be determined from this link.
+ # # also, the number of replies may be found in one of these links.
+ # elsif ($tag{'href'} =~ /^\/groups\/$$settings{'id'}\/?\?(.*&)?id=([^&]+)(&.*)?$/) {
+ # if ($thread{'id'} eq '') {
+ # $thread{'id'} = $2;
+ # print "Thread $thread{'id'}\n";
+ # }
+ # $mode = 'thread-replies';
+ # }
+
+ # end of duplicated code
}
}
# an attached image
elsif ($mode eq 'thread-attachment-img') {
if ($tag{'<'} eq 'img') {
- my $imgkey = saveimg($tag{'src'},$thread{'img-'.$attnumber},$$settings{'id'});
+ my $imgkey = saveimg($tag{'src'},$thread{($shared?'shared-':'').'img-'.$attnumber},$$settings{'id'});
if ($imgkey ne '') {
- $thread{'imgkey-'.$attnumber}=$imgkey;
+ $thread{($shared?'shared-':'').'imgkey-'.$attnumber}=$imgkey;
}
else {
- delete $thread{'img-'.$attnumber};
+ delete $thread{($shared?'shared-':'').'img-'.$attnumber};
--$attnumber;
}
}
elsif ($tag{'<'} eq '/a') {
- $mode = 'thread';
+ $mode = ($content?'thread-content':'thread');
}
}
$imgid.=$imgurl;
my $imgkey = saveimg($tag{'src'},$imgid,$$settings{'id'});
if ($imgkey ne '') {
- $thread{'img-'.$attnumber}=$imgid;
- $thread{'imgkey-'.$attnumber}=$imgkey;
+ $thread{($shared?'shared-':'').'img-'.$attnumber}=$imgid;
+ $thread{($shared?'shared-':'').'imgkey-'.$attnumber}=$imgkey;
}
}
elsif ($tag{'<'} eq '/a') {
- $mode = 'thread';
+ $mode = ($content?'thread-content':'thread');
}
}
}
}
+ elsif ($mode eq 'thread-likes') {
+ if ($tag{'<'} eq '/a') {
+ $mode = 'thread';
+ }
+ }
+
# list of posts. look for <div>s with posts.
elsif ($mode eq 'posts') {
# post found
# delete previous information about attachments - the numbers
# could have changed.
foreach my $ind (keys %post2) {
- if($ind =~ /^img(key)?-[0-9]+$/) {
+ if($ind =~ /^((img(key)?)|(link(text|title)?))-[0-9]+$/) {
delete $post2{$ind};
}
}
}
elsif ($tag{'<'} eq 'a') {
+ if (lc($tag{'aria-label'})eq 'likes') {
+ $mode='post-likes';
+ }
# there is an image attached
- if ($tag{'href'} =~ /^\/photo\.php\?(.*&)?fbid=([0-9]+)(&.*)?$/) {
+ elsif ($tag{'href'} =~ /^\/photo\.php\?(.*&)?fbid=([0-9]+)(&.*)?$/) {
+ my $imgnum=$2;
+ my $imgid='a_';
+
+ while(length($imgnum)>240) {
+ $imgid.=substr($imgnum,0,120).'-/';
+ $imgnum=substr($imgnum,120);
+ }
+ $imgid.=$imgnum;
+
++$attnumber;
- $post{'img-'.$attnumber}='a_'.$2;
+ $post{'img-'.$attnumber}=$imgid;
$mode = 'post-img';
}
# there is a link attached
# name can be found in hyperlinks
if ($tag{'<'} eq 'a') {
# there are two types of facebook user IDs
- if ($tag{'href'} =~ /^\/([A-Za-z0-9\.]+)(\?.*)?$/) {
+ if ($tag{'href'} =~ /^\/([A-Za-z0-9\.]+)\/?(\?.*)?$/) {
my $author = $1;
if ($tag{'href'} =~ /^\/profile\.php\?(.*&)?id=([^&]+)(&.*)?$/) {
$author = urldecode($2);
$link=1;
}
# a link to a user
- elsif ($tag{'href'} =~ /^\/([A-Za-z0-9\.]+)(\?.*)?$/) {
+ elsif ($tag{'href'} =~ /^\/([A-Za-z0-9\.]+)\/?(\?.*)?$/) {
my $person = $1;
if ($tag{'href'} =~ /^\/profile\.php\?(.*&)?id=([^&]+)(&.*)?$/) {
$person = urldecode($2);
}
}
+ elsif ($mode eq 'post-likes') {
+ if ($tag{'<'} eq '/a') {
+ $mode = 'post';
+ }
+ }
+
# dealing with the tag is finished.
# if the tag ends with "/>" chande it into an "</" tag ang go through it
if($mode eq 'thread-content') {
unless ($ignoretext or $hidename){
- $thread{'postcontent'}.=$text;
+ $thread{($shared?'shared-':'').'postcontent'}.=$text;
}
}
# the format facebook uses for showing time is not always helpful (for
# at least in the m.facebook.com. The bot corrently DOES NOT interpret the
# text.
elsif ($mode eq 'thread-time') {
- $thread{'timetext'}.=$text;
+ $thread{($shared?'shared-':'').'timetext'}.=$text;
}
elsif ($mode eq 'thread-attachment-link-title') {
- $thread{'linktitle-'.$attnumber}.=$text;
+ $thread{($shared?'shared-':'').'linktitle-'.$attnumber}.=$text;
}
elsif ($mode eq 'thread-attachment-link') {
- $thread{'linktext-'.$attnumber}.=$text;
+ $thread{($shared?'shared-':'').'linktext-'.$attnumber}.=$text;
}
elsif ($mode eq 'thread-replies') {
if(lc($text) =~ /^[ \t\r\n]*([0-9]+)[ \t\r\n]+comments?/) {
$thread{'replies'} = $1;
}
}
+ elsif ($mode eq 'thread-likes') {
+ if(lc($text) =~ /^[ \t\r\n]*([0-9]+)[ \t\r\n]*?/) {
+ $thread{'likes'} = $1;
+ }
+ }
if($mode eq 'post-content') {
unless ($ignoretext or $hidename){
$post{'replies'} = $1;
}
}
-
+ elsif ($mode eq 'post-likes') {
+ if(lc($text) =~ /^[ \t\r\n]*([0-9]+)[ \t\r\n]*?/) {
+ $post{'likes'} = $1;
+ }
+ }
}
close ($contentfile);
}
-# Function to get a timenumber from a "date" http header field value.
-# It's a 14 digit number: 4 - year, 2 - month, 2 - day, 2 - hour, 2 - minute,
-# 2 - second.
-sub gettimenumber {
- (my $date) = @_;
- my $year;
- my $month;
- my $day;
- my $hour;
- my $minute;
- my $second;
-
- # There are 3 possible formats.
- # See https://tools.ietf.org/html/rfc2616#section-3.3.1
- if ($date =~ /^[A-Za-z]{3}, ([0-9]{2}) ([A-Za-z]{3}) ([0-9]{4}) ([0-9]{2}):([0-9]{2}):([0-9]{2})/){
- $day=$1;
- $month=lc($2);
- $year=$3;
- $hour=$4;
- $minute=$5;
- $second=$6;
- }
- elsif ($date =~ /^[A-Za-z]{3,}, ([0-9]{2})-([A-Za-z]{3})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})/) {
- $day=$1;
- $month=lc($2);
- $year='20'.$3; # Assuming 21st century!
- $hour=$4;
- $minute=$5;
- $second=$6;
- }
- elsif ($date =~ /^[A-Za-z]{3} ([A-Za-z]{3}) ([ 0-9][0-9]) ([0-9]{2}):([0-9]{2}):([0-9]{2}) ([0-9]{4})/) {
- $month=lc($1);
- $day=$2;
- $hour=$3;
- $minute=$4;
- $second=$5;
- $year=$6;
- $day =~ s/ /0/;
- }
- else {
- return undef;
- }
-
- if ($month =~ /^jan/) {
- $month = '01';
- }
- elsif ($month =~ /^feb/) {
- $month = '02';
- }
- elsif ($month =~ /^mar/) {
- $month = '03';
- }
- elsif ($month =~ /^apr/) {
- $month = '04';
- }
- elsif ($month =~ /^may/) {
- $month = '05';
- }
- elsif ($month =~ /^jun/) {
- $month = '06';
- }
- elsif ($month =~ /^jul/) {
- $month = '07';
- }
- elsif ($month =~ /^aug/) {
- $month = '08';
- }
- elsif ($month =~ /^sep/) {
- $month = '09';
- }
- elsif ($month =~ /^oct/) {
- $month = '10';
- }
- elsif ($month =~ /^nov/) {
- $month = '11';
- }
- elsif ($month =~ /^dec/) {
- $month = '12';
- }
- else {
- return undef;
- }
-
- return $year.$month.$day.$hour.$minute.$second;
-}
-
# Function to get information about a html tag.
# The argument is the tag text without the <>!
# It returns a hash with the attributes' values.
$header{'id'}=$id;
$header{'groupid'}=$groupid;
$header{'timenumber'}=strftime('%Y%m%d%H%M%S',gmtime(time()));
+ $header{'last-modified'}=strftime('%a, %d %b %Y %H:%M:%S GMT',gmtime(time()));
if ($headopen) {
unless (seek($headfile,0,0)) {
# config.txt is generated from config.1.txt
-# 8<----------------------------------------------------------------------------
+
+8<------------------------------------------------------------------------------
# Copy this to your Apache2 configuration:
+###CGI_ALIAS;
+###PATH_ALIAS;
-# 8<----------------------------------------------------------------------------
+8<------------------------------------------------------------------------------
# Copy this to your crontab:
###BOT_CRONTAB;
+###RM_ACCESS_CRONTAB;
+###OLDLOGS_CRONTAB;
-# 8<----------------------------------------------------------------------------
+8<------------------------------------------------------------------------------
#!/usr/bin/perl
+# configure.pl
+# 02.01.2016
+#
# The facebook interface software, when run on a server, will use different
# directories, host names, tcp ports, etc. than the server on which this
# software was originally written.
# These things are defined in the file 'settings'.
# This script is called from the makefile. It reads the settings file and
# inserts the information in the source files.
+#
+# Copyright (C) 2015-2016 Balthasar SzczepaĆski
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
unless ($ARGV[0]) {
print STDERR "Configfile missing.\n";
$def{'IF_CSS_PATH'} = "use constant IF_CSS_PATH => '".$set{'interface_path'}."/if.css';";
$def{'INTERFACE_PATH'} = "use constant INTERFACE_PATH => '".$set{'interface_path'}."/view';";
$def{'LOGIN_PATH'} = "use constant LOGIN_PATH => '".$set{'interface_path'}."/view/login';";
+$def{'LOGOUT_PATH'} = "use constant LOGOUT_PATH => '".$set{'interface_path'}."/view/logout';";
$def{'LIST_PATH'} = "use constant LIST_PATH => '".$set{'interface_path'}."/view/list';";
$def{'GROUP_PATH'} = "use constant GROUP_PATH => '".$set{'interface_path'}."/view/group';";
$def{'THREAD_PATH'} = "use constant THREAD_PATH => '".$set{'interface_path'}."/view/thread';";
$def{'ACCESS_PATH'} = "use constant ACCESS_PATH => '".$set{'data_path'}."access/';";
$def{'TIMEOUT_UNLOCK'} = "use constant TIMEOUT_UNLOCK => ".$set{'timeout_unlock'}.";";
$def{'TIMEOUT_INACT'} = "use constant TIMEOUT_INACT => ".$set{'timeout_inact'}.";";
+$def{'HTML_HEAD'} = "use constant HTML_HEAD => '".$set{'html_head'}."';";
+$def{'HTML_TOP'} = "use constant HTML_TOP => '".$set{'html_top'}."';";
+$def{'HTML_BOTTOM'} = "use constant HTML_BOTTOM => '".$set{'html_bottom'}."';";
$def{'PROXY_LIB'} = "use lib '".$set{'proxy_lib_path'}."';";
$def{'INTERFACE_PL'} = '#define INTERFACE_PL "'.$set{'bin_path'}.'interface.pl"';
$def{'INTERFACE_PL_ERRLOG'} = '#define INTERFACE_PL_ERRLOG "'.$set{'log_path'}.'interface-stderr.log"';
-$def{'BOT_CRONTAB'} = $set{'bot_crontab'}.' '.$set{'bin_path'}.'bot'.(($set{'bot_args'} ne '')?(' '.$set{'bot_args'}):'').' >'.$set{'log_path'}.'bot.log';
+$wwwpath = $set{'www_path'};
+$wwwpath =~ s/\/$//;
+
+$def{'CGI_ALIAS'} = 'ScriptAlias '.$set{'interface_path'}.'/view '.$set{'bin_path'}.'interface';
+$def{'PATH_ALIAS'} = 'Alias '.$set{'interface_path'}.' '.$wwwpath;
+
+$def{'BOT_CRONTAB'} = $set{'bot_crontab'}.' '.$set{'bin_path'}.'bot'.(($set{'bot_args'} ne '')?(' '.$set{'bot_args'}):'').' >'.$set{'log_path'}.'bot.log';
+$def{'RM_ACCESS_CRONTAB'} = $set{'rm_access_crontab'}.' '.$set{'rm'}.' '.$set{'data_path'}.'access/*';
+$def{'OLDLOGS_CRONTAB'} = $set{'oldlogs_crontab'}.' '.$set{'proxy_bin_path'}.'oldlogs '.$set{'log_path'}.' '.$set{'log_size_limit'}.' '.$set{'logs_total'}.' '.$set{'logs_uncompressed'};
$def{'CC'} = 'CC='.$set{'gcc'};
$def{'CF'} = 'CF='.$set{'c_flags'};
# facebug_lib.pm is generated from facebug_lib.1.pm
+# 02.01.2016
+#
+# Here are some functions used both by the bot and the interface
+#
+# Copyright (C) 2015-2016 Balthasar SzczepaĆski
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
package facebug_lib;
$VERSION = 0.000000;
@ISA = qw(Exporter);
@EXPORT = ();
-@EXPORT_OK = qw(key readdatafile writedatafile);
+@EXPORT_OK = qw(gettimenumber key readdatafile writedatafile);
%EXPORT_TAGS = ();
# Function to generate a random hexadecimal number (key) with a defined number
return 1;
}
+# Function to get a timenumber from a "date" http header field value.
+# It's a 14 digit number: 4 - year, 2 - month, 2 - day, 2 - hour, 2 - minute,
+# 2 - second.
+# Returns undef on failure.
+sub gettimenumber {
+ (my $date) = @_;
+ my $year;
+ my $month;
+ my $day;
+ my $hour;
+ my $minute;
+ my $second;
+
+ # There are 3 possible formats.
+ # See https://tools.ietf.org/html/rfc2616#section-3.3.1
+ if ($date =~ /^[A-Za-z]{3}, ([0-9]{2}) ([A-Za-z]{3}) ([0-9]{4}) ([0-9]{2}):([0-9]{2}):([0-9]{2})/){
+ $day=$1;
+ $month=lc($2);
+ $year=$3;
+ $hour=$4;
+ $minute=$5;
+ $second=$6;
+ }
+ elsif ($date =~ /^[A-Za-z]{3,}, ([0-9]{2})-([A-Za-z]{3})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})/) {
+ $day=$1;
+ $month=lc($2);
+ $year='20'.$3; # Assuming 21st century!
+ $hour=$4;
+ $minute=$5;
+ $second=$6;
+ }
+ elsif ($date =~ /^[A-Za-z]{3} ([A-Za-z]{3}) ([ 0-9][0-9]) ([0-9]{2}):([0-9]{2}):([0-9]{2}) ([0-9]{4})/) {
+ $month=lc($1);
+ $day=$2;
+ $hour=$3;
+ $minute=$4;
+ $second=$5;
+ $year=$6;
+ $day =~ s/ /0/;
+ }
+ else {
+ return undef;
+ }
+
+ if ($month =~ /^jan/) {
+ $month = '01';
+ }
+ elsif ($month =~ /^feb/) {
+ $month = '02';
+ }
+ elsif ($month =~ /^mar/) {
+ $month = '03';
+ }
+ elsif ($month =~ /^apr/) {
+ $month = '04';
+ }
+ elsif ($month =~ /^may/) {
+ $month = '05';
+ }
+ elsif ($month =~ /^jun/) {
+ $month = '06';
+ }
+ elsif ($month =~ /^jul/) {
+ $month = '07';
+ }
+ elsif ($month =~ /^aug/) {
+ $month = '08';
+ }
+ elsif ($month =~ /^sep/) {
+ $month = '09';
+ }
+ elsif ($month =~ /^oct/) {
+ $month = '10';
+ }
+ elsif ($month =~ /^nov/) {
+ $month = '11';
+ }
+ elsif ($month =~ /^dec/) {
+ $month = '12';
+ }
+ else {
+ return undef;
+ }
+
+ return $year.$month.$day.$hour.$minute.$second;
+}
+
1;
border-color: #0057af;\r
border-width: 4px 16px 16px 16px;\r
border-style: solid;\r
- margin: 1em 0em 1em 0em;\r
+ margin: 1em 4px 1em 4px;\r
+ /* border-spacing: 0px; */\r
+}\r
+div.post-0\r
+{\r
+ border-color: #0057af;\r
+ border-width: 4px 16px 16px 16px;\r
+ border-style: solid;\r
+ margin: 1em 4px 1em 4px;\r
+ background-color: #ffffff;\r
+ /* border-spacing: 0px; */\r
+}\r
+div.post-1\r
+{\r
+ border-color: #0057af;\r
+ border-width: 4px 16px 16px 16px;\r
+ border-style: solid;\r
+ margin: 1em 4px 1em 4px;\r
+ background-color: #D9ECFF;\r
/* border-spacing: 0px; */\r
}\r
div.in\r
// interface.c is generated from interface.1.c
-//
+// 02.01.2016
+//
// This is the wrapper for interface.pl.
// It's run with SETUID to have accesss to some files where the www server
// should not. That's why it has a C wrapper. In modern systems running scripts
// directly with SETUID is considered unsafe and not allowed.
+//
+// Copyright (C) 2015-2016 Balthasar SzczepaĆski
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as
+// published by the Free Software Foundation, either version 3 of the
+// License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <unistd.h>
#include <stdio.h>
###PERL;
# interface.pl is generated from interface.1.pl
-
-#interface list/thread/post/postreply ???
+# 02.01.2015
+#
+# This is the software of the facebook interface, to access archived groups,
+# threads, images, etc.
+#
+# Copyright (C) 2015-2016 Balthasar SzczepaĆski
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
use strict;
#use warnings;
###PROXY_LIB;
###FACEBUG_LIB;
use proxy_lib qw(entityencode getcgi urldecode readconfigfile);
-use facebug_lib qw(key readdatafile);
+use facebug_lib qw(key readdatafile gettimenumber);
###IF_CSS_PATH;
###LOGIN_PATH;
###PASS_PATH;
###ACCESS_PATH;
###INTERFACE_PATH;
+###LOGOUT_PATH;
###LIST_PATH;
###GROUP_PATH;
###THREAD_PATH;
###ARCH_PATH;
###POSTS_IN_PAGE;
###THREADS_IN_PAGE;
+###HTML_HEAD;
+###HTML_TOP;
+###HTML_BOTTOM;
my %http;
my %cgi;
my $method;
my $IP;
my $id;
-my $skey;
-my $key;
-my $tkey;
-my $gpage;
-my $tpage;
-my $grev;
-my $rev;
+my $skey; # session key
+my $key; # key of accessed content
+my $tkey; # key of parent thread
+my $gpage; # page number on thread list, relevant when coming back
+my $tpage; # page number on parentthread, relevant when coming back
+my $grev; # reversed order when coming back to thread list
+my $rev; # reversed order
my $page;
-my @idt;
+my @idt; # array of ID segments
my $time = time();
srand ($time-$$);
$cgi{$ind}=$cgipost{$ind};
}
}
+ # multipart not supported
else{
exit failpage("Status: 415 Unsupported Media Type\n","415 Unsupported Media Type","Unsupported Content-type: $http{'content-type'}.");
}
}
-if ($ENV{'PATH_INFO'} =~ /^\/(list|group|thread|post|image|login|logout)(\/((.+)\/?)?)?$/) {
+# How the URLs work:
+# domain_and_path/mode/id
+#
+# id:
+# group: group_id/page_number
+# thread: group_id/thread_id/page_number
+# post: group_id/thread_id/post_id/page_number
+# image: group_id/image_id
+#
+# Any next path segments are ignored. Except when in "image" mode - then they
+# are treated as part of the id.
+#
+# If there is an "id" CGI parameter it's used instead of the id in the path in
+# the URL. If there is a "mode" CGI parameter it's used instead of the mode in
+# the URL. If there is a "p" CGI parameter it's used instead of the page number
+# inside the ID. If there is no page number 1 is default.
+
+if ($cgi{'mode'} ne '') {
+ if ($cgi{'mode'} =~ /^(list|group|thread|post|image|login|logout)$/) {
+ $mode = $1;
+ $id = '';
+ }
+ else {
+ exit failpage("Status: 404 Not Found\n","404 Not Found\n","\"$cgi{'mode'}\" is not a valid mode.");
+ }
+}
+elsif ($ENV{'PATH_INFO'} =~ /^\/(list|group|thread|post|image|login|logout)(\/((.+)\/?)?)?$/) {
$mode = $1;
$id = $4;
}
$id = $cgi{'id'};
}
+# Some http header checks should be added here.
+# if(defined($http{'expect'})) {
+ # exit failpage("Status: 406 Not Acceptable\n","406 Not Acceptable","\"Expect\" header field not supported.");
+# }
-if(defined($http{'expect'})) {
- exit failpage("Status: 406 Not Acceptable\n","406 Not Acceptable","\"Expect\" header field not supported.");
-}
-
+# IP required for login verification
if ($ENV{'REMOTE_ADDR'} =~ /^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)$/) {
$IP=$1;
}
}
if ($mode !~ /^(login|logout)$/) {
+ # session key required for accessing anything
unless ($skey=access($time,$IP,$cgi{'skey'})) {
exit loginpage ("You must log in to access this $mode.","Status: 403 Forbidden\n");
}
if ($mode eq 'image') {
- if($id =~ /^(([0-9]*)\/([a-zA-Z]_([A-Za-z0-9\-\._\/]|(\@[A-Fa-f0-9]{2}))+))$/) {
+ # image id validation
+ if($id =~ /^(([0-9]+)\/([a-zA-Z]_([A-Za-z0-9\-\._\/]|(\@[A-Fa-f0-9]{2}))+))$/) {
$id = $1;
$idt[0]=$2;
$idt[1]=$3;
}
}
else {
- if($id =~ /^([0-9\/]*)$/) {
+ # first part of (non-image) id validation.
+ if($id =~ /^([0-9\/\-]*)$/) {
$id = $1;
@idt = split('/',$id)
}
if($mode eq 'login') {
exit login();
}
-#if($mode eq 'logout') {
-# exit logout();
-#}
+if($mode eq 'logout') {
+ exit logout();
+}
if ($mode eq 'list') {
exit list();
}
-if ($idt[0]eq '') {
+# first id segment required for group, thread, post, image
+if ($idt[0] !~ /^([0-9]+)$/) {
exit failpage("Status: 404 Not Found\n","404 Not Found","No $mode ID.");
}
if ($mode eq 'group') {
- if ($cgi{'rev'} ne '') {
+ # negative page number (in path only!) causes antichronological order
+ if ($idt[1] =~ /^-([0-9]+)$/) {
+ $idt[1]=$1;
+ $rev=1;
+ }
+ # cgi parameter also does this
+ elsif ($cgi{'rev'} ne '') {
$rev=1;
}
exit thread();
}
-if ($idt[1]eq '') {
+# second path segment required for thread, post, image
+if ((($idt[1] !~ /^([0-9]+)$/) and ($mode ne 'image')) or $idt[1] eq '') {
exit failpage("Status: 404 Not Found\n","404 Not Found","Incomplete $mode ID.");
}
+# these things also require a key
if ($cgi{'key'} =~ /^([A-Fa-f0-9]+)$/) {
$key=$1;
}
if ($mode eq 'image') {
exit image();
}
+# if order was reversed in theread list
if ($cgi{'grev'} ne '') {
$grev=1;
}
+# page number on thread list
if ($cgi{'gp'} =~ /^([0-9]+)$/) {
$gpage=$1;
}
if ($mode eq 'thread') {
exit thread();
}
-if ($idt[2]eq '') {
+# third page segment required by post
+if ($idt[2] !~ /^([0-9]+)$/) {
exit failpage("Status: 404 Not Found\n","404 Not Found","Incomplete $mode ID.");
}
+# parent thread key
if ($cgi{'tkey'} =~ /^([A-Fa-f0-9]+)$/) {
$tkey=$1;
}
+# parent thread page number
if ($cgi{'tp'} =~ /^([0-9]+)$/) {
$tpage=$1;
}
}
exit failpage("Status: 500 Internal Server Error\n","500 Internal Server Error","$mode: $id");
+sub logout {
+ # logging out is acomplished by removing the access file
+ unless ($skey=access($time,$IP,$cgi{'skey'})) {
+ exit loginpage ("You were not logged in.","Status: 403 Forbidden\n");
+ }
+ my $accesspath=ACCESS_PATH.$skey;
+ unlink $accesspath or return failpage("Status: 500 Internal Server Error\n","500 Internal Server Error","$Couldn't remove access file.");
+
+ if($method eq 'HEAD') {
+ print "Status: 200 Ok\n\n";
+ return;
+ }
+ print "Content-type: text/html\n\n";
+ print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">'."\n";
+ print '<html lang="en"><head>'."\n";
+ print '<title>Logout successful - the redundant facebook copy</title>'."\n";
+ print '<meta http-equiv="Content-type" content="text/html; charset=UTF-8">'."\n";
+ print '<link rel="stylesheet" href="'.IF_CSS_PATH.'">'."\n";
+ print HTML_HEAD."\n";
+ print '</head><body>'."\n";
+ print HTML_TOP."\n";
+ print '<h1>The redundant facebook copy</h1>'."\n";
+ print '<h2>Logout successful</h2>'."\n";
+ print '<p><b class="ni">You have successfully logged out.</b></p>'."\n";
+ print HTML_BOTTOM."\n";
+ print '</body></html>'."\n";
+}
+
+# Function which displays one post/thread on a list of posts/threads
+# Arguments:
+# 1. LAST SEGMENT of ID.
+# 2. mode: 'thread', 'post', 'posstreply'
+# 3. if post is even or odd
+# 4. if post is a firstpost on a thread
+# Returns 1 on success and 0 on failure
sub showpost {
(my $postid, my $pmode, my $even, my $firstpost) = @_;
my $post;
else {
return 0;
}
+ # path depends on mode
$postpath=ARCH_PATH.$idt[0].'/'.$pmode.'/'.(($pmode eq 'thread')?'':($idt[1].'/'.(($pmode eq 'post')?'':($idt[2].'/')))).$postid;
%posth=readdatafile($postpath);
$post=\%posth;
$postcontent = \($$post{'content'});
}
$$postcontent =~ s/&img([^;]+);/insertimg($1)/ge;
- print '<div class="post" id="'.(($pmode eq 'thread')?'':($idt[1].'/'.(($pmode eq 'post')?'':($idt[2].'/')))).$postid.'">';
- print '<div class="post-name">'.entityencode($$post{'name'}).(($$post{'timetext'} ne '')?(' • '.$$post{'timetext'}):'').(($$post{'replies'} ne '')?(' • replies: '.$$post{'replies'}):'').'</div>'."\n";
- print '<div class="'.($even?'post-content-0':'post-content-1').'">'.$$postcontent.'</div>'."\n";
+ print '<div class="post-'.($even?'0':'1').'" id="'.(($pmode eq 'thread')?'':($idt[1].'-'.(($pmode eq 'post')?'':($idt[2].'-')))).$postid.'">';
+ print '<div class="post-name">'.entityencode($$post{'name'}).(($$post{'timetext'} ne '')?(' • '.$$post{'timetext'}):'').(($$post{'likes'} ne '')?(' • likes: <b>'.$$post{'likes'}.'</b>'):'').(($$post{'replies'} ne '')?(' • replies: <b>'.$$post{'replies'}.'</b>'):'').'</div>'."\n";
+ print '<div class="post-content-'.($even?'0':'1').'">'.$$postcontent.'</div>'."\n";
+ # "shared post" (post inside a post)
+ if ($$post{'shared'}) {
+ if ($pmode eq 'thread') {
+ $postcontent = \($$post{'shared-postcontent'});
+ }
+ else{
+ $postcontent = \($$post{'shared-content'});
+ }
+ $$postcontent =~ s/&img([^;]+);/insertimg($1)/ge;
+ print '<div class="post-'.($even?'1':'0').'" id="'.(($pmode eq 'thread')?'':($idt[1].'-'.(($pmode eq 'post')?'':($idt[2].'-')))).'-shared'.$postid.'">';
+ print '<div class="post-name">'.entityencode($$post{'shared-name'}).(($$post{'shared-timetext'} ne '')?(' • '.$$post{'shared-timetext'}):'').'</div>'."\n";
+ print '<div class="post-content-'.($even?'1':'0').'">'.$$postcontent.'</div>'."\n";
+
+ # shared posts can have attachments too
+ $first=1;
+ for(my $ind=1;;++$ind) {
+ if($$post{'shared-link-'.$ind} ne ''){
+ if($first){
+ print '<div class="post-content-'.($even?'1':'0').'">'."\n";
+ $first=0;
+ }
+ print '<div class="post-attachment">';
+ if($$post{'shared-img-'.$ind} ne ''){
+ print '<div class="left"><a href="'.entityencode($$post{'shared-link-'.$ind}).'"><img class="post-attachment" src="'.IMAGE_PATH.'/'.$idt[0].'/'.$$post{'shared-img-'.$ind}.'?key='.$$post{'shared-imgkey-'.$ind}.'&skey='.$skey.'" alt="image '.$ind.'"></a></div>';
+ }
+ print '<div class="left"><a href="'.entityencode($$post{'shared-link-'.$ind}).'" class="br"><b>'.$$post{'shared-linktitle-'.$ind}.'</b></a><br><a href="'.entityencode($$post{'shared-link-'.$ind}).'" class="br">'.$$post{'shared-linktext-'.$ind}.'</a></div></div>'."\n";
+ }
+ elsif($$post{'shared-img-'.$ind} ne ''){
+ if($first){
+ print '<div class="post-content-'.($even?'1':'0').'">'."\n";
+ $first=0;
+ }
+ print '<img class="post-attachment" src="'.IMAGE_PATH.'/'.$idt[0].'/'.$$post{'shared-img-'.$ind}.'?key='.$$post{'shared-imgkey-'.$ind}.'&skey='.$skey.'" alt="image '.$ind.'">';
+ }
+ else{
+ last;
+ }
+ }
+ unless($first) {
+ print '</div>'."\n";
+ }
+ print '</div>'."\n";
+ }
+
+ # attachments
$first=1;
for(my $ind=1;;++$ind) {
if($$post{'link-'.$ind} ne ''){
if($first){
- print '<div class="'.($even?'post-content-0':'post-content-1').'">'."\n";
+ print '<div class="post-content-'.($even?'0':'1').'">'."\n";
$first=0;
}
print '<div class="post-attachment">';
}
elsif($$post{'img-'.$ind} ne ''){
if($first){
- print '<div class="'.($even?'post-content-0':'post-content-1').'">'."\n";
+ print '<div class="post-content-'.($even?'0':'1').'">'."\n";
$first=0;
}
print '<img class="post-attachment" src="'.IMAGE_PATH.'/'.$idt[0].'/'.$$post{'img-'.$ind}.'?key='.$$post{'imgkey-'.$ind}.'&skey='.$skey.'" alt="image '.$ind.'">';
print '</div>'."\n";
}
+ # if post/thread has replies show a button that takes to the (sub)thread
if(($pmode ne 'postreply')and !$firstpost) {
if ($pmode eq 'thread') {
$repliespath=ARCH_PATH.$idt[0].'/post/'.$postid.'/';
$repliespath=ARCH_PATH.$idt[0].'/postreply/'.$idt[1].'/'.$postid.'/';
}
if (-d $repliespath) {
- print '<div class="'.($even?'post-content-0':'post-content-1').'"><form class="inline" method="post" action="'.(($pmode eq 'thread')?THREAD_PATH:POST_PATH).'/'.$idt[0].'/'.(($pmode eq 'thread')?'':($idt[1].'/')).$postid.'">';
+ print '<div class="post-content-'.($even?'0':'1').'">';
+ print '<form class="inline" method="post" action="'.(($pmode eq 'thread')?THREAD_PATH:POST_PATH).'/'.$idt[0].'/'.(($pmode eq 'thread')?'':($idt[1].'/')).$postid.'">';
print '<input type="submit" class="button" value="show '.(($pmode eq 'thread')?'':'sub').'thread">';
print '<input type="hidden" name="skey" value="'.$skey.'">';
if ($pmode eq 'thread') {
return 1;
}
+# function to send an image, supports if-modified-since.
sub image {
my $headerpath;
my $imagepath;
my $imagefile;
my %header;
my $buffer;
+ my $notmodified=0;
+ my $modifiedsince;
$imagepath=ARCH_PATH.$idt[0].'/image/'.$idt[1];
+ # "header" file with metadata
$headerpath=$imagepath.'@h';
$imagepath.='@v';
%header = readdatafile($headerpath);
- ### 304 !!! !!! !!!
-
if($header{'id'}!~/^[a-zA-Z]_([A-Za-z0-9\-\._\/]|(\@[A-Fa-f0-9]{2}))+$/) {
return failpage("Status: 404 Not Found\n","404 Not Found","Image \"$id\" not found.");
}
+
+ if(($header{'key'} ne'') and ($key ne $header{'key'})) {
+ exit loginpage ("You must log in to access this image.","Status: 403 Forbidden\n");
+ }
+
+ if(defined($http{'if-modified-since'})) {
+ if(($modifiedsince=gettimenumber($http{'if-modified-since'})) and ($header{'timenumber'} ne '')) {
+ if($header{'timenumber'} <= $modifiedsince) {
+ $notmodified=1;
+ }
+ }
+ }
+
+ if($notmodified) {
+ print "Status: 304 Not Modified\n\n";
+ return;
+ }
+
open($imagefile,'<',$imagepath) or return failpage("Status: 500 Internal Server Error\n","500 Internal Server Error"," Can't open image file.");
unless(binmode($imagefile)) {
close($imagefile);
return failpage("Status: 500 Internal Server Error\n","500 Internal Server Error"," Can't switch to binary mode.");
}
- if(($header{'key'} ne'') and ($key ne $header{'key'})) {
- exit loginpage ("You must log in to access this image.","Status: 403 Forbidden\n");
- }
-
+ # some header fields from the file should be sent
foreach my $ind (keys %header) {
- if ($ind =~ /^content-/) {
+ if ($ind =~ /^((content-.*)|last-modified)$/) {
print "$ind: $header{$ind}\n";
}
}
+
print "\n";
if ($method eq 'HEAD'){
close($imagefile);
}
+# function to send a page of a list of threads / a thread / a subthread
sub thread {
my $dir;
my $threadpath;
}
}
-
if ($cgi{'p'} =~ /^([0-9]+)$/) {
$page=int($1);
}
$page=1;
}
+ # list of the posts in a thread
$postspath=ARCH_PATH.'/'.(($mode eq 'group')?($threadid.'/thread/'):($idt[0].'/'.$pmode.'/'.(($mode eq 'thread')?'':($idt[1].'/')).$threadid.'/'));
if (opendir ($dir, $postspath)) {
$noreplies=0;
}
$postsq=scalar @posts;
- $pagesq= int(($postsq+(($mode eq 'group')?1:0))/$postsinpage)+1;
+ # in thread/post mode there is one more post (firstpost) which is not on the
+ # list!
+ $pagesq= int(($postsq-(($mode eq 'group')?1:0))/$postsinpage)+1;
if($pagesq<=0) {
$pagesq=1;
}
print '<title>'.(($mode eq 'group')?'List of threads':('Thread '.$threadid)).(($pagesq>1)?(', page '.$page.' of '.$pagesq):'').' - the redundant facebook copy</title>'."\n";
print '<meta http-equiv="Content-type" content="text/html; charset=UTF-8">'."\n";
print '<link rel="stylesheet" href="'.IF_CSS_PATH.'">'."\n";
+ print HTML_HEAD."\n";
print '</head><body>'."\n";
+ print HTML_TOP."\n";
print '<h1>'.(($mode eq 'group')?((($thread{'name'}ne'')?(entityencode($thread{'name'})):$threadid).' - t'):'T').'he redundant facebook copy</h1>'."\n";
print '<h2>'.(($mode eq 'group')?'List of threads':('Thread '.$threadid)).(($pagesq>1)?(', page '.$page.' of '.$pagesq):'').'</h2>'."\n";
+ # for(){} because there are the same buttons/inputs before and after the posts.
for (my $jnd=0; $jnd<2; ++$jnd) {
+ print '<form class="inline" method="post" action="'.LOGOUT_PATH.'">';
+ print '<input type="submit" value="log out" class="button"><input type="hidden" name="skey" value="'.$skey.'">';
+ print '</form>'."\n";
+
if ($mode eq 'group') {
print '<form class="inline" method="post" action="'.LIST_PATH.'">';
print '<input type="submit" value="back to the group list" class="button"><input type="hidden" name="skey" value="'.$skey.'">';
print '</form>'."\n";
+ # reverse order
print '<form class="inline" method="post" action="'.GROUP_PATH.'/'.$threadid.'" ><input type="hidden" name="skey" value="'.$skey.'">';
if($rev){
print '<input type="submit" value="show chronological" class="button">';
print '</form>'."\n";
}
elsif($mode eq 'thread') {
- print '<form class="inline" method="post" action="'.GROUP_PATH.'/'.$idt[0].(($gpage ne '')?('/'.$gpage):'').'">';
- if($grev ne '') {
+ print '<form class="inline" method="post" action="'.GROUP_PATH.'/'.$idt[0].(($gpage ne '')?('/'.(($grev ne '')?'-':'').$gpage):'').'">';
+ if(($grev ne '')and ($gpage eq '')) {
print '<input type="hidden" name="rev" value="'.$grev.'">';
}
print '<input type="hidden" name="skey" value="'.$skey.'">';
print '</form>'."\n";
}
-
+ # page links
if($pagesq > 1){
print ' Page: ';
if($page>1){
for(my $ind=(($page>6)?(($page<$pagesq)?($page-3):($page-4)):2);$ind<$page;++$ind) {
pagebutton($idpath,$ind,$rev);
}
- pagebutton($idt[0].'/'.$threadid,$page,$rev,1);
+ pagebutton($idpath,$page,$rev,1);
for(my $ind=$page+1;$ind<=(($page+6<=$pagesq)?(($page==1)?($page+4):($page+3)):($pagesq-1));++$ind) {
pagebutton($idpath,$ind,$rev);
}
}
}
}
+ print HTML_BOTTOM."\n";
+ print '</body></html>'."\n";
+
}
+# function to convert image IDs to image URLs in post text
sub insertimg {
(my $imgtext) = @_;
my $imgid;
my $imgkey;
- # &img@ir_v2@2Fyo@2Fr@2FX8YPpi6kcyo.png@k47793b703215f9410a43c96202872683a25c8e9fc474fd9822d39ee677f98281;
if ($imgtext=~ /^\@i([a-zA-Z]_([A-Za-z0-9\-\._\/]|(\@[A-Fa-f0-9]{2}))+)\@k([A-Fa-f0-9]+)$/) {
return IMAGE_PATH.'/'.$idt[0].'/'.$1.'?key='.$4.'&skey='.$skey;
}
+# function to show a page button
+# arguments:
+# 1. FULL id.
+# 2. page number
+# 3. if reversed order
+# 4. if links to the same page
sub pagebutton {
(my $id, my $page, my $reversed, my $samepage) = @_;
- print '<form class="inline" method="post" action="'.(($mode eq 'post')?POST_PATH:(($mode eq 'thread')?THREAD_PATH:GROUP_PATH)).'/'.$id.'/'.$page.'">';
+ print '<form class="inline" method="post" action="'.(($mode eq 'post')?POST_PATH:(($mode eq 'thread')?THREAD_PATH:GROUP_PATH)).'/'.$id.'/'.($reversed?'-':'').$page.'">';
print '<input type="hidden" name="skey" value="'.$skey.'">';
if($key ne '') {
print '<input type="hidden" name="key" value="'.$key.'">';
if($grev ne '') {
print '<input type="hidden" name="grev" value="'.$grev.'">';
}
- if($reversed){
- print '<input type="hidden" name="rev" value="1">';
- }
+ # if($reversed){
+ # print '<input type="hidden" name="rev" value="1">';
+ # }
print '<input type="submit" class="'.($samepage?'samepagebutton':'pagebutton').'" value="'.$page.'">';
print '</form>'."\n";
}
+# function to send a list of archived facebook groups
sub list {
my $dir;
my $groupfile;
print '<title>List of groups - the redundant facebook copy</title>'."\n";
print '<meta http-equiv="Content-type" content="text/html; charset=UTF-8">'."\n";
print '<link rel="stylesheet" href="'.IF_CSS_PATH.'">'."\n";
+ print HTML_HEAD."\n";
print '</head><body>'."\n";
+ print HTML_TOP."\n";
print '<h1>The redundant facebook copy</h1>'."\n";
print '<h2>List of groups</h2>'."\n";
print '<table class="list"><tr class="list-name-b"><td colspan="2">Available groups</td></tr>'."\n";
$even=0;
- ###PAGE???
+ # the list is assumed to be short. no pagination.
+
while (defined ($groupid = readdir $dir)) {
if ($groupid =~ /^([0-9]+)$/) {
%group = readconfigfile(GROUPSETTINGS_PATH.$1);
print '<tr class="'.($even?'list-entry-0':'list-entry-1').'"><td class="list-cell">'.(($group{'name'}ne'')?(entityencode($group{'name'})):$groupid).'</td><td class="list-cell"><form method="post" action="'.GROUP_PATH.'/'.$groupid.'" class="inline"><input type="hidden" name="skey" value="'.$skey.'"><input type="submit" value="show chronological" class="button"></form> <form method="post" action="'.GROUP_PATH.'/'.$groupid.'" class="inline"><input type="hidden" name="skey" value="'.$skey.'"><input type="hidden" name="rev" value="1"><input type="submit" value="show antichronological" class="button"></form></td></tr>'."\n";
}
- print '</table></body></html>'."\n";
+ print '</table>'."\n";
+ print '<form class="inline" method="post" action="'.LOGOUT_PATH.'">';
+ print '<input type="submit" value="log out" class="button"><input type="hidden" name="skey" value="'.$skey.'">';
+ print '</form>'."\n";
+ print HTML_BOTTOM."\n";
+ print '</body></html>'."\n";
closedir ($dir);
}
+# Function to check if logged in
+# Arguments:
+# 1. timestamp (current time)
+# 2. IP address
+# 3. session key
+# Returns session key on success and 0 on failure
sub access {
(my $time, my $ip, my $key) = @_;
my $timeout_unlock = TIMEOUT_UNLOCK*60;
return 0;
}
+ # the session key is the filename
$accesspath=ACCESS_PATH.$key;
if (! (-e $accesspath)) {
return 0;
}
if ($lastip =~ /^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)$/) {
- $ip = $1;
+ $lastip = $1;
}
else {
close ($accessfile);
return 0;
}
+ if ($lastip ne $ip) {
+ close ($accessfile);
+ return 0;
+ }
if ((abs($time-$unlocktime)>$timeout_unlock) or (abs($time-$lasttime)>$timeout_inact) or ($ip ne $lastip)){
close ($accessfile);
}
}
+# The function to log in
sub login {
my $passpath;
my $passfile;
return loginpage('Wrong username or password.',"Status: 403 Forbidden\n");
}
+ # if password confirmed create the key and the access file
$key=key(KEY_BITS);
$accesspath=ACCESS_PATH.$key;
close ($accessfile);
if($method eq 'HEAD') {
- print "Status: 200 Ok\n";
+ print "Status: 200 Ok\n\n";
return;
}
print "Content-type: text/html\n\n";
print '<title>Login successful - the redundant facebook copy</title>'."\n";
print '<meta http-equiv="Content-type" content="text/html; charset=UTF-8">'."\n";
print '<link rel="stylesheet" href="'.IF_CSS_PATH.'">'."\n";
+ print HTML_HEAD."\n";
print '</head><body>'."\n";
+ print HTML_TOP."\n";
print '<h1>The redundant facebook copy</h1>'."\n";
print '<h2>Login successful</h2>'."\n";
print '<p><b class="ni">You have successfully logged in.</b></p>'."\n";
- print '<form method="post" action="'.LIST_PATH.'">'."\n";
- print '<input type="submit" value="show the list" class="button"><br>'."\n";
+ print '<form class ="inline" method="post" action="'.LIST_PATH.'">'."\n";
+ print '<input type="submit" value="show the list" class="button">'."\n";
print '<input type="hidden" name="skey" value="'.entityencode($key).'">'."\n";
- print '</form></body></html>'."\n";
+ print '</form>'."\n";
+ print '<form class="inline" method="post" action="'.LOGOUT_PATH.'">';
+ print '<input type="submit" value="log out" class="button"><input type="hidden" name="skey" value="'.entityencode($key).'">';
+ print '</form>'."\n";
+
+ if ($cgi{'rmode'} =~ /^(group|thread|post|image)$/){
+ # if this is a login to access some content after getting a 403 before
+ # there should be a link to it after successfully logging in.
+ # also some values (keys, page numbers) have to be determined for this.
+ my %info;
+ my $path;
+ my $ind;
+ my @list;
+ my $dir;
+
+ print '<form class="inline" method="post" action="'.INTERFACE_PATH.'">';
+ print '<input type="submit" value="show the previous page" class="button">';
+ print '<input type="hidden" name="skey" value="'.entityencode($key).'">';
+ print '<input type="hidden" name="mode" value="'.entityencode($cgi{'rmode'}).'">';
+ if ($cgi{'rid'} ne '') {
+ print '<input type="hidden" name="id" value="'.entityencode($cgi{'rid'}).'">';
+ }
+ if ($cgi{'rmode'} =~ /^(thread|post)$/) {
+ if($cgi{'rid'} =~ /^([0-9]+)\/([0-9]+)(\/([0-9]+))?(\/.*)?/) {
+ if (($cgi{'rmode'} eq 'post') and ($4 ne '')) {
+ $path = ARCH_PATH.$1.'/post/'.$2.'/'.$4;
+ %info = readdatafile($path);
+ if ($info{'key'} ne '') {
+ print '<input type="hidden" name="key" value="'.entityencode($info{'key'}).'">';
+ }
+ $path = ARCH_PATH.$1.'/post/'.$2.'/';
+ if (opendir ($dir, $path)) {
+ while (defined ($ind = readdir $dir)) {
+ if ($ind =~ /^([0-9]+)$/) {
+ push @list, $1;
+ }
+ }
+ closedir($dir);
+ @list=sort { $a <=> $b } @list;
+ $ind = getposition(\@list,$4);
+ print '<input type="hidden" name="tp" value="'.(int(($ind+1)/POSTS_IN_PAGE)+1).'">';
+ }
+ }
+ $path = ARCH_PATH.$1.'/thread/'.$2;
+ %info = readdatafile($path);
+ if ($info{'key'} ne '') {
+ if($cgi{'rmode'} eq 'post') {
+ print '<input type="hidden" name="tkey" value="'.entityencode($info{'key'}).'">';
+ }
+ else {
+ print '<input type="hidden" name="key" value="'.entityencode($info{'key'}).'">';
+ }
+ }
+ $path = ARCH_PATH.$1.'/thread/';
+ if (opendir ($dir, $path)) {
+ while (defined ($ind = readdir $dir)) {
+ if ($ind =~ /^([0-9]+)$/) {
+ push @list, $1;
+ }
+ }
+ closedir($dir);
+ @list=sort { $a <=> $b } @list;
+ $ind = getposition(\@list,$2);
+ print '<input type="hidden" name="gp" value="'.(int($ind/THREADS_IN_PAGE)+1).'">';
+ }
+ }
+ }
+ elsif ($cgi{'rmode'} eq 'image') {
+ if($cgi{'rid'} =~ /^(([0-9]+)\/([a-zA-Z]_([A-Za-z0-9\-\._\/]|(\@[A-Fa-f0-9]{2}))+))$/) {
+ $path=ARCH_PATH.$1.'/image/'.$2.'@h';
+ %info = readdatafile($path);
+ if ($info{'key'} ne '') {
+ print '<input type="hidden" name="key" value="'.entityencode($info{'key'}).'">';
+ }
+ }
+ }
+ print '</form>'."\n";
+ }
+ print HTML_BOTTOM."\n";
+ print '</body></html>'."\n";
}
-
+# function to get values of http header fields. Returns a hash. names of header
+# fields are lowercase
sub gethttpheader {
(my $env) = @_;
# Function for showing the login form page.
-# arguments: 1 - additional message (optional), 2 - additional header fields
-# (optional)
+# arguments: 1 - additional message , 2 - additional header fields
sub loginpage {
(my $message, my $header)=@_;
if($header ne ''){
print '<title>Log in - the redundant facebook copy</title>'."\n";
print '<meta http-equiv="Content-type" content="text/html; charset=UTF-8">'."\n";
print '<link rel="stylesheet" href="'.IF_CSS_PATH.'">'."\n";
+ print HTML_HEAD."\n";
print '</head><body>'."\n";
+ print HTML_TOP."\n";
print '<h1>The redundant facebook copy</h1>'."\n";
print '<h2>Log in</h2>'."\n";
if($message ne ''){
print '<p><b class="br">'.entityencode($message).'</b></p>'."\n";
}
print '<form method="post" action="'.LOGIN_PATH.'"><table>'."\n";
- print '<tr><td><b>Username: <b></td><td><input type="text" name="username" class="textfield"></td></tr>'."\n";
- print '<tr><td><b>Password: <b></td><td><input type="password" name="password" class="textfield"></td></tr>'."\n";
+ print '<tr><td><b>Username: </b></td><td><input type="text" name="username" class="textfield"></td></tr>'."\n";
+ print '<tr><td><b>Password: </b></td><td><input type="password" name="password" class="textfield"></td></tr>'."\n";
print '</table><input type="submit" value="log in" class="button">'."\n";
- print '</form></body></html>'."\n";
+ if ($mode eq 'login') {
+ if ($cgi{'rmode'} ne '') {
+ print '<input type="hidden" name="rmode" value="'.entityencode($cgi{'rmode'}).'">';
+ }
+ if ($cgi{'rid'} ne '') {
+ print '<input type="hidden" name="rid" value="'.entityencode($cgi{'rid'}).'">';
+ }
+ }
+ else {
+ print '<input type="hidden" name="rmode" value="'.$mode.'">';
+ print '<input type="hidden" name="rid" value="'.entityencode($id).'">';
+ }
+ print '</form>'."\n";
+ print HTML_BOTTOM."\n";
+ print '</body></html>'."\n";
}
+# Function to show an error page
+# arguments: 1 - header fields, 2 - page title, 3 - error message
sub failpage {
(my $header, my $title, my $message)=@_;
if($header ne ''){
}
print '<meta http-equiv="Content-type" content="text/html; charset=UTF-8">'."\n";
print '<link rel="stylesheet" href="'.IF_CSS_PATH.'">'."\n";
+ print HTML_HEAD."\n";
print '</head><body>'."\n";
+ print HTML_TOP."\n";
if($title ne ''){
print "<h1>$title - the redundant facebook copy</h1>"."\n";
}
if($message ne ''){
print '<p><b class="br">'.entityencode($message).'</b></p>'."\n";
}
- print '<form class="hl" method="post" action="'.INTERFACE_PATH.'">';
+ print '<form class="inline" method="post" action="'.INTERFACE_PATH.'">';
if($cgi{'skey'} =~ /^([A-Fa-f0-9]+)$/){
print '<input type="hidden" name="skey" value="'.$1.'">';
}
print '<input type="submit" value="back to the interface" class="button"></form>'."\n";
+ print '<form class="inline" method="post" action="'.LOGOUT_PATH.'">';
+ print '<input type="submit" value="log out" class="button"><input type="hidden" name="skey" value="'.$skey.'">';
+ print '</form>'."\n";
+ print HTML_BOTTOM."\n";
print '</body></html>'."\n";
}
+
+# example from perlmonks.org
+sub getposition {
+ my ($array, $word) = @_;
+ my $low = 0;
+ my $high = @$array - 1;
+
+ while ( $low <= $high ) {
+ my $try = int( ($low+$high) / 2 );
+ $low = $try+1, next if $array->[$try] < $word;
+ $high = $try-1, next if $array->[$try] > $word;
+ return $try;
+ }
+ return;
+}
This is the facebook bot and the interface
It depends on the proxy and some other software:
--Apache2 (2.2) (only the interface - not written yet)
+-Apache2 (2.2)
-Perl
-curl
--gzip (only for compressing old log files)
and for compilation:
-cp
-move
location.
It will also generate config.txt.
Open this file and copy its fragments to your Apache2 config and crontab.
-#Restart Apache2. (no need for this yet)
+Restart Apache2. (no need for this yet)
To add a facebook group:
"0" or "no" means no, anything else means yes. default value if
undefined is yes. Not implemented yet (maybe never will). Now it
will always hide names.
+name - the name of the group
+
create another file, add "-names" to the group id for the file name.
In this file should be name mappings:
facebook_id = filtered_name
default = filtered_name.
The bot accepts group IDs as commandline arguments. If there are none the bot
-will process all groups that have a config file.
\ No newline at end of file
+will process all groups that have a config file.
+
+To set an username/password (for accessing interface):
+Create a file in data_path/pass. Username is filename.
+Inside the file should be one line with URL-encoded password.
+Usernames can be made of letters, numbers and "_".
#not a directory path
#Time in minutes
-timeout_unlock = 90 # lock the proxy this many minutes after unlocking
-timeout_inact = 15 # lock the proxy this many minutes after last activity
+timeout_unlock = 90 # log out this many minutes after logging in
+timeout_inact = 30 # log out this many minutes after last activity
path = /usr/local/bin:/usr/bin:/bin #The path environment variable. Must be
#overwritten if SETUID. Otherwise
gzip = /bin/gzip
c_flags = -g -Wall
-key_bits = 256
-max_redirections = 16
+key_bits = 256 # too many bits may not work! (filename too long)
+max_redirections = 16 # to prevent infinite redirection loop when bot looks for
+ # page
posts_in_page = 40
threads_in_page = 20
logs_uncompressed = 2 # How many uncompressed old logs to keep
logs_total = 10 # How many old logs to keep
-rm_access_crontab = 0 1 * * * # How often to remove leftover unlock info.
-cleararch_crontab = 30 0 * * * # How often to clear the archive from old files.
-oldlogs_crontab = 0 0 * * * # How often to deal with old logs
+rm_access_crontab = 10 2 * * * # How often to remove leftover unlock info.
+oldlogs_crontab = 0 2 * * * # How often to deal with old logs
bot_crontab = 20 2 * * * # How often to run the bot
-# Not a good idea to launch oldlogs just after cleararch, I think.
bot_args = 207426296087284 # facebook groups which will be processed by the bot
# numbers separated by spaces. Can be left empty.
# The bot will process all groups then.
+
+# custom html to insert:
+html_top = <a href="/"><img border="0" alt="1190.bicyclesonthemoon.info" src="/img/botmlogo2.png"></img></a><br>
+html_bottom = <br><br>The facebook interface by Balthasar SzczepaĆski, 2015-2016<br>Released under the <a href="http://www.gnu.org/licenses/agpl.html">AGPL3 license</a><br>The sources and instructions are available <a href="http://1190.bicyclesonthemoon.info/facebug/">here</a>.<br><br><a href="/">1190.bicyclesonthemoon.info</a>
+html_head = <link rel="icon" type="image/png" href="/img/favicon.png">