From 78cd27b3ec8300e0a8ed7e6b909e3ea99fa75911 Mon Sep 17 00:00:00 2001 From: x2003bruneau Date: Mon, 27 Feb 2006 12:04:25 +0000 Subject: [PATCH] Importe le HEAD de arch git-svn-id: svn+ssh://murphy/home/svn/banana/trunk@2 9869982d-c50d-0410-be91-f2a2ec7c7c7b --- AUTHORS | 7 + COPYING | 341 ++++++++++++++ Changelog | 67 +++ Makefile | 47 ++ README | 7 + TODO | 2 + banana/NetNNTP.inc.php | 503 ++++++++++++++++++++ banana/banana.inc.php.in | 319 +++++++++++++ banana/groups.inc.php | 126 +++++ banana/misc.inc.php | 235 ++++++++++ banana/post.inc.php | 124 +++++ banana/spool.inc.php | 425 +++++++++++++++++ banana/utf8.php | 85 ++++ css/banana.css | 67 +++ css/style.css | 41 ++ debian/changelog | 18 + debian/control | 15 + debian/copyright | 15 + debian/patches/10.correct_spool_path.patch | 11 + debian/php-banana.install | 4 + debian/php-banana.postinst | 8 + debian/php-banana.postrm | 16 + debian/rules | 24 + examples/index.php | 35 ++ examples/spoolgen.php | 54 +++ examples/xface.php | 6 + img/I.gif | Bin 0 -> 68 bytes img/L-direct.gif | Bin 0 -> 73 bytes img/L.gif | Bin 0 -> 67 bytes img/T-direct.gif | Bin 0 -> 77 bytes img/T.gif | Bin 0 -> 71 bytes img/e.gif | Bin 0 -> 42 bytes img/k1.gif | Bin 0 -> 61 bytes img/k2.gif | Bin 0 -> 66 bytes img/s-direct.gif | Bin 0 -> 61 bytes img/s.gif | Bin 0 -> 55 bytes po/Makefile | 28 ++ po/banana.pot | 158 +++++++ po/en.po | 158 +++++++ po/fr.po | 158 +++++++ po/shtool | 716 +++++++++++++++++++++++++++++ 41 files changed, 3820 insertions(+) create mode 100644 AUTHORS create mode 100644 COPYING create mode 100644 Changelog create mode 100644 Makefile create mode 100644 README create mode 100644 TODO create mode 100644 banana/NetNNTP.inc.php create mode 100644 banana/banana.inc.php.in create mode 100644 banana/groups.inc.php create mode 100644 banana/misc.inc.php create mode 100644 banana/post.inc.php create mode 100644 banana/spool.inc.php create mode 100644 banana/utf8.php create mode 100644 css/banana.css create mode 100644 css/style.css create mode 100644 debian/changelog create mode 100644 debian/control create mode 100644 debian/copyright create mode 100644 debian/patches/10.correct_spool_path.patch create mode 100644 debian/php-banana.install create mode 100644 debian/php-banana.postinst create mode 100644 debian/php-banana.postrm create mode 100755 debian/rules create mode 100644 examples/index.php create mode 100644 examples/spoolgen.php create mode 100644 examples/xface.php create mode 100644 img/I.gif create mode 100644 img/L-direct.gif create mode 100644 img/L.gif create mode 100644 img/T-direct.gif create mode 100644 img/T.gif create mode 100644 img/e.gif create mode 100644 img/k1.gif create mode 100644 img/k2.gif create mode 100644 img/s-direct.gif create mode 100644 img/s.gif create mode 100644 po/Makefile create mode 100644 po/banana.pot create mode 100644 po/en.po create mode 100644 po/fr.po create mode 100755 po/shtool diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..958a271 --- /dev/null +++ b/AUTHORS @@ -0,0 +1,7 @@ +Original Author : + + 2003-2004 : David Bachelart < david dot bachelart at polytechnique dot org > + +Current Authors : + + since 2005 : Pierre Habouzit < pierre dot habouzit at polytechnique dot org > diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..86568a9 --- /dev/null +++ b/COPYING @@ -0,0 +1,341 @@ + GNU GENERAL PUBLIC LICENSE + 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 + + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) 19yy + + This program 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 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) 19yy name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --git a/Changelog b/Changelog new file mode 100644 index 0000000..35bdf25 --- /dev/null +++ b/Changelog @@ -0,0 +1,67 @@ +================================================================================ +VERSION 1.2 + +Wed, 19 Oct 2005 Pierre Habouzit + + * Fix a problem wrt responses (Re: in subject). + * Fix a problem with empty overviews. + * Fix Header encoding problems. + +================================================================================ +VERSION 1.1 + +Tue, 24 May 2005 Pierre Habouzit + + * Fix one problem with $this->ids beeing empty in Spool. + * Fix encoding issues since iconv truncates strings sometimes. + * Make the post forms use utf-8. + +================================================================================ +VERSION 1.0 + +Fri, 07 Jan 2005 Pierre Habouzit + + * Banana is now a real standalone class. + * Clean hooks. + * Update the script spoolgen.php. + +Wed, 05 Jan 2005 Pierre Habouzit + + * continue the work with post.php. + +Tue, 04 Jan 2005 Pierre Habouzit + + * prepare Banana to be a library : + - delete a lot of echo's. + - use a lot of string passing. + - create more Banana:: functions. + => API IS NOT STABLE ATM. + +Mon, 03 Jan 2005 Pierre Habouzit + + * no more $news -> class Banana. + * continue include rework. + * hooks functions enters. + * $banana is now the only global variable we need. + * exit format.inc.php. + +Sun, 02 Jan 2005 Pierre Habouzit + + * _(..) -> _b_(..) that performs a dgettext('banana', ...). + * use gettext and no more $locales. + * rework includes. + +Sat, 01 Jan 2005 Pierre Habouzit + + * rework headerDecode function (biggest bottleneck). + * rework includes. + +================================================================================ +VERSION 0.7.1 + +Before Jan 2005 David Bachelart + + * first version. + +================================================================================ +vim:set ts=4 sw=4: diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f43994d --- /dev/null +++ b/Makefile @@ -0,0 +1,47 @@ +# definitions + +VERSION=$(shell grep VERSION Changelog | head -1 | sed -e "s/VERSION //;s/\t.*//") +PKG_DIST = banana-$(VERSION) + +PKG_FILES = AUTHORS Changelog COPYING README Makefile TODO + +PKG_DIRS = banana po css examples img + +VCS_FILTER = ! -name .arch-ids ! -name .arch-inventory + +# global targets + +build: pkg-build + +dist: clean pkg-dist + +clean: + rm -rf locale banana/include/banana.inc.php + make -C po clean + +%: %.in Makefile + sed -e 's,@VERSION@,$(VERSION) The Bearded Release,g' $< > $@ + + +# banana package targets + +pkg-build: banana/banana.inc.php + make -C po + make -C po clean + +pkg-dist: pkg-build + rm -rf $(PKG_DIST) $(PKG_DIST).tar.gz + mkdir $(PKG_DIST) + cp -a $(PKG_FILES) $(PKG_DIST) + for dir in `find $(PKG_DIRS) -type d $(VCS_FILTER)`; \ + do \ + mkdir -p $(PKG_DIST)/$$dir; \ + find $$dir -type f $(VCS_FILTER) -maxdepth 1 -exec cp {} $(PKG_DIST)/$$dir \; ; \ + done + tar czf $(PKG_DIST).tar.gz $(PKG_DIST) + rm -rf $(PKG_DIST) + + + +.PHONY: build dist clean pkg-build pkg-dist lib-build lib-dist + diff --git a/README b/README new file mode 100644 index 0000000..8c28f1c --- /dev/null +++ b/README @@ -0,0 +1,7 @@ +banana - a web interface for a NNTP server + +DISTRIBUTING +============ + +banana is distributed under the terms of the GNU General Public +License (GPL) (see COPYING) diff --git a/TODO b/TODO new file mode 100644 index 0000000..96d173d --- /dev/null +++ b/TODO @@ -0,0 +1,2 @@ +* MIME support +* strict NNTP support diff --git a/banana/NetNNTP.inc.php b/banana/NetNNTP.inc.php new file mode 100644 index 0000000..13e574a --- /dev/null +++ b/banana/NetNNTP.inc.php @@ -0,0 +1,503 @@ +ns = fsockopen($url['host'], $url['port'], $errno, $errstr, $_timeout); + if (!$this->ns) { + $this = false; + return false; + } + + $result = $this->gline(); + $this->posting = (substr($result, 0, 3)=="200"); + if ($_reader && ($result{0}=="2")) { + $this->pline("MODE READER\r\n"); + $result = $this->gline(); + $this->posting = ($result{0}=="200"); + } + if ($result{0}=="2" && $url['user'] && $url['user']!='anonymous') { + return $this->authinfo($url['user'], $url['pass']); + } + return ($result{0}=="2"); + } + +# Socket functions + + /** get a line from server + * @return STRING + */ + + function gline() + { + return rtrim(fgets($this->ns, 1200)); + } + + /** puts a line on server + * @param STRING $_line line to put + */ + + function pline($_line) + { + return fputs($this->ns, $_line, strlen($_line)); + } + +# strict NNTP Functions [RFC 977] +# see http://www.faqs.org/rfcs/rfc977.html + + /** authentification + * @param $_user STRING login + * @param $_pass INTEGER password + * @return BOOLEAN true if authentication was successful + */ + + function authinfo($_user, $_pass) + { + $user = preg_replace("/(\r|\n)/", "", $_user); + $pass = preg_replace("/(\r|\n)/", "", $_pass); + $this->pline("AUTHINFO USER $user\r\n"); + $this->gline(); + $this->pline("AUTHINFO PASS $pass\r\n"); + $result=$this->gline(); + if ($result{0}!="2") { + $this->lasterrorcode = substr($result, 0, 3); + $this->lasterrortext = substr($result, 4); + return false; + } + return true; + } + + /** retrieves an article + * MSGID is a numeric ID a shown in article's headers. MSGNUM is a + * server-dependent ID (see X-Ref on many servers) and retriving + * an article by this way will change the current article pointer. + * If an error occur, false is returned. + * @param $_msgid STRING MSGID or MSGNUM of article + * @return ARRAY lines of the article + * @see body + * @see head + */ + + function article($_msgid="") + { + $msgid = preg_replace("/(\r|\n)/", "", $_msgid); + $this->pline("ARTICLE $msgid\r\n"); + $result = $this->gline(); + if ($result{0} != '2') { + $this->lasterrorcode = substr($result, 0, 3); + $this->lasterrortext = substr($result, 4); + return false; + } + $result = $this->gline(); + while ($result != ".") { + $array[] = $result; + $result = $this->gline(); + } + return $array; + } + + /** post a message + * if an error occur, false is returned + * @param $_message STRING message to post + * @return STRING MSGID of article + */ + + function post($_message) + { + if (is_array($_message)) { + $message=join("\n", $_message); + } else { + $message=$_message; + } + $this->pline("POST \r\n"); + $result=$this->gline(); + if ($result{0} != '3') { + $this->lasterrorcode = substr($result, 0, 3); + $this->lasterrortext = substr($result, 4); + return false; + } + $this->pline($message."\r\n.\r\n"); + $result = $this->gline(); + if ($result{0} != '2') { + $this->lasterrorcode = substr($result, 0, 3); + $this->lasterrortext = substr($result, 4); + return false; + } + if ($result{0} == '2') { + if (preg_match("/(<[^@>]+@[^@>]+>)/", $result, $regs)) { + return $regs[0]; + } else { + return true; + } + } + return false; + } + + /** fetches the body of an article + * params are the same as article + * @param $_msgid STRING MSGID or MSGNUM of article + * @return ARRAY lines of the article + * @see article + * @see head + */ + + function body($_msgid="") + { + $msgid = preg_replace("/(\r|\n)/", "", $_msgid); + $this->pline("BODY $msgid\r\n"); + $result = $this->gline(); + if ($result{0} != '2') { + $this->lasterrorcode = substr($result, 0, 3); + $this->lasterrortext = substr($result, 4); + return false; + } + $array = Array(); + while (($result = $this->gline()) != ".") { + $array[] = $result; + } + return $array; + } + + /** fetches the headers of an article + * params are the same as article + * @param $_msgid STRING MSGID or MSGNUM of article + * @return ARRAY lines of the article + * @see article + * @see body + */ + + function head($_msgid="") + { + $msgid = preg_replace("/(\r|\n)/", "", $_msgid); + $this->pline("HEAD $msgid\r\n"); + $result = $this->gline(); + if ($result{0}!="2") { + $this->lasterrorcode = substr($result, 0, 3); + $this->lasterrortext = substr($result, 4); + return false; + } + $result = $this->gline(); + while ($result != ".") { + $array[] = $result; + $result = $this->gline(); + } + return $array; + } + + /** set current group + * @param $_group STRING + * @return ARRAY array : nb of articles in group, MSGNUM of first article, MSGNUM of last article, and group name + */ + + function group($_group) + { + $group = preg_replace("/(\r|\n)/", "", $_group); + $this->pline("GROUP $group\r\n"); + $line = $this->gline(); + if ($line{0}!="2") { + $this->lasterrorcode = substr($line, 0, 3); + $this->lasterrortext = substr($line, 4); + return false; + } + if (preg_match("/^2\d{2} (\d+) (\d+) (\d+) ([^ ]+)/", $line, $regs)) { + return array($regs[1], $regs[2], $regs[3], $regs[4]); + } + return false; + } + + /** set the article pointer to the previous article in current group + * @return STRING MSGID of article + * @see next + */ + + function last() + { + $this->pline("LAST \r\n"); + $line = $this->gline(); + if ($line{0}!="2") { + $this->lasterrorcode = substr($result, 0, 3); + $this->lasterrortext = substr($result, 4); + return false; + } + if (preg_match("/^2\d{2} \d+ <([^>]+)>/", $line, $regs)) { + return "<{$regs[1]}>"; + } + return false; + } + + /** set the article pointer to the next article in current group + * @return STRING MSGID of article + * @see last + */ + + function next() + { + $this->pline("NEXT \r\n"); + $line = $this->gline(); + if ($line{0}!="2") { + $this->lasterrorcode = substr($result, 0, 3); + $this->lasterrortext = substr($result, 4); + return false; + } + if (preg_match("/^2\d{2} \d+ <([^>]+)>/", $line, $regs)) { + return "<{$regs[1]}>"; + } + return false; + } + + /** set the current article pointer + * @param $_msgid STRING MSGID or MSGNUM of article + * @return BOOLEAN true if authentication was successful, error code otherwise + * @see article + * @see body + */ + + function nntpstat($_msgid) + { + $msgid = preg_replace("/(\r|\n)/", "", $_msgid); + $this->pline("STAT $msgid\r\n"); + $line = $this->gline(); + if ($line{0}!="2") { + $this->lasterrorcode = substr($result, 0, 3); + $this->lasterrortext = substr($result, 4); + return false; + } + if (preg_match("/^2\d{2} \d+ <([^>]+)>/", $line, $regs)) { + return "<{$regs[1]}>"; + } + return false; + } + + /** returns true if posting is allowed + * @return BOOLEAN true if posting is allowed lines + */ + + function postok() + { + return ($this->posting); + } + + /** gets information about all active newsgroups + * @return ARRAY group name => (MSGNUM of first article, MSGNUM of last article, NNTP flags) + * @see newgroups + */ + + function liste() + { + $this->pline("LIST\r\n"); + if (substr($this->gline(), 0, 1)!="2") return false; + $result = $this->gline(); + $array = Array(); + while ($result != ".") { + preg_match("/([^ ]+) (\d+) (\d+) (.)/", $result, $regs); + $array[$regs[1]] = array(intval($regs[2]), intval($regs[3]), intval($regs[4])); + $result = $this->gline(); + } + return $array; + } + + /** get information about recent newsgroups + * same as list, but information are limited to newgroups created after $_since + * @param $_since INTEGER unix timestamp + * @param $_distributions STRING distributions + * @return ARRAY same format as liste + * @see liste + */ + + function newgroups($_since, $_distributions="") + { +#assume $_since is a unix timestamp + $distributions = preg_replace("/(\r|\n)/", "", $_distributions); + $this->pline("NEWGROUPS ".gmdate("ymd His", $_since) + ." GMT $distributions\r\n"); + if (substr($this->gline(), 0, 1)!="2") { + return false; + } + $result = $this->gline(); + $array = array(); + while ($result != ".") { + preg_match("/([^ ]+) (\d+) (\d+) (.)/", $result, $regs); + $array[$regs[1]] = array(intval($regs[2]), intval($regs[3]), intval($regs[4])); + $result = $this->gline(); + } + return $array; + } + + /** gets a list of new articles + * @param $_since INTEGER unix timestamp + * @parma $_groups STRING pattern of intersting groups + * @return ARRAY MSGID of new articles + */ + + function newnews($_since, $_groups="*", $_distributions="") + { + $distributions = preg_replace("/(\r|\n)/", "", $_distributions); + $groups = preg_replace("/(\r|\n)/", "", $_groups); + $array = array(); +#assume $since is a unix timestamp + $this->pline("NEWNEWS $_groups ".gmdate("ymd His", $_since)." GMT $distributions\r\n"); + if (substr($this->gline(), 0, 1)!="2") { + return false; + } + while (($result = $this->gline()) != ".") { + $array[] = $result; + } + return $array; + } + + /** Tell the remote server that I am not a user client, but probably another news server + * @return BOOLEAN true if sucessful + */ + + function slave() + { + $this->pline("SLAVE \r\n"); + return (substr($this->gline(), 0, 1)=="2"); + } + + /** implements IHAVE method + * @param $_msgid STRING MSGID of article + * @param $_message STRING article + * @return BOOLEAN + */ + + function ihave($_msgid, $_message=false) + { + $msgid = preg_replace("/(\r|\n)/", "", $_msgid); + if (is_array($message)) { + $message = join("\n", $_message); + } else { + $message = $_message; + } + $this->pline("IHAVE $msgid \r\n"); + $result = $this->gline(); + if ($message && ($result{0}=="3")) { + $this->pline("$message\r\n.\r\n"); + $result = $this->gline(); + } + return ($result{0}=="2"); + } + + /** closes connection to server + */ + + function quit() + { + $this->pline("QUIT\r\n"); + $this->gline(); + fclose($this->ns); + } + +# NNTP Extensions [RFC 2980] + + /** Returns the date on the remote server + * @return INTEGER timestamp + */ + + function date() + { + $this->pline("DATE \r\n"); + $result = $this->gline(); + if (preg_match("/^111 (\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})$/", $result, $r)) { + return gmmktime($r[4], $r[5], $r[6], $r[2], $r[3], $r[1]); + } + return false; + } + + /** returns group descriptions + * @param $_pattern STRING pattern of intersting groups + * @return ARRAY group name => description + */ + + function xgtitle($_pattern="*") + { + $pattern = preg_replace("/[\r\n]/", "", $_pattern); + $this->pline("XGTITLE $pattern \r\n"); + if (substr($this->gline(), 0, 1)!="2") return false; + $result = $this->gline(); + while ($result != ".") { + preg_match("/([^ \t]+)[ \t]+(.+)$/", $result, $regs); + $array[$regs[1]] = $regs[2]; + $result = $this->gline(); + } + return $array; + } + + /** obtain the header field $hdr for all the messages specified + * @param $_hdr STRING name of the header (eg: 'From') + * @param $_range STRING range of articles + * @return ARRAY MSGNUM => header value + */ + + function xhdr($_hdr, $_range="") + { + $hdr = preg_replace("/(\r|\n)/", "", $_hdr); + $range = preg_replace("/(\r|\n)/", "", $_range); + $this->pline("XHDR $hdr $range \r\n"); + if (substr($this->gline(), 0, 1)!="2") { + return false; + } + + $array = array(); + while (($result = $this->gline()) != '.') { + preg_match("/([^ \t]+) (.*)$/", $result, $regs); + $array[$regs[1]] = $regs[2]; + } + return $array; + } + + /** obtain the header field $_hdr matching $_pat for all the messages specified + * @param $_hdr STRING name of the header (eg: 'From') + * @param $_range STRING range of articles + * @param $_pat STRING pattern + * @return ARRAY MSGNUM => header value + */ + + function xpat($_hdr, $_range, $_pat) + { + $hdr = preg_replace("/(\r|\n)/", "", $_hdr); + $range = preg_replace("/(\r|\n)/", "", $_range); + $pat = preg_replace("/(\r|\n)/", "", $_pat); + $this->pline("XPAT $hdr $range $pat\r\n"); + if (substr($this->gline(), 0, 1)!="2") { + return false; + } + $result = $this->gline(); + while ($result != ".") { + preg_match("/([^ \t]+) (.*)$/", $result, $regs); + $array[$regs[1]] = $regs[2]; + $result = $this->gline(); + } + return $array; + } +} + +?> diff --git a/banana/banana.inc.php.in b/banana/banana.inc.php.in new file mode 100644 index 0000000..bb8475d --- /dev/null +++ b/banana/banana.inc.php.in @@ -0,0 +1,319 @@ + 'Anonymous ', 'sig' => '', 'org' => '', + 'customhdr' =>'', 'display' => 0, 'lastnews' => 0, 'locale' => 'fr_FR', 'subscribe' => array()); + + var $state = Array('group' => null, 'artid' => null); + var $nntp; + var $groups; + var $newgroups; + var $post; + var $spool; + + function Banana() + { + $this->_require('NetNNTP'); + setlocale(LC_ALL, $this->profile['locale']); + $this->nntp = new nntp($this->host); + } + + function run($class = 'Banana') + { + global $banana; + Banana::_require('misc'); + $banana = new $class(); + + if (!$banana->nntp) { + return '

