Apache-Session-Browseable-1.3.19000755001750001750 015201255027 15516 5ustar00yaddyadd000000000000Apache-Session-Browseable-1.3.19/Build.PL000444001750001750 176415201255027 17157 0ustar00yaddyadd000000000000use Module::Build; # See perldoc Module::Build for details of how this works Module::Build->new( dist_author => 'LLNG Team ', module_name => 'Apache::Session::Browseable', license => 'perl', requires => { 'Apache::Session' => 0, 'JSON' => 0, 'Crypt::URandom' => 0, }, recommends => { 'DBI' => 0, 'Net::LDAP' => 0.38, 'DBD::Cassandra' => 0, 'Redis::Fast' => 0, }, test_requires => { DBI => 0, 'DBD::SQLite' => 0, }, test_recommends => { 'LWP::Protocol::PSGI' => 0, }, dist_version => '1.3.19', autosplit => [qw(lib/Apache/Session/Browseable/_common.pm)], configure_requires => { 'Module::Build' => 0, }, meta_merge => { resources => { repository => 'https://github.com/LemonLDAPNG/Apache-Session-Browseable' } }, )->create_build_script; Apache-Session-Browseable-1.3.19/COPYRIGHT000444001750001750 30315201255027 17122 0ustar00yaddyadd000000000000Copyright (C) 2009-2025 by Xavier Guimard Copyright (C) 2013-2025 by Clement Oudot Copyright (C) 2019-2025 by Maxime Besson Copyright (C) 2018-2025 by Worteks Copyright (C) 2023-2025 by Linagora Apache-Session-Browseable-1.3.19/Changes000444001750001750 1013415201255027 17165 0ustar00yaddyadd000000000000Revision history for Perl extension Apache::Session::Browseable. 1.3.19 - Fix CVE-2026-8503: Apache::Session::Generate::SHA256 used a low-entropy seed (time, PID, rand, stringified hash ref) to derive session identifiers. Use Crypt::URandom to generate session ids from a cryptographically secure source, falling back to the previous hashing method only if Crypt::URandom is unavailable. Similar in scope to CVE-2025-40931 and CVE-2025-40932. - Fix Redis indexes: never cleaned before - Improve resilience and reliability Patroni driver 1.3.18 - Add persistence option for Redis 1.3.17 - Add Patroni support 1.3.16 - Optimize deleteIfLowerThan for Redis 1.3.15 - Improve Redis driver performance - Implement searchOn/deleteIfLowerThan into Redis - Prefer Redis::Fast 1.3.14 - restrict mysql_enable_utf8 to DBD::mysql - PgJSON: Fix GKFAS when called with a column list 1.3.13 - Fix versions - Update Cassandra doc 1.3.12 - Add Cassandra support via DBD::Cassandra 1.3.11 - Revert 1.3.10 changes 1.3.10 - Add quote for fields in INSERT query 1.3.9 - Return number of deleted rows when called in array context. See [LemonLDAP issue #2428](https://gitlab.ow2.org/lemonldap-ng/lemonldap-ng/-/issues/2428) 1.3.8 - Add specific error handling for old versions (#28) 1.3.7 - Fix ldap+tls:// regression in 1.3.6 (#27) 1.3.6 - Improve logs (#26) - Add ldapVerify option for SSL cert validation (#25) 1.3.5 - Update cast syntax for vanilla MySQL (#21) - Redis: doc and tests improvements (#23) 1.3.4 - Don't stop parsing sessions when one is bad 1.3.3 - LDAP: Add ldapRaw parameter (#20) 1.3.2 - Allow sentinel list to be passed as a comma-delimited string (#19) 1.3.1 - Fix typo on Oracle.pm (#15) - Postgres: ensure that returned @fields keep their original case (Closes: #17) 1.3.0 - Fix also PgHstore error when searchOn is used without fields 1.2.9 - Use either Redis::Fast or Redis - Fix error when searchOn is used without fields (PgJSON) 1.2.8 - Missing UTF-8 hook 1.2.7 - Force UTF-8 1.2.6 - Force allow_nonref option (#14) 1.2.5 Thu Apr 4 07:09:23 2017 - PostgreSQL "hstore" and "json" support - Add "deleteIfLowerThan" method 1.2.4 Sun Feb 19 08:25:10 2016 - Incorrect logic for old database formats (fixes: #11) 1.2.3 Tue Jun 7 15:55:56 2016 - Replace "/" for Windows 1.2.2 Fri Apr 1 13:22:22 2016 - Manage old session format for databases 1.2.1 Thu Mar 10 07:27:45 2016 - Add an empty Browseable.pm due to new Pause restrictions 1.2 Tue Mar 08 22:08:09 2016 - replace MD5 by SHA256 - replace serialization by JSON 1.0.1 Fri Aug 30 06:40:02 2013 - Add Apache::Session in required dependencies (was ommited in 1.0) 1.0.2 Thu Oct 17 20:27:24 2013 - _common::_tabInTab() must return 0 if no fields are required Closes http://jira.ow2.org/browse/LEMONLDAP-627 1.0 Sat Jul 06 19:57:46 2013 - Add SQLite support - Corrects POD ($args was forgotten) - Add searchOnExpr() sub: - default implementation in _common - optimized implementation in LDAP and DBI - Optimize SQL queries when only indexed files are required - Create _common.pm lib for unoptimized functions - Add basic tests for all libs - Add advanced tests using SQLite backend 0.9 Thu Feb 28 06:51:51 2013 - Fix Undefined value warning with Redis backend (https://github.com/coudot/apache-session-browseable/issues/1) - Update copyright 0.7 Sun Jun 24 09:07:21 2012 - Add "eval" to avoid errors in unserialize (LDAP) 0.6 Mon Dec 8 16:43:23 2010 - Add LDAP (Closes LEMONLDAP-243) - Redis parsing returned nothing 0.5 Mon Dec 6 21:54:23 2010 - Add Redis (Closes LEMONLDAP-244) 0.4 Mon Aug 16 17:16:12 2010 - Missing "use" 0.3 Sun Nov 1 17:12:34 2009 - Add Sybase, Oracle, Informix, File and Postgres 0.2 Sun Nov 1 10:06:51 2009 - Remove 5.10 dependency 0.1 Sat Oct 31 08:10:54 2009 - Initial release 0.8 Fri Oct 12 06:20:54 2012 - storable must not be always used in DBI Apache-Session-Browseable-1.3.19/LICENSE000444001750001750 5007415201255027 16706 0ustar00yaddyadd000000000000Terms of Perl itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --------------------------------------------------------------------------- The General Public License (GPL) Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 675 Mass Ave, Cambridge, MA 02139, USA. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS --------------------------------------------------------------------------- The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. Aggregation of this Package with a commercial distribution is always permitted provided that the use of this Package is embedded; that is, when no overt attempt is made to make this Package's interfaces visible to the end user of the commercial distribution. Such use shall not be construed as a distribution of this Package. 9. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 10. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End Apache-Session-Browseable-1.3.19/MANIFEST000444001750001750 372415201255027 17012 0ustar00yaddyadd000000000000Build.PL Changes COPYRIGHT lib/Apache/Session/Browseable.pm lib/Apache/Session/Browseable/_common.pm lib/Apache/Session/Browseable/Cassandra.pm lib/Apache/Session/Browseable/DBI.pm lib/Apache/Session/Browseable/File.pm lib/Apache/Session/Browseable/Informix.pm lib/Apache/Session/Browseable/LDAP.pm lib/Apache/Session/Browseable/MySQL.pm lib/Apache/Session/Browseable/MySQLJSON.pm lib/Apache/Session/Browseable/Oracle.pm lib/Apache/Session/Browseable/Patroni.pm lib/Apache/Session/Browseable/PgHstore.pm lib/Apache/Session/Browseable/PgJSON.pm lib/Apache/Session/Browseable/Postgres.pm lib/Apache/Session/Browseable/Redis.pm lib/Apache/Session/Browseable/SQLite.pm lib/Apache/Session/Browseable/Store/Cassandra.pm lib/Apache/Session/Browseable/Store/DBI.pm lib/Apache/Session/Browseable/Store/File.pm lib/Apache/Session/Browseable/Store/Informix.pm lib/Apache/Session/Browseable/Store/LDAP.pm lib/Apache/Session/Browseable/Store/MySQL.pm lib/Apache/Session/Browseable/Store/Oracle.pm lib/Apache/Session/Browseable/Store/Patroni.pm lib/Apache/Session/Browseable/Store/Postgres.pm lib/Apache/Session/Browseable/Store/Redis.pm lib/Apache/Session/Browseable/Store/SQLite.pm lib/Apache/Session/Browseable/Store/Sybase.pm lib/Apache/Session/Browseable/Sybase.pm lib/Apache/Session/Generate/SHA256.pm lib/Apache/Session/Serialize/Hstore.pm lib/Apache/Session/Serialize/JSON.pm LICENSE MANIFEST META.json META.yml Module meta-data (added by MakeMaker) README.md RELEASE.md rpm/Apache-Session-Browseable.spec t/Apache-Session-Browseable-Cassandra.t t/Apache-Session-Browseable-common.t t/Apache-Session-Browseable-DBI.t t/Apache-Session-Browseable-File.t t/Apache-Session-Browseable-LDAP.t t/Apache-Session-Browseable-Patroni.t t/Apache-Session-Browseable-Redis.t t/Apache-Session-Browseable-SQLite.t t/Apache-Session-Browseable-Store-DBI.t t/Apache-Session-Browseable-Store-MySQL.t t/Apache-Session-Browseable-Store-Patroni.t t/test-browseable-functions-using-File.t t/test-browseable-functions-using-SQLite.t Apache-Session-Browseable-1.3.19/META.json000444001750001750 1363115201255027 17320 0ustar00yaddyadd000000000000{ "abstract" : "Add index and search methods to Apache::Session", "author" : [ "LLNG Team " ], "dynamic_config" : 1, "generated_by" : "Module::Build version 0.4234", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "Apache-Session-Browseable", "prereqs" : { "configure" : { "requires" : { "Module::Build" : "0" } }, "runtime" : { "recommends" : { "DBD::Cassandra" : "0", "DBI" : "0", "Net::LDAP" : "0.38", "Redis::Fast" : "0" }, "requires" : { "Apache::Session" : "0", "Crypt::URandom" : "0", "JSON" : "0" } }, "test" : { "requires" : { "DBD::SQLite" : "0", "DBI" : "0" } } }, "provides" : { "Apache::Session::Browseable" : { "file" : "lib/Apache/Session/Browseable.pm", "version" : "v1.3.19" }, "Apache::Session::Browseable::Cassandra" : { "file" : "lib/Apache/Session/Browseable/Cassandra.pm", "version" : "v1.3.13" }, "Apache::Session::Browseable::DBI" : { "file" : "lib/Apache/Session/Browseable/DBI.pm", "version" : "v1.3.9" }, "Apache::Session::Browseable::File" : { "file" : "lib/Apache/Session/Browseable/File.pm", "version" : "v1.3.5" }, "Apache::Session::Browseable::Informix" : { "file" : "lib/Apache/Session/Browseable/Informix.pm", "version" : "v1.2.2" }, "Apache::Session::Browseable::LDAP" : { "file" : "lib/Apache/Session/Browseable/LDAP.pm", "version" : "v1.3.6" }, "Apache::Session::Browseable::MySQL" : { "file" : "lib/Apache/Session/Browseable/MySQL.pm", "version" : "v1.2.5" }, "Apache::Session::Browseable::MySQLJSON" : { "file" : "lib/Apache/Session/Browseable/MySQLJSON.pm", "version" : "v1.3.9" }, "Apache::Session::Browseable::Oracle" : { "file" : "lib/Apache/Session/Browseable/Oracle.pm", "version" : "v1.2.2" }, "Apache::Session::Browseable::Patroni" : { "file" : "lib/Apache/Session/Browseable/Patroni.pm", "version" : "v1.3.19" }, "Apache::Session::Browseable::PgHstore" : { "file" : "lib/Apache/Session/Browseable/PgHstore.pm", "version" : "v1.3.9" }, "Apache::Session::Browseable::PgJSON" : { "file" : "lib/Apache/Session/Browseable/PgJSON.pm", "version" : "v1.3.9" }, "Apache::Session::Browseable::Postgres" : { "file" : "lib/Apache/Session/Browseable/Postgres.pm", "version" : "v1.3.1" }, "Apache::Session::Browseable::Redis" : { "file" : "lib/Apache/Session/Browseable/Redis.pm", "version" : "v1.3.18" }, "Apache::Session::Browseable::SQLite" : { "file" : "lib/Apache/Session/Browseable/SQLite.pm", "version" : "v1.2.2" }, "Apache::Session::Browseable::Store::Cassandra" : { "file" : "lib/Apache/Session/Browseable/Store/Cassandra.pm", "version" : "v1.3.13" }, "Apache::Session::Browseable::Store::DBI" : { "file" : "lib/Apache/Session/Browseable/Store/DBI.pm", "version" : "v1.3.11" }, "Apache::Session::Browseable::Store::File" : { "file" : "lib/Apache/Session/Browseable/Store/File.pm", "version" : "v1.2.2" }, "Apache::Session::Browseable::Store::Informix" : { "file" : "lib/Apache/Session/Browseable/Store/Informix.pm", "version" : "v1.2.2" }, "Apache::Session::Browseable::Store::LDAP" : { "file" : "lib/Apache/Session/Browseable/Store/LDAP.pm", "version" : "v1.3.8" }, "Apache::Session::Browseable::Store::MySQL" : { "file" : "lib/Apache/Session/Browseable/Store/MySQL.pm", "version" : "v1.2.2" }, "Apache::Session::Browseable::Store::Oracle" : { "file" : "lib/Apache/Session/Browseable/Store/Oracle.pm", "version" : "v1.2.2" }, "Apache::Session::Browseable::Store::Patroni" : { "file" : "lib/Apache/Session/Browseable/Store/Patroni.pm", "version" : "v1.3.19" }, "Apache::Session::Browseable::Store::Postgres" : { "file" : "lib/Apache/Session/Browseable/Store/Postgres.pm", "version" : "v1.2.2" }, "Apache::Session::Browseable::Store::Redis" : { "file" : "lib/Apache/Session/Browseable/Store/Redis.pm", "version" : "v1.3.18" }, "Apache::Session::Browseable::Store::SQLite" : { "file" : "lib/Apache/Session/Browseable/Store/SQLite.pm", "version" : "v1.2.7" }, "Apache::Session::Browseable::Store::Sybase" : { "file" : "lib/Apache/Session/Browseable/Store/Sybase.pm", "version" : "v1.2.2" }, "Apache::Session::Browseable::Sybase" : { "file" : "lib/Apache/Session/Browseable/Sybase.pm", "version" : "v1.2.2" }, "Apache::Session::Generate::SHA256" : { "file" : "lib/Apache/Session/Generate/SHA256.pm", "version" : "v1.3.19" }, "Apache::Session::Serialize::Hstore" : { "file" : "lib/Apache/Session/Serialize/Hstore.pm", "version" : "v1.2.5" }, "Apache::Session::Serialize::JSON" : { "file" : "lib/Apache/Session/Serialize/JSON.pm", "version" : "v1.2.6" } }, "release_status" : "stable", "resources" : { "license" : [ "http://dev.perl.org/licenses/" ], "repository" : { "url" : "https://github.com/LemonLDAPNG/Apache-Session-Browseable" } }, "version" : "v1.3.19", "x_serialization_backend" : "JSON::PP version 4.16" } Apache-Session-Browseable-1.3.19/META.yml000444001750001750 1034415201255027 17146 0ustar00yaddyadd000000000000--- abstract: 'Add index and search methods to Apache::Session' author: - 'LLNG Team ' build_requires: DBD::SQLite: '0' DBI: '0' configure_requires: Module::Build: '0' dynamic_config: 1 generated_by: 'Module::Build version 0.4234, CPAN::Meta::Converter version 2.150010' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Apache-Session-Browseable provides: Apache::Session::Browseable: file: lib/Apache/Session/Browseable.pm version: v1.3.19 Apache::Session::Browseable::Cassandra: file: lib/Apache/Session/Browseable/Cassandra.pm version: v1.3.13 Apache::Session::Browseable::DBI: file: lib/Apache/Session/Browseable/DBI.pm version: v1.3.9 Apache::Session::Browseable::File: file: lib/Apache/Session/Browseable/File.pm version: v1.3.5 Apache::Session::Browseable::Informix: file: lib/Apache/Session/Browseable/Informix.pm version: v1.2.2 Apache::Session::Browseable::LDAP: file: lib/Apache/Session/Browseable/LDAP.pm version: v1.3.6 Apache::Session::Browseable::MySQL: file: lib/Apache/Session/Browseable/MySQL.pm version: v1.2.5 Apache::Session::Browseable::MySQLJSON: file: lib/Apache/Session/Browseable/MySQLJSON.pm version: v1.3.9 Apache::Session::Browseable::Oracle: file: lib/Apache/Session/Browseable/Oracle.pm version: v1.2.2 Apache::Session::Browseable::Patroni: file: lib/Apache/Session/Browseable/Patroni.pm version: v1.3.19 Apache::Session::Browseable::PgHstore: file: lib/Apache/Session/Browseable/PgHstore.pm version: v1.3.9 Apache::Session::Browseable::PgJSON: file: lib/Apache/Session/Browseable/PgJSON.pm version: v1.3.9 Apache::Session::Browseable::Postgres: file: lib/Apache/Session/Browseable/Postgres.pm version: v1.3.1 Apache::Session::Browseable::Redis: file: lib/Apache/Session/Browseable/Redis.pm version: v1.3.18 Apache::Session::Browseable::SQLite: file: lib/Apache/Session/Browseable/SQLite.pm version: v1.2.2 Apache::Session::Browseable::Store::Cassandra: file: lib/Apache/Session/Browseable/Store/Cassandra.pm version: v1.3.13 Apache::Session::Browseable::Store::DBI: file: lib/Apache/Session/Browseable/Store/DBI.pm version: v1.3.11 Apache::Session::Browseable::Store::File: file: lib/Apache/Session/Browseable/Store/File.pm version: v1.2.2 Apache::Session::Browseable::Store::Informix: file: lib/Apache/Session/Browseable/Store/Informix.pm version: v1.2.2 Apache::Session::Browseable::Store::LDAP: file: lib/Apache/Session/Browseable/Store/LDAP.pm version: v1.3.8 Apache::Session::Browseable::Store::MySQL: file: lib/Apache/Session/Browseable/Store/MySQL.pm version: v1.2.2 Apache::Session::Browseable::Store::Oracle: file: lib/Apache/Session/Browseable/Store/Oracle.pm version: v1.2.2 Apache::Session::Browseable::Store::Patroni: file: lib/Apache/Session/Browseable/Store/Patroni.pm version: v1.3.19 Apache::Session::Browseable::Store::Postgres: file: lib/Apache/Session/Browseable/Store/Postgres.pm version: v1.2.2 Apache::Session::Browseable::Store::Redis: file: lib/Apache/Session/Browseable/Store/Redis.pm version: v1.3.18 Apache::Session::Browseable::Store::SQLite: file: lib/Apache/Session/Browseable/Store/SQLite.pm version: v1.2.7 Apache::Session::Browseable::Store::Sybase: file: lib/Apache/Session/Browseable/Store/Sybase.pm version: v1.2.2 Apache::Session::Browseable::Sybase: file: lib/Apache/Session/Browseable/Sybase.pm version: v1.2.2 Apache::Session::Generate::SHA256: file: lib/Apache/Session/Generate/SHA256.pm version: v1.3.19 Apache::Session::Serialize::Hstore: file: lib/Apache/Session/Serialize/Hstore.pm version: v1.2.5 Apache::Session::Serialize::JSON: file: lib/Apache/Session/Serialize/JSON.pm version: v1.2.6 recommends: DBD::Cassandra: '0' DBI: '0' Net::LDAP: '0.38' Redis::Fast: '0' requires: Apache::Session: '0' Crypt::URandom: '0' JSON: '0' resources: license: http://dev.perl.org/licenses/ repository: https://github.com/LemonLDAPNG/Apache-Session-Browseable version: v1.3.19 x_serialization_backend: 'CPAN::Meta::YAML version 0.018' Apache-Session-Browseable-1.3.19/README.md000444001750001750 100115201255027 17122 0ustar00yaddyadd000000000000# Apache::Session::Browseable [![Build Status](https://github.com/LemonLDAPNG/Apache-Session-Browseable/actions/workflows/ci.yml/badge.svg)](https://github.com/LemonLDAPNG/Apache-Session-Browseable/actions/workflows/ci.yml) This module is an Apache::Session implementation allowing to define index to speed up searches. ## Installation To install this module type the following: ```` perl Build.PL ./Build ./Build test ./Build install ```` ## CPAN See http://search.cpan.org/dist/Apache-Session-Browseable/ Apache-Session-Browseable-1.3.19/RELEASE.md000444001750001750 46715201255027 17244 0ustar00yaddyadd000000000000# Release process ## Version Update version in `lib/Apache/Session/Browseable.pm` ## Changes Update changelog in `Changes` file ## Github release Create a new release on [https://github.com/LemonLDAPNG/Apache-Session-Browseable/releases](https://github.com/LemonLDAPNG/Apache-Session-Browseable/releases) Apache-Session-Browseable-1.3.19/lib000755001750001750 015201255027 16264 5ustar00yaddyadd000000000000Apache-Session-Browseable-1.3.19/lib/Apache000755001750001750 015201255027 17445 5ustar00yaddyadd000000000000Apache-Session-Browseable-1.3.19/lib/Apache/Session000755001750001750 015201255027 21070 5ustar00yaddyadd000000000000Apache-Session-Browseable-1.3.19/lib/Apache/Session/Browseable.pm000444001750001750 403415201255027 23651 0ustar00yaddyadd000000000000package Apache::Session::Browseable; our $VERSION = '1.3.19'; print STDERR "Use a sub module of Apache::Session::Browseable such as Apache::Session::Browseable::File"; 1; __END__ =head1 NAME Apache::Session::Browseable - Add index and search methods to Apache::Session =head1 DESCRIPTION Apache::Session::browseable provides some class methods to manipulate all sessions and add the capability to index some fields to make research faster. It has been written to increase performances of LemonLDAP::NG. Read the chosen module documentation carefully to set the indexes. =head1 AVAILABLE MODULES =head2 SQL databases =head3 PostgreSQL =over =item L =item L: uses "hstore" field =item L: uses "json/jsonb" field =item L: uses "json/jsonb" field and manage connection using Patroni API to find master node of PostgreSQL cluster =back =head3 MySQL or MariaDB =over =item L: for MySQL and MariaDB =item L: for MySQL only, uses "json" field =back =head3 Other =over =item L =item L =item L =back =head2 NoSQL =over =item L =item L =back =head1 SEE ALSO L, L, L =head1 COPYRIGHT AND LICENSE =encoding utf8 Copyright (C): =over =item 2009-2025 by Xavier Guimard =item 2013-2025 by Clément Oudot =item 2019-2025 by Maxime Besson =item 2013-2025 by Worteks =item 2023-2025 by Linagora =back This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.1 or, at your option, any later version of Perl 5 you may have available. =cut Apache-Session-Browseable-1.3.19/lib/Apache/Session/Browseable000755001750001750 015201255027 23155 5ustar00yaddyadd000000000000Apache-Session-Browseable-1.3.19/lib/Apache/Session/Browseable/Cassandra.pm000444001750001750 602415201255027 25551 0ustar00yaddyadd000000000000package Apache::Session::Browseable::Cassandra; use strict; use Apache::Session; use Apache::Session::Lock::Null; use Apache::Session::Browseable::Store::Cassandra; use Apache::Session::Generate::SHA256; use Apache::Session::Serialize::JSON; use Apache::Session::Browseable::DBI; our $VERSION = '1.3.13'; our @ISA = qw(Apache::Session::Browseable::DBI Apache::Session); sub populate { my $self = shift; $self->{object_store} = new Apache::Session::Browseable::Store::Cassandra $self; $self->{lock_manager} = new Apache::Session::Lock::Null $self; $self->{generate} = \&Apache::Session::Generate::SHA256::generate; $self->{validate} = \&Apache::Session::Generate::SHA256::validate; $self->{serialize} = \&Apache::Session::Serialize::JSON::serialize; $self->{unserialize} = \&Apache::Session::Serialize::JSON::unserialize; return $self; } 1; =pod =head1 NAME Apache::Session::Browseable::Cassandra - Apache::Session backend to store sessions in a Cassadra database. =head1 SYNOPSIS use Apache::Session::Browseable::Cassandra; my $args = { DataSource => 'dbi:Cassandra:host=localhost;keyspace=llng', UserName => $db_user, Password => $db_pass, # Choose your browseable fileds Index => '_whatToTrace _session_kind _utime iAddr', }; # Use it like Apache::Session my %session; tie %session, 'Apache::Session::Browseable::Cassandra', $id, $args; $session{uid} = 'me'; $session{mail} = 'me@me.com'; $session{unindexedField} = 'zz'; untie %session; =head1 DESCRIPTION Apache::Session::Browseable::Cassandra is an implementation of Apache::Session for Cassandra database. =head1 SCHEMA To use this module, you will need at least these columns in a table called 'sessions': id text a_session text To create this schema, you can execute this command using cqlsh: CREATE TABLE sessions ( id text PRIMARY KEY, a_session text ); =head1 CONFIGURATION The module must know what datasource, username, and password to use when connecting to the database. These values can be set using the options hash (see Apache::Session documentation). The options are DataSource, UserName, and Password. Example: tie %hash, 'Apache::Session::Cassandra', $id, { DataSource => 'dbi:Cassandra:host=localhost;keyspace=llng', UserName => 'database_user', Password => 'K00l' }; Instead, you may pass in an already-opened DBI handle to your database. tie %hash, 'Apache::Session::Cassandra', $id, { Handle => $dbh }; =head1 SEE ALSO L, L =head1 COPYRIGHT AND LICENSE =encoding utf8 Copyright (C): =over =item 2009-2025 by Xavier Guimard =item 2013-2025 by Clément Oudot =item 2019-2025 by Maxime Besson =item 2013-2025 by Worteks =item 2023-2025 by Linagora =back This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.1 or, at your option, any later version of Perl 5 you may have available. =cut Apache-Session-Browseable-1.3.19/lib/Apache/Session/Browseable/DBI.pm000444001750001750 1610215201255027 24266 0ustar00yaddyadd000000000000package Apache::Session::Browseable::DBI; use strict; use DBI; use Apache::Session; use Apache::Session::Browseable::_common; our $VERSION = '1.3.9'; our @ISA = qw(Apache::Session Apache::Session::Browseable::_common); sub searchOn { my $class = shift; my ( $args, $selectField, $value, @fields ) = @_; # Escape quotes $selectField =~ s/'/''/g; if ( $class->_fieldIsIndexed( $args, $selectField ) ) { return $class->_query( $args, $selectField, $value, { query => "$selectField=?", values => [$value] }, @fields ); } else { return $class->SUPER::searchOn(@_); } } sub searchOnExpr { my $class = shift; my ( $args, $selectField, $value, @fields ) = @_; # Escape quotes $value =~ s/'/''/g; $selectField =~ s/'/''/g; if ( $class->_fieldIsIndexed( $args, $selectField ) ) { $value =~ s/\*/%/g; return $class->_query( $args, $selectField, $value, { query => "$selectField like ?", values => [$value] }, @fields ); } else { return $class->SUPER::searchOnExpr(@_); } } sub _query { my ( $class, $args, $selectField, $value, $query, @fields ) = @_; my %res = (); my $index = ref( $args->{Index} ) ? $args->{Index} : [ split /\s+/, $args->{Index} ]; my $dbh = $class->_classDbh($args); my $table_name = $args->{TableName} || $Apache::Session::Store::DBI::TableName; # Case 1: all requested fields are also indexed my $indexed = $class->_tabInTab( \@fields, $index ); my $sth; if ($indexed) { my $fields = join( ',', 'id', map { s/'//g; $_ } @fields ); $sth = $dbh->prepare( "SELECT $fields from $table_name where $query->{query}"); $sth->execute( @{ $query->{values} } ); return $sth->fetchall_hashref('id'); } # Case 1: at least one field isn't indexed, decoding is needed else { $sth = $dbh->prepare( "SELECT id,a_session from $table_name where $query->{query}"); $sth->execute( @{ $query->{values} } ); while ( my @row = $sth->fetchrow_array ) { no strict 'refs'; my $self = eval "&${class}::populate();"; my $sub = $self->{unserialize}; eval { my $tmp = &$sub( { serialized => $row[1] } ); if (@fields) { $res{ $row[0] }->{$_} = $tmp->{$_} foreach (@fields); } else { $res{ $row[0] } = $tmp; } }; if ($@) { print STDERR "Error in session $row[0]: $@\n"; delete $res{ $row[0] }; } } } return \%res; } sub deleteIfLowerThan { my ( $class, $args, $rule ) = @_; my ( $query, %fields ); my $index = ref( $args->{Index} ) ? $args->{Index} : [ split /\s+/, $args->{Index} ]; if ( $rule->{or} ) { $query = join ' OR ', map { $fields{$_}++; $class->_buildLowerThanExpression( $_, $rule->{or}->{$_} ) } keys %{ $rule->{or} }; } elsif ( $rule->{and} ) { $query = join ' AND ', map { $fields{$_}++; $class->_buildLowerThanExpression( $_, $rule->{and}->{$_} ) } keys %{ $rule->{and} }; } if ( $rule->{not} ) { $query = "($query) AND " . join( ' AND ', map { $rule->{not}->{$_} =~ s/'/''/g; $fields{$_}++; "$_ <> '$rule->{not}->{$_}'" } keys %{ $rule->{not} } ); } return 0 unless ( $query and $class->_tabInTab( [ keys %fields ], $index ) ); my $dbh = $class->_classDbh($args); my $table_name = $args->{TableName} || $Apache::Session::Store::DBI::TableName; my $rows = $dbh->do("DELETE FROM $table_name WHERE $query"); return 0 unless defined $rows; if (wantarray) { $rows = 0 if $rows == -1; return ( 1, $rows ); } else { return 1; } } # Let specialized modules override this syntax if they need to sub _buildLowerThanExpression { my ( $class, $field, $value ) = @_; return "cast($field as integer) < $value"; } sub get_key_from_all_sessions { my $class = shift; my $args = shift; my $data = shift; my $table_name = $args->{TableName} || $Apache::Session::Store::DBI::TableName; my $dbh = $class->_classDbh($args); # Special case if all wanted fields are indexed if ( $data and ref($data) ne 'CODE' ) { $data = [$data] unless ( ref($data) ); my $index = ref( $args->{Index} ) ? $args->{Index} : [ split /\s+/, $args->{Index} ]; # Test if one field isn't indexed my $indexed = $class->_tabInTab( $data, $index ); # OK, all fields are indexed if ($indexed) { my $sth = $dbh->prepare_cached( 'SELECT id,' . join( ',', map { s/'/''/g; $_ } @$data ) . " from $table_name" ); $sth->execute; return $sth->fetchall_hashref('id'); } } my $sth = $dbh->prepare_cached("SELECT id,a_session from $table_name"); $sth->execute; my %res; my $next = ( $args->{DataSource} =~ /^sybase/i ? sub { require Storable; return Storable::thaw( pack( 'H*', $_[0] ) ); } : $args->{DataSource} =~ /^mysql/i ? sub { require MIME::Base64; require Storable; return Storable::thaw( MIME::Base64::decode_base64( $_[0] ) ); } : undef ); while ( my @row = $sth->fetchrow_array ) { no strict 'refs'; my $self = eval "&${class}::populate();"; eval { my $sub = $self->{unserialize}; my $tmp = &$sub( { serialized => $row[1] }, $next ); if ( ref($data) eq 'CODE' ) { $tmp = &$data( $tmp, $row[0] ); $res{ $row[0] } = $tmp if ( defined($tmp) ); } elsif ($data) { $data = [$data] unless ( ref($data) ); $res{ $row[0] }->{$_} = $tmp->{$_} foreach (@$data); } else { $res{ $row[0] } = $tmp; } }; if ($@) { print STDERR "Error in session $row[0]: $@\n"; delete $res{ $row[0] }; } } return \%res; } sub _classDbh { my $class = shift; my $args = shift; my $datasource = $args->{DataSource} or die "No datasource given !"; my $username = $args->{UserName}; my $password = $args->{Password}; my $dbh = DBI->connect_cached( $datasource, $username, $password, { RaiseError => 1, AutoCommit => 1 } ) || die $DBI::errstr; if ( $datasource =~ /^dbi:sqlite/i ) { $dbh->{sqlite_unicode} = 1; } elsif ( $datasource =~ /^dbi:mysql/i ) { $dbh->{mysql_enable_utf8} = 1; } elsif ( $datasource =~ /^dbi:pg/i ) { $dbh->{pg_enable_utf8} = 1; } return $dbh; } 1; Apache-Session-Browseable-1.3.19/lib/Apache/Session/Browseable/File.pm000444001750001750 442215201255027 24531 0ustar00yaddyadd000000000000package Apache::Session::Browseable::File; use strict; use Apache::Session; use Apache::Session::Lock::File; use Apache::Session::Browseable::Store::File; use Apache::Session::Generate::SHA256; use Apache::Session::Serialize::JSON; use Apache::Session::Browseable::_common; use constant SL => ( $^O and $^O =~ /(?:MSWin|Windows)/i ? '\\' : '/' ); our $VERSION = '1.3.5'; our @ISA = qw(Apache::Session Apache::Session::Browseable::_common); sub populate { my $self = shift; $self->{object_store} = new Apache::Session::Browseable::Store::File $self; $self->{lock_manager} = new Apache::Session::Lock::File $self; $self->{generate} = \&Apache::Session::Generate::SHA256::generate; $self->{validate} = \&Apache::Session::Generate::SHA256::validate; $self->{serialize} = \&Apache::Session::Serialize::JSON::serialize; $self->{unserialize} = \&Apache::Session::Serialize::JSON::unserialize; return $self; } sub DESTROY { my $self = shift; $self->save; $self->{object_store}->close; $self->release_all_locks; } sub get_key_from_all_sessions { my ( $class, $args, $data ) = @_; $args->{Directory} ||= $Apache::Session::Store::File::Directory; unless ( opendir DIR, $args->{Directory} ) { die "Cannot open directory $args->{Directory}\n"; } my @t = grep { -f $args->{Directory} . SL . $_ and /^[A-Za-z0-9@\-]+$/ } readdir(DIR); closedir DIR; my %res; for my $f (@t) { eval { open F, $args->{Directory} . SL . $f or die $!; my $row = join '', ; if ( ref($data) eq 'CODE' ) { $res{$f} = &$data( &Apache::Session::Serialize::JSON::_unserialize($row), $f ); } elsif ($data) { $data = [$data] unless ( ref($data) ); my $tmp = &Apache::Session::Serialize::JSON::_unserialize($row); $res{$f}->{$_} = $tmp->{$_} foreach (@$data); } else { $res{$f} = &Apache::Session::Serialize::JSON::_unserialize($row); } }; if ($@) { print STDERR "Error in session $f: $@\n"; delete $res{$f}; } } return \%res; } 1; __END__ Apache-Session-Browseable-1.3.19/lib/Apache/Session/Browseable/Informix.pm000444001750001750 160215201255027 25442 0ustar00yaddyadd000000000000package Apache::Session::Browseable::Informix; use strict; use Apache::Session; use Apache::Session::Lock::Null; use Apache::Session::Browseable::Store::Informix; use Apache::Session::Generate::SHA256; use Apache::Session::Serialize::JSON; use Apache::Session::Browseable::DBI; our $VERSION = '1.2.2'; our @ISA = qw(Apache::Session::Browseable::DBI Apache::Session); sub populate { my $self = shift; $self->{object_store} = new Apache::Session::Browseable::Store::Informix $self; $self->{lock_manager} = new Apache::Session::Lock::Null $self; $self->{generate} = \&Apache::Session::Generate::SHA256::generate; $self->{validate} = \&Apache::Session::Generate::SHA256::validate; $self->{serialize} = \&Apache::Session::Serialize::JSON::serialize; $self->{unserialize} = \&Apache::Session::Serialize::JSON::unserialize; return $self; } 1; Apache-Session-Browseable-1.3.19/lib/Apache/Session/Browseable/LDAP.pm000444001750001750 1452115201255027 24413 0ustar00yaddyadd000000000000package Apache::Session::Browseable::LDAP; use strict; use Apache::Session; use Apache::Session::Lock::Null; use Apache::Session::Browseable::Store::LDAP; use Apache::Session::Generate::SHA256; use Apache::Session::Serialize::JSON; use Apache::Session::Browseable::_common; use Net::LDAP::Util qw(escape_filter_value); our $VERSION = '1.3.6'; our @ISA = qw(Apache::Session Apache::Session::Browseable::_common); sub populate { my $self = shift; $self->{object_store} = new Apache::Session::Browseable::Store::LDAP $self; $self->{lock_manager} = new Apache::Session::Lock::Null $self; $self->{generate} = \&Apache::Session::Generate::SHA256::generate; $self->{validate} = \&Apache::Session::Generate::SHA256::validate; $self->{serialize} = \&Apache::Session::Serialize::JSON::serialize; $self->{unserialize} = \&Apache::Session::Serialize::JSON::unserialize; return $self; } sub unserialize { my $session = shift; my $tmp = { serialized => $session }; Apache::Session::Serialize::JSON::unserialize($tmp); return $tmp->{data}; } sub searchOn { my ( $class, $args, $selectField, $value, @fields ) = @_; my $index = ref( $args->{Index} ) ? $args->{Index} : [ split /\s+/, $args->{Index} ]; if ( grep { $_ eq $selectField } @$index ) { ( $selectField, $value ) = escape_filter_value( $selectField, $value ); return $class->_query( $args, $selectField, $value, @fields ); } else { return $class->SUPER::searchOn( $args, $selectField, $value, @fields ); } } sub searchOnExpr { my ( $class, $args, $selectField, $value, @fields ) = @_; my $index = ref( $args->{Index} ) ? $args->{Index} : [ split /\s+/, $args->{Index} ]; if ( grep { $_ eq $selectField } @$index ) { ( $selectField, $value ) = escape_filter_value( $selectField, $value ); $value =~ s/\\2a/\*/gi; return $class->_query( $args, $selectField, $value, @fields ); } else { return $class->SUPER::searchOn( $args, $selectField, $value, @fields ); } } sub _query { my ( $class, $args, $selectField, $value, @fields ) = @_; $args->{ldapObjectClass} ||= 'applicationProcess'; $args->{ldapAttributeId} ||= 'cn'; $args->{ldapAttributeContent} ||= 'description'; $args->{ldapAttributeIndex} ||= 'ou'; my %res = (); my $ldap = Apache::Session::Browseable::Store::LDAP::ldap( { args => $args } ); my $msg = $ldap->search( base => $args->{ldapConfBase}, filter => "(&(objectClass=" . $args->{ldapObjectClass} . ")(" . $args->{ldapAttributeIndex} . "=${selectField}_$value))", #scope => 'base', attrs => [ $args->{ldapAttributeContent}, $args->{ldapAttributeId} ], ); $ldap->unbind(); $ldap->disconnect(); if ( $msg->code ) { Apache::Session::Browseable::Store::LDAP->logError($msg); } else { foreach my $entry ( $msg->entries ) { my $id = $entry->get_value( $args->{ldapAttributeId} ) or die; my $tmp = $entry->get_value( $args->{ldapAttributeContent} ); next unless ($tmp); eval { $tmp = unserialize($tmp); }; next if ($@); if (@fields) { $res{$id}->{$_} = $tmp->{$_} foreach (@fields); } else { $res{$id} = $tmp; } } } return \%res; } sub get_key_from_all_sessions { my $class = shift; my $args = shift; my $data = shift; $args->{ldapObjectClass} ||= 'applicationProcess'; $args->{ldapAttributeId} ||= 'cn'; $args->{ldapAttributeContent} ||= 'description'; $args->{ldapAttributeIndex} ||= 'ou'; my %res; my $ldap = Apache::Session::Browseable::Store::LDAP::ldap( { args => $args } ); my $msg = $ldap->search( base => $args->{ldapConfBase}, # VERY STRANGE BUG ! With this filter, description isn't base64 encoded !!! #filter => '(objectClass=applicationProcess)', filter => '(&(objectClass=' . $args->{ldapObjectClass} . ')(' . $args->{ldapAttributeIndex} . '=*))', attrs => [ $args->{ldapAttributeId}, $args->{ldapAttributeContent} ], ); $ldap->unbind(); if ( $msg->code ) { Apache::Session::Browseable::Store::LDAP->logError($msg); } else { foreach my $entry ( $msg->entries ) { my $id = $entry->get_value( $args->{ldapAttributeId} ) or die; my $tmp = $entry->get_value( $args->{ldapAttributeContent} ); next unless ($tmp); eval { $tmp = unserialize($tmp); }; next if ($@); if ( ref($data) eq 'CODE' ) { $res{$id} = &$data( $tmp, $id ); } elsif ($data) { $data = [$data] unless ( ref($data) ); $res{$id}->{$_} = $tmp->{$_} foreach (@$data); } else { $res{$id} = $tmp; } } } return \%res; } 1; =pod =head1 NAME Apache::Session::Browseable::LDAP - An implementation of Apache::Session::LDAP =head1 SYNOPSIS use Apache::Session::Browseable::LDAP; tie %hash, 'Apache::Session::Browseable::LDAP', $id, { ldapServer => 'ldap://localhost:389', ldapConfBase => 'dmdName=applications,dc=example,dc=com', ldapBindDN => 'cn=admin,dc=example,dc=com', ldapBindPassword => 'pass', Index => 'uid ipAddr', ldapObjectClass => 'applicationProcess', ldapAttributeId => 'cn', ldapAttributeContent => 'description', ldapAttributeIndex => 'ou', ldapVerify => 'require', ldapCAFile => '/etc/ssl/certs/ca-certificates.crt', ldapTimeout => 10, }; =head1 DESCRIPTION This module is an implementation of Apache::Session. It uses an LDAP directory to store datas. =head1 COPYRIGHT AND LICENSE =encoding utf8 =over =item 2009-2025 by Xavier Guimard =item 2013-2025 by Clément Oudot =item 2019-2025 by Maxime Besson =item 2013-2025 by Worteks =item 2023-2025 by Linagora =back This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.0 or, at your option, any later version of Perl 5 you may have available. =head1 SEE ALSO L =cut Apache-Session-Browseable-1.3.19/lib/Apache/Session/Browseable/MySQL.pm000444001750001750 763315201255027 24626 0ustar00yaddyadd000000000000package Apache::Session::Browseable::MySQL; use strict; use Apache::Session; use Apache::Session::Lock::Null; use Apache::Session::Browseable::Store::MySQL; use Apache::Session::Generate::SHA256; use Apache::Session::Serialize::JSON; use Apache::Session::Browseable::DBI; our $VERSION = '1.2.5'; our @ISA = qw(Apache::Session::Browseable::DBI Apache::Session); sub populate { my $self = shift; $self->{object_store} = new Apache::Session::Browseable::Store::MySQL $self; $self->{lock_manager} = new Apache::Session::Lock::Null $self; $self->{generate} = \&Apache::Session::Generate::SHA256::generate; $self->{validate} = \&Apache::Session::Generate::SHA256::validate; $self->{serialize} = \&Apache::Session::Serialize::JSON::serialize; $self->{unserialize} = \&Apache::Session::Serialize::JSON::unserialize; return $self; } # Override default CAST syntax from DBI.pm sub _buildLowerThanExpression { my ( $class, $field, $value ) = @_; return "CAST($field AS SIGNED INTEGER) < $value"; } 1; __END__ =head1 NAME Apache::Session::Browseable::MySQL - Add index and search methods to Apache::Session::MySQL =head1 SYNOPSIS Create table with columns for indexed fields. Example for Lemonldap::NG: CREATE TABLE sessions ( id varchar(64) not null primary key, a_session text, _whatToTrace text, _session_kind text, _utime bigint, ipAddr text ); Add indexes: CREATE INDEX uid1 ON sessions (_whatToTrace) USING BTREE; CREATE INDEX s1 ON sessions (_session_kind); CREATE INDEX u1 ON sessions (_utime); CREATE INDEX ip1 ON sessions (ipAddr) USING BTREE; Use it with Perl: use Apache::Session::Browseable::MySQL; my $args = { DataSource => 'dbi:mysql:sessions', UserName => $db_user, Password => $db_pass, LockDataSource => 'dbi:mysql:sessions', LockUserName => $db_user, LockPassword => $db_pass, # Choose your browseable fileds Index => 'uid mail', }; # Use it like Apache::Session my %session; tie %session, 'Apache::Session::Browseable::MySQL', $id, $args; $session{uid} = 'me'; $session{mail} = 'me@me.com'; $session{unindexedField} = 'zz'; untie %session; # Apache::Session::Browseable add some global class methods # # 1) search on a field (indexed or not) my $hash = Apache::Session::Browseable::MySQL->searchOn( $args, 'uid', 'me' ); foreach my $id (keys %$hash) { print $id . ":" . $hash->{$id}->{mail} . "\n"; } # 2) Parse all sessions # a. get all sessions my $hash = Apache::Session::Browseable::MySQL->get_key_from_all_sessions(); # b. get some fields from all sessions my $hash = Apache::Session::Browseable::MySQL->get_key_from_all_sessions('uid', 'mail') # c. execute something with datas from each session : # Example : get uid and mail if mail domain is my $hash = Apache::Session::Browseable::MySQL->get_key_from_all_sessions( sub { my ( $session, $id ) = @_; if ( $session->{mail} =~ /mydomain.com$/ ) { return { $session->{uid}, $session->{mail} }; } } ); foreach my $id (keys %$hash) { print $id . ":" . $hash->{$id}->{uid} . "=>" . $hash->{$id}->{mail} . "\n"; } =head1 DESCRIPTION Apache::Session::browseable provides some class methods to manipulate all sessions and add the capability to index some fields to make research faster. =head1 SEE ALSO L =head1 COPYRIGHT AND LICENSE =encoding utf8 =over =item 2009-2025 by Xavier Guimard =item 2013-2025 by Clément Oudot =item 2019-2025 by Maxime Besson =item 2013-2025 by Worteks =item 2023-2025 by Linagora =back This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.1 or, at your option, any later version of Perl 5 you may have available. =cut Apache-Session-Browseable-1.3.19/lib/Apache/Session/Browseable/MySQLJSON.pm000444001750001750 1620015201255027 25326 0ustar00yaddyadd000000000000package Apache::Session::Browseable::MySQLJSON; use strict; use Apache::Session; use Apache::Session::Lock::Null; use Apache::Session::Browseable::Store::MySQL; use Apache::Session::Generate::SHA256; use Apache::Session::Serialize::JSON; use Apache::Session::Browseable::DBI; our $VERSION = '1.3.9'; our @ISA = qw(Apache::Session::Browseable::DBI Apache::Session); sub populate { my $self = shift; $self->{object_store} = new Apache::Session::Browseable::Store::MySQL $self; $self->{lock_manager} = new Apache::Session::Lock::Null $self; $self->{generate} = \&Apache::Session::Generate::SHA256::generate; $self->{validate} = \&Apache::Session::Generate::SHA256::validate; $self->{serialize} = \&Apache::Session::Serialize::JSON::serialize; $self->{unserialize} = \&Apache::Session::Serialize::JSON::unserialize; return $self; } sub searchOn { my ( $class, $args, $selectField, $value, @fields ) = @_; $selectField =~ s/'/''/g; my $query = { query => qq'a_session->>"\$.$selectField" =?', values => [$value] }; return $class->_query( $args, $query, @fields ); } sub searchOnExpr { my ( $class, $args, $selectField, $value, @fields ) = @_; $selectField =~ s/'/''/g; $value =~ s/\*/%/g; my $query = { query => qq'a_session->>"\$.$selectField" like ?', values => [$value] }; return $class->_query( $args, $query, @fields ); } sub _query { my ( $class, $args, $query, @fields ) = @_; my %res = (); my $index = ref( $args->{Index} ) ? $args->{Index} : [ split /\s+/, $args->{Index} ]; my $dbh = $class->_classDbh($args); my $table_name = $args->{TableName} || $Apache::Session::Store::DBI::TableName; my $sth; my $fields = join( ',', 'id', map { s/'//g; qq(a_session->>"\$.$_" AS $_) } @fields ); $sth = $dbh->prepare("SELECT $fields from $table_name where $query->{query}"); $sth->execute( @{ $query->{values} } ); # In this case, PostgreSQL change field name in lowercase my $res = $sth->fetchall_hashref('id') or return {}; foreach (@fields) { if ( $_ ne lc($_) ) { foreach my $s ( keys %$res ) { $res->{$s}->{$_} = delete $res->{$s}->{ lc $_ }; } } } return $res; } sub deleteIfLowerThan { my ( $class, $args, $rule ) = @_; my $query; if ( $rule->{or} ) { $query = join ' OR ', map { qq{cast(a_session->>"\$.$_" as UNSIGNED) < $rule->{or}->{$_}} } keys %{ $rule->{or} }; } elsif ( $rule->{and} ) { $query = join ' AND ', map { qq{cast(a_session->>"\$.$_" as UNSIGNED) < $rule->{or}->{$_}} } keys %{ $rule->{or} }; } if ( $rule->{not} ) { $query = "($query) AND " . join( ' AND ', map { qq{a_session->>"\$.$_" <> '$rule->{not}->{$_}'} } keys %{ $rule->{not} } ); } return 0 unless ($query); my $dbh = $class->_classDbh($args); my $table_name = $args->{TableName} || $Apache::Session::Store::DBI::TableName; my $rows = $dbh->do("DELETE FROM $table_name WHERE $query"); return 0 unless defined $rows; if (wantarray) { $rows = 0 if $rows == -1; return ( 1, $rows ); } else { return 1; } } sub get_key_from_all_sessions { my ( $class, $args, $data ) = @_; my $table_name = $args->{TableName} || $Apache::Session::Store::DBI::TableName; my $dbh = $class->_classDbh($args); my $sth; # Special case if all wanted fields are indexed if ( $data and ref($data) ne 'CODE' ) { $data = [$data] unless ( ref($data) ); my $fields = join ',', map { s/'//g; qq{a_session->>"\$.$_" AS $_} } @$data; $sth = $dbh->prepare("SELECT $fields from $table_name"); $sth->execute; return $sth->fetchall_hashref('id'); } $sth = $dbh->prepare_cached("SELECT id,a_session from $table_name"); $sth->execute; my %res; while ( my @row = $sth->fetchrow_array ) { no strict 'refs'; my $self = eval "&${class}::populate();"; eval { my $sub = $self->{unserialize}; my $tmp = &$sub( { serialized => $row[1] } ); if ( ref($data) eq 'CODE' ) { $tmp = &$data( $tmp, $row[0] ); $res{ $row[0] } = $tmp if ( defined($tmp) ); } elsif ($data) { $data = [$data] unless ( ref($data) ); $res{ $row[0] }->{$_} = $tmp->{$_} foreach (@$data); } else { $res{ $row[0] } = $tmp; } }; if ($@) { print STDERR "Error in session $row[0]: $@\n"; delete $res{ $row[0] }; } } return \%res; } sub _classDbh { my ( $class, $args ) = @_; my $datasource = $args->{DataSource} or die "No datasource given !"; my $username = $args->{UserName}; my $password = $args->{Password}; my $dbh = DBI->connect_cached( $datasource, $username, $password, { RaiseError => 1, AutoCommit => 1 } ) || die $DBI::errstr; $dbh->{mysql_enable_utf8} = 1; return $dbh; } 1; __END__ =head1 NAME Apache::Session::Browseable::MySQL - Add index and search methods to Apache::Session::MySQL =head1 SYNOPSIS Create table with columns for indexed fields. Example for Lemonldap::NG with optional virtual tables and indexes: CREATE TABLE sessions ( id varchar(64) not null primary key, a_session json, as_wt varchar(32) AS (a_session->"$._whatToTrace") VIRTUAL, as_sk varchar(12) AS (a_session->"$._session_kind") VIRTUAL, as_ut bigint AS (a_session->"$._utime") VIRTUAL, as_ip varchar(40) AS (a_session->"$.ipAddr") VIRTUAL, KEY as_wt (as_wt), KEY as_sk (as_sk), KEY as_ut (as_ut), KEY as_ip (as_ip) ) ENGINE=InnoDB; Use it with Perl: use Apache::Session::Browseable::MySQLJSON; my $args = { DataSource => 'dbi:mysql:sessions', UserName => $db_user, Password => $db_pass, LockDataSource => 'dbi:mysql:sessions', LockUserName => $db_user, LockPassword => $db_pass, # Choose your browseable fileds Index => 'uid mail', }; Use it like L =head1 DESCRIPTION Apache::Session::browseable provides some class methods to manipulate all sessions and add the capability to index some fields to make research faster. Apache::Session::Browseable::MySQLJSON implements it for MySQL databases using "json" type to be able to browse sessions. THIS MODULE ISN'T USABLE WITH MARIADB FOR NOW. =head1 SEE ALSO L, L, L =head1 COPYRIGHT AND LICENSE =encoding utf8 =over =item 2009-2025 by Xavier Guimard =item 2013-2025 by Clément Oudot =item 2019-2025 by Maxime Besson =item 2013-2025 by Worteks =item 2023-2025 by Linagora =back This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.1 or, at your option, any later version of Perl 5 you may have available. =cut Apache-Session-Browseable-1.3.19/lib/Apache/Session/Browseable/Oracle.pm000444001750001750 157015201255027 25060 0ustar00yaddyadd000000000000package Apache::Session::Browseable::Oracle; use strict; use Apache::Session; use Apache::Session::Lock::Null; use Apache::Session::Browseable::Store::Oracle; use Apache::Session::Generate::SHA256; use Apache::Session::Serialize::JSON; use Apache::Session::Browseable::DBI; our $VERSION = '1.2.2'; our @ISA = qw(Apache::Session::Browseable::DBI Apache::Session); sub populate { my $self = shift; $self->{object_store} = new Apache::Session::Browseable::Store::Oracle $self; $self->{lock_manager} = new Apache::Session::Lock::Null $self; $self->{generate} = \&Apache::Session::Generate::SHA256::generate; $self->{validate} = \&Apache::Session::Generate::SHA256::validate; $self->{serialize} = \&Apache::Session::Serialize::JSONserialize; $self->{unserialize} = \&Apache::Session::Serialize::JSONunserialize; return $self; } 1; Apache-Session-Browseable-1.3.19/lib/Apache/Session/Browseable/Patroni.pm000444001750001750 1167415201255027 25315 0ustar00yaddyadd000000000000package Apache::Session::Browseable::Patroni; use strict; use Apache::Session::Lock::Null; use Apache::Session::Browseable::PgJSON; use Apache::Session::Browseable::Store::Patroni; use Apache::Session::Generate::SHA256; use Apache::Session::Serialize::JSON; our @ISA = qw(Apache::Session::Browseable::PgJSON); our $VERSION = '1.3.19'; sub populate { my $self = shift; $self->{object_store} = new Apache::Session::Browseable::Store::Patroni $self; $self->{lock_manager} = new Apache::Session::Lock::Null $self; $self->{generate} = \&Apache::Session::Generate::SHA256::generate; $self->{validate} = \&Apache::Session::Generate::SHA256::validate; $self->{serialize} = \&Apache::Session::Serialize::JSON::serialize; $self->{unserialize} = \&Apache::Session::Serialize::JSON::unserialize; return $self; } 1; __END__ =head1 NAME Apache::Session::Browseable::Patroni - PostgreSQL/Patroni cluster support for L =head1 SYNOPSIS CREATE UNLOGGED TABLE sessions ( id varchar(64) not null primary key, a_session jsonb, ); Optionally, add indexes on some fields. Example for Lemonldap::NG: CREATE INDEX uid1 ON sessions USING BTREE ( (a_session ->> '_whatToTrace') ); CREATE INDEX s1 ON sessions ( (a_session ->> '_session_kind') ); CREATE INDEX u1 ON sessions ( ( cast(a_session ->> '_utime' AS bigint) ) ); CREATE INDEX ip1 ON sessions USING BTREE ( (a_session ->> 'ipAddr') ); Use it with Perl: use Apache::Session::Browseable::Patroni; my $args = { DataSource => 'dbi:Pg:dbname=sessions', UserName => $db_user, Password => $db_pass, Commit => 1, # List Patroni API endpoints (comma or space separated) # Put preferred (local) endpoints first PatroniUrl => 'http://1.2.3.4:8008/cluster, http://2.3.4.5:8008/cluster', # Optional parameters with defaults: # PatroniTimeout => 3, # API request timeout in seconds # PatroniCacheTTL => 60, # Leader cache TTL in seconds # PatroniCircuitBreakerDelay => 30, # Delay before retrying failed API # SSL options (verification enabled by default): # PatroniVerifySSL => 1, # Verify SSL certificates (default: 1) # PatroniSSLCAFile => '/path/to/ca.pem', # Custom CA file # PatroniSSLCAPath => '/path/to/certs/', # Custom CA directory }; # Use it like L =head1 DESCRIPTION Apache::Session::Browseable provides some class methods to manipulate all sessions and add the capability to index some fields to make research faster. Apache::Session::Browseable::Patroni implements it for PostgreSQL databases using "json" or "jsonb" type to be able to browse sessions and is able to dial directly with Patroni API to find the master node of PostgreSQL cluster in case of error. =head2 Resilience features =over 4 =item * B: Avoids hammering the Patroni API when it's failing. After a failure, the API won't be queried again for C seconds (default: 30). =item * B: The discovered leader is cached for C seconds (default: 60). This cache is used as fallback when the API is unavailable. =item * B: Refuses to use a cluster that reports multiple leaders. =item * B: Verifies that the leader is in "running" state before using it. =item * B: Each DataSource maintains its own independent cache, allowing multiple Patroni clusters to be used simultaneously. =back =head2 SSL/TLS Configuration By default, SSL certificate verification is B when connecting to HTTPS Patroni endpoints. This protects against man-in-the-middle attacks. Available SSL options: =over 4 =item * C (default: 1) Set to 0 to disable SSL certificate verification. B: This makes HTTPS connections vulnerable to MITM attacks. Only use in development or when you have other network-level protections. PatroniVerifySSL => 0, # INSECURE - disable SSL verification =item * C Path to a custom CA certificate file (PEM format) for verifying the Patroni API server certificate. PatroniSSLCAFile => '/etc/ssl/certs/patroni-ca.pem', =item * C Path to a directory containing CA certificates for verification. PatroniSSLCAPath => '/etc/ssl/certs/', =back =head1 SEE ALSO L, L =head1 COPYRIGHT AND LICENSE =encoding utf8 =over =item 2009-2025 by Xavier Guimard =item 2013-2025 by Clément Oudot =item 2019-2025 by Maxime Besson =item 2013-2025 by Worteks =item 2023-2025 by Linagora =back This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.1 or, at your option, any later version of Perl 5 you may have available. =cut Apache-Session-Browseable-1.3.19/lib/Apache/Session/Browseable/PgHstore.pm000444001750001750 1554315201255027 25433 0ustar00yaddyadd000000000000package Apache::Session::Browseable::PgHstore; use strict; use Apache::Session; use Apache::Session::Lock::Null; use Apache::Session::Browseable::Store::Postgres; use Apache::Session::Generate::SHA256; use Apache::Session::Serialize::Hstore; our $VERSION = '1.3.9'; our @ISA = qw(Apache::Session); sub populate { my $self = shift; $self->{object_store} = new Apache::Session::Browseable::Store::Postgres $self; $self->{lock_manager} = new Apache::Session::Lock::Null $self; $self->{generate} = \&Apache::Session::Generate::SHA256::generate; $self->{validate} = \&Apache::Session::Generate::SHA256::validate; $self->{serialize} = \&Apache::Session::Serialize::Hstore::serialize; $self->{unserialize} = \&Apache::Session::Serialize::Hstore::unserialize; return $self; } sub searchOn { my ( $class, $args, $selectField, $value, @fields ) = @_; $selectField =~ s/'/''/g; my $query = { query => "a_session -> '$selectField' =?", values => [$value] }; return $class->_query( $args, $query, @fields ); } sub searchOnExpr { my ( $class, $args, $selectField, $value, @fields ) = @_; $selectField =~ s/'/''/g; $value =~ s/\*/%/g; my $query = { query => "a_session -> '$selectField' like ?", values => [$value] }; return $class->_query( $args, $query, @fields ); } sub _query { my ( $class, $args, $query, @fields ) = @_; my %res = (); my $dbh = $class->_classDbh($args); my $table_name = $args->{TableName} || $Apache::Session::Store::DBI::TableName; my $sth; my $fields = @fields ? join( ',', 'id', map { s/'//g; "a_session -> '$_' AS $_" } @fields ) : '*'; $sth = $dbh->prepare("SELECT $fields from $table_name where $query->{query}"); $sth->execute( @{ $query->{values} } ); # In this case, PostgreSQL change field name in lowercase my $res = $sth->fetchall_hashref('id') or return {}; if (@fields) { foreach (@fields) { if ( $_ ne lc($_) ) { foreach my $s ( keys %$res ) { $res->{$s}->{$_} = delete $res->{$s}->{ lc $_ }; } } } } else { my $self = eval "&${class}::populate();"; my $sub = $self->{unserialize}; foreach my $s ( keys %$res ) { eval { my $tmp = &$sub( { serialized => $res->{$s}->{a_session} } ); $res->{$s} = $tmp; }; if ($@) { print STDERR "Error in session $s: $@\n"; delete $res->{$s}; } } } return $res; } sub deleteIfLowerThan { my ( $class, $args, $rule ) = @_; my $query; if ( $rule->{or} ) { $query = join ' OR ', map { "cast(a_session -> '$_' as bigint) < $rule->{or}->{$_}" } keys %{ $rule->{or} }; } elsif ( $rule->{and} ) { $query = join ' AND ', map { "cast(a_session -> '$_' as bigint) < $rule->{or}->{$_}" } keys %{ $rule->{or} }; } if ( $rule->{not} ) { $query = "($query) AND " . join( ' AND ', map { "a_session -> '$_' <> '$rule->{not}->{$_}'" } keys %{ $rule->{not} } ); } return 0 unless ($query); my $dbh = $class->_classDbh($args); my $table_name = $args->{TableName} || $Apache::Session::Store::DBI::TableName; my $rows = $dbh->do("DELETE FROM $table_name WHERE $query"); return 0 unless defined $rows; if (wantarray) { $rows = 0 if $rows == -1; return ( 1, $rows ); } else { return 1; } } sub get_key_from_all_sessions { my ( $class, $args, $data ) = @_; my $table_name = $args->{TableName} || $Apache::Session::Store::DBI::TableName; my $dbh = $class->_classDbh($args); my $sth; # Special case if all wanted fields are indexed if ( $data and ref($data) ne 'CODE' ) { $data = [$data] unless ( ref($data) ); my $fields = join ',', map { s/'//g; "a_session -> '$_' AS $_" } @$data; $sth = $dbh->prepare("SELECT $fields from $table_name"); $sth->execute; return $sth->fetchall_hashref('id'); } $sth = $dbh->prepare_cached("SELECT id,a_session from $table_name"); $sth->execute; my %res; while ( my @row = $sth->fetchrow_array ) { no strict 'refs'; my $self = eval "&${class}::populate();"; my $sub = $self->{unserialize}; my $tmp = &$sub( { serialized => $row[1] } ); if ( ref($data) eq 'CODE' ) { $tmp = &$data( $tmp, $row[0] ); $res{ $row[0] } = $tmp if ( defined($tmp) ); } elsif ($data) { $data = [$data] unless ( ref($data) ); $res{ $row[0] }->{$_} = $tmp->{$_} foreach (@$data); } else { $res{ $row[0] } = $tmp; } } return \%res; } sub _classDbh { my ( $class, $args ) = @_; my $datasource = $args->{DataSource} or die "No datasource given !"; my $username = $args->{UserName}; my $password = $args->{Password}; my $dbh = DBI->connect_cached( $datasource, $username, $password, { RaiseError => 1, AutoCommit => 1 } ) || die $DBI::errstr; $dbh->{pg_enable_utf8} = 1; return $dbh; } 1; __END__ =head1 NAME Apache::Session::Browseable::PgHstore - Hstore type support for L =head1 SYNOPSIS Enable "hstore" extension in PostgreSQL database CREATE EXTENSION hstore; Create table: CREATE UNLOGGED TABLE sessions ( id varchar(64) not null primary key, a_session hstore, ); Optionally, add indexes on some fields. Example for Lemonldap::NG: CREATE INDEX uid1 ON sessions USING BTREE ( (a_session -> '_whatToTrace') ); CREATE INDEX s1 ON sessions ( (a_session -> '_session_kind') ); CREATE INDEX u1 ON sessions ( ( cast(a_session -> '_utime' AS bigint) ) ); CREATE INDEX ip1 ON sessions USING BTREE ( (a_session -> 'ipAddr') ); Use it like L except that you don't need to declare indexes =head1 DESCRIPTION Apache::Session::Browseable provides some class methods to manipulate all sessions and add the capability to index some fields to make research faster. Apache::Session::Browseable::PgHstore implements it for PosqtgreSQL databases using "hstore" extension to be able to browse sessions. =head1 SEE ALSO L, L =head1 COPYRIGHT AND LICENSE =encoding utf8 =over =item 2009-2025 by Xavier Guimard =item 2013-2025 by Clément Oudot =item 2019-2025 by Maxime Besson =item 2013-2025 by Worteks =item 2023-2025 by Linagora =back This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.1 or, at your option, any later version of Perl 5 you may have available. =cut Apache-Session-Browseable-1.3.19/lib/Apache/Session/Browseable/PgJSON.pm000444001750001750 1576215201255027 24743 0ustar00yaddyadd000000000000package Apache::Session::Browseable::PgJSON; use strict; use Apache::Session; use Apache::Session::Lock::Null; use Apache::Session::Browseable::Store::Postgres; use Apache::Session::Generate::SHA256; use Apache::Session::Serialize::JSON; our $VERSION = '1.3.9'; our @ISA = qw(Apache::Session); sub populate { my $self = shift; $self->{object_store} = new Apache::Session::Browseable::Store::Postgres $self; $self->{lock_manager} = new Apache::Session::Lock::Null $self; $self->{generate} = \&Apache::Session::Generate::SHA256::generate; $self->{validate} = \&Apache::Session::Generate::SHA256::validate; $self->{serialize} = \&Apache::Session::Serialize::JSON::serialize; $self->{unserialize} = \&Apache::Session::Serialize::JSON::unserialize; return $self; } sub searchOn { my ( $class, $args, $selectField, $value, @fields ) = @_; $selectField =~ s/'/''/g; my $query = { query => "a_session ->> '$selectField' =?", values => [$value] }; return $class->_query( $args, $query, @fields ); } sub searchOnExpr { my ( $class, $args, $selectField, $value, @fields ) = @_; $selectField =~ s/'/''/g; $value =~ s/\*/%/g; my $query = { query => "a_session ->> '$selectField' like ?", values => [$value] }; return $class->_query( $args, $query, @fields ); } sub _query { my ( $class, $args, $query, @fields ) = @_; my %res = (); my $dbh = $class->_classDbh($args); my $table_name = $args->{TableName} || $Apache::Session::Store::DBI::TableName; my $sth; my $fields = @fields ? join( ',', 'id', map { s/'//g; "a_session ->> '$_' AS $_" } @fields ) : '*'; $sth = $dbh->prepare("SELECT $fields from $table_name where $query->{query}"); $sth->execute( @{ $query->{values} } ); # In this case, PostgreSQL change field name in lowercase my $res = $sth->fetchall_hashref('id') or return {}; if (@fields) { foreach (@fields) { if ( $_ ne lc($_) ) { foreach my $s ( keys %$res ) { $res->{$s}->{$_} = delete $res->{$s}->{ lc $_ }; } } } } else { my $self = eval "&${class}::populate();"; my $sub = $self->{unserialize}; foreach my $s ( keys %$res ) { eval { my $tmp = &$sub( { serialized => $res->{$s}->{a_session} } ); $res->{$s} = $tmp; }; if ($@) { print STDERR "Error in session $s: $@\n"; delete $res->{$s}; } } } return $res; } sub deleteIfLowerThan { my ( $class, $args, $rule ) = @_; my $query; if ( $rule->{or} ) { $query = join ' OR ', map { "cast(a_session ->> '$_' as bigint) < $rule->{or}->{$_}" } keys %{ $rule->{or} }; } elsif ( $rule->{and} ) { $query = join ' AND ', map { "cast(a_session ->> '$_' as bigint) < $rule->{or}->{$_}" } keys %{ $rule->{or} }; } if ( $rule->{not} ) { $query = "($query) AND " . join( ' AND ', map { "a_session ->> '$_' <> '$rule->{not}->{$_}'" } keys %{ $rule->{not} } ); } return 0 unless ($query); my $dbh = $class->_classDbh($args); my $table_name = $args->{TableName} || $Apache::Session::Store::DBI::TableName; my $rows = $dbh->do("DELETE FROM $table_name WHERE $query"); return 0 unless defined $rows; if (wantarray) { $rows = 0 if $rows == -1; return ( 1, $rows ); } else { return 1; } } sub get_key_from_all_sessions { my ( $class, $args, $data ) = @_; my $table_name = $args->{TableName} || $Apache::Session::Store::DBI::TableName; my $dbh = $class->_classDbh($args); my $sth; # Special case if all wanted fields are indexed if ( $data and ref($data) ne 'CODE' ) { $data = [$data] unless ( ref($data) ); my $fields = join ',', 'id', map { s/'//g; "a_session ->> '$_' AS \"$_\"" } @$data; $sth = $dbh->prepare("SELECT $fields from $table_name"); $sth->execute; return $sth->fetchall_hashref('id'); } $sth = $dbh->prepare_cached("SELECT id,a_session from $table_name"); $sth->execute; my %res; while ( my @row = $sth->fetchrow_array ) { no strict 'refs'; my $self = eval "&${class}::populate();"; eval { my $sub = $self->{unserialize}; my $tmp = &$sub( { serialized => $row[1] } ); if ( ref($data) eq 'CODE' ) { $tmp = &$data( $tmp, $row[0] ); $res{ $row[0] } = $tmp if ( defined($tmp) ); } elsif ($data) { $data = [$data] unless ( ref($data) ); $res{ $row[0] }->{$_} = $tmp->{$_} foreach (@$data); } else { $res{ $row[0] } = $tmp; } }; if ($@) { print STDERR "Error in session $row[0]: $@\n"; delete $res{ $row[0] }; } } return \%res; } sub _classDbh { my ( $class, $args ) = @_; my $datasource = $args->{DataSource} or die "No datasource given !"; my $username = $args->{UserName}; my $password = $args->{Password}; my $dbh = DBI->connect_cached( $datasource, $username, $password, { RaiseError => 1, AutoCommit => 1 } ) || die $DBI::errstr; $dbh->{pg_enable_utf8} = 1; return $dbh; } 1; __END__ =head1 NAME Apache::Session::Browseable::PgJSON - Hstore type support for L =head1 SYNOPSIS Create table: CREATE UNLOGGED TABLE sessions ( id varchar(64) not null primary key, a_session jsonb, ); Optionally, add indexes on some fields. Example for Lemonldap::NG: CREATE INDEX uid1 ON sessions USING BTREE ( (a_session ->> '_whatToTrace') ); CREATE INDEX s1 ON sessions ( (a_session ->> '_session_kind') ); CREATE INDEX u1 ON sessions ( ( cast(a_session ->> '_utime' AS bigint) ) ); CREATE INDEX ip1 ON sessions USING BTREE ( (a_session ->> 'ipAddr') ); Use it like L except that you don't need to declare indexes =head1 DESCRIPTION Apache::Session::Browseable provides some class methods to manipulate all sessions and add the capability to index some fields to make research faster. Apache::Session::Browseable::PgJSON implements it for PosqtgreSQL databases using "json" or "jsonb" type to be able to browse sessions. =head1 SEE ALSO L, L =head1 COPYRIGHT AND LICENSE =encoding utf8 =over =item 2009-2025 by Xavier Guimard =item 2013-2025 by Clément Oudot =item 2019-2025 by Maxime Besson =item 2013-2025 by Worteks =item 2023-2025 by Linagora =back This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.1 or, at your option, any later version of Perl 5 you may have available. =cut Apache-Session-Browseable-1.3.19/lib/Apache/Session/Browseable/Postgres.pm000444001750001750 1127415201255027 25503 0ustar00yaddyadd000000000000package Apache::Session::Browseable::Postgres; use strict; use Apache::Session; use Apache::Session::Lock::Null; use Apache::Session::Browseable::Store::Postgres; use Apache::Session::Generate::SHA256; use Apache::Session::Serialize::JSON; use Apache::Session::Browseable::DBI; our $VERSION = '1.3.1'; our @ISA = qw(Apache::Session::Browseable::DBI Apache::Session); sub populate { my $self = shift; $self->{object_store} = new Apache::Session::Browseable::Store::Postgres $self; $self->{lock_manager} = new Apache::Session::Lock::Null $self; $self->{generate} = \&Apache::Session::Generate::SHA256::generate; $self->{validate} = \&Apache::Session::Generate::SHA256::validate; $self->{serialize} = \&Apache::Session::Serialize::JSON::serialize; $self->{unserialize} = \&Apache::Session::Serialize::JSON::unserialize; return $self; } sub searchOn { my $class = shift; my ( $args, $selectField, $value, @fields ) = @_; my $res = $class->SUPER::searchOn(@_); # Ensure fields case is preserved foreach (@fields) { if ( $_ ne lc($_) ) { foreach my $s ( keys %$res ) { $res->{$s}->{$_} = delete $res->{$s}->{ lc $_ } if $res->{$s}->{ lc $_ }; } } } return $res; } sub searchOnExpr { my $class = shift; my ( $args, $selectField, $value, @fields ) = @_; my $res = $class->SUPER::searchOnExpr(@_); # Ensure fields case is preserved foreach (@fields) { if ( $_ ne lc($_) ) { foreach my $s ( keys %$res ) { $res->{$s}->{$_} = delete $res->{$s}->{ lc $_ } if $res->{$s}->{ lc $_ }; } } } return $res; } 1; __END__ =head1 NAME Apache::Session::Browseable::Postgres - Add index and search methods to L =head1 SYNOPSIS Create table with columns for indexed fields. Example for Lemonldap::NG: CREATE UNLOGGED TABLE sessions ( id varchar(64) not null primary key, a_session text, _whatToTrace text, _session_kind text, _utime bigint, ipAddr varchar(64) ); Add indexes: CREATE INDEX uid1 ON sessions USING BTREE (_whatToTrace); CREATE INDEX s1 ON sessions (_session_kind); CREATE INDEX u1 ON sessions (_utime); CREATE INDEX ip1 ON sessions USING BTREE (ipAddr); Use it with Perl: use Apache::Session::Browseable::Postgres; my $args = { DataSource => 'dbi:Pg:sessions', UserName => $db_user, Password => $db_pass, Commit => 1, # Choose your browseable fileds Index => '_whatToTrace _session_kind _utime iAddr', }; # Use it like Apache::Session my %session; tie %session, 'Apache::Session::Browseable::Postgres', $id, $args; $session{uid} = 'me'; $session{mail} = 'me@me.com'; $session{unindexedField} = 'zz'; untie %session; # Apache::Session::Browseable add some global class methods # # 1) search on a field (indexed or not) my $hash = Apache::Session::Browseable::Postgres->searchOn( $args, 'uid', 'me' ); foreach my $id (keys %$hash) { print $id . ":" . $hash->{$id}->{mail} . "\n"; } # 2) Parse all sessions # a. get all sessions my $hash = Apache::Session::Browseable::Postgres->get_key_from_all_sessions(); # b. get some fields from all sessions my $hash = Apache::Session::Browseable::Postgres->get_key_from_all_sessions('uid', 'mail') # c. execute something with datas from each session : # Example : get uid and mail if mail domain is my $hash = Apache::Session::Browseable::Postgres->get_key_from_all_sessions( sub { my ( $session, $id ) = @_; if ( $session->{mail} =~ /mydomain.com$/ ) { return { $session->{uid}, $session->{mail} }; } } ); foreach my $id (keys %$hash) { print $id . ":" . $hash->{$id}->{uid} . "=>" . $hash->{$id}->{mail} . "\n"; } =head1 DESCRIPTION Apache::Session::Browseable provides some class methods to manipulate all sessions and add the capability to index some fields to make research faster. Apache::Session::Browseable::Postgres implements it for PosqtgreSQL databases. =head1 SEE ALSO L, L =head1 COPYRIGHT AND LICENSE =encoding utf8 =over =item 2009-2025 by Xavier Guimard =item 2013-2025 by Clément Oudot =item 2019-2025 by Maxime Besson =item 2013-2025 by Worteks =item 2023-2025 by Linagora =back This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.1 or, at your option, any later version of Perl 5 you may have available. =cut Apache-Session-Browseable-1.3.19/lib/Apache/Session/Browseable/Redis.pm000444001750001750 2605515201255027 24746 0ustar00yaddyadd000000000000package Apache::Session::Browseable::Redis; use strict; use Apache::Session; use Apache::Session::Browseable::Store::Redis; use Apache::Session::Generate::SHA256; use Apache::Session::Lock::Null; use Apache::Session::Serialize::JSON; use Apache::Session::Browseable::_common; our $VERSION = '1.3.18'; our @ISA = qw(Apache::Session); sub populate { my $self = shift; $self->{object_store} = new Apache::Session::Browseable::Store::Redis $self; $self->{lock_manager} = new Apache::Session::Lock::Null $self; $self->{generate} = \&Apache::Session::Generate::SHA256::generate; $self->{validate} = \&Apache::Session::Generate::SHA256::validate; $self->{serialize} = \&Apache::Session::Serialize::JSON::serialize; $self->{unserialize} = \&Apache::Session::Serialize::JSON::unserialize; return $self; } sub unserialize { my $session = shift; my $tmp = { serialized => $session }; Apache::Session::Serialize::JSON::unserialize($tmp); return $tmp->{data}; } sub searchOn { my ( $class, $args, $selectField, $value, @fields ) = @_; my %res = (); if ( $class->isIndexed( $args, $selectField ) ) { my $redisObj = $class->_getRedis($args); my $index_key = "${selectField}_$value"; my @keys = $redisObj->smembers($index_key); foreach my $k (@keys) { next unless ($k); my $tmp = $redisObj->get($k); unless ($tmp) { # Lazy cleanup: remove orphan from index eval { $redisObj->srem( $index_key, $k ) }; next; } eval { $tmp = unserialize($tmp); if (@fields) { $res{$k}->{$_} = $tmp->{$_} foreach (@fields); } else { $res{$k} = $tmp; } }; if ($@) { print STDERR "Error in session $k: $@\n"; delete $res{$k}; } } } else { $class->get_key_from_all_sessions( $args, sub { my $entry = shift; my $id = shift; return undef unless ( defined $entry->{$selectField} and $entry->{$selectField} eq $value ); if (@fields) { $res{$id}->{$_} = $entry->{$_} foreach (@fields); } else { $res{$id} = $entry; } undef; } ); } return \%res; } sub searchOnExpr { my ( $class, $args, $selectField, $value, @fields ) = @_; my %res; if ( $class->isIndexed( $args, $selectField ) ) { my $redisObj = $class->_getRedis($args); my $cursor = 0; do { my ( $new_cursor, $sets ) = $redisObj->scan( $cursor, MATCH => "${selectField}_$value" ); foreach my $set (@$sets) { next unless $redisObj->type($set) eq 'set'; my @keys = $redisObj->smembers($set); foreach my $k (@keys) { my $v = $redisObj->get($k); unless ($v) { # Lazy cleanup: remove orphan from index eval { $redisObj->srem( $set, $k ) }; next; } my $tmp = unserialize($v); if ($tmp) { $res{$k} = $class->extractFields( $tmp, @fields ); } } } $cursor = $new_cursor; } while ( $cursor != 0 ); } else { $value = quotemeta($value); $value =~ s/\\\*/\.\*/g; $value = qr/^$value$/; $class->get_key_from_all_sessions( $args, sub { my ( $entry, $id ) = @_; return undef unless ( $entry->{$selectField} =~ $value ); $res{$id} = $class->extractFields( $entry, @fields ); undef; } ); } return \%res; } sub deleteIfLowerThan { my ( $class, $args, $rule ) = @_; my $deleted = 0; my $redisObj = $class->_getRedis($args); my $index = ref( $args->{Index} ) ? $args->{Index} : [ split /\s+/, $args->{Index} ]; $class->get_key_from_all_sessions( $args, sub { my ( $v, $k ) = @_; if ( $rule->{not} ) { foreach ( keys %{ $rule->{not} } ) { if (defined( $v->{$_} ) and $v->{$_} eq $rule->{not}->{$_}) { return (); } } } # Empty or data-less sessions should be purged my $dominated = 0; if ( !$v || !%$v || !exists $v->{_session_id} ) { $dominated = 1; } elsif ( $rule->{or} ) { foreach ( keys %{ $rule->{or} } ) { if ( !defined( $v->{$_} ) ) { # Session missing a required field: treat as expired $dominated = 1; last; } if ( $v->{$_} < $rule->{or}->{$_} ) { $dominated = 1; last; } } } elsif ( $rule->{and} ) { my $res = 1; foreach ( keys %{ $rule->{and} } ) { $res = 0 unless !defined( $v->{$_} ) or $v->{$_} < $rule->{and}->{$_}; } $dominated = $res; } if ($dominated) { # Clean up index entries before deleting the session my $index_ok = 1; foreach my $i (@$index) { my $t = $v->{$i}; next unless ( defined($t) and length($t) > 0 ); eval { $redisObj->srem( "${i}_$t", $k ) }; if ($@) { warn "Failed to remove '$k' from index '${i}_$t': $@"; $index_ok = 0; } } if ($index_ok) { $redisObj->del($k); $deleted++; } else { warn "Skipping deletion of session '$k' due to index cleanup failure"; } } return (); }, ); return ( 1, $deleted ); } sub extractFields { my ( $class, $entry, @fields ) = @_; my $res; if (@fields) { $res->{$_} = $entry->{$_} foreach (@fields); } else { $res = $entry; } return $res; } sub isIndexed { my ( $class, $args, $field ) = @_; my $indexes = ref( $args->{Index} ) ? $args->{Index} : [ split /\s+/, $args->{Index} ]; return grep { $_ eq $field } @$indexes; } sub isLlngKey { my ( $class, $args, $name ) = @_; my $expr = $args->{keysRe} || '^[0-9a-f]{32,}$'; return ( $name =~ /$expr/o ); } sub get_key_from_all_sessions { my ( $class, $args, $data ) = @_; my %res; my $redisObj = $class->_getRedis($args); my $cursor = 0; do { my ( $new_cursor, $keys ) = $redisObj->scan($cursor); foreach my $k (@$keys) { # Keep only our keys next unless $class->isLlngKey( $args, $k ); # Don't scan sets,... next unless $redisObj->type($k) eq 'string'; eval { my $v = $redisObj->get($k); next unless $v; my $tmp = unserialize($v); if ( ref($data) eq 'CODE' ) { $tmp = &$data( $tmp, $k ); $res{$k} = $tmp if ( defined($tmp) ); } elsif ($data) { $data = [$data] unless ( ref($data) ); $res{$k}->{$_} = $tmp->{$_} foreach (@$data); } else { $res{$k} = $tmp; } }; if ($@) { print STDERR "Error in session $k: $@\n"; # Don't delete, it may own to another app #delete $res{$k}; } } $cursor = $new_cursor; } while ( $cursor != 0 ); return \%res; } sub _getRedis { my ( $class, $args ) = @_; return Apache::Session::Browseable::Store::Redis->_getRedis($args); } 1; __END__ =head1 NAME Apache::Session::Browseable::Redis - Add index and search methods to Apache::Session::Redis =head1 SYNOPSIS use Apache::Session::Browseable::Redis; my $args = { server => '127.0.0.1:6379', # Select database (optional) #database => 0, # Use a persistent connection to the Redis server # (value is the connection cache key) # You'll probably also want to set # read_timeout, write_timeout, reconnect and every reuse => "myserver", # Choose your browseable fields Index => 'uid mail', # Optional: set a Redis TTL on session keys (in seconds) # TTL => 86400, }; # Use it like Apache::Session my %session; tie %session, 'Apache::Session::Browseable::Redis', $id, $args; $session{uid} = 'me'; $session{mail} = 'me@me.com'; $session{unindexedField} = 'zz'; untie %session; # Apache::Session::Browseable add some global class methods # # 1) search on a field (indexed or not) my $hash = Apache::Session::Browseable::Redis->searchOn( $args, 'uid', 'me' ); foreach my $id (keys %$hash) { print $id . ":" . $hash->{$id}->{mail} . "\n"; } # 2) Parse all sessions # a. get all sessions my $hash = Apache::Session::Browseable::Redis->get_key_from_all_sessions($args); # b. get some fields from all sessions my $hash = Apache::Session::Browseable::Redis->get_key_from_all_sessions($args, 'uid', 'mail') # c. execute something with datas from each session : # Example : get uid and mail if mail domain is my $hash = Apache::Session::Browseable::Redis->get_key_from_all_sessions( $args, sub { my ( $session, $id ) = @_; if ( $session->{mail} =~ /mydomain.com$/ ) { return { $session->{uid}, $session->{mail} }; } } ); foreach my $id (keys %$hash) { print $id . ":" . $hash->{$id}->{uid} . "=>" . $hash->{$id}->{mail} . "\n"; } =head1 DESCRIPTION Apache::Session::browseable provides some class methods to manipulate all sessions and add the capability to index some fields to make research faster. This module use either L or L. =head1 SEE ALSO L =head1 COPYRIGHT AND LICENSE =over =item 2009-2025 by Xavier Guimard =item 2013-2025 by Clément Oudot =item 2019-2025 by Maxime Besson =item 2013-2025 by Worteks =item 2023-2025-2025 by Linagora =back This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.1 or, at your option, any later version of Perl 5 you may have available. =cut Apache-Session-Browseable-1.3.19/lib/Apache/Session/Browseable/SQLite.pm000444001750001750 542715201255027 25021 0ustar00yaddyadd000000000000############################################################################# # # Apache::Session::Browseable::SQLite # Apache persistent user sessions in a SQLite database # Copyright(c) 2013-2017 Xavier Guimard # Inspired by Apache::Session::Postgres # (copyright(c) 1998, 1999, 2000 Jeffrey William Baker (jwbaker@acm.org)) # Distribute under the Perl License # ############################################################################ package Apache::Session::Browseable::SQLite; use strict; use Apache::Session; use Apache::Session::Lock::Null; use Apache::Session::Browseable::Store::SQLite; use Apache::Session::Generate::SHA256; use Apache::Session::Serialize::JSON; use Apache::Session::Browseable::DBI; our $VERSION = '1.2.2'; our @ISA = qw(Apache::Session::Browseable::DBI Apache::Session); sub populate { my $self = shift; $self->{object_store} = new Apache::Session::Browseable::Store::SQLite $self; $self->{lock_manager} = new Apache::Session::Lock::Null $self; $self->{generate} = \&Apache::Session::Generate::SHA256::generate; $self->{validate} = \&Apache::Session::Generate::SHA256::validate; $self->{serialize} = \&Apache::Session::Serialize::JSON::serialize; $self->{unserialize} = \&Apache::Session::Serialize::JSON::unserialize; return $self; } 1; =pod =head1 NAME Apache::Session::Browseable::SQLite - An implementation of Apache::Session =head1 SYNOPSIS use Apache::Session::Browseable::SQLite; #if you want Apache::Session to open new DB handles: tie %hash, 'Apache::Session::Browseable::SQLite', $id, { DataSource => 'dbi:Pg:dbname=sessions', UserName => $db_user, Password => $db_pass, Commit => 1 }; #or, if your handles are already opened: tie %hash, 'Apache::Session::Browseable::SQLite', $id, { Handle => $dbh, Commit => 1 }; L function are also available =head1 DESCRIPTION This module is an implementation of Apache::Session. It uses the SQLite backing store and no locking. See the example, and the documentation for Apache::Session::Browseable::Store::SQLite for more details. =head1 USAGE The special Apache::Session argument for this module is Commit. You MUST provide the Commit argument, which instructs this module to either commit the transaction when it is finished, or to simply do nothing. This feature is provided so that this module will not have adverse interactions with your local transaction policy, nor your local database handle caching policy. The argument is mandatory in order to make you think about this problem. =head1 AUTHOR This module was written by Xavier Guimard using Apache::Session::Postgres from Jeffrey William Baker as example. =head1 SEE ALSO L Apache-Session-Browseable-1.3.19/lib/Apache/Session/Browseable/Sybase.pm000444001750001750 200515201255027 25073 0ustar00yaddyadd000000000000package Apache::Session::Browseable::Sybase; use strict; use Apache::Session; use Apache::Session::Lock::Null; use Apache::Session::Browseable::Store::Sybase; use Apache::Session::Generate::SHA256; use Apache::Session::Serialize::Sybase; use Apache::Session::Browseable::DBI; our $VERSION = '1.2.2'; our @ISA = qw(Apache::Session::Browseable::DBI Apache::Session); *serialize = \&Apache::Session::Serialize::Sybase::serialize; *unserialize = \&Apache::Session::Serialize::Sybase::unserialize; sub populate { my $self = shift; $self->{object_store} = new Apache::Session::Browseable::Store::Sybase $self; $self->{lock_manager} = new Apache::Session::Lock::Null $self; $self->{generate} = \&Apache::Session::Generate::SHA256::generate; $self->{validate} = \&Apache::Session::Generate::SHA256::validate; $self->{serialize} = \&Apache::Session::Serialize::Sybase::serialize; $self->{unserialize} = \&Apache::Session::Serialize::Sybase::unserialize; return $self; } 1; Apache-Session-Browseable-1.3.19/lib/Apache/Session/Browseable/_common.pm000444001750001750 332715201255027 25304 0ustar00yaddyadd000000000000package Apache::Session::Browseable::_common; use strict; use AutoLoader 'AUTOLOAD'; our $VERSION = '1.2.2'; sub _tabInTab { my ( $class, $t1, $t2 ) = @_; # if no fields are required, return 0 return 0 unless(@$t1 and @$t2); foreach my $f (@$t1) { unless ( grep { $_ eq $f } @$t2 ) { return 0; } } return 1; } sub _fieldIsIndexed { my ( $class, $args, $field ) = @_; my $index = ref( $args->{Index} ) ? $args->{Index} : [ split /\s+/, $args->{Index} ]; return ( grep { $_ eq $field } @$index ); } 1; __END__ sub searchOn { my ( $class, $args, $selectField, $value, @fields ) = splice @_; my %res = (); $class->get_key_from_all_sessions( $args, sub { my $entry = shift; my $id = shift; return undef unless ( $entry->{$selectField} eq $value ); if (@fields) { $res{$id}->{$_} = $entry->{$_} foreach (@fields); } else { $res{$id} = $entry; } undef; } ); return \%res; } sub searchOnExpr { my ( $class, $args, $selectField, $value, @fields ) = splice @_; $value = quotemeta($value); $value =~ s/\\\*/\.\*/g; $value = qr/^$value$/; my %res = (); $class->get_key_from_all_sessions( $args, sub { my $entry = shift; my $id = shift; return undef unless ( $entry->{$selectField} =~ $value ); if (@fields) { $res{$id}->{$_} = $entry->{$_} foreach (@fields); } else { $res{$id} = $entry; } undef; } ); return \%res; } 1; Apache-Session-Browseable-1.3.19/lib/Apache/Session/Browseable/Store000755001750001750 015201255027 24251 5ustar00yaddyadd000000000000Apache-Session-Browseable-1.3.19/lib/Apache/Session/Browseable/Store/Cassandra.pm000444001750001750 744015201255027 26650 0ustar00yaddyadd000000000000package Apache::Session::Browseable::Store::Cassandra; use strict; use Apache::Session::Store::DBI; use Apache::Session::Browseable::Store::DBI; use Apache::Session::Browseable::Store::Cassandra; our @ISA = qw(Apache::Session::Browseable::Store::DBI); our $VERSION = '1.3.13'; our $DataSource = undef; our $UserName = undef; our $Password = undef; sub connection { my $self = shift; my $session = shift; return if ( defined $self->{dbh} ); if ( exists $session->{args}->{Handle} ) { $self->{dbh} = $session->{args}->{Handle}; return; } my $datasource = $session->{args}->{DataSource} || $DataSource; my $username = $session->{args}->{UserName} || $UserName; my $password = $session->{args}->{Password} || $Password; $self->{dbh} = DBI->connect( $datasource, $username, $password, { RaiseError => 1 } ) || die $DBI::errstr; #If we open the connection, we close the connection $self->{disconnect} = 1; } sub materialize { my $self = shift; my $session = shift; $self->connection($session); local $self->{dbh}->{RaiseError} = 1; local $self->{dbh}->{LongReadLen} = $session->{args}->{LongReadLen} || 8 * 2**10; if ( !defined $self->{materialize_sth} ) { $self->{materialize_sth} = $self->{dbh}->prepare_cached( qq{ SELECT a_session FROM sessions WHERE id = ? FOR UPDATE} ); } $self->{materialize_sth}->bind_param( 1, $session->{data}->{_session_id} ); $self->{materialize_sth}->execute; my $results = $self->{materialize_sth}->fetchrow_arrayref; if ( !( defined $results ) ) { die "Object does not exist in the data store"; } $self->{materialize_sth}->finish; $session->{serialized} = $results->[0]; } sub DESTROY { my $self = shift; if ( $self->{disconnect} ) { $self->{dbh}->disconnect; } } 1; =pod =head1 NAME Apache::Session::Browseable::Store::Cassandra - Store persistent data in a Cassandra database =head1 SYNOPSIS use Apache::Session::Browseable::Store::Cassandra; my $store = new Apache::Session::Browseable::Store::Cassandra; $store->insert($ref); $store->update($ref); $store->materialize($ref); $store->remove($ref); =head1 DESCRIPTION Apache::Session::Browseable::Store::Cassandra fulfills the storage interface of Apache::Session. Session data is stored in a Cassandra database. =head1 SCHEMA To use this module, you will need at least these columns in a table called 'sessions': id text a_session text To create this schema, you can execute this command using cqlsh: CREATE TABLE sessions ( id text PRIMARY KEY, a_session text ); =head1 CONFIGURATION The module must know what datasource, username, and password to use when connecting to the database. These values can be set using the options hash (see Apache::Session documentation). The options are DataSource, UserName, and Password. Example: tie %hash, 'Apache::Session::Cassandra', $id, { DataSource => 'dbi:Cassandra:host=localhost;keyspace=llng', UserName => 'database_user', Password => 'K00l' }; Instead, you may pass in an already-opened DBI handle to your database. tie %hash, 'Apache::Session::Cassandra', $id, { Handle => $dbh }; =head1 SEE ALSO L, L =head1 COPYRIGHT AND LICENSE =encoding utf8 Copyright (C): =over =item 2009-2025 by Xavier Guimard =item 2013-2025 by Clément Oudot =item 2019-2025 by Maxime Besson =item 2013-2025 by Worteks =item 2023-2025 by Linagora =back This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.1 or, at your option, any later version of Perl 5 you may have available. =cut Apache-Session-Browseable-1.3.19/lib/Apache/Session/Browseable/Store/DBI.pm000444001750001750 361415201255027 25346 0ustar00yaddyadd000000000000package Apache::Session::Browseable::Store::DBI; use strict; use Apache::Session::Store::DBI; our @ISA = qw(Apache::Session::Store::DBI); our $VERSION = 1.3.11; sub insert { my ( $self, $session ) = @_; $self->connection($session); local $self->{dbh}->{RaiseError} = 1; my $index = ref( $session->{args}->{Index} ) ? $session->{args}->{Index} : [ split /\s+/, $session->{args}->{Index} ]; $self->{insert_sth} //= $self->{dbh}->prepare_cached( "INSERT INTO $self->{table_name} (" . join( ',', 'id', 'a_session', map { s/'/''/g; $_ } @$index ) . ') VALUES (' . join( ',', ('?') x ( 2 + @$index ) ) . ')' ); $self->{insert_sth}->bind_param( 1, $session->{data}->{_session_id} ); $self->{insert_sth}->bind_param( 2, $session->{serialized} ); my $i = 3; foreach my $f (@$index) { $self->{insert_sth}->bind_param( $i, $session->{data}->{$f} ); $i++; } $self->{insert_sth}->execute; $self->{insert_sth}->finish; } sub update { my $self = shift; my $session = shift; $self->connection($session); local $self->{dbh}->{RaiseError} = 1; my $index = ref( $session->{args}->{Index} ) ? $session->{args}->{Index} : [ split /\s+/, $session->{args}->{Index} ]; if ( !defined $self->{update_sth} ) { $self->{update_sth} = $self->{dbh}->prepare_cached( "UPDATE $self->{table_name} SET " . join( ' = ?, ', 'a_session', @$index ) . ' = ? WHERE id = ?' ); } $self->{update_sth}->bind_param( 1, $session->{serialized} ); my $i = 2; foreach my $f (@$index) { $self->{update_sth}->bind_param( $i, $session->{data}->{$f} ); $i++; } $self->{update_sth}->bind_param( $i, $session->{data}->{_session_id} ); $self->{update_sth}->execute; $self->{update_sth}->finish; } 1; Apache-Session-Browseable-1.3.19/lib/Apache/Session/Browseable/Store/File.pm000444001750001750 25515201255027 25605 0ustar00yaddyadd000000000000package Apache::Session::Browseable::Store::File; use strict; use Apache::Session::Store::File; our @ISA = qw(Apache::Session::Store::File); our $VERSION = 1.2.2; 1; Apache-Session-Browseable-1.3.19/lib/Apache/Session/Browseable/Store/Informix.pm000444001750001750 42015201255027 26513 0ustar00yaddyadd000000000000package Apache::Session::Browseable::Store::Informix; use strict; use Apache::Session::Browseable::Store::DBI; use Apache::Session::Store::Informix; our @ISA = qw(Apache::Session::Browseable::Store::DBI Apache::Session::Store::Informix); our $VERSION = '1.2.2'; 1; Apache-Session-Browseable-1.3.19/lib/Apache/Session/Browseable/Store/LDAP.pm000444001750001750 2110215201255027 25500 0ustar00yaddyadd000000000000package Apache::Session::Browseable::Store::LDAP; use strict; use Net::LDAP; our $VERSION = '1.3.8'; sub new { my $class = shift; return bless {}, $class; } sub insert { my $self = shift; my $session = shift; $self->{args} = $session->{args}; $self->{args}->{ldapObjectClass} ||= 'applicationProcess'; $self->{args}->{ldapAttributeId} ||= 'cn'; $self->{args}->{ldapAttributeContent} ||= 'description'; $self->{args}->{ldapAttributeIndex} ||= 'ou'; my $index = ref( $session->{args}->{Index} ) ? $session->{args}->{Index} : [ split /\s+/, $session->{args}->{Index} ]; my $id = $session->{data}->{_session_id}; my $attrIndex; foreach my $i (@$index) { my $t; next unless ( $t = $session->{data}->{$i} ); push @$attrIndex, "${i}_$t"; } my $attrs = [ objectClass => $self->{args}->{ldapObjectClass}, $self->{args}->{ldapAttributeId} => $session->{data}->{_session_id}, $self->{args}->{ldapAttributeContent} => $session->{serialized}, ]; push @$attrs, ( $self->{args}->{ldapAttributeIndex} => $attrIndex ) if ($attrIndex); my $msg = $self->ldap->add( $self->{args}->{ldapAttributeId} . "=$id," . $self->{args}->{ldapConfBase}, attrs => $attrs, ); $self->ldap->unbind() && delete $self->{ldap}; $self->logError($msg) if ( $msg->code ); } sub update { my $self = shift; my $session = shift; $self->{args} = $session->{args}; $self->{args}->{ldapObjectClass} ||= 'applicationProcess'; $self->{args}->{ldapAttributeId} ||= 'cn'; $self->{args}->{ldapAttributeContent} ||= 'description'; $self->{args}->{ldapAttributeIndex} ||= 'ou'; my $index = ref( $session->{args}->{Index} ) ? $session->{args}->{Index} : [ split /\s+/, $session->{args}->{Index} ]; my $id = $session->{data}->{_session_id}; my $attrIndex; foreach my $i (@$index) { my $t; next unless ( $t = $session->{data}->{$i} ); push @$attrIndex, "${i}_$t"; } my $attrs = { $self->{args}->{ldapAttributeContent} => $session->{serialized} }; $attrs->{ $self->{args}->{ldapAttributeIndex} } = $attrIndex if ($attrIndex); my $msg = $self->ldap->modify( $self->{args}->{ldapAttributeId} . "=" . $session->{data}->{_session_id} . "," . $self->{args}->{ldapConfBase}, replace => $attrs, ); $self->ldap->unbind() && delete $self->{ldap}; $self->logError($msg) if ( $msg->code ); } sub materialize { my $self = shift; my $session = shift; $self->{args} = $session->{args}; $self->{args}->{ldapObjectClass} ||= 'applicationProcess'; $self->{args}->{ldapAttributeId} ||= 'cn'; $self->{args}->{ldapAttributeContent} ||= 'description'; $self->{args}->{ldapAttributeIndex} ||= 'ou'; my $msg = $self->ldap->search( base => $self->{args}->{ldapAttributeId} . "=" . $session->{data}->{_session_id} . "," . $self->{args}->{ldapConfBase}, filter => '(objectClass=' . $self->{args}->{ldapObjectClass} . ')', scope => 'base', attrs => [ $self->{args}->{ldapAttributeContent} ], ); $self->ldap->unbind() && delete $self->{ldap}; $self->logError($msg) if ( $msg->code ); eval { $session->{serialized} = $msg->shift_entry() ->get_value( $self->{args}->{ldapAttributeContent} ); }; if ( !defined $session->{serialized} ) { die "Object does not exist in data store"; } } sub remove { my $self = shift; my $session = shift; $self->{args} = $session->{args}; $self->{args}->{ldapObjectClass} ||= 'applicationProcess'; $self->{args}->{ldapAttributeId} ||= 'cn'; $self->{args}->{ldapAttributeContent} ||= 'description'; $self->{args}->{ldapAttributeIndex} ||= 'ou'; $self->ldap->delete( $self->{args}->{ldapAttributeId} . "=" . $session->{data}->{_session_id} . "," . $self->{args}->{ldapConfBase} ); $self->ldap->unbind() && delete $self->{ldap}; } sub ldap { my $self = shift; return $self->{ldap} if ( $self->{ldap} ); # Parse servers configuration my $useTls = 0; my $tlsParam; my @servers = (); foreach my $server ( split /[\s,]+/, $self->{args}->{ldapServer} ) { if ( $server =~ m{^ldap\+tls://([^/]+)/?\??(.*)$} ) { $useTls = 1; $server = $1; $tlsParam = $2 || ""; } else { $useTls = 0; } push @servers, $server; } # Compatibility my $caFile = $self->{args}->{ldapCAFile} || $self->{args}->{caFile}; my $caPath = $self->{args}->{ldapCAPath} || $self->{args}->{caPath}; # Connect my $ldap = Net::LDAP->new( \@servers, onerror => undef, verify => $self->{args}->{ldapVerify} || "require", ( $caFile ? ( cafile => $caFile ) : () ), ( $caPath ? ( capath => $caPath ) : () ), ( $self->{args}->{ldapRaw} ? ( raw => $self->{args}->{ldapRaw} ) : () ), ( $self->{args}->{ldapPort} ? ( port => $self->{args}->{ldapPort} ) : () ), ( $self->{args}->{ldapTimeout} ? ( timeout => $self->{args}->{ldapTimeout} ) : () ), ) or die( 'Unable to connect to ' . join( ' ', @servers ) . ": " . $@ ); # Check SSL error for old Net::LDAP versions if ( $Net::LDAP::VERSION < '0.64' ) { # CentOS7 has a bug in which IO::Socket::SSL will return a broken # socket when certificate validation fails. Net::LDAP does not catch # it, and the process ends up crashing. # As a precaution, make sure the underlying socket is doing fine: if ( $ldap->socket->isa('IO::Socket::SSL') and $ldap->socket->errstr < 0 ) { die( "SSL connection error: " . $ldap->socket->errstr ); } } # Start TLS if needed if ($useTls) { my %h = split( /[&=]/, $tlsParam ); $h{verify} ||= ( $self->{args}->{ldapVerify} || "require" ); $h{cafile} ||= $caFile if ($caFile); $h{capath} ||= $caPath if ($caPath); my $start_tls = $ldap->start_tls(%h); if ( $start_tls->code ) { $self->logError($start_tls); return; } } # Bind with credentials my $bind = $ldap->bind( $self->{args}->{ldapBindDN}, password => $self->{args}->{ldapBindPassword} ); if ( $bind->code ) { $self->logError($bind); return; } $self->{ldap} = $ldap; return $ldap; } sub logError { my $self = shift; my $ldap_operation = shift; die "LDAP error " . $ldap_operation->code . ": " . $ldap_operation->error; } 1; =pod =head1 NAME Apache::Session::Browseable::Store::LDAP - Use LDAP to store persistent objects =head1 SYNOPSIS use Apache::Session::Browseable::Store::LDAP; my $store = new Apache::Session::Browseable::Store::LDAP; $store->insert($ref); $store->update($ref); $store->materialize($ref); $store->remove($ref); =head1 DESCRIPTION This module fulfills the storage interface of Apache::Session. The serialized objects are stored in an LDAP directory file using the Net::LDAP Perl module. =head1 OPTIONS This module requires one argument in the usual Apache::Session style. The keys ldapServer, ldapBase, ldapBindDN, ldapBindPassword are required. The key ldapPort, ldapObjectClass, ldapAttributeId, ldapAttributeContent, ldapAttributeIndex, and ldapRaw are optional. Example: tie %s, 'Apache::Session::Browseable::LDAP', undef, { ldapServer => 'localhost', ldapBase => 'dc=example,dc=com', ldapBindDN => 'cn=admin,dc=example,dc=com', ldapBindPassword => 'pass', Index => 'uid ipAddr', ldapObjectClass => 'applicationProcess', ldapAttributeId => 'cn', ldapAttributeContent => 'description', ldapAttributeIndex => 'ou', ldapRaw => '(?i:^jpegPhoto|;binary)', }; =head1 COPYRIGHT AND LICENSE =over =item 2009-2025 by Xavier Guimard =item 2013-2025 by Clément Oudot =item 2019-2025 by Maxime Besson =item 2013-2025 by Worteks =item 2023-2025 by Linagora =back This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.0 or, at your option, any later version of Perl 5 you may have available. =head1 SEE ALSO L =cut Apache-Session-Browseable-1.3.19/lib/Apache/Session/Browseable/Store/MySQL.pm000444001750001750 71215201255027 25671 0ustar00yaddyadd000000000000package Apache::Session::Browseable::Store::MySQL; use strict; use Apache::Session::Browseable::Store::DBI; use Apache::Session::Store::MySQL; our @ISA = qw(Apache::Session::Browseable::Store::DBI Apache::Session::Store::MySQL); our $VERSION = '1.2.2'; sub connection { my($self,$session)=@_; $self->SUPER::connection($session); if ( $self->{dbh}->{Driver}->{Name} eq "mysql" ) { $self->{dbh}->{mysql_enable_utf8} = 1; } } 1; Apache-Session-Browseable-1.3.19/lib/Apache/Session/Browseable/Store/Oracle.pm000444001750001750 41215201255027 26126 0ustar00yaddyadd000000000000package Apache::Session::Browseable::Store::Oracle; use strict; use Apache::Session::Browseable::Store::DBI; use Apache::Session::Store::Oracle; our @ISA = qw(Apache::Session::Browseable::Store::DBI Apache::Session::Store::Oracle); our $VERSION = '1.2.2'; 1; Apache-Session-Browseable-1.3.19/lib/Apache/Session/Browseable/Store/Patroni.pm000444001750001750 1774015201255027 26411 0ustar00yaddyadd000000000000package Apache::Session::Browseable::Store::Patroni; use strict; use DBI; use Apache::Session::Store::Postgres; our @ISA = qw(Apache::Session::Store::Postgres); our $VERSION = '1.3.19'; # Cache structure per DataSource: # { # leader => { host => '...', port => '...', time => ... }, # lastFailure => timestamp, # } our %patroniCache; sub connection { my $self = shift; my $session = shift; return if ( defined $self->{dbh} ); $self->{'table_name'} = $session->{args}->{TableName} || $Apache::Session::Store::DBI::TableName; if ( exists $session->{args}->{Handle} ) { $self->{dbh} = $session->{args}->{Handle}; $self->{commit} = $session->{args}->{Commit}; return; } # Store original DataSource as cache key my $originalDataSource = $session->{args}->{DataSource}; $self->{_originalDataSource} = $originalDataSource; # Use cached leader if available and not expired my $cache = $patroniCache{$originalDataSource} || {}; my $cacheTTL = $session->{args}->{PatroniCacheTTL} || 60; if ( $cache->{leader} and $cache->{leader}->{time} and ( time() - $cache->{leader}->{time} ) < $cacheTTL ) { $session->{args}->{DataSource} = _buildDataSource( $originalDataSource, $cache->{leader} ); } foreach ( 0 .. 1 ) { ( $self->checkMaster( $session->{args} ) or warn "Patroni check failed" ) if $self->{failure}; eval { $self->{dbh} = DBI->connect( $session->{args}->{DataSource}, $session->{args}->{UserName}, $session->{args}->{Password}, { RaiseError => 1, AutoCommit => 0 } ) || die $DBI::errstr; }; if ( $@ and !$_ ) { $self->{failure} = 1; } else { last; } } die $@ if $@; #If we open the connection, we close the connection $self->{disconnect} = 1; #the programmer has to tell us what commit policy to use $self->{commit} = $session->{args}->{Commit} // 1; } sub _try { my $self = shift; my $sub = shift; my $res; foreach ( 0 .. 1 ) { $res = eval { Apache::Session::Store::Postgres->can($sub)->( $self, @_ ) }; if ( $@ and $@ !~ /Object does not exist/ and !$_ ) { $self->{failure} = 1; $self->DESTROY; delete $self->{"${sub}_sth"}; delete $self->{dbh}; } else { last; } } die $@ if $@; return $res; } sub insert { my $self = shift; return $self->_try( 'insert', @_ ); } sub update { my $self = shift; return $self->_try( 'update', @_ ); } sub materialize { my $self = shift; return $self->_try( 'materialize', @_ ); } sub remove { my $self = shift; return $self->_try( 'remove', @_ ); } sub checkMaster { my ( $self, $args ) = @_; delete $self->{failure}; my $originalDataSource = $self->{_originalDataSource} || $args->{DataSource}; my $cache = $patroniCache{$originalDataSource} ||= {}; # Circuit breaker: avoid hammering Patroni API if it's failing my $circuitBreakerDelay = $args->{PatroniCircuitBreakerDelay} || 30; if ( $cache->{lastFailure} and ( time() - $cache->{lastFailure} ) < $circuitBreakerDelay ) { # Circuit breaker active, try cached leader as fallback return $self->_useCachedLeader( $args, $originalDataSource, "Circuit breaker active" ); } require JSON; require LWP::UserAgent; require IO::Socket::SSL; # SSL verification: secure by default, can be disabled with PatroniVerifySSL => 0 my $verify_ssl = $args->{PatroniVerifySSL} // 1; my %ssl_opts; if ($verify_ssl) { %ssl_opts = ( verify_hostname => 1, SSL_verify_mode => &IO::Socket::SSL::SSL_VERIFY_PEER, ( $args->{PatroniSSLCAFile} ? ( SSL_ca_file => $args->{PatroniSSLCAFile} ) : () ), ( $args->{PatroniSSLCAPath} ? ( SSL_ca_path => $args->{PatroniSSLCAPath} ) : () ), ); } else { %ssl_opts = ( verify_hostname => 0, SSL_verify_mode => &IO::Socket::SSL::SSL_VERIFY_NONE, ); } my $ua = LWP::UserAgent->new( env_proxy => 1, ssl_opts => \%ssl_opts, timeout => $args->{PatroniTimeout} || 3, ); my $res; foreach my $patroniUrl ( split /[,\s]\s*/, ( $args->{PatroniUrl} || $args->{patroniUrl} ) ) { my $resp = $ua->get($patroniUrl); if ( $resp->is_success ) { my $c = eval { JSON::from_json( $resp->decoded_content ) }; if ( $@ or !$c->{members} or ref( $c->{members} ) ne 'ARRAY' ) { print STDERR "Bad response from $patroniUrl: " . $resp->decoded_content . "\n"; next; } my @leaders = grep { $_->{role} eq 'leader' } @{ $c->{members} }; # Check for split-brain scenario if ( @leaders > 1 ) { my $leadersList = join( ', ', map { "$_->{host}:$_->{port}" } @leaders ); print STDERR "Multiple leaders detected (split-brain) from $patroniUrl" . " - Leaders: $leadersList\n"; next; } my ($leader) = @leaders; unless ($leader) { print STDERR "No leader found from $patroniUrl: " . $resp->decoded_content . "\n"; next; } # Validate leader has required fields unless ( defined $leader->{host} && defined $leader->{port} ) { print STDERR "Leader missing host or port from $patroniUrl: " . $resp->decoded_content . "\n"; next; } # Check leader health state if ( $leader->{state} && $leader->{state} ne 'running' ) { print STDERR "Leader not in running state (state=$leader->{state})" . " from $patroniUrl\n"; next; } # Cache the leader info $cache->{leader} = { host => $leader->{host}, port => $leader->{port}, time => time() }; # Reset circuit breaker on success delete $cache->{lastFailure}; $args->{DataSource} = _buildDataSource( $originalDataSource, $leader ); $res = 1; last; } } # If API failed, record for circuit breaker and try cached leader unless ($res) { $cache->{lastFailure} = time(); $res = $self->_useCachedLeader( $args, $originalDataSource, "Patroni API unavailable" ); } return $res; } # Use cached leader as fallback sub _useCachedLeader { my ( $self, $args, $originalDataSource, $reason ) = @_; my $cache = $patroniCache{$originalDataSource} || {}; my $cacheTTL = $args->{PatroniCacheTTL} || 60; if ( $cache->{leader} and $cache->{leader}->{time} and ( time() - $cache->{leader}->{time} ) < $cacheTTL ) { my $age = time() - $cache->{leader}->{time}; print STDERR "$reason, using cached leader (${age}s old)\n"; $args->{DataSource} = _buildDataSource( $originalDataSource, $cache->{leader} ); return 1; } return 0; } # Build DataSource string with new host/port sub _buildDataSource { my ( $originalDataSource, $leader ) = @_; my $chain = $originalDataSource; # Remove existing host/port parameters $chain =~ s/;\s*host=[^;]+//gi; $chain =~ s/;\s*port=[^;]+//gi; $chain =~ s/\s+host=[^\s;]+//gi; $chain =~ s/\s+port=[^\s;]+//gi; # Clean up trailing semicolons $chain =~ s/;+$//; # Add new host and port my $separator = ( $chain =~ /:$/ ) ? '' : ';'; return "${chain}${separator}host=$leader->{host};port=$leader->{port}"; } 1; Apache-Session-Browseable-1.3.19/lib/Apache/Session/Browseable/Store/Postgres.pm000444001750001750 61715201255027 26536 0ustar00yaddyadd000000000000package Apache::Session::Browseable::Store::Postgres; use strict; use Apache::Session::Browseable::Store::DBI; use Apache::Session::Store::Postgres; our @ISA = qw(Apache::Session::Browseable::Store::DBI Apache::Session::Store::Postgres); our $VERSION = '1.2.2'; sub connection { my($self,$session)=@_; $self->SUPER::connection($session); $self->{dbh}->{pg_enable_utf8} = 1; } 1; Apache-Session-Browseable-1.3.19/lib/Apache/Session/Browseable/Store/Redis.pm000444001750001750 1307515201255027 26040 0ustar00yaddyadd000000000000package Apache::Session::Browseable::Store::Redis; use strict; use JSON qw(decode_json); our $VERSION = '1.3.18'; our $redis; our %reused_connections; BEGIN { $redis = 'Redis::Fast'; eval 'use Redis::Fast'; if ($@) { require Redis; $redis = 'Redis'; } } sub new { my ( $class, $session ) = @_; my $self; $self->{cache} = $class->_getRedis( $session->{args} ); bless $self, $class; } sub insert { my ( $self, $session ) = @_; my $index = ref( $session->{args}->{Index} ) ? $session->{args}->{Index} : [ split /\s+/, $session->{args}->{Index} ]; my $id = $session->{data}->{_session_id}; my $ttl = $session->{args}->{TTL}; if ($ttl) { $self->{cache}->set( $id, $session->{serialized}, 'EX', $ttl ); } else { $self->{cache}->set( $id, $session->{serialized} ); } foreach my $i (@$index) { my $t = $session->{data}->{$i}; next unless ( defined($t) and ( length($t) > 0 ) ); $self->{cache}->sadd( "${i}_$t", $id ); } } sub update { my ( $self, $session ) = @_; my $index = ref( $session->{args}->{Index} ) ? $session->{args}->{Index} : [ split /\s+/, $session->{args}->{Index} ]; my $id = $session->{data}->{_session_id}; # Read old data to clean up stale index entries my $old_raw = eval { $self->{cache}->get($id) }; if ($@) { warn "Failed to read previous session '$id' from Redis: $@"; } my $old_data; if ( defined $old_raw && length $old_raw ) { $old_data = eval { decode_json($old_raw) }; if ($@) { warn "Failed to decode previous session '$id': $@"; } } # Store new data my $ttl = $session->{args}->{TTL}; if ($ttl) { $self->{cache}->set( $id, $session->{serialized}, 'EX', $ttl ); } else { $self->{cache}->set( $id, $session->{serialized} ); } foreach my $i (@$index) { my $old_val = defined($old_data) ? $old_data->{$i} : undef; my $new_val = $session->{data}->{$i}; # Remove old index entry if value changed if ( defined($old_val) && length($old_val) > 0 ) { if ( !defined($new_val) || length($new_val) == 0 || $old_val ne $new_val ) { eval { $self->{cache}->srem( "${i}_$old_val", $id ) }; } } # Add new index entry if ( defined($new_val) && length($new_val) > 0 ) { $self->{cache}->sadd( "${i}_$new_val", $id ); } } } sub materialize { my ( $self, $session ) = @_; $session->{serialized} = $self->{cache}->get( $session->{data}->{_session_id} ) or die 'Object does not exist in data store.'; } sub remove { my ( $self, $session ) = @_; my $index = ref( $session->{args}->{Index} ) ? $session->{args}->{Index} : [ split /\s+/, $session->{args}->{Index} ]; my $id = $session->{data}->{_session_id}; foreach my $i (@$index) { my $t; next unless ( $t = $session->{data}->{$i} ); eval { $self->{cache}->srem( "${i}_$t", $id ); }; } $self->{cache}->del($id); } sub _getRedis { my $class = shift; my $args = shift; my $redisObj; # Manage undef encoding $args->{encoding} = undef if ( $args->{encoding} and $args->{encoding} eq "undef" ); # If sentinels is not given as an array ref, try to parse # a comma delimited list instead if ( $args->{sentinels} and ref $args->{sentinels} ne 'ARRAY' ) { $args->{sentinels} = [ split /[,\s]+/, $args->{sentinels} ]; } if ( $args->{reuse} and $reused_connections{ $args->{reuse} } ) { $redisObj = $reused_connections{ $args->{reuse} }; } else { $redisObj = $redis->new( %{$args} ); if ( $args->{reuse} ) { $reused_connections{ $args->{reuse} } = $redisObj; } } # Manage database $redisObj->select( $args->{database} ) if defined $args->{database}; return $redisObj; } 1; __END__ =pod =head1 NAME Apache::Session::Browseable::Store::Redis - An implementation of Apache::Session::Store =head1 SYNOPSIS use Apache::Session::Browseable::Redis; tie %hash, 'Apache::Session::Browseable::Redis', $id, { # optional: default to localhost server => '127.0.0.1:6379', # optional: set a Redis TTL (in seconds) on session keys TTL => 86400, }; =head1 DESCRIPTION This module is an implementation of Apache::Session::Browseable. It uses the Redis storage system. =head1 OPTIONS =over =item B Optional. If set, session keys will be stored with a Redis TTL (in seconds) using C. The TTL is refreshed on every update. This acts as a safety net: sessions are automatically removed by Redis if the application fails to delete them. Index sets are not expired by Redis, but orphan index entries will be cleaned up by C or manual maintenance. Without this option, session keys have no expiration and must be explicitly deleted or purged. =back =head1 SEE ALSO L, L, L =head1 COPYRIGHT AND LICENSE =over =item 2009-2025 by Xavier Guimard =item 2013-2025 by Clément Oudot =item 2019-2025 by Maxime Besson =item 2013-2025 by Worteks =item 2023-2025 by Linagora =back This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.1 or, at your option, any later version of Perl 5 you may have available. =cut Apache-Session-Browseable-1.3.19/lib/Apache/Session/Browseable/Store/SQLite.pm000444001750001750 1104615201255027 26127 0ustar00yaddyadd000000000000############################################################################# # # Apache::Session::Browseable::SQLite # Apache persistent user sessions in a SQLite database # Copyright(c) 2013 Xavier Guimard # Inspired by Apache::Session::Store::Postgres # (copyright(c) 1998, 1999, 2000 Jeffrey William Baker (jwbaker@acm.org)) # Distribute under the Perl License # ############################################################################ package Apache::Session::Browseable::Store::SQLite; use strict; use DBI; use Apache::Session::Store::DBI; use Apache::Session::Browseable::Store::DBI; our @ISA = qw(Apache::Session::Browseable::Store::DBI Apache::Session::Store::DBI); our $VERSION = '1.2.7'; $Apache::Session::Browseable::Store::SQLite::DataSource = undef; sub connection { my $self = shift; my $session = shift; return if ( defined $self->{dbh} ); $session->{args}->{Commit} = exists( $session->{args}->{Commit} ) ? $session->{args}->{Commit} : 1; $self->{'table_name'} = $session->{args}->{TableName} || $Apache::Session::Store::DBI::TableName; if ( exists $session->{args}->{Handle} ) { $self->{dbh} = $session->{args}->{Handle}; $self->{commit} = $session->{args}->{Commit}; return; } my $datasource = $session->{args}->{DataSource} || $Apache::Session::Store::MySQL::DataSource; $self->{dbh} = DBI->connect( $datasource, '', '', { RaiseError => 1, AutoCommit => 0 } ) || die $DBI::errstr; $self->{dbh}->{sqlite_unicode} = 1; #If we open the connection, we close the connection $self->{disconnect} = 1; #the programmer has to tell us what commit policy to use $self->{commit} = $session->{args}->{Commit}; } sub materialize { my $self = shift; my $session = shift; $self->connection($session); local $self->{dbh}->{RaiseError} = 1; if ( !defined $self->{materialize_sth} ) { $self->{materialize_sth} = $self->{dbh}->prepare_cached( qq{ SELECT a_session FROM $self->{'table_name'} WHERE id = ?} ); } $self->{materialize_sth}->bind_param( 1, $session->{data}->{_session_id} ); $self->{materialize_sth}->execute; my $results = $self->{materialize_sth}->fetchrow_arrayref; if ( !( defined $results ) ) { $self->{materialize_sth}->finish; die "Object does not exist in the data store"; } $self->{materialize_sth}->finish; $session->{serialized} = $results->[0]; } sub DESTROY { my $self = shift; if ( $self->{commit} ) { $self->{dbh}->commit; } if ( $self->{disconnect} ) { $self->{dbh}->disconnect; } } 1; =pod =head1 NAME Apache::Session::Browseable::Store::SQLite - Store persistent data in a SQLite database =head1 SYNOPSIS use Apache::Session::Browseable::Store::SQLite; my $store = new Apache::Session::Browseable::Store::SQLite; $store->insert($ref); $store->update($ref); $store->materialize($ref); $store->remove($ref); =head1 DESCRIPTION Apache::Session::Browseable::Store::SQLite fulfills the storage interface of Apache::Session. Session data is stored in a SQLite database. =head1 SCHEMA To use this module, you will need at least these columns in a table called 'sessions', or another name if you supply the TableName parameter. id char(32) # or however long your session IDs are. a_session text # This has an ~8 KB limit :( To create this schema, you can execute this command using the sqlite program: CREATE TABLE sessions ( id char(32) not null primary key, a_session text ); If you use some other command, ensure that there is a unique index on the table's id column. =head1 CONFIGURATION The module must know what datasource, username, and password to use when connecting to the database. These values can be set using the options hash (see Apache::Session documentation). The options are: =over 4 =item DataSource =item UserName =item Password =item Handle =item TableName =back Example: tie %hash, 'Apache::Session::Browseable::SQLite', $id, { DataSource => 'dbi:Pg:dbname=database', UserName => 'database_user', Password => 'K00l' }; Instead, you may pass in an already-opened DBI handle to your database. tie %hash, 'Apache::Session::Browseable::SQLite', $id, { Handle => $dbh }; =head1 AUTHOR This modules was written by Jeffrey William Baker A fix for the commit policy was contributed by Michael Schout =head1 SEE ALSO L, L Apache-Session-Browseable-1.3.19/lib/Apache/Session/Browseable/Store/Sybase.pm000444001750001750 41215201255027 26147 0ustar00yaddyadd000000000000package Apache::Session::Browseable::Store::Sybase; use strict; use Apache::Session::Browseable::Store::DBI; use Apache::Session::Store::Sybase; our @ISA = qw(Apache::Session::Browseable::Store::DBI Apache::Session::Store::Sybase); our $VERSION = '1.2.2'; 1; Apache-Session-Browseable-1.3.19/lib/Apache/Session/Generate000755001750001750 015201255027 22622 5ustar00yaddyadd000000000000Apache-Session-Browseable-1.3.19/lib/Apache/Session/Generate/SHA256.pm000444001750001750 231715201255027 24170 0ustar00yaddyadd000000000000# Directly copied from LemonLDAP::NG project (http://lemonldap-ng.org/) package Apache::Session::Generate::SHA256; use strict; use vars qw($VERSION); use Crypt::URandom; $VERSION = '1.3.19'; sub generate { my $session = shift; my $length = 64; if ( exists $session->{args}->{IDLength} ) { $length = $session->{args}->{IDLength}; } eval { $session->{data}->{_session_id} = substr( unpack( 'H*', Crypt::URandom::urandom( int( ( $length + 1 ) / 2 ) ) ), 0, $length ); }; if ($@) { require Digest::SHA; $session->{data}->{_session_id} = substr( Digest::SHA::sha256_hex( Digest::SHA::sha256_hex( time() . {} . rand() . $$ ) ), 0, $length ); } } sub validate { #This routine checks to ensure that the session ID is in the form #we expect. This must be called before we start diddling around #in the database or the disk. my $session = shift; if ( $session->{data}->{_session_id} =~ /^([a-fA-F0-9]+)$/ ) { $session->{data}->{_session_id} = $1; } else { die "Invalid session ID: " . $session->{data}->{_session_id}; } } 1; Apache-Session-Browseable-1.3.19/lib/Apache/Session/Serialize000755001750001750 015201255027 23017 5ustar00yaddyadd000000000000Apache-Session-Browseable-1.3.19/lib/Apache/Session/Serialize/Hstore.pm000444001750001750 533415201255027 24763 0ustar00yaddyadd000000000000package Apache::Session::Serialize::Hstore; use strict; use JSON qw(to_json from_json); our $VERSION = '1.2.5'; sub serialize { my ($session) = @_; $session->{serialized} = {}; my $data = $session->{data}; my $res = ''; if ( ref $data and %$data ) { foreach ( keys %$data ) { my $v; if ( ref $data->{$_} ) { $v = '_json://' . to_json( $data->{$_} ); } else { $v = $data->{$_}; } $v =~ s/"/#%22/g; $res .= qq'"$_" => "$v",'; } } $res =~ s/,$//; $session->{serialized} = $res; } sub unserialize { my ($session) = @_; my $data = _unserialize( $session->{serialized} ); die "Session could not be unserialized" unless defined $data; $session->{data} = $data; } sub _unserialize { my ( $serialized, $next ) = @_; my $res = {}; while ( $serialized =~ s/\s*"([^"]*)"\s*=>\s*"([^"]*)"\s*,?// ) { my ( $k, $v ) = ( $1, $2 ); $v =~ s/#%22/"/g; if ( $v =~ s#^_json://## ) { my $tmp; eval { $tmp = from_json($v) }; if ($@) { print STDERR "JSON error: $@\n"; return undef; } $v = $tmp; } $res->{$k} = $v; } return $res; } 1; =pod =head1 NAME =encoding utf8 Apache::Session::Serialize::Hstore - Serialize/unserialize datas for PostgreSQL "hstore" storage. =head1 SYNOPSIS use Apache::Session::Serialize::Hstore; $zipped = Apache::Session::Serialize::Hstore::serialize($ref); $ref = Apache::Session::Serialize::Hstore::unserialize($zipped); =head1 DESCRIPTION This module fulfills the serialization interface of Apache::Session. It serializes only ref data value for PostgreSQL "hstore" fields. =head1 SEE ALSO L, L =head1 BUG REPORT Use OW2 system to report bug or ask for features: L =head1 COPYRIGHT AND LICENSE =over =item 2009-2025 by Xavier Guimard =item 2013-2025 by Clément Oudot =item 2019-2025 by Maxime Besson =item 2013-2025 by Worteks =item 2023-2025 by Linagora =back This library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see L. =cut Apache-Session-Browseable-1.3.19/lib/Apache/Session/Serialize/JSON.pm000444001750001750 430515201255027 24265 0ustar00yaddyadd000000000000# Directly copied from Lemonldap::NG project (http://lemonldap-ng.org/) package Apache::Session::Serialize::JSON; use strict; use JSON qw(to_json from_json); our $VERSION = '1.2.6'; sub serialize { my $session = shift; $session->{serialized} = to_json( $session->{data}, { allow_nonref => 1 } ); } sub unserialize { my ( $session, $next ) = @_; my $data = _unserialize( $session->{serialized}, $next ); die "Session could not be unserialized" unless defined $data; $session->{data} = $data; } sub _unserialize { my ( $serialized, $next ) = @_; my $tmp; eval { $tmp = from_json( $serialized, { allow_nonref => 1 } ) }; if ($@) { require Storable; $next ||= \&Storable::thaw; return &$next($serialized); } return $tmp; } 1; =pod =head1 NAME =encoding utf8 Apache::Session::Serialize::JSON - Use JSON to zip up data =head1 SYNOPSIS use Apache::Session::Serialize::JSON; $zipped = Apache::Session::Serialize::JSON::serialize($ref); $ref = Apache::Session::Serialize::JSON::unserialize($zipped); =head1 DESCRIPTION This module fulfills the serialization interface of Apache::Session. It serializes the data in the session object by use of JSON C and C. The serialized data is UTF-8 text. =head1 SEE ALSO L, L =head1 BUG REPORT Use OW2 system to report bug or ask for features: L =head1 COPYRIGHT AND LICENSE =over =item 2009-2025 by Xavier Guimard =item 2013-2025 by Clément Oudot =item 2019-2025 by Maxime Besson =item 2013-2025 by Worteks =item 2023-2025 by Linagora =back This library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see L. =cut Apache-Session-Browseable-1.3.19/rpm000755001750001750 015201255027 16314 5ustar00yaddyadd000000000000Apache-Session-Browseable-1.3.19/rpm/Apache-Session-Browseable.spec000444001750001750 505315201255027 24215 0ustar00yaddyadd000000000000#============================================================================== # Specification file for Apache::Session::Browseable #============================================================================== %define real_name Apache-Session-Browseable %define real_version 1.3.14 #============================================================================== # Main package #============================================================================== Name: perl-%{real_name} Version: %{real_version} Release: 1%{?dist} Summary: Add index and search methods to Apache::Session Group: Applications/System License: GPL+ or Artistic URL: http://search.cpan.org/dist/Apache-Session-Browseable/ Source0: http://search.cpan.org/CPAN/authors/id/G/GU/GUIMARD/%{real_name}-%{real_version}.tar.gz BuildRoot: %{_tmppath}/%{name}-%{version}-%{release} BuildArch: noarch BuildRequires: perl BuildRequires: perl(Apache::Session) BuildRequires: perl(Module::Build) Requires: perl(Apache::Session) %description Virutal Apache::Session backend allowing to browse sessions upon criteria. %prep %setup -n %{real_name}-%{real_version} -q # Redis not mandatory cat << \EOF > %{name}-req #!/bin/sh %{__perl_requires} $* |\ sed -e '/perl(Redis)/d' EOF %define __perl_requires %{_builddir}/%{real_name}-%{real_version}/%{name}-req chmod +x %{__perl_requires} %if 0%{?rhel} >= 7 %{?perl_default_filter} %global __requires_exclude perl\\(Redis %endif %build perl Build.PL --installdirs=vendor ./Build %install rm -rf %{buildroot} ./Build install --destdir=%{buildroot} --create_packlist=0 %check ./Build test %files %defattr(-,root,root,-) %doc %{_mandir}/man3/Apache::Session::*.3pm.gz %{perl_vendorlib}/Apache/Session/* %{perl_vendorlib}/auto/Apache/Session/* %changelog * Thu Dec 19 2024 Clement Oudot - 1.3.14-1 - Update to 1.3.14 * Wed Aug 18 2021 Clement Oudot - 1.3.9-1 - Update to 1.3.9 * Sun Sep 06 2020 Clement Oudot - 1.3.8-1 - Update to 1.3.8 * Fri Sep 04 2020 Clement Oudot - 1.3.7-1 - Update to 1.3.7 * Fri Jan 17 2020 Clement Oudot - 1.3.5-1 - Update to 1.3.5 * Thu Sep 19 2019 Clement Oudot - 1.3.3-1 - Update to 1.3.3 * Thu Jul 04 2019 Clement Oudot - 1.3.2-1 - Update to 1.3.2 * Tue Jan 23 2018 Clement Oudot - 1.2.8-1 - Update to 1.2.8 * Mon Jan 12 2015 Clement Oudot - 1.0.2-1 - First package for 1.0.2 Apache-Session-Browseable-1.3.19/t000755001750001750 015201255027 15761 5ustar00yaddyadd000000000000Apache-Session-Browseable-1.3.19/t/Apache-Session-Browseable-Cassandra.t000444001750001750 31415201255027 25043 0ustar00yaddyadd000000000000use Test::More; plan skip_all => "Optional modules (DBD::Cassandra) not installed" unless eval { require DBD::Cassandra; }; plan tests => 1; use_ok('Apache::Session::Browseable::Cassandra'); Apache-Session-Browseable-1.3.19/t/Apache-Session-Browseable-DBI.t000444001750001750 26015201255027 23542 0ustar00yaddyadd000000000000use Test::More; plan skip_all => "Optional modules (DBI) not installed" unless eval { require DBI; }; plan tests => 1; use_ok('Apache::Session::Browseable::DBI'); Apache-Session-Browseable-1.3.19/t/Apache-Session-Browseable-File.t000444001750001750 14715201255027 24027 0ustar00yaddyadd000000000000use Test::More; plan tests => 1; $package = 'Apache::Session::Browseable::File'; use_ok($package); Apache-Session-Browseable-1.3.19/t/Apache-Session-Browseable-LDAP.t000444001750001750 33315201255027 23665 0ustar00yaddyadd000000000000use Test::More; plan skip_all => "Optional modules (Net::LDAP) not installed" unless eval { require Net::LDAP; }; plan tests => 1; $package = 'Apache::Session::Browseable::Store::LDAP'; use_ok($package); Apache-Session-Browseable-1.3.19/t/Apache-Session-Browseable-Patroni.t000444001750001750 224515201255027 24605 0ustar00yaddyadd000000000000use Test::More; plan skip_all => "Optional modules (DBD::Pg, DBI) not installed" unless eval { require DBI; require DBD::Pg; }; $package = 'Apache::Session::Browseable::Store::Patroni'; use_ok($package); my $foo = $package->new; isa_ok $foo, $package; $package = 'Apache::Session::Browseable::Patroni'; use_ok($package); SKIP: { skip 'No patroniUrl, skipping', 1 unless $ENV{PATRONI_URL}; my $args = { DataSource => 'dbi:Pg:dbname=sessions;host=' . ( $ENV{PG_HOST} || '127.25.76.98:port=300' ), UserName => 'postgres', Password => 'postgres', PatroniUrl => $ENV{PATRONI_URL}, }; my %h; tie %h, $package, undef, $args; ok( %h && $h{_session_id}, 'Hash populated' ); my $id = $h{_session_id}; $h{a} = 'aa'; untie %h; %h = (); tie %h, $package, $id, $args; is( $h{a}, 'aa', 'data stored' ); untie %h; if ($ENV{PATRONI_NEXT}) { diag `$ENV{PATRONI_NEXT}`; sleep 1; } tie %h, $package, $id, $args; $h{a} = 'bb'; untie %h; %h = (); tie %h, $package, $id, $args; is( $h{a}, 'bb', 'data changed' ); untie %h; } done_testing(); Apache-Session-Browseable-1.3.19/t/Apache-Session-Browseable-Redis.t000444001750001750 2341715201255027 24263 0ustar00yaddyadd000000000000use Test::More; use JSON qw/from_json encode_json/; use utf8; our $test_dburl = $ENV{REDIS_URL} || 'localhost:6379'; our $test_dbnum = $ENV{REDIS_DBNUM} || 15; our $r; # Redis handle used for asserts plan skip_all => "Optional modules (Redis) not installed" unless eval { require Redis; }; plan skip_all => "Redis error : $@" unless eval { $r = Redis->new( server => $test_dburl ); $r->select($test_dbnum); $r->flushall(); }; plan tests => 57; $package = 'Apache::Session::Browseable::Redis'; use_ok($package); my $args = { server => $test_dburl, database => $test_dbnum, # Choose your browseable fileds Index => 'uid sn mail int2', }; use Data::Dumper; my $id; my $json; is( keys %{ $r->keys('*') }, 0, "Make sure database is empty" ); # Create new session my %session; tie %session, $package, $id, $args; $session{uid} = 'mé'; $session{mail} = 'mé@me.com'; $session{color} = 'zz'; $id = $session{_session_id}; untie %session; # Make sure it was stored: ok( $r->exists($id), "Test if new session id exists as a key in Redis" ); ok( $r->exists("uid_mé"), "Test if index exists" ); ok( $json = from_json( $r->get($id) ), "Parse redis value as JSON" ); is( $json->{mail}, 'mé@me.com', "Test if session subkey was correctly stored" ); # Read existing session tie %session, $package, $id, $args; is( $session{mail}, 'mé@me.com', "Test if session subkey can be read" ); # Delete session; tied(%session)->delete; ok( !$r->exists($id), "Test if new session id was removed" ); ok( !$r->exists("uid_mé"), "Test if index was removed" ); is( keys %{ $r->keys('*') }, 0, "Make sure database is empty after removal" ); untie %session; # Create a bunch of sessions to search on my ( %session1, %session2, %session3, %session4, %session5, $id1, $id2, $id3, $id4, $id5 ); tie %session1, $package, undef, $args; $session1{uid} = 'obiwan'; $session1{sn} = 'Kenobi'; $session1{color} = 'blue'; $session1{int1} = 10; $session1{int2} = 20; $id1 = $session1{_session_id}; untie %session1; tie %session2, $package, undef, $args; $session2{uid} = 'darthvader'; $session2{sn} = 'Skywalker'; $session2{color} = 'red'; $session2{int1} = 11; $session2{int2} = 21; $id2 = $session2{_session_id}; untie %session2; tie %session3, $package, undef, $args; $session3{uid} = 'luke'; $session3{sn} = 'Skywalker'; $session3{color} = 'green'; $session3{int1} = 12; $session3{int2} = 24; $id3 = $session3{_session_id}; untie %session3; tie %session4, $package, undef, $args; $session4{uid} = 'mace'; $session4{sn} = 'Windu'; $session4{color} = 'purple'; $session4{int1} = 13; $session4{int2} = 23; $id4 = $session4{_session_id}; untie %session4; tie %session5, $package, undef, $args; $session5{uid} = 'yoda'; $session5{sn} = 'Yoda'; $session5{color} = 'green'; $session5{int1} = 14; $session5{int2} = 22; $id5 = $session5{_session_id}; untie %session5; # Pollutes Redis my $redis = 'Apache::Session::Browseable::Store::Redis'->_getRedis($args); $redis->set( 'aaaa', 'bbbb' ); $redis->set( '@aaaa:aa', 'bbbb/bb' ); # Search all keys my $hash = $package->get_key_from_all_sessions( $args, "uid" ); is( keys %$hash, 5, "Found all 5 session" ); ok( exists( $hash->{$id4} ), "Found 'mace' in result" ); is( $hash->{$id4}->{uid}, 'mace', "Correct value in session 4" ); ok( !defined( $hash->{$id4}->{sn} ), 'only uid is returned' ); $hash = $package->get_key_from_all_sessions($args); is( keys %$hash, 5, "Found all 5 session" ); ok( exists( $hash->{$id4} ), "Found 'mace' in result" ); is( $hash->{$id4}->{uid}, 'mace', "Correct value in session 4" ); is( $hash->{$id4}->{sn}, 'Windu', 'All fields are returned' ); # Search on indexed field $hash = $package->searchOn( $args, 'sn', 'Skywalker' ); is( keys %$hash, 2, "Found 2 session" ); is( $hash->{$id2}->{uid}, 'darthvader', "Correct value" ); is( $hash->{$id3}->{uid}, 'luke', "Correct value" ); $hash = $package->searchOnExpr( $args, 'sn', '*walker' ); is( keys %$hash, 2, "Found 2 session" ); is( $hash->{$id2}->{uid}, 'darthvader', "Correct value" ); is( $hash->{$id3}->{uid}, 'luke', "Correct value" ); # Search on unindexed field $hash = $package->searchOn( $args, 'color', 'green' ); is( keys %$hash, 2, "Found 2 session" ); is( $hash->{$id3}->{uid}, 'luke', "Correct value" ); is( $hash->{$id5}->{uid}, 'yoda', "Correct value" ); $hash = $package->searchOnExpr( $args, 'color', '*ee*', 'uid' ); is( keys %$hash, 2, "Found 2 session" ); is( $hash->{$id3}->{uid}, 'luke', "Correct value" ); is( $hash->{$id5}->{uid}, 'yoda', "Correct value" ); ok( !defined( $hash->{$id3}->{sn} ), 'only uid is returned' ); # Test that updating an indexed field cleans up the old index tie %session1, $package, $id1, $args; ok( $r->sismember( "uid_obiwan", $id1 ), "Before update: id1 is in uid_obiwan index" ); $session1{uid} = 'benkenobi'; untie %session1; ok( !$r->sismember( "uid_obiwan", $id1 ), "After update: id1 removed from old uid_obiwan index" ); ok( $r->sismember( "uid_benkenobi", $id1 ), "After update: id1 added to new uid_benkenobi index" ); # Verify searchOn uses the updated index $hash = $package->searchOn( $args, 'uid', 'obiwan' ); is( keys %$hash, 0, "searchOn old value returns nothing" ); $hash = $package->searchOn( $args, 'uid', 'benkenobi' ); is( keys %$hash, 1, "searchOn new value returns 1" ); is( $hash->{$id1}->{uid}, 'benkenobi', "Correct updated value" ); # Restore original value for subsequent tests tie %session1, $package, $id1, $args; $session1{uid} = 'obiwan'; untie %session1; # Test that setting an indexed field to empty removes the index entry tie %session1, $package, $id1, $args; $session1{sn} = 'Kenobi'; untie %session1; ok( $r->sismember( "sn_Kenobi", $id1 ), "sn_Kenobi index contains id1" ); tie %session1, $package, $id1, $args; $session1{sn} = ''; untie %session1; ok( !$r->sismember( "sn_Kenobi", $id1 ), "After clearing sn, old index entry removed" ); # Restore for deleteIfLowerThan test tie %session1, $package, $id1, $args; $session1{sn} = 'Kenobi'; untie %session1; # Test deleteIfLowerThan cleans up indexes $package->deleteIfLowerThan( $args, { or => { int1 => 12, int2 => 23, }, not => { uid => 'yoda', } } ); $hash = $package->get_key_from_all_sessions($args); is( keys %$hash, 3, "Found 3 sessions after deleteIfLowerThan" ); # Verify that deleted sessions were removed from indexes ok( !$r->sismember( "uid_obiwan", $id1 ), "deleteIfLowerThan cleaned uid index for deleted session" ); ok( !$r->sismember( "sn_Kenobi", $id1 ), "deleteIfLowerThan cleaned sn index for deleted session" ); ok( !$r->sismember( "uid_darthvader", $id2 ), "deleteIfLowerThan cleaned uid index for session 2" ); ok( $r->sismember( "uid_luke", $id3 ), "Surviving session still in uid index" ); ok( $r->sismember( "uid_yoda", $id5 ), "Excluded session (yoda) still in uid index" ); # Test that deleteIfLowerThan purges sessions missing required fields # Create a session with no _utime (simulates an empty/interrupted session) my %session_empty; tie %session_empty, $package, undef, $args; my $id_empty = $session_empty{_session_id}; $session_empty{uid} = 'ghost'; untie %session_empty; # Remove _utime manually to simulate a bare session my $raw_empty = $r->get($id_empty); my $data_empty = from_json($raw_empty); delete $data_empty->{_utime}; $r->set($id_empty, JSON::encode_json($data_empty)); $hash = $package->get_key_from_all_sessions($args); ok( exists $hash->{$id_empty}, "Empty session exists before purge" ); $package->deleteIfLowerThan( $args, { or => { _utime => time }, } ); $hash = $package->get_key_from_all_sessions($args); ok( !exists $hash->{$id_empty}, "Session without _utime purged by deleteIfLowerThan" ); ok( !$r->sismember( "uid_ghost", $id_empty ), "Index cleaned for purged empty session" ); # Test lazy cleanup of orphan index entries in searchOn/searchOnExpr $r->flushall; my %session_lz1; tie %session_lz1, $package, undef, $args; $session_lz1{uid} = 'alive'; $session_lz1{mail} = 'alive@test.com'; my $id_lz1 = $session_lz1{_session_id}; untie %session_lz1; my %session_lz2; tie %session_lz2, $package, undef, $args; $session_lz2{uid} = 'alive'; $session_lz2{mail} = 'dead@test.com'; my $id_lz2 = $session_lz2{_session_id}; untie %session_lz2; # Both should be in uid_alive index ok( $r->sismember( "uid_alive", $id_lz1 ), "Session lz1 in uid_alive index" ); ok( $r->sismember( "uid_alive", $id_lz2 ), "Session lz2 in uid_alive index" ); # Delete lz2 directly from Redis (simulates TTL expiration) $r->del($id_lz2); # searchOn should return only lz1 and clean orphan lz2 from index $hash = $package->searchOn( $args, 'uid', 'alive' ); is( keys %$hash, 1, "searchOn returns only the surviving session" ); ok( exists $hash->{$id_lz1}, "searchOn returns lz1" ); ok( !$r->sismember( "uid_alive", $id_lz2 ), "searchOn lazy cleanup removed orphan lz2 from index" ); ok( $r->sismember( "uid_alive", $id_lz1 ), "searchOn kept valid lz1 in index" ); # Test lazy cleanup in searchOnExpr my %session_lz3; tie %session_lz3, $package, undef, $args; $session_lz3{uid} = 'expr_test'; $session_lz3{mail} = 'expr@test.com'; my $id_lz3 = $session_lz3{_session_id}; untie %session_lz3; ok( $r->sismember( "uid_expr_test", $id_lz3 ), "Session lz3 in uid_expr_test index" ); # Delete lz3 directly (simulates TTL expiration) $r->del($id_lz3); # searchOnExpr should clean orphan $hash = $package->searchOnExpr( $args, 'uid', 'expr_*' ); is( keys %$hash, 0, "searchOnExpr returns nothing for expired session" ); ok( !$r->sismember( "uid_expr_test", $id_lz3 ), "searchOnExpr lazy cleanup removed orphan lz3 from index" ); $r->flushall; Apache-Session-Browseable-1.3.19/t/Apache-Session-Browseable-SQLite.t000444001750001750 206515201255027 24332 0ustar00yaddyadd000000000000# First test with SQLite: Basic Apache::Session usage #!/usr/bin/perl use strict; use Test::More; use File::Temp qw(mktemp); my $dbfile = mktemp('tmp.db_XXXX'); plan skip_all => "DBD::SQLite is needed for this test" unless eval { require DBI; require DBD::SQLite; 1; }; plan skip_all => "DBD::SQLite error : $@" unless eval { my $dbh; $dbh = DBI->connect( "dbi:SQLite:dbname=$dbfile", "", "" ) or die $dbh->errstr; $dbh->do( 'CREATE TABLE sessions(id char(32) not null primary key,a_session text);' ) or die $dbh->errstr; $dbh->disconnect() or die $dbh->errstr; }; plan tests => 5; use_ok('Apache::Session::Browseable::SQLite'); my %session; ok( tie %session, 'Apache::Session::Browseable::SQLite', undef, { DataSource => "dbi:SQLite:$dbfile", Index => '' } ); ok( $session{a} = 'foo' ); my $id = $session{_session_id}; untie %session; ok( tie %session, 'Apache::Session::Browseable::SQLite', $id, { DataSource => "dbi:SQLite:$dbfile" } ); ok( $session{a} eq 'foo' ); unlink $dbfile if ( -e $dbfile ); Apache-Session-Browseable-1.3.19/t/Apache-Session-Browseable-Store-DBI.t000444001750001750 26715201255027 24643 0ustar00yaddyadd000000000000use Test::More; plan skip_all => "Optional modules (DBI) not installed" unless eval { require DBI; }; plan tests => 1; use_ok('Apache::Session::Browseable::Store::DBI'); Apache-Session-Browseable-1.3.19/t/Apache-Session-Browseable-Store-MySQL.t000444001750001750 45015201255027 25204 0ustar00yaddyadd000000000000use Test::More; plan skip_all => "Optional modules (DBD::mysql, DBI) not installed" unless eval { require DBI; require DBD::mysql; }; plan tests => 2; $package = 'Apache::Session::Browseable::Store::MySQL'; use_ok($package); my $foo = $package->new; isa_ok $foo, $package; Apache-Session-Browseable-1.3.19/t/Apache-Session-Browseable-Store-Patroni.t000444001750001750 4150615201255027 25722 0ustar00yaddyadd000000000000#!/usr/bin/perl use strict; use warnings; use Test::More; plan skip_all => "Optional modules (DBD::Pg, DBI) not installed" unless eval { require DBI; require DBD::Pg; }; plan tests => 34; my $package = 'Apache::Session::Browseable::Store::Patroni'; use_ok($package); my $store = $package->new; isa_ok( $store, $package ); # Test _buildDataSource function { no warnings 'once'; # Basic case: append host/port is( Apache::Session::Browseable::Store::Patroni::_buildDataSource( 'dbi:Pg:dbname=sessions', { host => '10.0.0.1', port => 5432 } ), 'dbi:Pg:dbname=sessions;host=10.0.0.1;port=5432', '_buildDataSource: basic append' ); # Replace existing host/port (semicolon separated) is( Apache::Session::Browseable::Store::Patroni::_buildDataSource( 'dbi:Pg:dbname=sessions;host=old.host;port=1234', { host => '10.0.0.2', port => 5433 } ), 'dbi:Pg:dbname=sessions;host=10.0.0.2;port=5433', '_buildDataSource: replace existing host/port' ); # Handle trailing colon in DSN is( Apache::Session::Browseable::Store::Patroni::_buildDataSource( 'dbi:Pg:', { host => '10.0.0.3', port => 5434 } ), 'dbi:Pg:host=10.0.0.3;port=5434', '_buildDataSource: trailing colon' ); # Complex DSN with other params is( Apache::Session::Browseable::Store::Patroni::_buildDataSource( 'dbi:Pg:dbname=mydb;host=127.0.0.1;port=5432;sslmode=require', { host => '192.168.1.1', port => 5435 } ), 'dbi:Pg:dbname=mydb;sslmode=require;host=192.168.1.1;port=5435', '_buildDataSource: complex DSN with other params' ); } # Test cache structure (multi-source support) { no warnings 'once'; # Clear cache %Apache::Session::Browseable::Store::Patroni::patroniCache = (); my $ds1 = 'dbi:Pg:dbname=db1'; my $ds2 = 'dbi:Pg:dbname=db2'; # Simulate caching for first datasource $Apache::Session::Browseable::Store::Patroni::patroniCache{$ds1} = { leader => { host => '10.0.0.1', port => 5432, time => time() } }; # Simulate caching for second datasource $Apache::Session::Browseable::Store::Patroni::patroniCache{$ds2} = { leader => { host => '10.0.0.2', port => 5433, time => time() } }; # Verify they are independent is( $Apache::Session::Browseable::Store::Patroni::patroniCache{$ds1} ->{leader}->{host}, '10.0.0.1', 'Multi-source: first datasource has correct host' ); is( $Apache::Session::Browseable::Store::Patroni::patroniCache{$ds2} ->{leader}->{host}, '10.0.0.2', 'Multi-source: second datasource has correct host' ); # Verify ports are independent is( $Apache::Session::Browseable::Store::Patroni::patroniCache{$ds1} ->{leader}->{port}, 5432, 'Multi-source: first datasource has correct port' ); is( $Apache::Session::Browseable::Store::Patroni::patroniCache{$ds2} ->{leader}->{port}, 5433, 'Multi-source: second datasource has correct port' ); # Clear cache %Apache::Session::Browseable::Store::Patroni::patroniCache = (); } # Test _useCachedLeader { no warnings 'once'; my $ds = 'dbi:Pg:dbname=testdb'; my $store = $package->new; $store->{_originalDataSource} = $ds; # No cache - should return 0 %Apache::Session::Browseable::Store::Patroni::patroniCache = (); my $args = { DataSource => $ds, PatroniCacheTTL => 60 }; # Capture STDERR my $stderr = ''; { local *STDERR; open STDERR, '>', \$stderr; my $result = $store->_useCachedLeader( $args, $ds, "Test reason" ); is( $result, 0, '_useCachedLeader: returns 0 when no cache' ); } # With valid cache $Apache::Session::Browseable::Store::Patroni::patroniCache{$ds} = { leader => { host => '10.0.0.5', port => 5432, time => time() - 10 # 10 seconds ago } }; $stderr = ''; { local *STDERR; open STDERR, '>', \$stderr; my $result = $store->_useCachedLeader( $args, $ds, "Test reason" ); is( $result, 1, '_useCachedLeader: returns 1 when cache valid' ); } like( $args->{DataSource}, qr/host=10\.0\.0\.5/, '_useCachedLeader: updates DataSource with cached host' ); like( $args->{DataSource}, qr/port=5432/, '_useCachedLeader: updates DataSource with cached port' ); # With expired cache $Apache::Session::Browseable::Store::Patroni::patroniCache{$ds} = { leader => { host => '10.0.0.6', port => 5433, time => time() - 120 # 2 minutes ago, expired } }; $args = { DataSource => $ds, PatroniCacheTTL => 60 }; $stderr = ''; { local *STDERR; open STDERR, '>', \$stderr; my $result = $store->_useCachedLeader( $args, $ds, "Test reason" ); is( $result, 0, '_useCachedLeader: returns 0 when cache expired' ); } # Clear cache %Apache::Session::Browseable::Store::Patroni::patroniCache = (); } # Test circuit breaker logic in checkMaster (without actual HTTP calls) { no warnings 'once'; my $ds = 'dbi:Pg:dbname=circuitdb'; my $store = $package->new; $store->{_originalDataSource} = $ds; # Set up circuit breaker as triggered $Apache::Session::Browseable::Store::Patroni::patroniCache{$ds} = { lastFailure => time() - 10, # Failed 10 seconds ago leader => { host => '10.0.0.7', port => 5432, time => time() - 5 # Cached 5 seconds ago } }; my $args = { DataSource => $ds, PatroniUrl => 'http://fake.patroni:8008/cluster', PatroniCircuitBreakerDelay => 30, PatroniCacheTTL => 60, }; # Circuit breaker should be active (failed 10s ago, delay is 30s) # It should use cached leader instead of calling API my $stderr = ''; { local *STDERR; open STDERR, '>', \$stderr; my $result = $store->checkMaster($args); is( $result, 1, 'Circuit breaker: uses cached leader when active' ); } like( $stderr, qr/Circuit breaker active/, 'Circuit breaker: prints appropriate message' ); like( $args->{DataSource}, qr/host=10\.0\.0\.7/, 'Circuit breaker: uses cached host' ); # Clear cache %Apache::Session::Browseable::Store::Patroni::patroniCache = (); } # Test that circuit breaker expires { no warnings 'once'; my $ds = 'dbi:Pg:dbname=expiredcb'; my $store = $package->new; $store->{_originalDataSource} = $ds; # Circuit breaker triggered long ago (should be expired) $Apache::Session::Browseable::Store::Patroni::patroniCache{$ds} = { lastFailure => time() - 60, # Failed 60 seconds ago leader => { host => '10.0.0.8', port => 5432, time => time() - 50 # Still valid cache } }; my $args = { DataSource => $ds, PatroniUrl => 'http://nonexistent.host:8008/cluster', PatroniCircuitBreakerDelay => 30, # Expired (60 > 30) PatroniCacheTTL => 120, }; # Circuit breaker should NOT be active (failed 60s ago, delay is 30s) # It will try to call API (which will fail) then use cache my $stderr = ''; { local *STDERR; open STDERR, '>', \$stderr; # This will try HTTP (fail) then fallback to cache my $result = $store->checkMaster($args); is( $result, 1, 'Circuit breaker expired: uses cache after API failure' ); } like( $stderr, qr/Patroni API unavailable/, 'Circuit breaker expired: API was tried' ); # Clear cache %Apache::Session::Browseable::Store::Patroni::patroniCache = (); } # Test default values { my $store = $package->new; my $ds = 'dbi:Pg:dbname=defaults'; $store->{_originalDataSource} = $ds; # Test with minimal args my $args = { DataSource => $ds, PatroniUrl => 'http://fake:8008/cluster', }; # Without cache, checkMaster will try HTTP and fail # This tests that defaults are applied correctly my $stderr = ''; { local *STDERR; open STDERR, '>', \$stderr; # Store the time before calling checkMaster my $before = time(); my $result = $store->checkMaster($args); # Verify failure was recorded with correct circuit breaker my $cache = $Apache::Session::Browseable::Store::Patroni::patroniCache{$ds}; ok( $cache->{lastFailure} >= $before, 'Default circuit breaker delay: failure recorded' ); } # Clear cache %Apache::Session::Browseable::Store::Patroni::patroniCache = (); } # Test custom TTL values { no warnings 'once'; my $ds = 'dbi:Pg:dbname=customttl'; # Set up cache with known age $Apache::Session::Browseable::Store::Patroni::patroniCache{$ds} = { leader => { host => '10.0.0.9', port => 5432, time => time() - 45 # 45 seconds ago } }; my $store = $package->new; $store->{_originalDataSource} = $ds; # With 30s TTL, cache should be expired my $args1 = { DataSource => $ds, PatroniCacheTTL => 30 }; my $stderr = ''; { local *STDERR; open STDERR, '>', \$stderr; my $result = $store->_useCachedLeader( $args1, $ds, "Test" ); is( $result, 0, 'Custom TTL 30s: cache expired at 45s' ); } # With 60s TTL, cache should be valid my $args2 = { DataSource => $ds, PatroniCacheTTL => 60 }; $stderr = ''; { local *STDERR; open STDERR, '>', \$stderr; my $result = $store->_useCachedLeader( $args2, $ds, "Test" ); is( $result, 1, 'Custom TTL 60s: cache valid at 45s' ); } # Clear cache %Apache::Session::Browseable::Store::Patroni::patroniCache = (); } # Test module can be loaded use_ok('Apache::Session::Browseable::Patroni'); # Test JSON parsing and leader validation with mocked HTTP using LWP::Protocol::PSGI SKIP: { skip 'LWP::Protocol::PSGI and JSON not available', 10 unless eval { require LWP::Protocol::PSGI; require JSON; 1 }; my $package = 'Apache::Session::Browseable::Store::Patroni'; my $ds = 'dbi:Pg:dbname=mocktest'; # Helper to create PSGI app with given response my $make_app = sub { my ($json_data) = @_; return sub { my $env = shift; return [ 200, [ 'Content-Type' => 'application/json' ], [ JSON::to_json($json_data) ] ]; }; }; # Test 1: Valid leader response { %Apache::Session::Browseable::Store::Patroni::patroniCache = (); my $guard = LWP::Protocol::PSGI->register( $make_app->( { members => [ { role => 'leader', host => '10.0.0.100', port => 5432, state => 'running' }, { role => 'replica', host => '10.0.0.101', port => 5432, state => 'streaming' } ] } ) ); my $store = $package->new; $store->{_originalDataSource} = $ds; my $args = { DataSource => $ds, PatroniUrl => 'http://mock:8008/cluster' }; my $stderr = ''; my $result; { local *STDERR; open STDERR, '>', \$stderr; $result = $store->checkMaster($args); } is( $result, 1, 'Valid leader: checkMaster returns 1' ); like( $args->{DataSource}, qr/host=10\.0\.0\.100/, 'Valid leader: correct host in DataSource' ); } # Test 2: Split-brain detection (multiple leaders) { %Apache::Session::Browseable::Store::Patroni::patroniCache = (); my $guard = LWP::Protocol::PSGI->register( $make_app->( { members => [ { role => 'leader', host => '10.0.0.100', port => 5432, state => 'running' }, { role => 'leader', host => '10.0.0.101', port => 5432, state => 'running' } ] } ) ); my $store = $package->new; $store->{_originalDataSource} = $ds; my $args = { DataSource => $ds, PatroniUrl => 'http://mock:8008/cluster' }; my $stderr = ''; my $result; { local *STDERR; open STDERR, '>', \$stderr; $result = $store->checkMaster($args); } is( $result, 0, 'Split-brain: checkMaster returns 0' ); like( $stderr, qr/Multiple leaders detected/, 'Split-brain: warning message' ); } # Test 3: Leader not in running state { %Apache::Session::Browseable::Store::Patroni::patroniCache = (); my $guard = LWP::Protocol::PSGI->register( $make_app->( { members => [ { role => 'leader', host => '10.0.0.100', port => 5432, state => 'starting' } ] } ) ); my $store = $package->new; $store->{_originalDataSource} = $ds; my $args = { DataSource => $ds, PatroniUrl => 'http://mock:8008/cluster' }; my $stderr = ''; my $result; { local *STDERR; open STDERR, '>', \$stderr; $result = $store->checkMaster($args); } is( $result, 0, 'Leader starting: checkMaster returns 0' ); like( $stderr, qr/not in running state/, 'Leader starting: warning message' ); } # Test 4: Leader missing host { %Apache::Session::Browseable::Store::Patroni::patroniCache = (); my $guard = LWP::Protocol::PSGI->register( $make_app->( { members => [ { role => 'leader', port => 5432, state => 'running' } ] } ) ); my $store = $package->new; $store->{_originalDataSource} = $ds; my $args = { DataSource => $ds, PatroniUrl => 'http://mock:8008/cluster' }; my $stderr = ''; my $result; { local *STDERR; open STDERR, '>', \$stderr; $result = $store->checkMaster($args); } is( $result, 0, 'Leader missing host: checkMaster returns 0' ); like( $stderr, qr/missing host or port/, 'Leader missing host: warning message' ); } # Test 5: No leader found { %Apache::Session::Browseable::Store::Patroni::patroniCache = (); my $guard = LWP::Protocol::PSGI->register( $make_app->( { members => [ { role => 'replica', host => '10.0.0.101', port => 5432, state => 'streaming' } ] } ) ); my $store = $package->new; $store->{_originalDataSource} = $ds; my $args = { DataSource => $ds, PatroniUrl => 'http://mock:8008/cluster' }; my $stderr = ''; my $result; { local *STDERR; open STDERR, '>', \$stderr; $result = $store->checkMaster($args); } is( $result, 0, 'No leader: checkMaster returns 0' ); like( $stderr, qr/No leader found/, 'No leader: warning message' ); } # Clear cache %Apache::Session::Browseable::Store::Patroni::patroniCache = (); } Apache-Session-Browseable-1.3.19/t/Apache-Session-Browseable-common.t000444001750001750 41215201255027 24433 0ustar00yaddyadd000000000000use Test::More; plan tests => 3; use_ok('Apache::Session::Browseable::_common'); my ( $a, $b ) = ( [qw(0 1 a)], [qw(0 1 a b)] ); ok( Apache::Session::Browseable::_common->_tabInTab( $a, $b ) ); ok( !Apache::Session::Browseable::_common->_tabInTab( $b, $a ) ); Apache-Session-Browseable-1.3.19/t/test-browseable-functions-using-File.t000444001750001750 673115201255027 25422 0ustar00yaddyadd000000000000# Complete tests with File use strict; use warnings; use Test::More; use constant SESSIONPATH => 't' . ( $^O and $^O =~ /(?:MSWin|Windows)/i ? '\\' : '/' ) . 'sessions'; eval { require File::Path; File::Path::remove_tree(SESSIONPATH); File::Path::mkpath(SESSIONPATH); }; plan skip_all => "Unable to use file system ($@)" if ($@); my @list = ( "aa" .. "ay", "aa" .. "ac" ); my $count = @list; plan tests => 27 + 5 * $count; use_ok('Apache::Session::Browseable::File'); my %session; my $args = { Directory => SESSIONPATH, Index => "f1 f2", }; foreach (@list) { ok( tie %session, 'Apache::Session::Browseable::File', undef, $args, "Create session $_" ); $session{f1} = "1_$_"; $session{f2} = "2_$_"; $session{f3} = "3_$_"; $session{f4} = "4_$_"; untie %session; } my $res; # 1. Get simply all sessions ok( $res = Apache::Session::Browseable::File->get_key_from_all_sessions($args), 'Get all sessions' ); ok( count($res) == $count, "get_key_from_all_sessions returns $count sessions (" . count($res) . ")" ); # 2. Test searchOn() on an indexed field ok( $res = Apache::Session::Browseable::File->searchOn( $args, 'f1', '1_aa' ) ); ok( count($res) == 2, 'Get 2 "aa" sessions (' . count($res) . ")" ); ok( $res = Apache::Session::Browseable::File->searchOn( $args, 'f1', '1_ad' ) ); ok( count($res) == 1, 'Get 1 "ad" sessions (' . count($res) . ")" ); # 3. Test searchOn() on an unindexed field ok( $res = Apache::Session::Browseable::File->searchOn( $args, 'f3', '3_aa' ) ); ok( count($res) == 2, 'Get 2 "aa" sessions (' . count($res) . ")" ); ok( $res = Apache::Session::Browseable::File->searchOn( $args, 'f3', '3_ad' ) ); ok( count($res) == 1, 'Get 1 "ad" sessions (' . count($res) . ")" ); # 4. Test searchOnExpr() on an indexed field ok( $res = Apache::Session::Browseable::File->searchOnExpr( $args, 'f1', '*aa' ) ); ok( count($res) == 2, 'Get 2 "aa" sessions (' . count($res) . ")" ); # 5. Test searchOnExpr() on an unindexed field ok( $res = Apache::Session::Browseable::File->searchOnExpr( $args, 'f3', '*aa' ) ); ok( count($res) == 2, 'Get 2 "aa" sessions (' . count($res) . ")" ); # 6. Test get_key_from_all_sessions to request for indexed fields ok( $res = Apache::Session::Browseable::File->get_key_from_all_sessions( $args, [ 'f1', 'f2' ] ) ); while ( my ( $id, $entry ) = each %$res ) { ok( $entry->{f1} =~ /^1_(\w{2})$/ ); my $t = $1; ok( $entry->{f2} =~ /^2_${t}$/ ); } # 7. Test searchOn to request for indexed fields ok( $res = Apache::Session::Browseable::File->searchOn( $args, 'f1', '1_aa', 'f1', 'f2' ) ); while ( my ( $id, $entry ) = each %$res ) { ok( $entry->{f1} =~ /^1_(\w{2})$/ ); my $t = $1; ok( $entry->{f2} =~ /^2_${t}$/ ); } # 8. Test get_key_from_all_sessions to request for unindexed fields ok( $res = Apache::Session::Browseable::File->get_key_from_all_sessions( $args, [ 'f1', 'f3' ] ) ); while ( my ( $id, $entry ) = each %$res ) { ok( $entry->{f1} =~ /^1_(\w{2})$/ ); my $t = $1; ok( $entry->{f3} =~ /^3_${t}$/ ); } # 9. Test searchOn to request for unindexed fields ok( $res = Apache::Session::Browseable::File->searchOn( $args, 'f1', '1_aa', 'f1', 'f3' ) ); eval { File::Path::remove_tree(SESSIONPATH) }; while ( my ( $id, $entry ) = each %$res ) { ok( $entry->{f1} =~ /^1_(\w{2})$/ ); my $t = $1; ok( $entry->{f3} =~ /^3_${t}$/ ); } sub count { my @c = keys %{ $_[0] }; return scalar @c; } 1; Apache-Session-Browseable-1.3.19/t/test-browseable-functions-using-SQLite.t000444001750001750 776315201255027 25712 0ustar00yaddyadd000000000000# Complete tests with SQLite use strict; use warnings; use Test::More; use File::Temp qw(mktemp); my $dbfile = mktemp('tmp.db_XXXX'); plan skip_all => "DBD::SQLite is needed for this test" unless eval { require DBI; require DBD::SQLite; 1; }; plan skip_all => "DBD::SQLite error : $@" unless eval { my $dbh; $dbh = DBI->connect( "dbi:SQLite:dbname=$dbfile", "", "" ) or die $dbh->errstr; $dbh->do( 'CREATE TABLE sessions(id char(32) not null primary key,a_session text,f1 text,f2 text);' ) or die $dbh->errstr; $dbh->do('CREATE INDEX f1_idx ON sessions (f1);') or die $dbh->errstr; $dbh->do('CREATE INDEX f2_idx ON sessions (f2);') or die $dbh->errstr; $dbh->disconnect() or die $dbh->errstr; }; my @list = ( "aa" .. "ay", "aa" .. "ac" ); my $count = @list; plan tests => 27 + 5 * $count; use_ok('Apache::Session::Browseable::SQLite'); my %session; my $args = { DataSource => "dbi:SQLite:$dbfile", Index => "f1 f2", }; foreach (@list) { ok( tie %session, 'Apache::Session::Browseable::SQLite', undef, $args, "Create session $_" ); $session{f1} = "1_$_"; $session{f2} = "2_$_"; $session{f3} = "3_$_"; $session{f4} = "4_$_"; untie %session; } my $res; # 1. Get simply all sessions ok( $res = Apache::Session::Browseable::SQLite->get_key_from_all_sessions($args), 'Get all sessions' ); ok( count($res) == $count, "get_key_from_all_sessions returns $count sessions (" . count($res) . ")" ); # 2. Test searchOn() on an indexed field ok( $res = Apache::Session::Browseable::SQLite->searchOn( $args, 'f1', '1_aa' ) ); ok( count($res) == 2, 'Get 2 "aa" sessions (' . count($res) . ")" ); ok( $res = Apache::Session::Browseable::SQLite->searchOn( $args, 'f1', '1_ad' ) ); ok( count($res) == 1, 'Get 1 "ad" sessions (' . count($res) . ")" ); # 3. Test searchOn() on an unindexed field ok( $res = Apache::Session::Browseable::SQLite->searchOn( $args, 'f3', '3_aa' ) ); ok( count($res) == 2, 'Get 2 "aa" sessions (' . count($res) . ")" ); ok( $res = Apache::Session::Browseable::SQLite->searchOn( $args, 'f3', '3_ad' ) ); ok( count($res) == 1, 'Get 1 "ad" sessions (' . count($res) . ")" ); # 4. Test searchOnExpr() on an indexed field ok( $res = Apache::Session::Browseable::SQLite->searchOnExpr( $args, 'f1', '*aa' ) ); ok( count($res) == 2, 'Get 2 "aa" sessions (' . count($res) . ")" ); # 5. Test searchOnExpr() on an unindexed field ok( $res = Apache::Session::Browseable::SQLite->searchOnExpr( $args, 'f3', '*aa' ) ); ok( count($res) == 2, 'Get 2 "aa" sessions (' . count($res) . ")" ); # 6. Test get_key_from_all_sessions to request for indexed fields ok( $res = Apache::Session::Browseable::SQLite->get_key_from_all_sessions( $args, [ 'f1', 'f2' ] ) ); while ( my ( $id, $entry ) = each %$res ) { ok( $entry->{f1} =~ /^1_(\w{2})$/ ); my $t = $1; ok( $entry->{f2} =~ /^2_${t}$/ ); } # 7. Test searchOn to request for indexed fields ok( $res = Apache::Session::Browseable::SQLite->searchOn( $args, 'f1', '1_aa', 'f1', 'f2' ) ); while ( my ( $id, $entry ) = each %$res ) { ok( $entry->{f1} =~ /^1_(\w{2})$/ ); my $t = $1; ok( $entry->{f2} =~ /^2_${t}$/ ); } # 8. Test get_key_from_all_sessions to request for unindexed fields ok( $res = Apache::Session::Browseable::SQLite->get_key_from_all_sessions( $args, [ 'f1', 'f3' ] ) ); while ( my ( $id, $entry ) = each %$res ) { ok( $entry->{f1} =~ /^1_(\w{2})$/ ); my $t = $1; ok( $entry->{f3} =~ /^3_${t}$/ ); } # 9. Test searchOn to request for unindexed fields ok( $res = Apache::Session::Browseable::SQLite->searchOn( $args, 'f1', '1_aa', 'f1', 'f3' ) ); unlink $dbfile if ( -e $dbfile ); while ( my ( $id, $entry ) = each %$res ) { ok( $entry->{f1} =~ /^1_(\w{2})$/ ); my $t = $1; ok( $entry->{f3} =~ /^3_${t}$/ ); } sub count { my @c = keys %{ $_[0] }; return scalar @c; } 1;