'._b_('Impossible de contacter le serveur').'

'; + } + + $group = empty($_GET['group']) ? null : strtolower($_GET['group']); + $artid = empty($_GET['artid']) ? null : strtolower($_GET['artid']); + $banana->state = Array ('group' => $group, 'artid' => $artid); + + if (is_null($group)) { + + if (isset($_GET['subscribe'])) { + return $banana->action_listSubs(); + } elseif (isset($_POST['subscribe'])) { + $banana->action_saveSubs(); + } + return $banana->action_listGroups(); + + } elseif (is_null($artid)) { + + if (isset($_POST['action']) && $_POST['action'] == 'new') { + return $banana->action_doFup($group, isset($_POST['artid']) ? intval($_POST['artid']) : -1); + } elseif (isset($_GET['action']) && $_GET['action'] == 'new') { + return $banana->action_newFup($group); + } else { + return $banana->action_showThread($group, isset($_GET['first']) ? intval($_GET['first']) : 1); + } + + } else { + + if (isset($_POST['action']) && $_POST['action']=='cancel') { + $res = $banana->action_cancelArticle($group, $artid); + } else { + $res = ''; + } + + if (isset($_GET['action'])) { + switch ($_GET['action']) { + case 'cancel': + $res .= $banana->action_showArticle($group, $artid); + if ($banana->post->checkcancel()) { + $form = '

'._b_('Voulez-vous vraiment annuler ce message ?').'

' + . "

" + . '' + . '' + . '

'; + return $form.$res; + } + return $res; + + case 'new': + return $banana->action_newFup($group, $artid); + } + } + return $res . $banana->action_showArticle($group, $artid); + } + } + + /**************************************************************************/ + /* actions */ + /**************************************************************************/ + + function action_saveSubs() + { + return; + } + + function action_listGroups() + { + $this->_newGroup(); + + $cuts = displayshortcuts(); + $res = '

'._b_('Les forums de Banana').'

'.$cuts.$this->groups->to_html(); + if (count($this->newgroups->overview)) { + $res .= '

'._b_('Les forums suivants ont été créés depuis ton dernier passage :').'

'; + $res .= $this->newgroups->to_html(); + } + + $this->nntp->quit(); + return $res.$cuts; + } + + function action_listSubs() + { + $this->_require('groups'); + $this->groups = new BananaGroups(BANANA_GROUP_ALL); + + $cuts = displayshortcuts(); + $res = '

'._b_('Abonnements').'

'.$cuts.$this->groups->to_html(true).$cuts; + + $this->nntp->quit(); + return $res; + } + + function action_showThread($group, $first) + { + $this->_newSpool($group, $this->profile['display'], $this->profile['lastnews']); + + if ($first > count($this->spool->overview)) { + $first = count($this->spool->overview); + } + + $first = $first - ($first % $this->tmax) + 1; + + $cuts = displayshortcuts($first); + + $res = '

'.$group.'

'.$cuts; + $res .= $this->spool->to_html($first, $first+$this->tmax); + + $this->nntp->quit(); + + return $res.$cuts; + } + + function action_showArticle($group, $id) + { + $this->_newSpool($group, $this->profile['display'], $this->profile['lastnews']); + $this->_newPost($id); + if (!$this->post) { + if ($this->nntp->lasterrorcode == "423") { + $this->spool->delid($id); + } + $this->nntp->quit(); + return displayshortcuts().'

'._b_('Impossible d\'accéder au message. Le message a peut-être été annulé').'

'; + } + + $cuts = displayshortcuts(); + $res = '

'._b_('Message').'

'.$cuts; + $res .= $this->post->to_html(); + + $this->nntp->quit(); + + return $res.$cuts; + } + + function action_cancelArticle($group, $id) + { + $this->_newSpool($group, $this->profile['display'], $this->profile['lastnews']); + $this->_newPost($id); + $mid = array_search($id, $this->spool->ids); + + if (!$this->post->checkcancel()) { + return '

'._b_('Vous n\'avez pas les permissions pour annuler ce message').'

'; + } + $msg = 'From: '.$this->profile['name']."\n" + . "Newsgroups: $group\n" + . "Subject: cmsg $mid\n" + . $this->custom + . "Control: cancel $mid\n" + . "\n" + . "Message canceled with Banana"; + if ($this->nntp->post($msg)) { + $this->spool->delid($id); + $this->nntp->quit(); + header("Location: ?group=$group&first=$id"); + } else { + return '

'._b_('Impossible d\'annuler le message').'

'; + } + } + + function action_newFup($group, $id = -1) + { + $subject = $body = ''; + $target = $group; + + if ($id > 0) { + $this->nntp->group($group); + $this->_newPost($id); + if ($this->post) { + $subject = preg_replace("/^re\s*:\s*/i", '', 'Re: '.$this->post->headers['subject']); + $body = utf8_encode($this->post->name." "._b_("a écrit"))." :\n".wrap($this->post->body, "> "); + $target = isset($this->post->headers['followup-to']) ? $this->post->headers['followup-to'] : $this->post->headers['newsgroups']; + } + } + + $this->nntp->quit(); + + $cuts = displayshortcuts(); + $html = '

'._b_('Nouveau message').'

'.$cuts; + $html .= '
'; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= ''; + $html .= '
'._b_('En-têtes').'
'._b_('Nom').''.htmlentities($this->profile['name']).'
'._b_('Sujet').'
'._b_('Forums').'
'._b_('Suivi à').'
'._b_('Organisation').''.$this->profile['org'].'
'._b_('Corps').'
'; + if ($id > 0) { + $html .= ''; + } + $html .= ''; + $html .= '
'; + + return $html.$cuts; + } + + function action_doFup($group, $artid = -1) + { + if ( ! ( is_utf8($_POST['subject']) && is_utf8($_POST['name']) + && is_utf8($_POST['org']) && is_utf8($_POST['body']) ) + ) { + foreach(array('subject', 'name', 'org', 'body') as $key) { + $_POST[$key] = utf8_encode($_POST[$key]); + } + } + + $this->_newSpool($group, $this->profile['display'], $this->profile['lastnews']); + $body = preg_replace("/\n\.[ \t\r]*\n/m", "\n..\n", $_POST['body']); + $msg = 'From: '.$this->profile['name']."\n" + . "Newsgroups: ".$_POST['newsgroups']."\n" + . "Subject: ".headerEncode($_POST['subject'], 128)."\n" + . (empty($this->profile['org']) ? '' : "Organization: {$this->profile['org']}\n") + . (empty($_POST['followup']) ? '' : 'Followup-To: '.$_POST['followup']."\n"); + + if ($artid != -1) { + $this->_require('post'); + $post = new BananaPost($artid); + $refs = ( isset($post->headers['references']) ? $post->headers['references']." " : "" ); + $msg .= "References: $refs{$post->headers['message-id']}\n"; + } + + $msg .= $this->custom.$this->profile['customhdr']."\n".wrap($body, "", $this->wrap); + + if ($this->nntp->post($msg)) { + header("Location: ?group=$group".($artid==-1 ? '' : "&first=$artid")); + } else { + return "

"._b_('Impossible de poster le message')."

".$this->action_showThread($group, $artid); + } + } + + /**************************************************************************/ + /* Private functions */ + /**************************************************************************/ + + function _newSpool($group, $disp=0, $since='') { + $this->_require('spool'); + if (!$this->spool || $this->spool->group != $group) { + $this->spool = new BananaSpool($group, $disp, $since); + } + } + + function _newPost($id) + { + $this->_require('post'); + $this->post = new BananaPost($id); + } + + function _newGroup() + { + $this->_require('groups'); + $this->groups = new BananaGroups(BANANA_GROUP_SUB); + if ($this->groups->type == BANANA_GROUP_SUB) { + $this->newgroups = new BananaGroups(BANANA_GROUP_NEW); + } + } + + function _require($file) + { + require_once (dirname(__FILE__).'/'.$file.'.inc.php'); + } +} + +?> diff --git a/banana/groups.inc.php b/banana/groups.inc.php new file mode 100644 index 0000000..964682f --- /dev/null +++ b/banana/groups.inc.php @@ -0,0 +1,126 @@ +type = $_type; + $desc = $banana->nntp->xgtitle(); + + if ($_type == BANANA_GROUP_NEW) { + $list = $banana->nntp->newgroups($banana->profile['lastnews']); + } else { + $list = $banana->nntp->liste(); + if ($_type == BANANA_GROUP_SUB) { + $mylist = Array(); + foreach ($banana->profile['subscribe'] as $g) { + if (isset($list[$g])) { + $mylist[$g] = $list[$g]; + } + } + $list = $mylist; + } + } + + foreach ($list as $g=>$l) { + $this->overview[$g][0] = isset($desc[$g]) ? $desc[$g] : '-'; + $this->overview[$g][1] = $l[0]; + } + ksort($this->overview); + + if (empty($this->overview) && $_type == BANANA_GROUP_SUB) { + $this = new BananaGroups(BANANA_GROUP_ALL); + } + } + + /** updates overview + * @param date INTEGER date of last update + */ + function update($_date) { + global $banana; + $serverdate = $banana->nntp->date(); + if (!$serverdate) $serverdate=time(); + $newlist = $banana->nntp->newgroups($_date); + if (!$newlist) return false; + $this->date = $serverdate; + foreach (array_keys($newlist) as $g) { + $groupstat = $banana->nntp->group($g); + $groupdesc = $banana->nntp->xgtitle($g); + $this->overview[$g][0]=($groupdesc?$groupdesc:"-"); + $this->overview[$g][1]=$groupstat[0]; + } + return true; + } + + function to_html($show_form = false) + { + global $banana; + if (empty($this->overview)) { + return; + } + + $html = ''."\n"; + $html .= ''."\n"; + + $b = true; + foreach ($this->overview as $g => $d) { + $b = !$b; + $ginfo = $banana->nntp->group($g); + $new = count($banana->nntp->newnews($banana->profile['lastnews'],$g)); + + $html .= ''."\n"; + $html .= ""; + if ($show_form) { + $html .= ''; + } elseif ($this->type == BANANA_GROUP_SUB) { + $html .= ''; + } + $html .= ""; + } + + $html .= '
'._b_('Total').''; + if ($show_form) { + $html .= _b_('Abo.').''; + } elseif ($this->type == BANANA_GROUP_SUB) { + $html .= _b_('Nouveaux').''; + } + $html .= _b_('Nom').''._b_('Description').'
{$ginfo[0]}profile['subscribe'])) { + $html .= ' checked="checked"'; + } + $html .= ' />'.($new ? $new : '-').'$g{$d[0]}
'; + + if ($show_form) { + return '
' + .$html.'
'; + } + + return $html; + } +} + +?> diff --git a/banana/misc.inc.php b/banana/misc.inc.php new file mode 100644 index 0000000..3258ef1 --- /dev/null +++ b/banana/misc.inc.php @@ -0,0 +1,235 @@ + $trim) { + $value = substr($value, 0, $trim) . "[...]"; + } + } + return "=?UTF-8?B?".base64_encode($value)."?="; +} + +function header_translate($hdr) { + switch ($hdr) { + case 'from': return _b_('De'); + case 'subject': return _b_('Sujet'); + case 'newsgroups': return _b_('Forums'); + case 'followup-to': return _b_('Suivi-à'); + case 'date': return _b_('Date'); + case 'organization': return _b_('Organisation'); + case 'references': return _b_('Références'); + case 'x-face': return _b_('Image'); + default: + if (function_exists('hook_headerTranslate') + && $res = hook_headerTranslate($hdr)) { + return $res; + } + return $hdr; + } +} + +function formatDisplayHeader($_header,$_text) { + global $banana; + switch ($_header) { + case "date": + return formatDate($_text); + + case "followup-to": + case "newsgroups": + $res = ""; + $groups = preg_split("/[\t ]*,[\t ]*/",$_text); + foreach ($groups as $g) { + $res.="$g, "; + } + return substr($res,0, -2); + + case "from": + return formatFrom($_text); + + case "references": + $rsl = ""; + $ndx = 1; + $text = str_replace("><","> <",$_text); + $text = preg_split("/[ \t]/",strtr($text,$banana->spool->ids)); + $parents = preg_grep("/^\d+$/",$text); + $p = array_pop($parents); + $par_ok = Array(); + + while ($p) { + $par_ok[]=$p; + $p = $banana->spool->overview[$p]->parent; + } + foreach (array_reverse($par_ok) as $p) { + $rsl .= "spool->group}&artid=$p\">$ndx "; + $ndx++; + } + return $rsl; + + case "x-face": + return 'x-face'; + + default: + if (function_exists('hook_formatDisplayHeader') + && $res = hook_formatDisplayHeader($_header, $_text)) + { + return $res; + } + return htmlentities($_text); + } +} + +/******************************************************************************** + * FORMATTING STUFF + */ + +function formatDate($_text) { + return strftime("%A %d %B %Y, %H:%M (fuseau serveur)", strtotime($_text)); +} + +function fancyDate($stamp) { + $today = intval(time() / (24*3600)); + $dday = intval($stamp / (24*3600)); + + if ($today == $dday) { + $format = "%H:%M"; + } elseif ($today == 1 + $dday) { + $format = _b_('hier')." %H:%M"; + } elseif ($today < 7 + $dday) { + $format = '%a %H:%M'; + } else { + $format = '%a %e %b'; + } + return strftime($format, $stamp); +} + +function formatFrom($text) { +# From: mark@cbosgd.ATT.COM +# From: mark@cbosgd.ATT.COM (Mark Horton) +# From: Mark Horton + $mailto = '".htmlentities($regs[1]."@".$regs[2]).""; + } + if (preg_match("/^([^ ]+)@([^ ]+) \((.*)\)$/",$text,$regs)) { + $result="$mailto{$regs[1]}@{$regs[2]}\">".htmlentities($regs[3]).""; + } + if (preg_match("/^\"?([^<>\"]+)\"? +<(.+)@(.+)>$/",$text,$regs)) { + $result="$mailto{$regs[2]}@{$regs[3]}\">".htmlentities($regs[1]).""; + } + return preg_replace("/\\\(\(|\))/","\\1",$result); +} + +function displayshortcuts($first = -1) { + global $banana; + extract($banana->state); + + $res = '
'; + $res .= '['._b_('Liste des forums').'] '; + if (is_null($group)) { + return $res.'['._b_('Abonnements').']
'; + } + + $res .= "[$group] "; + + if (is_null($artid)) { + $res .= "["._b_('Nouveau message')."] "; + if (sizeof($banana->spool->overview)>$banana->tmax) { + $res .= '
'; + $n = intval(log(count($banana->spool->overview), 10))+1; + for ($ndx=1; $ndx <= sizeof($banana->spool->overview); $ndx += $banana->tmax) { + if ($first==$ndx) { + $fmt = "[%0{$n}u-%0{$n}u] "; + } else { + $fmt = "[%0{$n}u-%0{$n}u] "; + } + $res .= sprintf($fmt, $ndx, min($ndx+$banana->tmax-1,sizeof($banana->spool->overview))); + } + } + } else { + $res .= "[" + ._b_('Répondre')."] "; + if ($banana->post->checkcancel()) { + $res .= "[" + ._b_('Annuler ce message')."] "; + } + } + return $res.''; +} + +/******************************************************************************** + * FORMATTING STUFF : BODY + */ + +function wrap($text, $_prefix="") +{ + $parts = preg_split("/\n-- ?\n/", $text); + if (count($parts) >1) { + $sign = "\n-- \n" . array_pop($parts); + $text = join("\n-- \n", $parts); + } else { + $sign = ''; + $text = $text; + } + + global $banana; + $length = $banana->wrap; + $cmd = "echo ".escapeshellarg($text)." | perl -MText::Autoformat -e 'autoformat {left=>1, right=>$length, all=>1 };'"; + exec($cmd, $result); + + return $_prefix.join("\n$_prefix", $result).($_prefix ? '' : $sign); +} + +function formatbody($_text) { + $res = "\n\n" . to_entities(wrap($_text, ""))."\n\n"; + $res = preg_replace("/(<|>|")/", " \\1 ", $res); + $res = preg_replace('/(["\[])?((https?|ftp|news):\/\/[a-z@0-9.~%$£µ&i#\-+=_\/\?]*)(["\]])?/i', "\\1\\2\\4", $res); + $res = preg_replace("/ (<|>|") /", "\\1", $res); + + $parts = preg_split("/\n-- ?\n/", $res); + + if (count($parts) > 1) { + $sign = "
" . array_pop($parts);
+        return join("\n-- \n", $parts).$sign;
+    } else {
+        return $res;
+    }
+}
+
+?>
diff --git a/banana/post.inc.php b/banana/post.inc.php
new file mode 100644
index 0000000..f9ca5cc
--- /dev/null
+++ b/banana/post.inc.php
@@ -0,0 +1,124 @@
+id = $_id;
+        $this->_header();
+
+        if ($body = $banana->nntp->body($_id)) {
+            $this->body = join("\n", $body);
+        } else {
+            return ($this = null);
+        }
+        
+        if (isset($this->headers['content-transfer-encoding'])) {
+            if (preg_match("/base64/", $this->headers['content-transfer-encoding'])) {
+                $this->body = base64_decode($this->body);
+            } elseif (preg_match("/quoted-printable/", $this->headers['content-transfer-encoding'])) {
+                $this->body = quoted_printable_decode($this->body);
+            }
+        }
+
+        if (preg_match('!charset=([^;]*)\s*(;|$)!', $this->headers['content-type'], $matches)) {
+            $this->body = iconv($matches[1], 'utf-8', $this->body);
+        } else {
+            $this->body = utf8_encode($this->body);
+        }
+    }
+
+    function _header()
+    {
+        global $banana;
+        $hdrs = $banana->nntp->head($this->id);
+        if (!$hdrs) {
+            $this = null;
+            return false;
+        }
+
+        // parse headers
+        foreach ($hdrs as $line) {
+            if (preg_match("/^[\t\r ]+/", $line)) {
+                $line = ($hdr=="X-Face"?"":" ").ltrim($line);
+                if (in_array($hdr, $banana->parse_hdr))  {
+                    $this->headers[$hdr] .= $line;
+                }
+            } else {
+                list($hdr, $val) = split(":[ \t\r]*", $line, 2);
+                $hdr = strtolower($hdr);
+                if (in_array($hdr, $banana->parse_hdr)) {
+                    $this->headers[$hdr] = $val;
+                }
+            }
+        }
+        // decode headers
+        foreach ($banana->hdecode as $hdr) {
+            if (isset($this->headers[$hdr])) {
+                $this->headers[$hdr] = headerDecode($this->headers[$hdr]);
+            }
+        }
+
+        $this->name = $this->headers['from'];
+        $this->name = preg_replace('/<[^ ]*>/', '', $this->name);
+        $this->name = trim($this->name);
+    }
+
+    function checkcancel()
+    {
+        if (function_exists('hook_checkcancel')) {
+            return hook_checkcancel($this->headers);
+        }
+        return ($this->headers['from'] == $_SESSION['name']." <".$_SESSION['mail'].">");
+    }
+
+    function to_html()
+    {
+        global $banana;
+
+        $res  = '';
+        $res .= '';
+
+        foreach ($banana->show_hdr as $hdr) {
+            if (isset($this->headers[$hdr])) {
+                $res2 = formatdisplayheader($hdr, $this->headers[$hdr]);
+                if ($res2) {
+                    $res .= '\n";
+                }
+            }
+        }
+
+        $res .= '';
+        $res .= '';
+        
+        $res .= '';
+        $ndx  = $banana->spool->getndx($this->id);
+        $res .= '';
+
+        return $res.'
'._b_('En-têtes').'
'.header_translate($hdr)."$res2
'._b_('Corps').'
'.formatbody($this->body).'
'._b_('apercu').'
'.$banana->spool->to_html($ndx-$banana->tbefore, $ndx+$banana->tafter, $ndx).'
'; + } +} + +?> diff --git a/banana/spool.inc.php b/banana/spool.inc.php new file mode 100644 index 0000000..6c17d62 --- /dev/null +++ b/banana/spool.inc.php @@ -0,0 +1,425 @@ +date>=$a->date); } + +/** Class spoolhead + * class used in thread overviews + */ +class BananaSpoolHead +{ + /** date (timestamp) */ + var $date; + /** subject */ + var $subject; + /** author */ + var $from; + /** reference of parent */ + var $parent; + /** paren is direct */ + var $parent_direct; + /** array of children */ + var $children = Array(); + /** true if post is read */ + var $isread; + /** number of posts deeper in this branch of tree */ + var $desc; + /** same as desc, but counts only unread posts */ + var $descunread; + + /** constructor + * @param $_date INTEGER timestamp of post + * @param $_subject STRING subject of post + * @param $_from STRING author of post + * @param $_desc INTEGER desc value (1 for a new post) + * @param $_read BOOLEAN true if read + * @param $_descunread INTEGER descunread value (0 for a new post) + */ + + function BananaSpoolHead($_date, $_subject, $_from, $_desc=1, $_read=true, $_descunread=0) + { + $this->date = $_date; + $this->subject = $_subject; + $this->from = $_from; + $this->desc = $_desc; + $this->isread = $_read; + $this->descunread = $_descunread; + } +} + +/** Class spool + * builds and updates spool + */ + +define("BANANA_SPOOL_VERSION", '0.2'); + +class BananaSpool +{ + var $version; + /** spool */ + var $overview; + /** group name */ + var $group; + /** array msgid => msgnum */ + var $ids; + /** thread starts */ + var $roots; + + /** constructor + * @param $_group STRING group name + * @param $_display INTEGER 1 => all posts, 2 => only threads with new posts + * @param $_since INTEGER time stamp (used for read/unread) + */ + function BananaSpool($_group, $_display=0, $_since="") + { + global $banana; + $this->group = $_group; + $groupinfo = $banana->nntp->group($_group); + if (!$groupinfo) { return ($this = null); } + + $this->_readFromFile(); + + $do_save = false; + $first = $banana->maxspool ? max($groupinfo[2]-$banana->maxspool, $groupinfo[1]) : $groupinfo[1]; + $last = $groupinfo[2]; + if ($this->version == BANANA_SPOOL_VERSION && is_array($this->overview)) { + if (count($this->overview)) { + for ($id = min(array_keys($this->overview)); $id<$first; $id++) { + $this->delid($id, false); + $do_save = true; + } + } + if (!empty($this->overview)) { + $first = max(array_keys($this->overview))+1; + } else { + return; + } + } else { + unset($this->overview, $this->ids); + $this->version = BANANA_SPOOL_VERSION; + } + + if ($first<=$last && $groupinfo[0]) { + $do_save = true; + $this->_updateSpool("$first-$last"); + } + + if ($do_save) { $this->_saveToFile(); } + + $this->_updateUnread($_since, $_display); + } + + function _readFromFile() + { + $file = $this->_spoolfile(); + if (file_exists($file)) { + $this = unserialize(file_get_contents($file)); + } + } + + function _saveToFile() + { + $file = $this->_spoolfile(); + uasort($this->overview, "spoolcompare"); + + $this->roots = Array(); + foreach($this->overview as $id=>$msg) { + if (is_null($msg->parent)) { + $this->roots[] = $id; + } + } + + file_put_contents($file, serialize($this)); + } + + function _spoolfile() + { + global $banana; + $url = parse_url($banana->host); + $file = $url['host'].'_'.$url['port'].'_'.$this->group; + return dirname(dirname(__FILE__)).'/spool/'.$file; + } + + function _updateSpool($arg) + { + global $banana; + $dates = array_map('strtotime', $banana->nntp->xhdr('Date', $arg)); + $subjects = array_map('headerdecode', $banana->nntp->xhdr('Subject', $arg)); + $froms = array_map('headerdecode', $banana->nntp->xhdr('From', $arg)); + $msgids = $banana->nntp->xhdr('Message-ID', $arg); + $refs = $banana->nntp->xhdr('References', $arg); + + if (is_array($this->ids)) { + $this->ids = array_merge($this->ids, array_flip($msgids)); + } else { + $this->ids = array_flip($msgids); + } + + foreach ($msgids as $id=>$msgid) { + $msg = new BananaSpoolHead($dates[$id], $subjects[$id], $froms[$id]); + $refs[$id] = str_replace('><', '> <', $refs[$id]); + $msgrefs = preg_split("/[ \t]/", strtr($refs[$id], $this->ids)); + $parents = preg_grep('/^\d+$/', $msgrefs); + $msg->parent = array_pop($parents); + $msg->parent_direct = preg_match('/^\d+$/', array_pop($msgrefs)); + + if (isset($this->overview[$id])) { + $msg->desc = $this->overview[$id]->desc; + $msg->children = $this->overview[$id]->children; + } + $this->overview[$id] = $msg; + + if ($p = $msg->parent) { + if (empty($this->overview[$p])) { + $this->overview[$p] = new BananaSpoolHead($dates[$p], $subjects[$p], $froms[$p], 1); + } + $this->overview[$p]->children[] = $id; + + while ($p) { + $this->overview[$p]->desc += $msg->desc; + $p = $this->overview[$p]->parent; + } + } + } + } + + function _updateUnread($since, $mode) + { + global $banana; + if (empty($since)) { return; } + + if (is_array($newpostsids = $banana->nntp->newnews($since, $this->group))) { + if (!is_array($this->ids)) { $this->ids = array(); } + $newpostsids = array_intersect($newpostsids, array_keys($this->ids)); + foreach ($newpostsids as $mid) { + $this->overview[$this->ids[$mid]]->isread = false; + $this->overview[$this->ids[$mid]]->descunread = 1; + $parentmid = $this->ids[$mid]; + while (isset($parentmid)) { + $this->overview[$parentmid]->descunread ++; + $parentmid = $this->overview[$parentmid]->parent; + } + } + + if (count($newpostsids)) { + switch ($mode) { + case 1: + foreach ($this->roots as $k=>$i) { + if ($this->overview[$i]->descunread==0) { + $this->killdesc($i); + unset($this->roots[$k]); + } + } + break; + } + } + } + } + + /** kill post and childrens + * @param $_id MSGNUM of post + */ + + function killdesc($_id) + { + if (sizeof($this->overview[$_id]->children)) { + foreach ($this->overview[$_id]->children as $c) { + $this->killdesc($c); + } + } + unset($this->overview[$_id]); + if (($msgid = array_search($_id, $this->ids)) !== false) { + unset($this->ids[$msgid]); + } + } + + /** delete a post from overview + * @param $_id MSGNUM of post + */ + + function delid($_id, $write=true) + { + if (isset($this->overview[$_id])) { + if (sizeof($this->overview[$_id]->parent)) { + $this->overview[$this->overview[$_id]->parent]->children = + array_diff($this->overview[$this->overview[$_id]->parent]->children, array($_id)); + if (sizeof($this->overview[$_id]->children)) { + $this->overview[$this->overview[$_id]->parent]->children = + array_merge($this->overview[$this->overview[$_id]->parent]->children, $this->overview[$_id]->children); + foreach ($this->overview[$_id]->children as $c) { + $this->overview[$c]->parent = $this->overview[$_id]->parent; + $this->overview[$c]->parent_direct = false; + } + } + $p = $this->overview[$_id]->parent; + while ($p) { + $this->overview[$p]->desc--; + $p = $this->overview[$p]->parent; + } + } elseif (sizeof($this->overview[$_id]->children)) { + foreach ($this->overview[$_id]->children as $c) { + $this->overview[$c]->parent = null; + } + } + unset($this->overview[$_id]); + $msgid = array_search($_id, $this->ids); + if ($msgid) { + unset($this->ids[$msgid]); + } + + if ($write) { $this->_saveToFile(); } + } + } + + /** displays children tree of a post + * @param $_id INTEGER MSGNUM of post + * @param $_index INTEGER linear number of post in the tree + * @param $_first INTEGER linear number of first post displayed + * @param $_last INTEGER linear number of last post displayed + * @param $_ref STRING MSGNUM of current post + * @param $_pfx_node STRING prefix used for current node + * @param $_pfx_end STRING prefix used for children of current node + * @param $_head BOOLEAN true if first post in thread + */ + + function _to_html($_id, $_index, $_first=0, $_last=0, $_ref="", $_pfx_node="", $_pfx_end="", $_head=true) + { + $spfx_f = 'o'; + $spfx_n = '*'; + $spfx_Tnd = '+'; + $spfx_Lnd = '`'; + $spfx_snd = '-'; + $spfx_T = '+'; + $spfx_L = '`'; + $spfx_s = '-'; + $spfx_e = ' '; + $spfx_I = '|'; + + if ($_index + $this->overview[$_id]->desc < $_first || $_index > $_last) { + return; + } + + $res = ''; + + if ($_index>=$_first) { + $hc = empty($this->overview[$_id]->children); + + $res .= '\n"; + $res .= "".fancyDate($this->overview[$_id]->date)." \n"; + $res .= "" + ."
$_pfx_node".($hc?($_head?$spfx_f:($this->overview[$_id]->parent_direct?$spfx_s:$spfx_snd)):$spfx_n) + ."
"; + if ($_index == $_ref) { + $res .= ''.htmlentities($this->overview[$_id]->subject).''; + } else { + $res .= "".htmlentities($this->overview[$_id]->subject).''; + } + $res .= "\n".formatFrom($this->overview[$_id]->from)."\n"; + + if ($hc) { return $res; } + } + + $_index ++; + + $children = $this->overview[$_id]->children; + while ($child = array_shift($children)) { + if ($_index > $_last) { return $res; } + if ($_index+$this->overview[$child]->desc >= $_first) { + if (sizeof($children)) { + $res .= $this->_to_html($child, $_index, $_first, $_last, $_ref, + $_pfx_end.($this->overview[$child]->parent_direct?$spfx_T:$spfx_Tnd), + $_pfx_end.$spfx_I, false); + } else { + $res .= $this->_to_html($child, $_index, $_first, $_last, $_ref, + $_pfx_end.($this->overview[$child]->parent_direct?$spfx_L:$spfx_Lnd), + $_pfx_end.$spfx_e, false); + } + } + $_index += $this->overview[$child]->desc; + } + + return $res; + } + + /** Displays overview + * @param $_first INTEGER MSGNUM of first post + * @param $_last INTEGER MSGNUM of last post + * @param $_ref STRING MSGNUM of current/selectionned post + */ + + function to_html($_first=0, $_last=0, $_ref = null) + { + $res = ''; + + if (is_null($_ref)) { + $res .= ''; + $res .= ''; + $res .= ''; + } + + $index = 1; + if (sizeof($this->overview)) { + foreach ($this->roots as $id) { + $res .= $this->_to_html($id, $index, $_first, $_last, $_ref); + $index += $this->overview[$id]->desc ; + if ($index > $_last) { break; } + } + } else { + $res .= ''; + } + + return $res .= '
'._b_('Date').''._b_('Sujet').''._b_('Auteur').'
'._b_('Aucun message dans ce forum').'
'; + } + + /** computes linear post index + * @param $_id INTEGER MSGNUM of post + * @return INTEGER linear index of post + */ + + function getndx($_id) + { + $ndx = 1; + $id_cur = $_id; + while (true) { + $id_parent = $this->overview[$id_cur]->parent; + if (is_null($id_parent)) break; + $pos = array_search($id_cur, $this->overview[$id_parent]->children); + + for ($i = 0; $i < $pos ; $i++) { + $ndx += $this->overview[$this->overview[$id_parent]->children[$i]]->desc; + } + $ndx++; //noeud père + + $id_cur = $id_parent; + } + + foreach ($this->roots as $i) { + if ($i==$id_cur) { + break; + } + $ndx += $this->overview[$i]->desc; + } + return $ndx; + } +} + +?> diff --git a/banana/utf8.php b/banana/utf8.php new file mode 100644 index 0000000..c847bdd --- /dev/null +++ b/banana/utf8.php @@ -0,0 +1,85 @@ += 240) && ($asciiPos <= 255)) // 4 chars representing one unicode character + $i=4; + else if (($asciiPos >= 224) && ($asciiPos <= 239)) // 3 chars representing one unicode character + $i=3; + else if (($asciiPos >= 192) && ($asciiPos <= 223)) // 2 chars representing one unicode character + $i=2; + else // 1 char (lower ascii) + $i=1; + $thisLetter = substr($source, $pos, $i); + $pos += $i; + + // process the string representing the letter to a unicode entity + $thisLen = strlen($thisLetter); + $thisPos = 0; + $decimalCode = 0; + while ($thisPos < $thisLen) + { + $thisCharOrd = ord(substr($thisLetter, $thisPos, 1)); + if ($thisPos == 0) + { + $charNum = intval($thisCharOrd - $decrement[$thisLen]); + $decimalCode += ($charNum << $shift[$thisLen][$thisPos]); + } + else + { + $charNum = intval($thisCharOrd - 128); + $decimalCode += ($charNum << $shift[$thisLen][$thisPos]); + } + + $thisPos++; + } + + $encodedLetter = '&#'. str_pad($decimalCode, ($thisLen==1)?3:5, '0', STR_PAD_LEFT).';'; + $encodedString .= $encodedLetter; + } + + return $encodedString; +} + +?> diff --git a/css/banana.css b/css/banana.css new file mode 100644 index 0000000..cf1940b --- /dev/null +++ b/css/banana.css @@ -0,0 +1,67 @@ +/*************************************************************************** + * Copyright (C) 2003-2004 Polytechnique.org * + * http://opensource.polytechnique.org/ * + * * + * This program 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 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., * + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * + ***************************************************************************/ + +body { + font-family:"Trebuchet MS",Verdana,Geneva,Arial,Helvetica,sans-serif; + margin:2em 1%; + padding:0; +} + +div.bloc { width: 800px; margin-left: auto; margin-right: auto; } + +div.foot { + border-top: 1px solid #a2c2e1; + padding-top: 1em; + margin-top: 1em; +} + +a:link, a:visited { color: #f60; background: transparent; } +a:active, a:hover { color: #369; background: transparent; } + +hr { border: none; border-top: 1px dotted #a2c2e1; } + +h1 { + color: #369; + background: inherit; + font-size: 200%; + text-align: center; + margin: 0em; + border-bottom: 2px solid #369; + padding: 4px; + margin: 1em 0em; +} + +table.bicol { + border-collapse: collapse; + border: 1px solid #a2c2e1; + width: 100%; +} + +table.bicol tr.impair { } +table.bicol tr.pair { color: inherit; background: #eee; } + +table.bicol th { + color: #369; + background: #d6e1ec; + padding: 0px 4px; +} + +table.bicol td { padding: 0px 4px; } + diff --git a/css/style.css b/css/style.css new file mode 100644 index 0000000..825a890 --- /dev/null +++ b/css/style.css @@ -0,0 +1,41 @@ +/******************************************************************************** +* css/style.css : Default css +* --------------- +* +* This file is part of the banana distribution +* Copyright: See COPYING files that comes with this distribution +********************************************************************************/ + +div.banana_scuts { text-align: left; padding: 0.5em 0em; } + +/** GROUP LIST **/ + +table.banana_group td.new { text-align: center; } +table.banana_group td.all { text-align: center; } +table.banana_group td.grp { text-align: left; } +table.banana_group td.dsc { text-align: left; } + +/** THREAD VIEW **/ + +table.banana_thread td { white-space: nowrap; height: 100%; vertical-align: middle; } + +table.banana_thread tr.new { font-weight: bold; } + +table.banana_thread td.date { width: 15%; text-align: center; } +table.banana_thread td.subj { text-align: left; overflow: hidden; } +table.banana_thread td.from { text-align: left; } + +table.banana_thread div.tree { float: left; padding-right: 0.3em; } +table.banana_thread span.cur { font-style: italic; font-size: 90%; } + +/** MESSAGE VIEW **/ + +table.banana_msg .hdr { width: 15%; text-align: right; font-weight: bold; padding-right: 1em; } + +table.banana_msg td.thrd { padding: 0px; } +table.banana_msg table { border: 0px; padding: 0px; margin: 0px; width: 100%; } + +/** MISC **/ + +div.center { text-align: center; padding: 1em; } +p.error { color: red; background: inherit; } diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 0000000..acad1c1 --- /dev/null +++ b/debian/changelog @@ -0,0 +1,18 @@ +banana (1.2-1) unstable; urgency=low + + * New upstream release. + + -- Pierre Habouzit Wed, 19 Oct 2005 20:00:06 +0200 + +banana (1.1-1) unstable; urgency=low + + * New upstream release. + + -- Pierre Habouzit Tue, 24 May 2005 09:13:39 +0200 + +banana (1.0-1) unstable; urgency=low + + * First upstream release. + + -- Pierre Habouzit Wed, 19 Jan 2005 21:55:41 +0100 + diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..e6424ee --- /dev/null +++ b/debian/control @@ -0,0 +1,15 @@ +Source: banana +Section: web +Priority: optional +Maintainer: Pierre Habouzit +Standards-Version: 3.6.1 +Build-Depends-Indep: cdbs, debhelper (>= 4.1.16) + +Package: php-banana +Architecture: all +Depends: php4-cli +Recommends: compface, imagemagick +Description: php library aimed to write NNTP <-> Web gateways + . + Homepage: http://opensource.polytechnique.org/banana/ + diff --git a/debian/copyright b/debian/copyright new file mode 100644 index 0000000..7fb510d --- /dev/null +++ b/debian/copyright @@ -0,0 +1,15 @@ +This package was debianized by Pierre Habouzit on +Fri, 07 Jan 2005 22:40:08 +0100 + +It was downloaded from http://opensource.polytechnique.org/banana/ + +Upstream Author: David Bachelart + +* Banana is licensed under the terms of the GPL version 2 + or later and is copyright : + + (c) 2003-2004 David Bachelart. + (c) 2005 Pierre Habouzit. + +On Debian GNU/Linux systems, the complete text of the GNU General Public +License may be found in `/usr/share/common-licenses/GPL'. diff --git a/debian/patches/10.correct_spool_path.patch b/debian/patches/10.correct_spool_path.patch new file mode 100644 index 0000000..c8999c8 --- /dev/null +++ b/debian/patches/10.correct_spool_path.patch @@ -0,0 +1,11 @@ +--- /home/x2000habouzit/dev/banana/banana/spool.inc.php 2005-01-07 23:47:41.000000000 +0100 ++++ banana/spool.inc.php 2005-01-07 23:46:58.000000000 +0100 +@@ -150,7 +150,7 @@ + global $banana; + $url = parse_url($banana->host); + $file = $url['host'].'_'.$url['port'].'_'.$this->group; +- return dirname(dirname(__FILE__)).'/spool/'.$file; ++ return "/var/spool/banana/$file"; + } + + function _updateSpool($arg) diff --git a/debian/php-banana.install b/debian/php-banana.install new file mode 100644 index 0000000..d2758db --- /dev/null +++ b/debian/php-banana.install @@ -0,0 +1,4 @@ +banana/ /usr/share/php/ +img/ /usr/share/banana/ +css/ /usr/share/banana/ +locale/ /usr/share/ diff --git a/debian/php-banana.postinst b/debian/php-banana.postinst new file mode 100644 index 0000000..92e96ab --- /dev/null +++ b/debian/php-banana.postinst @@ -0,0 +1,8 @@ +#! /bin/sh + +chown -R www-data /var/spool/banana + +#DEBHELPER# + +exit 0 + diff --git a/debian/php-banana.postrm b/debian/php-banana.postrm new file mode 100644 index 0000000..81c71ae --- /dev/null +++ b/debian/php-banana.postrm @@ -0,0 +1,16 @@ +#!/bin/sh -e + +ACTION=$1 +case "$ACTION" in + purge) + rm -rf /var/spool/banana + ;; + + *) + ;; +esac + + +#DEBHELPER# + +exit 0 diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..12c34e9 --- /dev/null +++ b/debian/rules @@ -0,0 +1,24 @@ +#!/usr/bin/make -f +include /usr/share/cdbs/1/rules/debhelper.mk +include /usr/share/cdbs/1/rules/simple-patchsys.mk + +# configure simple-patchsys +DEB_PATCHDIRS := debian/patches + +# documentation +DEB_INSTALL_DOCS_ALL := +DEB_INSTALL_DOCS_php-banana := AUTHORS TODO examples/ + +# changelogs +DEB_INSTALL_CHANGELOGS_ALL := +DEB_INSTALL_CHANGELOGS_php-banana := Changelog + +#directories +DEB_INSTALL_DIRS_php-banana := var/spool/banana/ + +install/php-banana:: + make + +clean:: + rm -f debian/compat + make clean diff --git a/examples/index.php b/examples/index.php new file mode 100644 index 0000000..7893f06 --- /dev/null +++ b/examples/index.php @@ -0,0 +1,35 @@ + + + + + + + + + + Banana, a NNTP<->Web Gateway + + + +
+ +
+ Banana, a Web interface for a NNTP Server
+ Developed under GPL License for Polytechnique.org +
+
+ + diff --git a/examples/spoolgen.php b/examples/spoolgen.php new file mode 100644 index 0000000..b848de2 --- /dev/null +++ b/examples/spoolgen.php @@ -0,0 +1,54 @@ +#! /usr/bin/php4 +host = "http://{$opt['u']}:{$opt['p']}@localhost:119/"; + echo $this->host; + parent::Banana(); + } + + function createAllSpool() + { + $this->_require('groups'); + $this->_require('spool'); + $this->_require('misc'); + + $groups = new BananaGroups(BANANA_GROUP_ALL); + + foreach (array_keys($groups->overview) as $g) { + print "Generating spool for $g : "; + $spool = new BananaSpool($g); + print "done.\n"; + unset($spool); + } + $this->nntp->quit(); + } +} + + +$banana = new MyBanana(); +$banana->createAllSpool(); +?> diff --git a/examples/xface.php b/examples/xface.php new file mode 100644 index 0000000..16d0332 --- /dev/null +++ b/examples/xface.php @@ -0,0 +1,6 @@ + diff --git a/img/I.gif b/img/I.gif new file mode 100644 index 0000000000000000000000000000000000000000..a7cb3a2c4a64cd64e6512c5a28d33bc0fa25e4bc GIT binary patch literal 68 zcmZ?wbhEHb0r5dH3{28J%*$u(e#_U>;gy|srO!Sl RQI5H9dc?99S(U5|)&Mv*6Egq+ literal 0 HcmV?d00001 diff --git a/img/L-direct.gif b/img/L-direct.gif new file mode 100644 index 0000000000000000000000000000000000000000..4884f3f2159c9ea4eec251977ff40bb1718fc14a GIT binary patch literal 73 zcmZ?wbhEHb|tka%#E_+oa!e9*m|34Bx literal 0 HcmV?d00001 diff --git a/img/L.gif b/img/L.gif new file mode 100644 index 0000000000000000000000000000000000000000..171dcb625bd0365954665581d170a3211df7cbfa GIT binary patch literal 67 zcmZ?wbhEHb0r5dH3`|lz%*$u(e#_U>;gy|srO&>H R;n9o6XPwJl%@Sj<1^_oy6z2c{ literal 0 HcmV?d00001 diff --git a/img/T-direct.gif b/img/T-direct.gif new file mode 100644 index 0000000000000000000000000000000000000000..1f470839ca9b5623804e55e700291330ac74ec9b GIT binary patch literal 77 zcmZ?wbhEHb|rHOLP^Oi16dztOV%3uuuMZ6OK literal 0 HcmV?d00001 diff --git a/img/T.gif b/img/T.gif new file mode 100644 index 0000000000000000000000000000000000000000..cf2335f6da2d4f18f83fbb5b76205a010d070533 GIT binary patch literal 71 zcmZ?wbhEHb0r5dH3`}x8%*$u(e#_U>;gy|srO&>H V;gLlpPexqCtcCA>>9I0c0|0yV6$AhP literal 0 HcmV?d00001 diff --git a/img/e.gif b/img/e.gif new file mode 100644 index 0000000000000000000000000000000000000000..e92eaac290eb94ef378e40d3d96c9a69d29df71c GIT binary patch literal 42 ncmZ?wbhEHbWMp7uXkcLY4+e@qSr{3BKnFyCWEhwjT^OtZ45|tA literal 0 HcmV?d00001 diff --git a/img/k1.gif b/img/k1.gif new file mode 100644 index 0000000000000000000000000000000000000000..9cbf0a4ce9f77a8418c37a0b615ec15d2ef3163b GIT binary patch literal 61 zcmZ?wbhEHb0r5dH3``h#ku LTOREYVXy`O$P^MT literal 0 HcmV?d00001 diff --git a/img/k2.gif b/img/k2.gif new file mode 100644 index 0000000000000000000000000000000000000000..37eb3680d0793e6430332d6b022b0bded6a93ac5 GIT binary patch literal 66 zcmZ?wbhEHb0r5dH3`~+e{VPx3Wmp_Dfl2zw+Aj6} PjHnYaA)WKw85yhr8dnmQ literal 0 HcmV?d00001 diff --git a/img/s-direct.gif b/img/s-direct.gif new file mode 100644 index 0000000000000000000000000000000000000000..211816c324869a4a6b28d1226cea3bef9d91ea17 GIT binary patch literal 61 zcmZ?wbhEHb0r5dH3`~4I{VPwu literal 0 HcmV?d00001 diff --git a/po/Makefile b/po/Makefile new file mode 100644 index 0000000..92f5b61 --- /dev/null +++ b/po/Makefile @@ -0,0 +1,28 @@ +# Horde .mo files makefile +# +# $Horde: horde/po/Makefile,v 1.2.2.3 2002/05/20 17:36:22 jan Exp $ +# + +LANGS:=$(shell ls *.po|sed -e s/\.po$$//) + +all: banana.pot ${LANGS:=.lang} + +clean: + rm -f *.po~ *.lang + +banana.pot: ../banana/*.php + @echo Parsing Tree for new messages + @echo + @xgettext --from-code=iso-8859-15 -j -k_b_ -o banana.pot $< + +%.lang: banana.pot ../banana/*.php %.po + @echo Generating $(@:.lang=.po) + @echo -n ' ' + @mkdir -p ../locale/$(@:.lang=)/LC_MESSAGES/ + @msgmerge -U $(@:lang=po) $< 2> /dev/null + @msgfmt --statistics -c -v -o ../locale/$(@:.lang=)/LC_MESSAGES/banana.mo $(@:lang=po) + @echo + @rm -f $(@:lang=po~) + @touch $@ + + diff --git a/po/banana.pot b/po/banana.pot new file mode 100644 index 0000000..d97857a --- /dev/null +++ b/po/banana.pot @@ -0,0 +1,158 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2005-10-19 19:58+0200\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +#: ../banana/banana.inc.php:54 +msgid "Impossible de contacter le serveur" +msgstr "" + +#: ../banana/banana.inc.php:93 +msgid "Voulez-vous vraiment annuler ce message ?" +msgstr "" + +#: ../banana/banana.inc.php:124 +msgid "Les forums de Banana" +msgstr "" + +#: ../banana/banana.inc.php:126 +msgid "Les forums suivants ont été créés depuis ton dernier passage :" +msgstr "" + +#: ../banana/banana.inc.php:140 ../banana/misc.inc.php:150 +msgid "Abonnements" +msgstr "" + +#: ../banana/banana.inc.php:175 +msgid "Impossible d'accéder au message. Le message a peut-être été annulé" +msgstr "" + +#: ../banana/banana.inc.php:179 +msgid "Message" +msgstr "" + +#: ../banana/banana.inc.php:194 +msgid "Vous n'avez pas les permissions pour annuler ce message" +msgstr "" + +#: ../banana/banana.inc.php:208 +msgid "Impossible d'annuler le message" +msgstr "" + +#: ../banana/banana.inc.php:222 +msgid "a écrit" +msgstr "" + +#: ../banana/banana.inc.php:230 ../banana/misc.inc.php:156 +msgid "Nouveau message" +msgstr "" + +#: ../banana/banana.inc.php:233 ../banana/post.inc.php:100 +msgid "En-têtes" +msgstr "" + +#: ../banana/banana.inc.php:234 ../banana/groups.inc.php:93 +msgid "Nom" +msgstr "" + +#: ../banana/banana.inc.php:235 ../banana/misc.inc.php:34 +#: ../banana/spool.inc.php:360 +msgid "Sujet" +msgstr "" + +#: ../banana/banana.inc.php:236 ../banana/misc.inc.php:35 +msgid "Forums" +msgstr "" + +#: ../banana/banana.inc.php:237 +msgid "Suivi à" +msgstr "" + +#: ../banana/banana.inc.php:238 ../banana/misc.inc.php:38 +msgid "Organisation" +msgstr "" + +#: ../banana/banana.inc.php:239 ../banana/post.inc.php:111 +msgid "Corps" +msgstr "" + +#: ../banana/banana.inc.php:275 ../banana/banana.inc.php:283 +msgid "Impossible de poster le message" +msgstr "" + +#: ../banana/groups.inc.php:87 +msgid "Total" +msgstr "" + +#: ../banana/groups.inc.php:89 +msgid "Abo." +msgstr "" + +#: ../banana/groups.inc.php:91 +msgid "Nouveaux" +msgstr "" + +#: ../banana/groups.inc.php:93 +msgid "Description" +msgstr "" + +#: ../banana/misc.inc.php:33 +msgid "De" +msgstr "" + +#: ../banana/misc.inc.php:36 +msgid "Suivi-à" +msgstr "" + +#: ../banana/misc.inc.php:37 ../banana/spool.inc.php:359 +msgid "Date" +msgstr "" + +#: ../banana/misc.inc.php:39 +msgid "Références" +msgstr "" + +#: ../banana/misc.inc.php:40 +msgid "Image" +msgstr "" + +#: ../banana/misc.inc.php:115 +msgid "hier" +msgstr "" + +#: ../banana/misc.inc.php:148 +msgid "Liste des forums" +msgstr "" + +#: ../banana/misc.inc.php:171 +msgid "Répondre" +msgstr "" + +#: ../banana/misc.inc.php:174 +msgid "Annuler ce message" +msgstr "" + +#: ../banana/post.inc.php:114 +msgid "apercu" +msgstr "" + +#: ../banana/spool.inc.php:361 +msgid "Auteur" +msgstr "" + +#: ../banana/spool.inc.php:372 +msgid "Aucun message dans ce forum" +msgstr "" diff --git a/po/en.po b/po/en.po new file mode 100644 index 0000000..8295d7e --- /dev/null +++ b/po/en.po @@ -0,0 +1,158 @@ +# translation of en.po to +# This file is distributed under the same license as the PACKAGE package. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER. +# Pierre Habouzit , 2005. +# +msgid "" +msgstr "" +"Project-Id-Version: en\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2005-05-24 21:04+0200\n" +"PO-Revision-Date: 2005-01-02 17:13+0100\n" +"Last-Translator: Pierre Habouzit \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Generator: KBabel 1.9.1\n" + +#: ../banana/banana.inc.php:54 +msgid "Impossible de contacter le serveur" +msgstr "Server unreachable" + +#: ../banana/banana.inc.php:93 +msgid "Voulez-vous vraiment annuler ce message ?" +msgstr "Do you really want to cancel that post ?" + +#: ../banana/banana.inc.php:124 +msgid "Les forums de Banana" +msgstr "Banana's Bewsgroups" + +#: ../banana/banana.inc.php:126 +msgid "Les forums suivants ont été créés depuis ton dernier passage :" +msgstr "This newsgroups are recent :" + +#: ../banana/banana.inc.php:140 ../banana/misc.inc.php:150 +msgid "Abonnements" +msgstr "Subscription list" + +#: ../banana/banana.inc.php:175 +msgid "Impossible d'accéder au message. Le message a peut-être été annulé" +msgstr "The post is not reachable. It may have been canceled" + +#: ../banana/banana.inc.php:179 +msgid "Message" +msgstr "Post" + +#: ../banana/banana.inc.php:194 +msgid "Vous n'avez pas les permissions pour annuler ce message" +msgstr "You are not allowed to cancel that post" + +#: ../banana/banana.inc.php:208 +msgid "Impossible d'annuler le message" +msgstr "Impossible to cancel that post" + +#: ../banana/banana.inc.php:222 +msgid "a écrit" +msgstr "wrote" + +#: ../banana/banana.inc.php:230 ../banana/misc.inc.php:156 +msgid "Nouveau message" +msgstr "New post" + +#: ../banana/banana.inc.php:233 ../banana/post.inc.php:100 +msgid "En-têtes" +msgstr "Headers" + +#: ../banana/banana.inc.php:234 ../banana/groups.inc.php:93 +msgid "Nom" +msgstr "From" + +#: ../banana/banana.inc.php:235 ../banana/misc.inc.php:34 +#: ../banana/spool.inc.php:360 +msgid "Sujet" +msgstr "Subject" + +#: ../banana/banana.inc.php:236 ../banana/misc.inc.php:35 +msgid "Forums" +msgstr "NewsGroups" + +#: ../banana/banana.inc.php:237 +msgid "Suivi à" +msgstr "Followup To" + +#: ../banana/banana.inc.php:238 ../banana/misc.inc.php:38 +msgid "Organisation" +msgstr "Organization" + +#: ../banana/banana.inc.php:239 ../banana/post.inc.php:111 +msgid "Corps" +msgstr "Body" + +#: ../banana/banana.inc.php:275 ../banana/banana.inc.php:283 +msgid "Impossible de poster le message" +msgstr "Impossible to post that message" + +#: ../banana/groups.inc.php:87 +msgid "Total" +msgstr "Total" + +#: ../banana/groups.inc.php:89 +msgid "Abo." +msgstr "Sub." + +#: ../banana/groups.inc.php:91 +msgid "Nouveaux" +msgstr "New" + +#: ../banana/groups.inc.php:93 +msgid "Description" +msgstr "Description" + +#: ../banana/misc.inc.php:33 +msgid "De" +msgstr "From" + +#: ../banana/misc.inc.php:36 +msgid "Suivi-à" +msgstr "Followup To" + +#: ../banana/misc.inc.php:37 ../banana/spool.inc.php:359 +msgid "Date" +msgstr "Date" + +#: ../banana/misc.inc.php:39 +msgid "Références" +msgstr "References" + +#: ../banana/misc.inc.php:40 +msgid "Image" +msgstr "Image" + +#: ../banana/misc.inc.php:115 +msgid "hier" +msgstr "yesterday" + +#: ../banana/misc.inc.php:148 +msgid "Liste des forums" +msgstr "Newsgroups list" + +#: ../banana/misc.inc.php:171 +msgid "Répondre" +msgstr "Answer" + +#: ../banana/misc.inc.php:174 +msgid "Annuler ce message" +msgstr "Cancel post" + +#: ../banana/post.inc.php:114 +msgid "apercu" +msgstr "preview" + +#: ../banana/spool.inc.php:361 +msgid "Auteur" +msgstr "Author" + +#: ../banana/spool.inc.php:372 +msgid "Aucun message dans ce forum" +msgstr "No post in this newsgroup" diff --git a/po/fr.po b/po/fr.po new file mode 100644 index 0000000..7e829b3 --- /dev/null +++ b/po/fr.po @@ -0,0 +1,158 @@ +# translation of fr.po to +# This file is distributed under the same license as the PACKAGE package. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER. +# Pierre Habouzit , 2005. +# +msgid "" +msgstr "" +"Project-Id-Version: fr\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2005-05-24 21:04+0200\n" +"PO-Revision-Date: 2005-01-02 17:13+0100\n" +"Last-Translator: Pierre Habouzit \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Generator: KBabel 1.9.1\n" + +#: ../banana/banana.inc.php:54 +msgid "Impossible de contacter le serveur" +msgstr "Impossible de contacter le serveur" + +#: ../banana/banana.inc.php:93 +msgid "Voulez-vous vraiment annuler ce message ?" +msgstr "Voulez-vous vraiment annuler ce message ?" + +#: ../banana/banana.inc.php:124 +msgid "Les forums de Banana" +msgstr "Les forums de Banana" + +#: ../banana/banana.inc.php:126 +msgid "Les forums suivants ont été créés depuis ton dernier passage :" +msgstr "Les forums suivants ont été créés depuis ton dernier passage :" + +#: ../banana/banana.inc.php:140 ../banana/misc.inc.php:150 +msgid "Abonnements" +msgstr "Abonnements" + +#: ../banana/banana.inc.php:175 +msgid "Impossible d'accéder au message. Le message a peut-être été annulé" +msgstr "Impossible d'accéder au message. Le message a peut-être été annulé" + +#: ../banana/banana.inc.php:179 +msgid "Message" +msgstr "Message" + +#: ../banana/banana.inc.php:194 +msgid "Vous n'avez pas les permissions pour annuler ce message" +msgstr "Vous n'avez pas les permissions pour annuler ce message" + +#: ../banana/banana.inc.php:208 +msgid "Impossible d'annuler le message" +msgstr "Impossible d'annuler le message" + +#: ../banana/banana.inc.php:222 +msgid "a écrit" +msgstr "a écrit" + +#: ../banana/banana.inc.php:230 ../banana/misc.inc.php:156 +msgid "Nouveau message" +msgstr "Nouveau message" + +#: ../banana/banana.inc.php:233 ../banana/post.inc.php:100 +msgid "En-têtes" +msgstr "En-têtes" + +#: ../banana/banana.inc.php:234 ../banana/groups.inc.php:93 +msgid "Nom" +msgstr "Nom" + +#: ../banana/banana.inc.php:235 ../banana/misc.inc.php:34 +#: ../banana/spool.inc.php:360 +msgid "Sujet" +msgstr "Sujet" + +#: ../banana/banana.inc.php:236 ../banana/misc.inc.php:35 +msgid "Forums" +msgstr "Forums" + +#: ../banana/banana.inc.php:237 +msgid "Suivi à" +msgstr "Suivi à" + +#: ../banana/banana.inc.php:238 ../banana/misc.inc.php:38 +msgid "Organisation" +msgstr "Organisation" + +#: ../banana/banana.inc.php:239 ../banana/post.inc.php:111 +msgid "Corps" +msgstr "Corps" + +#: ../banana/banana.inc.php:275 ../banana/banana.inc.php:283 +msgid "Impossible de poster le message" +msgstr "Impossible de poster le message" + +#: ../banana/groups.inc.php:87 +msgid "Total" +msgstr "Total" + +#: ../banana/groups.inc.php:89 +msgid "Abo." +msgstr "Abo." + +#: ../banana/groups.inc.php:91 +msgid "Nouveaux" +msgstr "Nouveaux" + +#: ../banana/groups.inc.php:93 +msgid "Description" +msgstr "Description" + +#: ../banana/misc.inc.php:33 +msgid "De" +msgstr "De" + +#: ../banana/misc.inc.php:36 +msgid "Suivi-à" +msgstr "Suivi-à" + +#: ../banana/misc.inc.php:37 ../banana/spool.inc.php:359 +msgid "Date" +msgstr "Date" + +#: ../banana/misc.inc.php:39 +msgid "Références" +msgstr "Références" + +#: ../banana/misc.inc.php:40 +msgid "Image" +msgstr "Image" + +#: ../banana/misc.inc.php:115 +msgid "hier" +msgstr "hier" + +#: ../banana/misc.inc.php:148 +msgid "Liste des forums" +msgstr "Liste des forums" + +#: ../banana/misc.inc.php:171 +msgid "Répondre" +msgstr "Répondre" + +#: ../banana/misc.inc.php:174 +msgid "Annuler ce message" +msgstr "Annuler ce message" + +#: ../banana/post.inc.php:114 +msgid "apercu" +msgstr "apercu" + +#: ../banana/spool.inc.php:361 +msgid "Auteur" +msgstr "Auteur" + +#: ../banana/spool.inc.php:372 +msgid "Aucun message dans ce forum" +msgstr "Aucun message dans ce forum" diff --git a/po/shtool b/po/shtool new file mode 100755 index 0000000..4c1a739 --- /dev/null +++ b/po/shtool @@ -0,0 +1,716 @@ +#!/bin/sh +## +## GNU shtool -- The GNU Portable Shell Tool +## Copyright (c) 1994-2000 Ralf S. Engelschall +## +## See http://www.gnu.org/software/shtool/ for more information. +## See ftp://ftp.gnu.org/gnu/shtool/ for latest version. +## +## Version 1.4.9 (16-Apr-2000) +## Ingredients: 3/17 available modules +## + +## +## This program 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 of the License, or +## (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; if not, write to the Free Software +## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, +## USA, or contact Ralf S. Engelschall . +## +## Notice: Given that you include this file verbatim into your own +## source tree, you are justified in saying that it remains separate +## from your package, and that this way you are simply just using GNU +## shtool. So, in this situation, there is no requirement that your +## package itself is licensed under the GNU General Public License in +## order to take advantage of GNU shtool. +## + +## +## Usage: shtool [] [ [] []] +## +## Available commands: +## echo Print string with optional construct expansion +## install Install a program, script or datafile +## mkdir Make one or more directories +## +## Not available commands (because module was not built-in): +## mdate Pretty-print modification time of a file or dir +## table Pretty-print a field-separated list as a table +## prop Display progress with a running propeller +## move Move files with simultaneous substitution +## mkln Make link with calculation of relative paths +## mkshadow Make a shadow tree through symbolic links +## fixperm Fix file permissions inside a source tree +## tarball Roll distribution tarballs +## guessos Simple operating system guesser +## arx Extended archive command +## slo Separate linker options by library class +## scpp Sharing C Pre-Processor +## version Generate and maintain a version information file +## path Deal with program paths +## + +if [ $# -eq 0 ]; then + echo "$0:Error: invalid command line" 1>&2 + echo "$0:Hint: run \`$0 -h' for usage" 1>&2 + exit 1 +fi +if [ ".$1" = ".-h" -o ".$1" = ".--help" ]; then + echo "This is GNU shtool, version 1.4.9 (16-Apr-2000)" + echo "Copyright (c) 1994-2000 Ralf S. Engelschall " + echo "Report bugs to " + echo '' + echo "Usage: shtool [] [ [] []]" + echo '' + echo 'Available global :' + echo ' -v, --version display shtool version information' + echo ' -h, --help display shtool usage help page (this one)' + echo ' -d, --debug display shell trace information' + echo '' + echo 'Available [] []:' + echo ' echo [-n] [-e] [ ...]' + echo ' install [-v] [-t] [-c] [-C] [-s] [-m] [-o] [-g]' + echo ' [-e] ' + echo ' mkdir [-t] [-f] [-p] [-m] [ ...]' + echo '' + echo 'Not available (because module was not built-in):' + echo ' mdate [-n] [-z] [-s] [-d] [-f] [-o] ' + echo ' table [-F] [-w] [-c] [-s] ...' + echo ' prop [-p]' + echo ' move [-v] [-t] [-e] [-p] ' + echo ' mkln [-t] [-f] [-s] [ ...] ' + echo ' mkshadow [-v] [-t] [-a] ' + echo ' fixperm [-v] [-t] [ ...]' + echo ' tarball [-t] [-v] [-o ] [-c ] [-d ] [-u' + echo ' ] [-g ] [-e ] [ ...]' + echo ' guessos ' + echo ' arx [-t] [-C] [ ...]' + echo ' slo [-p] -- -L -l [-L -l ...]' + echo ' scpp [-v] [-p] [-f] [-o] [-t] [-M]' + echo ' [-D] [-C] [ ...]' + echo ' version [-l] [-n] [-p] [-s] [-i]' + echo ' [-d] ' + echo ' path [-s] [-r] [-d] [-b] [-m] [-p] [ ...]' + echo '' + exit 0 +fi +if [ ".$1" = ".-v" -o ".$1" = ."--version" ]; then + echo "GNU shtool 1.4.9 (16-Apr-2000)" + exit 0 +fi +if [ ".$1" = ".-d" -o ".$1" = ."--debug" ]; then + shift + set -x +fi +name=`echo "$0" | sed -e 's;.*/\([^/]*\)$;\1;' -e 's;-sh$;;' -e 's;\.sh$;;'` +case "$name" in + echo|install|mkdir ) + # implicit tool command selection + tool="$name" + ;; + * ) + # explicit tool command selection + tool="$1" + shift + ;; +esac +arg_spec="" +opt_spec="" +gen_tmpfile=no + +## +## DISPATCH INTO SCRIPT PROLOG +## + +case $tool in + echo ) + str_tool="echo" + str_usage="[-n] [-e] [ ...]" + arg_spec="0+" + opt_spec="n.e." + opt_n=no + opt_e=no + ;; + install ) + str_tool="install" + str_usage="[-v] [-t] [-c] [-C] [-s] [-m] [-o] [-g] [-e] " + arg_spec="2=" + opt_spec="v.t.c.C.s.m:o:g:e:" + opt_v=no + opt_t=no + opt_c=no + opt_C=no + opt_s=no + opt_m="" + opt_o="" + opt_g="" + opt_e="" + ;; + mkdir ) + str_tool="mkdir" + str_usage="[-t] [-f] [-p] [-m] [ ...]" + arg_spec="1+" + opt_spec="t.f.p.m:" + opt_t=no + opt_f=no + opt_p=no + opt_m="" + ;; + -* ) + echo "$0:Error: unknown option \`$tool'" 2>&1 + echo "$0:Hint: run \`$0 -h' for usage" 2>&1 + exit 1 + ;; + * ) + echo "$0:Error: unknown command \`$tool'" 2>&1 + echo "$0:Hint: run \`$0 -h' for usage" 2>&1 + exit 1 + ;; +esac + +## +## COMMON UTILITY CODE +## + +# determine name of tool +if [ ".$tool" != . ]; then + # used inside shtool script + toolcmd="$0 $tool" + toolcmdhelp="shtool $tool" + msgprefix="shtool:$tool" +else + # used as standalone script + toolcmd="$0" + toolcmdhelp="sh $0" + msgprefix="$str_tool" +fi + +# parse argument specification string +eval `echo $arg_spec |\ + sed -e 's/^\([0-9]*\)\([+=]\)/arg_NUMS=\1; arg_MODE=\2/'` + +# parse option specification string +eval `echo h.$opt_spec |\ + sed -e 's/\([a-zA-Z0-9]\)\([.:+]\)/opt_MODE_\1=\2;/g'` + +# interate over argument line +opt_PREV='' +while [ $# -gt 0 ]; do + # special option stops processing + if [ ".$1" = ".--" ]; then + shift + break + fi + + # determine option and argument + opt_ARG_OK=no + if [ ".$opt_PREV" != . ]; then + # merge previous seen option with argument + opt_OPT="$opt_PREV" + opt_ARG="$1" + opt_ARG_OK=yes + opt_PREV='' + else + # split argument into option and argument + case "$1" in + -[a-zA-Z0-9]*) + eval `echo "x$1" |\ + sed -e 's/^x-\([a-zA-Z0-9]\)/opt_OPT="\1";/' \ + -e 's/";\(.*\)$/"; opt_ARG="\1"/'` + ;; + -[a-zA-Z0-9]) + opt_OPT=`echo "x$1" | cut -c3-` + opt_ARG='' + ;; + *) + break + ;; + esac + fi + + # eat up option + shift + + # determine whether option needs an argument + eval "opt_MODE=\$opt_MODE_${opt_OPT}" + if [ ".$opt_ARG" = . -a ".$opt_ARG_OK" != .yes ]; then + if [ ".$opt_MODE" = ".:" -o ".$opt_MODE" = ".+" ]; then + opt_PREV="$opt_OPT" + continue + fi + fi + + # process option + case $opt_MODE in + '.' ) + # boolean option + eval "opt_${opt_OPT}=yes" + ;; + ':' ) + # option with argument (multiple occurances override) + eval "opt_${opt_OPT}=\"\$opt_ARG\"" + ;; + '+' ) + # option with argument (multiple occurances append) + eval "opt_${opt_OPT}=\"\$opt_${opt_OPT} \$opt_ARG\"" + ;; + * ) + echo "$msgprefix:Error: unknown option: \`-$opt_OPT'" 1>&2 + echo "$msgprefix:Hint: run \`$toolcmdhelp -h' or \`man shtool' for details" 1>&2 + exit 1 + ;; + esac +done +if [ ".$opt_PREV" != . ]; then + echo "$msgprefix:Error: missing argument to option \`-$opt_PREV'" 1>&2 + echo "$msgprefix:Hint: run \`$toolcmdhelp -h' or \`man shtool' for details" 1>&2 + exit 1 +fi + +# process help option +if [ ".$opt_h" = .yes ]; then + echo "Usage: $toolcmdhelp $str_usage" + exit 0 +fi + +# complain about incorrect number of arguments +case $arg_MODE in + '=' ) + if [ $# -ne $arg_NUMS ]; then + echo "$msgprefix:Error: invalid number of arguments (exactly $arg_NUMS expected)" 1>&2 + echo "$msgprefix:Hint: run \`$toolcmd -h' or \`man shtool' for details" 1>&2 + exit 1 + fi + ;; + '+' ) + if [ $# -lt $arg_NUMS ]; then + echo "$msgprefix:Error: invalid number of arguments (at least $arg_NUMS expected)" 1>&2 + echo "$msgprefix:Hint: run \`$toolcmd -h' or \`man shtool' for details" 1>&2 + exit 1 + fi + ;; +esac + +# establish a temporary file on request +if [ ".$gen_tmpfile" = .yes ]; then + if [ ".$TMPDIR" != . ]; then + tmpdir="$TMPDIR" + elif [ ".$TEMPDIR" != . ]; then + tmpdir="$TEMPDIR" + else + tmpdir="/tmp" + fi + tmpfile="$tmpdir/.shtool.$$" + rm -f $tmpfile >/dev/null 2>&1 + touch $tmpfile +fi + +## +## DISPATCH INTO SCRIPT BODY +## + +case $tool in + +echo ) + ## + ## echo -- Print string with optional construct expansion + ## Copyright (c) 1998-2000 Ralf S. Engelschall + ## Originally written for WML as buildinfo + ## + + text="$*" + + # check for broken escape sequence expansion + seo='' + bytes=`echo '\1' | wc -c | awk '{ printf("%s", $1); }'` + if [ ".$bytes" != .3 ]; then + bytes=`echo -E '\1' | wc -c | awk '{ printf("%s", $1); }'` + if [ ".$bytes" = .3 ]; then + seo='-E' + fi + fi + + # check for existing -n option (to suppress newline) + minusn='' + bytes=`echo -n 123 2>/dev/null | wc -c | awk '{ printf("%s", $1); }'` + if [ ".$bytes" = .3 ]; then + minusn='-n' + fi + + # determine terminal bold sequence + term_bold='' + term_norm='' + if [ ".$opt_e" = .yes -a ".`echo $text | egrep '%[Bb]'`" != . ]; then + case $TERM in + # for the most important terminal types we directly know the sequences + xterm|xterm*|vt220|vt220*) + term_bold=`awk 'BEGIN { printf("%c%c%c%c", 27, 91, 49, 109); }' /dev/null` + term_norm=`awk 'BEGIN { printf("%c%c%c", 27, 91, 109); }' /dev/null` + ;; + vt100|vt100*) + term_bold=`awk 'BEGIN { printf("%c%c%c%c%c%c", 27, 91, 49, 109, 0, 0); }' /dev/null` + term_norm=`awk 'BEGIN { printf("%c%c%c%c%c", 27, 91, 109, 0, 0); }' /dev/null` + ;; + # for all others, we try to use a possibly existing `tput' or `tcout' utility + * ) + paths=`echo $PATH | sed -e 's/:/ /g'` + for tool in tput tcout; do + for dir in $paths; do + if [ -r "$dir/$tool" ]; then + for seq in bold md smso; do # 'smso' is last + bold="`$dir/$tool $seq 2>/dev/null`" + if [ ".$bold" != . ]; then + term_bold="$bold" + break + fi + done + if [ ".$term_bold" != . ]; then + for seq in sgr0 me rmso reset; do # 'reset' is last + norm="`$dir/$tool $seq 2>/dev/null`" + if [ ".$norm" != . ]; then + term_norm="$norm" + break + fi + done + fi + break + fi + done + if [ ".$term_bold" != . -a ".$term_norm" != . ]; then + break; + fi + done + ;; + esac + if [ ".$term_bold" = . -o ".$term_norm" = . ]; then + echo "$msgprefix:Warning: unable to determine terminal sequence for bold mode" 1>&2 + fi + fi + + # determine user name + username='' + if [ ".$opt_e" = .yes -a ".`echo $text | egrep '%[uU]'`" != . ]; then + username="$LOGNAME" + if [ ".$username" = . ]; then + username="$USER" + if [ ".$username" = . ]; then + username="`(whoami) 2>/dev/null |\ + awk '{ printf("%s", $1); }'`" + if [ ".$username" = . ]; then + username="`(who am i) 2>/dev/null |\ + awk '{ printf("%s", $1); }'`" + if [ ".$username" = . ]; then + username='unknown' + fi + fi + fi + fi + fi + + # determine user id + userid='' + if [ ".$opt_e" = .yes -a ".`echo $text | egrep '%U'`" != . ]; then + userid="`(id -u) 2>/dev/null`" + if [ ".$userid" = . ]; then + str="`(id) 2>/dev/null`" + if [ ".`echo $str | grep '^uid[ ]*=[ ]*[0-9]*('`" != . ]; then + userid=`echo $str | sed -e 's/^uid[ ]*=[ ]*//' -e 's/(.*//'` + fi + if [ ".$userid" = . ]; then + userid=`egrep "^${username}:" /etc/passwd 2>/dev/null | \ + sed -e 's/[^:]*:[^:]*://' -e 's/:.*$//'` + if [ ".$userid" = . ]; then + userid=`(ypcat passwd) 2>/dev/null | + egrep "^${username}:" | \ + sed -e 's/[^:]*:[^:]*://' -e 's/:.*$//'` + if [ ".$userid" = . ]; then + userid='?' + fi + fi + fi + fi + fi + + # determine host name + hostname='' + if [ ".$opt_e" = .yes -a ".`echo $text | egrep '%h'`" != . ]; then + hostname="`(uname -n) 2>/dev/null |\ + awk '{ printf("%s", $1); }'`" + if [ ".$hostname" = . ]; then + hostname="`(hostname) 2>/dev/null |\ + awk '{ printf("%s", $1); }'`" + if [ ".$hostname" = . ]; then + hostname='unknown' + fi + fi + case $hostname in + *.* ) + domainname=".`echo $hostname | cut -d. -f2-`" + hostname="`echo $hostname | cut -d. -f1`" + ;; + esac + fi + + # determine domain name + domainname='' + if [ ".$opt_e" = .yes -a ".`echo $text | egrep '%d'`" != . ]; then + if [ ".$domainname" = . ]; then + if [ -f /etc/resolv.conf ]; then + domainname="`egrep '^[ ]*domain' /etc/resolv.conf | head -1 |\ + sed -e 's/.*domain//' \ + -e 's/^[ ]*//' -e 's/^ *//' -e 's/^ *//' \ + -e 's/^\.//' -e 's/^/./' |\ + awk '{ printf("%s", $1); }'`" + if [ ".$domainname" = . ]; then + domainname="`egrep '^[ ]*search' /etc/resolv.conf | head -1 |\ + sed -e 's/.*search//' \ + -e 's/^[ ]*//' -e 's/^ *//' -e 's/^ *//' \ + -e 's/ .*//' -e 's/ .*//' \ + -e 's/^\.//' -e 's/^/./' |\ + awk '{ printf("%s", $1); }'`" + fi + fi + fi + fi + + # determine current time + time_day='' + time_month='' + time_year='' + time_monthname='' + if [ ".$opt_e" = .yes -a ".`echo $text | egrep '%[DMYm]'`" != . ]; then + time_day=`date '+%d'` + time_month=`date '+%m'` + time_year=`date '+%Y' 2>/dev/null` + if [ ".$time_year" = . ]; then + time_year=`date '+%y'` + case $time_year in + [5-9][0-9]) time_year="19$time_year" ;; + [0-4][0-9]) time_year="20$time_year" ;; + esac + fi + case $time_month in + 1|01) time_monthname='Jan' ;; + 2|02) time_monthname='Feb' ;; + 3|03) time_monthname='Mar' ;; + 4|04) time_monthname='Apr' ;; + 5|05) time_monthname='May' ;; + 6|06) time_monthname='Jun' ;; + 7|07) time_monthname='Jul' ;; + 8|08) time_monthname='Aug' ;; + 9|09) time_monthname='Sep' ;; + 10) time_monthname='Oct' ;; + 11) time_monthname='Nov' ;; + 12) time_monthname='Dec' ;; + esac + fi + + # expand special ``%x'' constructs + if [ ".$opt_e" = .yes ]; then + text=`echo $seo "$text" |\ + sed -e "s/%B/${term_bold}/g" \ + -e "s/%b/${term_norm}/g" \ + -e "s/%u/${username}/g" \ + -e "s/%U/${userid}/g" \ + -e "s/%h/${hostname}/g" \ + -e "s/%d/${domainname}/g" \ + -e "s/%D/${time_day}/g" \ + -e "s/%M/${time_month}/g" \ + -e "s/%Y/${time_year}/g" \ + -e "s/%m/${time_monthname}/g" 2>/dev/null` + fi + + # create output + if [ .$opt_n = .no ]; then + echo $seo "$text" + else + # the harder part: echo -n is best, because + # awk may complain about some \xx sequences. + if [ ".$minusn" != . ]; then + echo $seo $minusn "$text" + else + echo dummy | awk '{ printf("%s", TEXT); }' TEXT="$text" + fi + fi + ;; + +install ) + ## + ## install -- Install a program, script or datafile + ## Copyright (c) 1997-2000 Ralf S. Engelschall + ## Originally written for shtool + ## + + src="$1" + dst="$2" + + # If destination is a directory, append the input filename + if [ -d $dst ]; then + dst=`echo "$dst" | sed -e 's:/$::'` + dstfile=`echo "$src" | sed -e 's;.*/\([^/]*\)$;\1;'` + dst="$dst/$dstfile" + fi + + # Add a possible extension to src and dst + if [ ".$opt_e" != . ]; then + src="$src$opt_e" + dst="$dst$opt_e" + fi + + # Check for correct arguments + if [ ".$src" = ".$dst" ]; then + echo "$msgprefix:Error: source and destination are the same" 1>&2 + exit 1 + fi + + # Make a temp file name in the destination directory + dstdir=`echo $dst | sed -e 's;[^/]*$;;' -e 's;\(.\)/$;\1;' -e 's;^$;.;'` + dsttmp="$dstdir/#INST@$$#" + + # Verbosity + if [ ".$opt_v" = .yes ]; then + echo "$src -> $dst" 1>&2 + fi + + # Copy or move the file name to the temp name + # (because we might be not allowed to change the source) + if [ ".$opt_C" = .yes ]; then + opt_c=yes + fi + if [ ".$opt_c" = .yes ]; then + if [ ".$opt_t" = .yes ]; then + echo "cp $src $dsttmp" 1>&2 + fi + cp $src $dsttmp || exit $? + else + if [ ".$opt_t" = .yes ]; then + echo "mv $src $dsttmp" 1>&2 + fi + mv $src $dsttmp || exit $? + fi + + # Adjust the target file + # (we do chmod last to preserve setuid bits) + if [ ".$opt_s" = .yes ]; then + if [ ".$opt_t" = .yes ]; then + echo "strip $dsttmp" 1>&2 + fi + strip $dsttmp || exit $? + fi + if [ ".$opt_o" != . ]; then + if [ ".$opt_t" = .yes ]; then + echo "chown $opt_o $dsttmp" 1>&2 + fi + chown $opt_o $dsttmp || exit $? + fi + if [ ".$opt_g" != . ]; then + if [ ".$opt_t" = .yes ]; then + echo "chgrp $opt_g $dsttmp" 1>&2 + fi + chgrp $opt_g $dsttmp || exit $? + fi + if [ ".$opt_m" != . ]; then + if [ ".$opt_t" = .yes ]; then + echo "chmod $opt_m $dsttmp" 1>&2 + fi + chmod $opt_m $dsttmp || exit $? + fi + + # Determine whether to do a quick install + # (has to be done _after_ the strip was already done) + quick=no + if [ ".$opt_C" = .yes ]; then + if [ -r $dst ]; then + if cmp -s $src $dst; then + quick=yes + fi + fi + fi + + # Finally install the file to the real destination + if [ $quick = yes ]; then + if [ ".$opt_t" = .yes ]; then + echo "rm -f $dsttmp" 1>&2 + fi + rm -f $dsttmp + else + if [ ".$opt_t" = .yes ]; then + echo "rm -f $dst && mv $dsttmp $dst" 1>&2 + fi + rm -f $dst && mv $dsttmp $dst + fi + ;; + +mkdir ) + ## + ## mkdir -- Make one or more directories + ## Copyright (c) 1996-2000 Ralf S. Engelschall + ## Originally written for public domain by Noah Friedman + ## Cleaned up and enhanced for shtool + ## + + errstatus=0 + for p in ${1+"$@"}; do + # if the directory already exists... + if [ -d "$p" ]; then + if [ ".$opt_f" = .no ] && [ ".$opt_p" = .no ]; then + echo "$msgprefix:Error: directory already exists: $p" 1>&2 + errstatus=1 + break + else + continue + fi + fi + # if the directory has to be created... + if [ ".$opt_p" = .no ]; then + if [ ".$opt_t" = .yes ]; then + echo "mkdir $p" 1>&2 + fi + mkdir $p || errstatus=$? + else + # the smart situation + set fnord `echo ":$p" |\ + sed -e 's/^:\//%/' \ + -e 's/^://' \ + -e 's/\// /g' \ + -e 's/^%/\//'` + shift + pathcomp='' + for d in ${1+"$@"}; do + pathcomp="$pathcomp$d" + case "$pathcomp" in + -* ) pathcomp="./$pathcomp" ;; + esac + if [ ! -d "$pathcomp" ]; then + if [ ".$opt_t" = .yes ]; then + echo "mkdir $pathcomp" 1>&2 + fi + mkdir $pathcomp || errstatus=$? + if [ ".$opt_m" != . ]; then + if [ ".$opt_t" = .yes ]; then + echo "chmod $opt_m $pathcomp" 1>&2 + fi + chmod $opt_m $pathcomp || errstatus=$? + fi + fi + pathcomp="$pathcomp/" + done + fi + done + exit $errstatus + ;; + +esac + +exit 0 + +##EOF## -- 2.1.4