samidare-0.7/0000755000000000000000000000000011042075667011653 5ustar rootrootsamidare-0.7/tmp/0000755000000000000000000000000011042075667012453 5ustar rootrootsamidare-0.7/tmp/.cvsignore0000644000000000000000000000000511042075667014446 0ustar rootrootaf-* samidare-0.7/tmp/.htaccess0000644000000000000000000000004011042075667014243 0ustar rootrootOrder Deny,Allow Deny from all samidare-0.7/.cvsignore0000644000000000000000000000011311042075667013646 0ustar rootrootd.samidare latest.html latest.html.gz samidare sites.lirs.gz status.rm tmp samidare-0.7/AUTHORS0000644000000000000000000000005011042075667012716 0ustar rootrootTanaka Akira Akinori MUSHA akira yamada samidare-0.7/COPYING0000644000000000000000000004313111042075667012710 0ustar rootroot GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 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) 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) year 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. samidare-0.7/Makefile0000644000000000000000000000154211042075667013315 0ustar rootroot# Makefile - samidare makefile # # Copyright (C) 2003 Tanaka Akira # # 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 samidare: rb-link ruby rb-link -d d.samidare -o samidare main.rb -include d.* samidare-0.7/README0000644000000000000000000000145011042075667012533 0ustar rootroot= samidare - web page update checker == Author Tanaka Akira == License GPLv2 or later (rb-link and mconv.rb is the modified BSD license.) == Home Page http://www.a-k-r.org/samidare/ == Feature * Easy configuration: just list up URLs. * HTML generation by template. * tDiary theme supported. * generate/read LIRS. * check page content addition to Last-Modified. == Requirements * ruby 1.8.1 : http://www.ruby-lang.org/ * htree 0.4 : http://raa.ruby-lang.org/project/htree/ == Download * latest release: http://www.a-k-r.org/samidare/samidare-0.7.tar.gz * development version in CVS repository: http://cvs.m17n.org/viewcvs/ruby/samidare/ or checkout with: % cvs -d :pserver:anonymous@cvs.m17n.org:/cvs/ruby co samidare == Install % make % cp samidare /usr/local/bin samidare-0.7/README.ja0000644000000000000000000000353211042075667013127 0ustar rootroot= $B8^7n1+(B $B8^7n1+$O(B Web $B%Z!<%8$N99?7$r4F;k$7!"99?7>pJs$r$^$H$a$FI=<($9$k%=%U%H%&%'%"$G$9!#(B == $BFCD'(B * $B@_Dj$,4JC1(B $B@_Dj%U%!%$%k$K$O4pK\E*$K$O(B URL $B$rJB$Y$l$P$$$$$@$1$G$9!#(B $B%?%$%H%k$dCxpJs$O(B($B2DG=$JHO0O$G(B)$BBP>]$N%Z!<%8<+BN$+$iCj=P$5$l$^$9!#(B $B$^$?!"@_Dj%U%!%$%k$N7A<0$O(B YAML $B$G$9!#(B * $B%F%s%W%l!<%H$K$h$k(B HTML $B@8@.(B HTML $B@8@.$O%F%s%W%l!<%H$K$h$C$F9T$o$l!"%F%s%W%l!<%H$N=$@5$K$h$C$F!"(B $B=PNO$r%+%9%?%^%$%:$9$k$3$H$,$G$-$^$9!#(B * tDiary $B%F!<%^(B $B%G%U%)%k%H$N%F%s%W%l!<%H$,@8@.$9$k(B HTML $B$O(B tDiary $B%F!<%^$r;HMQ$G$-$k$h$&$K$J$C$F$$$^$9!#(B $B$=$N$?$a!"(BtDiary $B$NK-IY$J%F!<%^$rMxMQ$9$k$3$H$,$G$-$^$9!#(B * Web $B%Z!<%8$r%m!<%+%k$KJ]B8(B $B%G%U%)%k%H$G$O:G?7$N(B 2$B$D$NHG$,J]B8$5$l$^$9!#(B $BHG$N?t$O@_Dj2DG=$G$9!#(B $B$^$?!"Nc$($P:GDc(B 12$B;~4VJ]B8$9$k$H$$$&$h$&$K!";~4V$r;XDj$9$k$3$H$b2DG=$G$9!#(B * LIRS $B7A<0$N99?7>pJs$r@8@.(B * LIRS $B7A<0$N99?7>pJs$rFI$_9~$a$k(B * $B>l9g$K$h$C$F$O(B HTML $B$N%Z!<%8$r99?7>pJs$H$7$F;HMQ2DG=(B * $B%Z!<%8$N99?7;~9o$,F@$i$l$J$$>l9g$K$G$b!"FbMF$NJQ2=$K$h$j99?7$r8!=P(B $BFbMF$NJQ2=$O!"(BHTML $B$N%?%00J30$NItJ,$N%A%'%C%/%5%`$K$h$C$F8!=P$5$l$^$9!#(B $B$3$N$?$a!"%?%0$NCf$,JQ2=$9$k>l9g!"$?$H$($P(B img $B%?%0$G(B URL $B$,Kh2sJQ2=$9$k9-9p$O99?7$H$O8+$J$5$l$^$;$s!#(B $B$^$?!"%F%-%9%H$N2DJQItJ,$,$"$k>l9g$G$b!"(B $BJQ2=$rL5;k$9$k>l=j$r;XDj$G$-$^$9!#(B $B$3$l$O(B HTML $BCf$N(B class, id $BB0@-$H(B XPath $BIw$J;XDj$,2DG=$G$9!#(B == $BI,MW$J%=%U%H%&%'%"(B * ruby-1.8.1 ($B$3$l$h$j8E$$$b$N$G$OF0$-$^$;$s(B) http://www.ruby-lang.org * htree ($B:G?7$,A0Ds$G$9(B) http://cvs.m17n.org/cgi-bin/viewcvs/htree/?cvsroot=ruby == $BG[I[>l=j(B http://cvs.m17n.org/cgi-bin/viewcvs/samidare/?cvsroot=ruby == $B:n samidare-0.7/autofile.rb0000644000000000000000000001057211042075667014015 0ustar rootroot# autofile.rb - persistent temporary file management library. # # Copyright (C) 2003,2005,2006 Tanaka Akira # # 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 require 'thread' require 'fileutils' class AutoFile def AutoFile.directory=(dir) @directory = dir unless File.directory? dir FileUtils.mkdir_p(dir) end end def AutoFile.directory if defined? @directory @directory else raise "AutoFile.directory not defined" end end PREFIX = 'af-' def AutoFile.clear GC.start objs = [] ObjectSpace.each_object(AutoFile) {|obj| objs << obj } required_files = {} objs.each {|obj| required_files[obj.filename] = true } useless_files = [] Dir.foreach(AutoFile.directory) {|name| next unless /\A#{Regexp.quote PREFIX}/o =~ name next if required_files[name] useless_files << name } useless_files.each {|name| File.unlink(File.join(AutoFile.directory, name)) } end def initialize(filename_hint='', initial_content='', content_type=nil) dir = AutoFile.directory generate_filename_candidates(filename_hint, initial_content, content_type) {|cand| cand.gsub!(/--+/, '-') filename = File.join(dir, cand) begin file = File.open(filename, File::RDWR|File::CREAT|File::EXCL) file << initial_content file.close @filename = cand break rescue Errno::EEXIST next end } end attr_reader :filename def pathname File.join(AutoFile.directory, @filename) end def exist? File.exist? File.join(AutoFile.directory, @filename) end def content File.read(File.join(AutoFile.directory, @filename)) end ExtSynonym = { '.html' => ['.htm'] } ExtSynonym.default = [] def generate_filename_candidates(filename_hint, initial_content, content_type) initial_content = initial_content.dup.force_encoding("ascii-8bit") if initial_content.respond_to? :force_encoding filename_hint = filename_hint.dup base = nil ext = nil if %r{\A(http|https|ftp):/*} =~ filename_hint filename_hint = $' filename_hint = $` if /[?#]/ =~ filename_hint end if /\A\x1f\x8b/n !~ initial_content && /\.gz\z/ =~ filename_hint filename_hint = $` end # `php' and `cgi' doesn't express content at all. if /\.(?:php|cgi)\z/ =~ filename_hint filename_hint = $` end if /\ALIRS/i =~ initial_content ext = '.lirs' elsif / # # 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 class LIRS RecordHeader = 'LIRS' def LIRS.load(filename) File.open(filename) {|f| begin return decode(f) rescue LIRS::Error $!.message[0,0] = "#{filename}: " raise end } end def LIRS.decode(f) lirs = LIRS.new f.each_line {|line| lirs << Record.decode(line) if /^#/ !~ line } lirs end def initialize @record = {} end def size @record.size end def <<(record) @record[record.target_url] = record end def each @record.each {|url, record| yield record } end def [](url) @record[url] end class Record def Record.decode(l) l = l.sub(/\r?\n\z/, '') a = [] l.scan(/((?:[^,\\]|\\.)*),/m) {|quoted_field,| a.push(quoted_field.gsub(/\\(.)/m) { $1 }) } record_header = a.shift raise LIRS::Error.new("no record header") if record_header != RecordHeader raise LIRS::Error.new("too few record fields") if a.length < 8 return Record.new(*a) end def initialize(last_modified, last_detected, timezone, content_length, target_url, target_title, target_maintainer, antenna_url, *extension_fields) @last_modified = last_modified @last_detected = last_detected @time_zone = timezone @content_length = content_length @target_url = target_url @target_title = target_title @target_maintainer = target_maintainer @antenna_url = antenna_url @extension_fields = extension_fields end attr_reader :last_modified, :last_detected, :time_zone, :content_length, :target_url, :target_title, :target_maintainer, :antenna_url, :extension_fields def encode l = '' fs = [ RecordHeader, @last_modified, @last_detected, @time_zone, @content_length, @target_url, @target_title, @target_maintainer, @antenna_url, *@extension_fields ].each {|f| l << f.gsub(/[,\\]/) { "\\#{$&}" } << ',' } l << "\n" return l end end class Error < StandardError end end samidare-0.7/main.rb0000755000000000000000000012402011042075667013126 0ustar rootroot#!/usr/bin/env ruby # main.rb - samidare main program # # Copyright (C) 2003,2004,2005,2006 Tanaka Akira # # 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 #$KCODE = 'e' require 'open-uri' require 'uri' require 'time' require 'yaml' require 'mconv' require 'timeout' require 'net/http' require 'pp' require 'optparse' require 'zlib' require 'lirs' require 'autofile' require 'htree' require 'string-util' require 'tempfile' require 'presen' CONFIG_FILENAME = 'config.yml' STATUS_FILENAME = 'status.rm' TEMPLATE_LATEST_FILENAME = 't.latest.html' OUTPUT_LATEST_FILENAME = 'latest.html' OUTPUT_LIRS_FILENAME = 'sites.lirs.gz' AutoFile.directory = 'tmp' # xxx: should be configurable. def Time.httpdate_robust(str) Time.httpdate(str) rescue Time.parse(str) end class Entry ENTRIES = {} def initialize(hash, config) @status = hash @config = config related_uris.each {|uri| ENTRIES[uri] ||= [] ENTRIES[uri] << self } end attr_reader :status attr_reader :config def uri @config['URI'] end def related_uris result = [] result << @config['URI'] result << @config['LinkURI'] if @config['LinkURI'] result.concat @config['RelatedURI'].split(/\s+/) if @config['RelatedURI'] if logseq = @status['_log'] logseq.each {|log| result << log['baseURI'] if log['baseURI'] result << log['extractedLinkURI'] if log['extractedLinkURI'] } end result.uniq! result end def update_info? @config.include? 'UpdateInfo' end def should_check? ARGV.empty? or @status['_update_info'] or !(related_uris & ARGV).empty? end DefaultMinimumInterval = 5 * 60 DefaultMaximumInterval = 24 * 60 * 60 def timing_check t1 = next_timing t2 = Time.now t1 <= t2 end def expect_next_by_periodical h = find_last_200 return nil unless h periodical = h['lastModifiedSequence'] || h['periodical'] return nil unless periodical return nil if periodical.length < 2 last_modified = periodical.last intervals = [] prev = nil periodical.each {|curr| intervals << curr - prev if prev && prev < curr prev = curr } t = last_modified + intervals.min begin # adjust server/client time difference t += (h['clientDateEnd'] || h['clientDateBeg']) - Time.httpdate_robust(h['serverDateString']) rescue end t end def next_timing min = @config['MinimumInterval'] # xxx: should support units other than second. max = @config['MaximumInterval'] if !min if max && max < DefaultMinimumInterval min = max else min = DefaultMinimumInterval end end if !max if min && DefaultMaximumInterval < min max = min else max = DefaultMaximumInterval end end max = min if max < min if @status['_update_info'] Time.now elsif e1 = find_first_error e2 = find_last_error e1t = e1['clientDateEnd'] e2t = e2['clientDateEnd'] if e1.equal? e2 r = e1t + min else r = e2t + (e2t - e1t) end if r < e1t + min r = e1t + min end r elsif s1 = find_first_200_with_current_content # Is there any 200? s2 = find_last_success s2t = s2['clientDateEnd'] || s2['clientDateBeg'] if @config['Periodical'] s1t = expect_next_by_periodical return s1t if s1t && s2t < s1t end if !s1t begin s1_client_date = s1['clientDateEnd'] || s1['clientDateBeg'] s1_server_date = Time.httpdate_robust(s1['serverDateString']) s1t = Time.httpdate_robust(s1['lastModifiedString']) s1t += s1_client_date - s1_server_date rescue s1t = s1['clientDateEnd'] || s1['clientDateBeg'] end s1t = s2t if s2t < s1t end begin r = s2t + (s2t - s1t) rescue RangeError r = s2t + max end if r < s2t + min s2t + min elsif s2t + max < r s2t + max else r end else Time.now end end def check uri = @config['URI'] @status['_log'] = [] unless @status['_log'] logseq = @status['_log'] log = @config.dup log['clientDateBeg'] = client_date_1 = Time.now STDERR.puts "#{client_date_1.iso8601} fetch start #{uri}\n" if $VERBOSE page, meta = fetch(log) log['clientDateEnd'] = client_date_2 = Time.now if $VERBOSE if log['trouble'] STDERR.puts "#{client_date_2.iso8601} fetch end ERROR: #{log['trouble']} #{uri}\n" if log['backtrace'] STDERR.puts "|#{client_date_2.iso8601} ERROR: #{log['trouble']} (#{log['exception_class']}) #{uri}\n" log['backtrace'].each {|pos| STDERR.puts "| #{pos}\n" } end else STDERR.puts "#{client_date_2.iso8601} fetch end #{log['status']} #{log['statusMessage']} #{uri}\n" end end begin if page && !log['trouble'] && !log['backtrace'] && !log['exception_class'] examine(page, meta, log) end rescue STDERR.puts "|#{Time.now.iso8601} examine ERROR: #{$!.message} (#{$!.class}) #{uri}\n" $!.backtrace.each {|pos| STDERR.puts "| #{pos}\n" } log['trouble'] = "exception" log['backtrace'] = $!.backtrace log['exception_class'] = $!.class end add_log(log) @status.delete '_update_info' end def fetch(log) uri = @config['URI'] opts = { "Accept-Encoding"=>"gzip, deflate", "User-Agent" => @config.fetch('UserAgent', 'samidare') } if h = find_last_200 and @status['_log'].last['status'] != '412' # DJB's publicfile rejects requests which have If-None-Match as: # 412 I do not accept If-None-Match # Since 412 means `Precondition Failed', samidare tries request without # precondition. If it success, samidare may know new valid condition. # For example apache is replaced with publicfile, # ETag should be forgotten. Above 412 handling handle this case. if @config.fetch('UseIfModifiedSince', true) opts['If-Modified-Since'] = h['lastModifiedString'] if h['lastModifiedString'] end opts['If-None-Match'] = h['eTag'] if h['eTag'] end if @config.include? 'Header' opts.update @config['Header'] end #PP.pp([uri, opts], STDERR) if $VERBOSE page = nil meta = nil status = nil status_message = nil exception_class = nil trouble = nil backtrace = nil begin page = timeout(@config['Timeout'] || 200) { URI.parse(uri).read(opts) } if page.empty? trouble = "empty page" end meta = page.meta status = page.status[0] status_message = page.status[1] rescue OpenURI::HTTPError if $!.io.status.first == '304' meta = $!.io.meta status = $!.io.status[0] status_message = $!.io.status[1] else meta = $!.io.meta status = $!.io.status[0] status_message = $!.io.status[1] trouble = "#{status} #{status_message}" exception_class = $!.class.name end rescue StandardError, TimeoutError trouble = $!.message backtrace = $!.backtrace unless TimeoutError === $! exception_class = $!.class.name end log['status'] = status log['statusMessage'] = status_message if status_message log['serverDateString'] = meta['date'] if meta && meta['date'] log['trouble'] = trouble if trouble log['backtrace'] = backtrace if backtrace log['exception_class'] = exception_class if exception_class if @config['LogMeta'] log['logSendHeader'] = opts log['logRecvHeader'] = meta end return page, meta end def examine(page, meta, log) uri = @config['URI'] log['baseURI'] = page.base_uri.to_s if page.base_uri.to_s != uri log['lastModifiedString'] = meta['last-modified'] if meta['last-modified'] log['eTag'] = meta['etag'] if meta['etag'] content_type = log['contentType'] = page.content_type if page.content_type content, content_encoding = decode_content_encoding(page, log) log['content'] = AutoFile.new(uri, content, content_type) if 1000000 < content.length raise ArgumentError, "page too big (#{content.length}) : #{uri}" end content_charset = @config.fetch('ForceCharset') { c = page.charset { nil } c = nil if c && !Mconv.valid_charset?(c) c = @config['DefaultCharset'] if !c c = content.guess_charset if !c && !content_encoding c } content_charset = content_charset.downcase log['contentCharset'] = content_charset if content_charset if "".respond_to? :force_encoding if content && content_charset begin enc = Encoding.find(content_charset) content.force_encoding(enc) rescue ArgumentError end end end # checksum for gzip/deflate decoded content. # compression level is not affected. log['checksum'] = content.sum return if content_encoding decoded_content = content.decode_charset(content_charset) if content_charset examine_html(content_type, decoded_content, log) examine_lirs(decoded_content, log) case @config['UpdateInfo'] when 'lirs' check_lirs(content) when 'html' check_html(log) end end def examine_html(content_type, decoded_content, log) if %r{\A(?:text/html|text/xml|application/(?:[A-Za-z0-9.-]+\+)?xml)\z} !~ content_type && /\A<\?xml/ !~ decoded_content return end t = HTree.parse(decoded_content) title = t.title log['extractedTitle'] = title.to_s.strip if title author = t.author log['extractedAuthor'] = author.to_s if author t.traverse_element('meta', '{http://www.w3.org/1999/xhtml}meta') {|e| begin next unless e.fetch_attr("http-equiv").downcase == "last-modified" log['extractedLastModified'] = Time.httpdate_robust(e.fetch_attr("content")) break rescue IndexError, ArgumentError end } root = (t.root rescue nil) if root and root.name == 'rss' || root.name == '{http://www.w3.org/1999/02/22-rdf-syntax-ns#}RDF' if link = t.find_element('link', '{http://purl.org/rss/1.0/}link', '{http://my.netscape.com/rdf/simple/0.9/}link') base_uri = URI.parse(log['baseURI'] || @config['URI']) link_uri = base_uri + link.extract_text.to_s.strip if link_uri.scheme == 'http' && base_uri.host.downcase == link_uri.host.downcase # xxx: refine safety test log['extractedLinkURI'] = link_uri.to_s end end end if root ['http://www.w3.org/2005/Atom', 'http://purl.org/atom/ns#'].each {|xmlns| if root.name == "{#{xmlns}}feed" link_uri = nil t.traverse_element("{#{xmlns}}link") {|e| begin next unless e.fetch_attr('rel').downcase == 'alternate' base_uri = URI.parse(log['baseURI'] || @config['URI']) link_uri = base_uri + e.fetch_attr('href').to_s.strip break rescue IndexError, ArgumentError end } if link_uri and link_uri.scheme == 'http' && base_uri.host.downcase == link_uri.host.downcase # xxx: refine safety test log['extractedLinkURI'] = link_uri.to_s break end end } end t, checksum_filter = ignore_tree(t) log['checksum_filter'] = checksum_filter unless checksum_filter.empty? log['checksum_filtered'] = t.extract_text.rcdata.gsub(/\s+/, '').sum end def ignore_tree(tree, config=@config) if ignore_path = config['IgnorePath'] ignore_path = ignore_path.split(/\s+/) else ignore_path = [] end ignore_pattern = path2pattern(*ignore_path) if ignore_class = config['IgnoreClass'] ignore_class = ignore_class.split(/\s+/) else ignore_class = [] end if ignore_id = config['IgnoreID'] ignore_id = ignore_id.split(/\s+/) else ignore_id = [] end if ignore_element = config['IgnoreElement'] ignore_element = ignore_element.split(/\s+/) else ignore_element = [] end ignore_text = [] if ignore_text_raw = config['IgnoreText'] ignore_text_raw.scan(%r{/((?:[^/\\]|\\.)*)/}) { ignore_text << Regexp.compile($1) } end t = tree.make_loc.filter {|e| path = e.path.sub(%r{^doc\(\)}, '') e = e.to_node not( (e.text? && (/\A\s*\z/ =~ e.to_s || ignore_text.any? {|pat| pat =~ e.to_s })) || (e.elem? && (%r[\A(?:\{http://www.w3.org/1999/xhtml\})?style\z] =~ e.name || %r[\A(?:\{http://www.w3.org/1999/xhtml\})?script\z] =~ e.name || ignore_element.include?(e.name))) || ignore_pattern =~ path || (e.elem? && ((cs = e.get_attr('class') and ignore_class & cs.split(/\s+/) != []) || ignore_id.include?(e.get_attr('id')))) ) } # xxx: checksum_filter format should be changed. checksum_filter = [] checksum_filter.concat ['IgnorePath', *ignore_path] if !ignore_path.empty? checksum_filter.concat ['IgnoreClass', *ignore_class] if !ignore_class.empty? checksum_filter.concat ['IgnoreID', *ignore_id] if !ignore_id.empty? checksum_filter.concat ['IgnoreElement', *ignore_element] if !ignore_element.empty? checksum_filter.concat ['IgnoreText', *ignore_text] if !ignore_text.empty? [t, checksum_filter] end def examine_lirs(decoded_content, log) uri = URI.parse(@config['URI']) return if %r{\.lirs(?:.gz)?\z} !~ uri.path return if log['extractedTitle'] && log['extractedAuthor'] lirs = LIRS.decode(decoded_content) if $VERBOSE lirs.each {|record| now = Time.now if record.last_modified != '0' && record.last_detected != '0' && record.last_modified.to_i > record.last_detected.to_i STDERR.puts "#{now.iso8601} info: strange LIRS: Last-Modified/Detected inversion: #{record.last_modified.to_i - record.last_detected.to_i}sec #{uri} #{record.encode.inspect}\n" end if record.last_modified != '0' && record.last_modified.to_i > now.to_i STDERR.puts "#{now.iso8601} info: strange LIRS: future Last-Modified: #{record.last_modified.to_i - now.to_i}sec #{uri} #{record.encode.inspect}\n" end } end return if lirs.size != 1 lirs.each {|record| target_uri = URI.parse(record.target_url) return if target_uri.scheme != uri.scheme return if target_uri.host.downcase != uri.host.downcase log['extractedLinkURI'] = record.target_url unless log['extractedLinkURI'] log['extractedTitle'] = record.target_title unless log['extractedTitle'] log['extractedAuthor'] = record.target_maintainer unless log['extractedAuthor'] log['extractedLinkURI'] = record.target_url unless log['extractedLinkURI'] } rescue LIRS::Error # ignore invalid lirs file. STDERR.puts "#{Time.now.iso8601} LIRS Error: #{uri}\n" if $VERBOSE end def path2pattern(*paths) /\A#{Regexp.union(*paths.map {|path| Regexp.new(path.gsub(%r{[^/]+}) {|step| if /\[(\d+)\]\z/ =~ step n = $1.to_i if $1.to_i == 1 Regexp.quote($`) + "(?:\\[#{n}\\])?" else Regexp.quote(step) end else Regexp.quote(step) + '(\[\d+\])?' end }.gsub(%r{//+}) { "/(?:[^/]+/)*" }) })}\z/ end def decode_content_encoding(page, log) content = page if page.content_encoding.empty? content = content.dup.force_encoding("ascii-8bit") if content.respond_to? :force_encoding if /\A\x1f\x8b/n =~ content # gziped? begin content = content.decode_gzip rescue Zlib::Error end end else content_encoding = page.content_encoding.dup while !content_encoding.empty? case content_encoding.last when 'gzip', 'x-gzip' begin content = content.decode_gzip rescue Zlib::Error break end when 'deflate' content = content.decode_deflate else break end content_encoding.pop end content_encoding = nil if content_encoding.empty? log['contentEncoding'] = content_encoding if content_encoding end return content, content_encoding end def check_lirs(new_lirs) logseq = @status['_log'] old_lirs = nil logseq.reverse_each {|h| if h['content'] begin old_lirs = h['content'].content break rescue Errno::ENOENT end end } begin l1 = LIRS.decode(old_lirs) if old_lirs l2 = LIRS.decode(new_lirs) count_all = 0 count_interest = 0 count_update = 0 l2.each {|r2| count_all += 1 uri = r2.target_url if es = ENTRIES[uri] es.each {|e| count_interest += 1 if !old_lirs or (r1 = l1[uri] and r1.last_modified != r2.last_modified) t1 = Time.at(r1.last_modified.to_i) if old_lirs t2 = Time.at(r2.last_modified.to_i) last_success = e.find_last_success if last_success && last_success['clientDateEnd'] < t2 #xxx: not so acculate. count_update += 1 p [:LIRS_UPDATE, uri, t1, t2, @config['URI']] e.status['_update_info'] = true end end } end } STDERR.puts "LIRS total: #{count_update} / #{count_interest} / #{count_all} - #{@config['URI']}\n" if $VERBOSE rescue # External update information is a just hint. # So it is ignorable even if it has some trouble. STDERR.puts "check_lirs: error on #{@config['URI']}: #$!\n" #pp $!.backtrace end end def extract_html_update_info_rec(elt, result, base_uri_cell) hrefs = [] if elt.elem? && %r[\A(?:\{http://www.w3.org/1999/xhtml\})?base\z] =~ elt.name if href = elt.get_attr('href') base_uri_cell[0] = URI.parse(href) end elsif elt.elem? && %r[\A(?:\{http://www.w3.org/1999/xhtml\})?a\z] =~ elt.name if href = elt.get_attr('href') href = (base_uri_cell[0] + URI.parse(href)).to_s hrefs << href if ENTRIES[href] end else elt.children.each {|e| next unless e.elem? hrefs.concat extract_html_update_info_rec(e, result, base_uri_cell) } end hrefs.uniq! if elt.elem? && @config.fetch('UpdateElement', %r[\A(?:\{http://www.w3.org/1999/xhtml\})?a\z]) === elt.name hrefs.each {|uri| result[uri] ||= [] result[uri] << elt } return [] else return hrefs end end def extract_html_update_info(log) return {} unless log && log['content'] && log['contentCharset'] begin content = log['content'].content rescue Errno::ENOENT return {} end content = content.decode_charset(log['contentCharset']) tree = HTree.parse(content) tree, checksum_filter = ignore_tree(tree, log) base_uri = URI.parse(log['baseURI'] || log['URI']) extract_html_update_info_rec(tree, info={}, [base_uri]) info end def compare_html_update_info(old_log, new_log) count_update = 0 count_interest = 0 old_info = extract_html_update_info(old_log) new_info = extract_html_update_info(new_log) (old_info.keys & new_info.keys).each {|uri| count_interest += 1 old_str = old_info[uri].map {|elt| elt.extract_text }.join new_str = new_info[uri].map {|elt| elt.extract_text }.join if old_str != new_str #pp [uri, old_info[uri]] #pp [uri, new_info[uri]] count_update += 1 p [:HTML_UPDATE, uri, old_str, new_str, @config['URI']] yield uri end } STDERR.puts "HTML total: #{count_update} / #{count_interest} - #{@config['URI']}\n" if $VERBOSE end def check_html(new_log=nil) begin if new_log old_log = find_last_200 else new_log = find_last_200 old_log = find_last_200_with_previous_content end compare_html_update_info(old_log, new_log) {|uri| ENTRIES[uri].each {|e| e.status['_update_info'] = true } } rescue # External update information is a just hint. # So it is ignorable even if it has some trouble. STDERR.puts "check_html error on #{@config['URI']}: #$!\n" end end StatusMap = { '200' => 's', # Success '304' => 'n', # Not-Modified } StatusMap.default = 'e' # Error MaxPeriodicalNum = 30 def add_periodical_info(h) return if h['status'] != '200' logseq = @status['_log'] periodical = nil logseq.reverse_each {|l| if l['lastModifiedSequence'] periodical = l['lastModifiedSequence'].dup break elsif l['periodical'] periodical = l['periodical'].dup break end } periodical ||= [] begin t = Time.httpdate_robust(h['lastModifiedString']) rescue end if t && (periodical.empty? || periodical.last != t) periodical << t end if MaxPeriodicalNum < periodical.length periodical = periodical[(-MaxPeriodicalNum)..(-1)] end h['lastModifiedSequence'] = periodical if !periodical.empty? end def content_unchanged(log1, log2) return true if log1['checksum'] && log2['checksum'] && log1['checksum'] == log2['checksum'] return true if log1['checksum_filtered'] && log2['checksum_filtered'] && log1['checksum_filter'] == log2['checksum_filter'] && log1['checksum_filtered'] == log2['checksum_filtered'] false end def add_log(log) @status['_log'] = [] unless @status['_log'] #add_periodical_info(log) if @config['Periodical'] add_periodical_info(log) logseq = @status['_log'] case StatusMap[log['status']] when 'e' history = logseq.map {|l| StatusMap[l['status']] }.join + ' ' + StatusMap[log['status']] if /ee e/ =~ history logseq.pop end logseq << log when 's', 'n' logseq.reject! {|l| StatusMap[l['status']] == 'e' } logseq.shift while !logseq.empty? && StatusMap[logseq.first['status']] == 'n' logseq << log #pp logseq.map {|l| StatusMap[l['status']] + "#{l['checksum']}" } logs = [[]] logseq.each {|l| if logs.last.empty? logs.last << l elsif StatusMap[l['status']] == 'n' logs.last << l elsif content_unchanged(logs.last.last, l) logs.last << l else logs << [l] end } #pp logs.map {|ll| ll.map {|l| StatusMap[l['status']] + "#{l['checksum']}" } } logs[0...-1].each {|ll| ll.reject! {|l| StatusMap[l['status']] == 'n' } ll[1..-1] = [] if 2 <= ll.length } ll = logs.last ll.reject! {|l| StatusMap[l['status']] == 'n' } # removes `log' if it is 'n'. ll[1...-1] = [] if 2 < ll.length if StatusMap[log['status']] == 'n' ll << log # re-add `log'. end num_discards = 0 nlogs = @config.fetch('NumLogs', 2) #pp logs.map {|ll| ll.map {|l| StatusMap[l['status']] + "#{l['checksum']}" } } if nlogs < logs.length num_discards = logs.length - nlogs end #pp logs.map {|ll| ll.map {|l| StatusMap[l['status']] + "#{l['checksum']}" } } if log_expire = @config['LogExpire'] log_expire = parse_time_suffix(log_expire) || 0 if String === log_expire limit = Time.now - log_expire while 0 < num_discards && limit < logs[num_discards-1][0]['clientDateBeg'] num_discards -= 1 end end logs[0, num_discards] = [] logseq.replace logs.flatten else raise "unrecognized log-status [bug]: #{StatusMap[log['status']].inspect}" end unless logseq.last.equal? log raise "current log is not added [bug]" end end def parse_time_suffix(str) case str when /\A(\d+)(s|sec|second)?\z/ $1.to_i when /\A(\d+)(m|min|minute)\z/ $1.to_i * 60 when /\A(\d+)(h|hour)\z/ $1.to_i * 60 * 60 when /\A(\d+)(d|day)\z/ $1.to_i * 60 * 60 * 24 else nil end end def find_last_200_with_previous_content current = nil @status['_log'].reverse_each {|log| next unless log['status'] == '200' if !current current = log elsif !content_unchanged(current, log) return log end } nil end def find_first_200_with_current_content result = nil @status['_log'].reverse_each {|h| if h['status'] == '200' if !result result = h elsif !content_unchanged(result, h) return result else result = h end end } result end def find_last_200 @status['_log'].reverse_each {|h| return h if h['status'] == '200' } nil end def find_last_success # 200 or 304 @status['_log'].reverse_each {|h| return h if StatusMap[h['status']] != 'e' } nil end def find_first_error @status['_log'].each {|h| return h if StatusMap[h['status']] == 'e' } nil end def find_last_error @status['_log'].reverse_each {|h| return h if StatusMap[h['status']] == 'e' } nil end def presentation_data h = @config.dup logseq = @status['_log'] h.update @status # xxx h['title'] = h['Title'] h['author'] = h['Author'] h['last-modified'] = nil h['info'] = '' h['linkURI'] = h['LinkURI'] unless logseq.empty? if l = find_first_200_with_current_content h['last-modified-found'] = l['clientDateBeg'] # xxx: clientDateEnd is better? if l.include?('lastModifiedString') and begin h['last-modified'] = Time.httpdate_robust(l['lastModifiedString']) rescue false end h['last-modified'].localtime l2 = find_last_200 unless l.equal? l2 if l['lastModifiedString'] != l2['lastModifiedString'] h['info'] << '[Touch]' else h['info'] << '[NoIMS]' end end elsif l.include? 'extractedLastModified' h['last-modified'] = l['extractedLastModified'].getlocal else h['last-modified'] = l['clientDateBeg'].getlocal h['info'] << '[NoLM]' end if l.include? 'baseURI' h['info'] << '[Redirect]' end h['title'] ||= l['extractedTitle'] if l['extractedTitle'] h['author'] ||= l['extractedAuthor'] if l['extractedAuthor'] h['linkURI'] ||= l['extractedLinkURI'] if l['extractedLinkURI'] end if StatusMap[logseq.last['status']] == 'e' l = logseq.last if l['status'] if l['statusMessage'] h['info'] << "[#{l['status']} #{l['statusMessage']}]" else h['info'] = "[#{l['status']}]" end elsif l['trouble'] h['info'] = "[#{l['trouble']}]" else h['info'] = '[no status]' end end end h['title'] ||= h['LinkURI'] if h['LinkURI'] h['title'] ||= h['URI'] h['linkURI'] ||= h['URI'] h end def merge(hash) @status = hash.dup.update(@status) end def recent_log2 if logseq = @status['_log'] log1 = log2 = nil logseq.reverse_each {|log| next unless log['content'] if log2 == nil log2 = log else log1 = log break unless content_unchanged(log1, log2) end } [log1, log2] end end def dump_filenames2 log1, log2 = recent_log2 puts "#{log1['content'].pathname}\n" if log1 puts "#{log2['content'].pathname}\n" if log2 end def diff_content log1, log2 = recent_log2 return unless log1 && log2 filename1 = log1['content'].pathname filename2 = log2['content'].pathname tree1, checksum_filter1 = ignore_tree(HTree.parse(File.read(filename1).decode_charset_guess), log1) tree2, checksum_filter2 = ignore_tree(HTree.parse(File.read(filename2).decode_charset_guess), log2) text1 = [] tree1.make_loc.traverse_text {|n| path = n.path.sub(%r{^doc\(\)}, '') n = n.to_node text1 << [n.to_s, path] } text2 = [] tree2.make_loc.traverse_text {|n| path = n.path.sub(%r{^doc\(\)}, '') n = n.to_node text2 << [n.to_s, path] } puts "checksum1: #{tree1.extract_text.to_s.sum} #{checksum_filter1.inspect} #{filename1}\n" puts "checksum2: #{tree2.extract_text.to_s.sum} #{checksum_filter2.inspect} #{filename2}\n" [text1.length, text2.length].min.times { t1, p1 = text1.last t2, p2 = text2.last t1 = t1.gsub(/\s+/, '') if t1 t2 = t2.gsub(/\s+/, '') if t2 if t1 == t2 text1.pop text2.pop else break end } num = 10 0.upto([text1.length, text2.length].max - 1) {|i| t1, p1 = text1[i] t2, p2 = text2[i] t1 = t1.gsub(/\s+/, '') if t1 t2 = t2.gsub(/\s+/, '') if t2 if t1 != t2 pp [text1[i], text2[i]] num -= 1 if num == 0 puts "...\n" break end end } tf1 = Tempfile.new('htmldiff1') PP.pp(tree1, tf1) tf1.close tf2 = Tempfile.new('htmldiff2') PP.pp(tree2, tf2) tf2.close system("diff -u #{tf1.path} #{tf2.path}") end end module Enumerable $opt_max_threads = 8 def concurrent_map(max_threads=$opt_max_threads, &block) arr = self.to_a.dup if max_threads == 1 || arr.length == 1 self.map(&block) else queue = (0...arr.length).to_a max_threads = arr.length if arr.length < max_threads threads = [] max_threads.times { threads << Thread.new { while i = queue.shift arr[i] = yield arr[i] end } } threads.each {|t| t.join } arr end end end class Samidare def open_lock(filename, nonblock=false) dirname = File.dirname filename basename = File.basename filename tmpname = "#{dirname}/.,#{basename},#$$" 1.times { begin target = File.open(filename, File::RDWR|File::CREAT) stat1 = target.stat if nonblock unless target.flock(File::LOCK_EX | File::LOCK_NB) STDERR.puts "fail to lock: #{filename}\n" return end else target.flock(File::LOCK_EX) end stat2 = File.stat(filename) redo if stat1.ino != stat2.ino begin File.open(tmpname, 'w') {|tmp| yield target, tmp } stat2 = File.stat(filename) # manually unlocked? File.rename(tmpname, filename) if stat1.ino == stat2.ino ensure File.unlink tmpname if FileTest.exist? tmpname end ensure target.close if target end } end def config_flatten(arr, default={}) result = [] arr.each {|elt| case elt when Hash if elt.include? 'URI' result << default.dup.update(elt) else default = default.dup.update(elt) end when Array result.concat config_flatten(elt, default) when String result << default.dup.update({'URI'=>elt}) end } result end def deep_copy(o) Marshal.load(Marshal.dump(o)) end def deep_freeze(o) objs = [] o = Marshal.load(Marshal.dump(o), lambda {|obj| objs << obj; obj }) objs.each {|obj| obj.freeze } o end def load_config @configuration = {} config = config_flatten(File.open(CONFIG_FILENAME) {|f| YAML.load(f) }) config.each_with_index {|h, i| h.reject! {|k, v| /\A[A-Z]/ !~ k } uri = h['URI'] if @configuration.include? uri @configuration[uri].update h config[i] = nil else @configuration[uri] = h end } config.compact! config end #def load_status(f) YAML.load(f) end #def save_status(f, d) f.puts d.to_yaml end def load_status(f) Marshal.load(f) end def save_status(d, f) Marshal.dump(d, f) end def open_status(readonly=false) if readonly open(STATUS_FILENAME) {|f| if f.stat.size == 0 status = [] else status = load_status(f) end status = deep_freeze(status) yield status } else open_lock(STATUS_FILENAME, true) {|f, out| if f.stat.size == 0 status = [] else status = load_status(f) AutoFile.clear end yield status save_status(status, out) } end end def output_file(filename, content) dir = File.dirname filename if FileTest.writable? dir filename_new = filename + '.new' open(filename_new, 'w') {|f| f.print content } File.rename filename_new, filename else open(filename, 'w') {|f| f.print content } end end class GuessCharsetPathname def initialize(filename) @filename = filename end def read result = File.read(@filename) result.decode_charset_guess end end def generate_output(data) data = Presen.new(data) result = HTree.expand_template(GuessCharsetPathname.new(@opt_template), data, '') result << "\n" if /\n\z/ !~ result if @opt_output != '-' output_file(@opt_output, result) output_file(@opt_output + '.gz', result.encode_gzip) else puts "#{result}\n" end end def generate_lirs(data) str = '' data["antenna"].each {|h| next unless h['last-modified'] && h['last-modified-found'] #p ['LIRS', h['last-modified'], h['last-modified-found'], h['URI'], h['title'], h['author']] str << 'LIRS,' str << h['last-modified'].to_i.to_s << ',' str << h['last-modified-found'].to_i.to_s << ',' str << '32400,' str << '0,' str << h['linkURI'].gsub(/[,\\]/) { "\\#$&" } << ',' str << h['title'].gsub(/[,\\]/) { "\\#$&" }.strip.gsub(/\s/, ' ') << ',' str << (h['author'] || '0').gsub(/[,\\]/) { "\\#$&" }.strip.gsub(/\s/, ' ') << ',' str << '0,' str << "\n" } str = str.encode_charset('euc-jp') str = str.encode_gzip output_file(@opt_output_lirs, str) end def parse_options @opt_output = OUTPUT_LATEST_FILENAME @opt_output_lirs = OUTPUT_LIRS_FILENAME @opt_dont_check = nil @opt_force_check = nil @opt_timing = nil @opt_dump_config = nil @opt_dump_status = nil @opt_dump_template_data = nil @opt_template = TEMPLATE_LATEST_FILENAME @opt_remove_entry = nil @opt_dump_filenames = nil @opt_dump_filenames2 = nil @opt_diff_content = nil ARGV.options {|q| q.banner = 'samidare [opts]' q.def_option('--help', 'show this message') {puts q; exit(0)} q.def_option('--verbose', '-v', 'verbose') { $VERBOSE = true } q.def_option('--no-check', '-n', 'don\'t check web') { @opt_dont_check = true } q.def_option('--force', '-f', 'force check (avoid timing control mechanism)') { @opt_force_check = true } q.def_option('--output=filename', '-o', 'specify output html file') {|filename| @opt_output = filename } q.def_option('--output-lirs=filename', 'specify output lirs file') {|filename| @opt_output_lirs = filename } q.def_option('--template=filename', '-T', 'specify template') {|filename| @opt_template = filename } q.def_option('--timing', '-t', 'show timings') { @opt_timing = true } q.def_option('--dump-config', 'dump flatten configuration') { @opt_dump_config = true } q.def_option('--dump-status', 'dump status') { @opt_dump_status = true } q.def_option('--dump-template-data', 'dump data for expand template') { @opt_dump_template_data = true } q.def_option('--dump-filenames', 'dump filenames of specified entry') { @opt_dump_filenames = true } q.def_option('--dump-filenames2', 'dump two recent filenames') { @opt_dump_filenames2 = true } q.def_option('--remove-entry', 'remove entry') { @opt_remove_entry = true } q.def_option('--single-thread', 'disable multi-threading') { $opt_max_threads = 1 } q.def_option('--diff-content', 'show difference') { @opt_diff_content = true } q.parse! } require 'resolv-replace' if $opt_max_threads != 1 end def dump_status(status, entries) if ARGV.empty? status.each {|ent| pp ent } else entries.each {|ent| unless (ARGV & ent.related_uris).empty? pp ent.status puts "next time: #{ent.next_timing.localtime}" end } end end def dump_filenames(entries) entries.each {|ent| unless (ARGV & ent.related_uris).empty? if logseq = ent.status['_log'] logseq.each {|log| if content = log['content'] puts content.pathname end } end end } end def dump_filenames2(entries) entries.each {|ent| unless (ARGV & ent.related_uris).empty? ent.dump_filenames2 end } end def diff_content(entries) entries.each {|ent| unless (ARGV & ent.related_uris).empty? ent.diff_content end } end def create_entries(config, status, readonly=false) logs = {} status.each {|status_ent| if status_ent.include?('URI') && status_ent.include?('_log') logs[status_ent['URI']] = status_ent['_log'] end } status.clear unless readonly entries = [] config.each {|config_ent| uri = config_ent['URI'] logseq = logs[uri] || [] status_ent = { 'URI' => uri, '_log' => logseq } status << status_ent unless readonly entries << Entry.new(status_ent, config_ent) } entries end def main parse_options config = load_config if @opt_dump_config puts config.to_yaml return end data = nil readonly = @opt_timing || @opt_dont_check || @opt_dump_status || @opt_dump_template_data || @opt_dump_filenames || @opt_dump_filenames2 || @opt_diff_content open_status(readonly) {|status| entries = create_entries(config, status, readonly) if @opt_dump_status dump_status(status, entries) elsif @opt_dump_filenames dump_filenames(entries) elsif @opt_dump_filenames2 dump_filenames2(entries) elsif @opt_diff_content diff_content(entries) elsif @opt_timing entries = entries.map {|entry| [entry.next_timing.localtime, entry] }.sort now = Time.now entries.each {|timing, entry| if now && timing > now puts "#{now} --- now ---" now = nil end h = entry.presentation_data s = "#{timing}: #{h['title']}" s << " (#{h['Author']})" if h['Author'] puts s } if now puts "#{now} --- now ---" end elsif @opt_remove_entry removing_uris = {} entries.each {|e| unless (e.related_uris & ARGV).empty? || e.status['_log'].empty? removing_uris[e.uri] = true end } status.reject! {|log| uri = log['URI'] if removing_uris[uri] STDERR.puts "removed: #{uri}" if $VERBOSE true else false end } else unless readonly update_info_entries, non_update_info_entries = entries.partition {|e| e.update_info? } update_info_entries.concurrent_map {|entry| next unless entry.update_info? entry.check if entry.should_check? && (@opt_force_check || entry.timing_check) } non_update_info_entries.concurrent_map {|entry| next if entry.update_info? entry.check if entry.should_check? && (@opt_force_check || entry.timing_check) } end update_infos, entries = entries.partition {|entry| entry.update_info? } data = { "antenna" => entries.map {|entry| entry.presentation_data }.sort_by {|h| # [h['last-modified'], h['title']] if h['last-modified-found'] [2, h['last-modified-found'], h['last-modified'], h['title']] elsif h['last-modified'] [1, h['last-modified'], h['title']] else [0, h['title']] end }.reverse, "update_info" => update_infos.map {|update_info| update_info.presentation_data }.sort_by {|h| # [h['last-modified'], h['title']] if h['last-modified-found'] [2, h['last-modified-found'], h['last-modified'], h['title']] elsif h['last-modified'] [1, h['last-modified'], h['title']] else [0, h['title']] end }.reverse } if @opt_dump_template_data pp data return end STDERR.print "generating output..." if $VERBOSE t1 = Time.now generate_output(data) t2 = Time.now STDERR.puts " #{t2-t1}sec" if $VERBOSE STDERR.print "generating lirs..." if $VERBOSE t1 = Time.now generate_lirs(data) t2 = Time.now STDERR.puts " #{t2-t1}sec" if $VERBOSE end } #PP.pp(data, STDERR) if $VERBOSE end end class Hash v = $VERBOSE $VERBOSE = nil def pretty_print(q) q.group(1, '{', '}') { keys = self.keys keys.sort! if keys.all? {|k| String === k } q.seplist(keys) {|k| v = self[k] q.group { q.pp k q.text '=>' q.group(1) { q.breakable '' q.pp v } } } } end $VERBOSE = v end if $0 == __FILE__ Samidare.new.main end samidare-0.7/mconv.rb0000644000000000000000000001667511042075667013341 0ustar rootroot# -*- coding: ASCII-8BIT -*- # mconv.rb - character code conversion library using iconv # # Copyright (C) 2003 Tanaka Akira # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # 1. Redistributions of source code must retain the above copyright notice, this # list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright notice, # this list of conditions and the following disclaimer in the documentation # and/or other materials provided with the distribution. # 3. The name of the author may not be used to endorse or promote products # derived from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO # EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT # OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING # IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY # OF SUCH DAMAGE. require 'iconv' module Mconv def Mconv.internal_mime_charset if Object.const_defined? :Encoding enc = Encoding.default_external.name else enc = $KCODE end case enc when /\Ae/i; 'euc-jp' when /\As/i; 'shift_jis' when /\Au/i; 'utf-8' when /\An/i; 'iso-8859-1' when /ascii-8bit/i; 'iso-8859-1' else raise "unknown default external encoding : #{enc}" end end def Mconv.valid_charset?(str) /\A(us-ascii|iso-2022-jp|euc-jp|shift_jis|utf-8|iso-8859-1)\z/i =~ str end def Mconv.conv(str, to, from) ic = Iconv.new(to, from) result = '' rest = str if rest.respond_to? :force_encoding rest = rest.dup.force_encoding("ascii-8bit") end begin s = ic.iconv(rest) result << s rescue Iconv::Failure result << $!.success rest = $!.failed # following processing should be customizable by block? result << '?' rest = rest[1..-1] retry end result << ic.close result end CharsetTable = { 'us-ascii' => /\A[\s\x21-\x7e]*\z/, 'euc-jp' => /\A(?:\s (?# white space character) | [\x21-\x7e] (?# ASCII) | [\xa1-\xfe][\xa1-\xfe] (?# JIS X 0208) | \x8e(?:([\xa1-\xdf]) (?# JIS X 0201 Katakana) |([\xe0-\xfe])) (?# There is no character in E0 to FE) | \x8f[\xa1-\xfe][\xa1-\xfe] (?# JIS X 0212) )*\z/nx, "iso-2022-jp" => # with katakana /\A[\s\x21-\x7e]* (?# initial ascii ) (\e\(B[\s\x21-\x7e]* (?# ascii ) |\e\(J[\s\x21-\x7e]* (?# JIS X 0201 latin ) |\e\(I[\s\x21-\x7e]* (?# JIS X 0201 katakana ) |\e\$@(?:[\x21-\x7e][\x21-\x7e])* (?# JIS X 0201 ) |\e\$B(?:[\x21-\x7e][\x21-\x7e])* (?# JIS X 0201 ) )*\z/nx, 'shift_jis' => /\A(?:\s (?# white space character) | [\x21-\x7e] (?# JIS X 0201 Latin) | ([\xa1-\xdf]) (?# JIS X 0201 Katakana) | [\x81-\x9f\xe0-\xef][\x40-\x7e\x80-\xfc] (?# JIS X 0208) | ([\xf0-\xfc][\x40-\x7e\x80-\xfc]) (?# extended area) )*\z/nx, 'utf-8' => /\A(?:\s | [\x21-\x7e] | [\xc0-\xdf][\x80-\xbf] | [\xe0-\xef][\x80-\xbf][\x80-\xbf] | [\xf0-\xf7][\x80-\xbf][\x80-\xbf][\x80-\xbf] | [\xf8-\xfb][\x80-\xbf][\x80-\xbf][\x80-\xbf][\x80-\xbf] | [\xfc-\xfd][\x80-\xbf][\x80-\xbf][\x80-\xbf][\x80-\xbf][\x80-\xbf] )*\z/nx } Preference = ['us-ascii', "iso-2022-jp", 'euc-jp', 'utf-8', 'shift_jis'] def Mconv.guess_charset(str) guess_charset_list(str).first end def Mconv.guess_charset_list(str) if str.respond_to? :force_encoding str = str.dup.force_encoding("ascii-8bit") end case str when /\A\xff\xfe/n; return ['utf-16le'] when /\A\xfe\xff/n; return ['utf-16be'] end count = {} CharsetTable.each {|name, regexp| count[name] = 0 } str.scan(/\S+/n) {|fragment| CharsetTable.each {|name, regexp| count[name] += 1 if regexp =~ fragment } } max = count.values.max count.reject! {|k, v| v != max } return count.keys if count.size == 1 return ['us-ascii'] if count['us-ascii'] # xxx: needs more accurate guess Preference.reject {|name| !count[name] } end def Mconv.minimize_charset(charset, string) # shortcut if /\A(?:euc-jp|utf-8|iso-8859-1)\z/i =~ charset if /\A[\x00-\x7f]*\z/ =~ string return 'us-ascii' else return charset end end charset2 = 'us-ascii' begin # round trip? s2 = Iconv.conv(charset, charset2, Iconv.conv(charset2, charset, string)) return charset2 if string == s2 rescue Iconv::Failure end charset end ValidPrefix = { 'us-ascii' => /\A[\x00-\x7f]*/, 'iso-8859-1' => /\A[\x00-\xff]*/n, 'euc-jp' => /\A(?: [\x00-\x7f] (?# ASCII) | [\xa1-\xfe][\xa1-\xfe] (?# JIS X 0208) | \x8e(?:([\xa1-\xdf]) (?# JIS X 0201 Katakana) |([\xe0-\xfe])) (?# There is no character in E0 to FE) | \x8f[\xa1-\xfe][\xa1-\xfe] (?# JIS X 0212) )*/nx, 'shift_jis' => /\A(?: [\x00-\x7f] (?# JIS X 0201 Latin) | ([\xa1-\xdf]) (?# JIS X 0201 Katakana) | [\x81-\x9f\xe0-\xef][\x40-\x7e\x80-\xfc] (?# JIS X 0208) | ([\xf0-\xfc][\x40-\x7e\x80-\xfc]) (?# extended area) )*/nx, 'utf-8' => /\A(?: [\x00-\x7f] | [\xc0-\xdf][\x80-\xbf] | [\xe0-\xef][\x80-\xbf][\x80-\xbf] | [\xf0-\xf7][\x80-\xbf][\x80-\xbf][\x80-\xbf] | [\xf8-\xfb][\x80-\xbf][\x80-\xbf][\x80-\xbf][\x80-\xbf] | [\xfc-\xfd][\x80-\xbf][\x80-\xbf][\x80-\xbf][\x80-\xbf][\x80-\xbf] )*/nx } def Mconv.validize(str, charset) if str.respond_to? :force_encoding enc = str.encoding str = str.dup.force_encoding("ascii-8bit") end pat = ValidPrefix[charset] ret = '' until str.empty? pat =~ str ret << str[0, $&.length] str = str[$&.length..-1] unless str.empty? ret << '?' str = str[1..-1] end end if str.respond_to? :force_encoding ret.force_encoding enc end ret end end class String def decode_charset(charset) Mconv.validize(Mconv.conv(self, Mconv.internal_mime_charset, charset), Mconv.internal_mime_charset) end def encode_charset(charset) Mconv.conv(self, charset, Mconv.internal_mime_charset) end def guess_charset Mconv.guess_charset(self) end def guess_charset_list Mconv.guess_charset_list(self) end def decode_charset_guess decode_charset(guess_charset) end end samidare-0.7/presen.rb0000644000000000000000000000252011042075667013473 0ustar rootroot# presen.rb - presentation class # # Copyright (C) 2005 Tanaka Akira # # 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 class Presen def initialize(data) @data = data end attr_reader :data def current_cache(entry) entry['_log'].compact.reverse.inject(nil) {|h0, h1| if !h1['content'] || !h1['content'].exist? h0 elsif !h0 h1 elsif (h0['checksum'] && h1['checksum'] && h0['checksum'] == h1['checksum']) || (h0['checksum_filtered'] && h1['checksum_filtered'] && h0['checksum_filtered'] == h1['checksum_filtered']) h1 else break h0 end } end end samidare-0.7/rb-link0000755000000000000000000001045511042075667013144 0ustar rootroot#!/usr/bin/env ruby # rb-link - ruby linker # # Copyright (C) 2003,2006,2007 Tanaka Akira # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # 1. Redistributions of source code must retain the above copyright notice, this # list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright notice, # this list of conditions and the following disclaimer in the documentation # and/or other materials provided with the distribution. # 3. The name of the author may not be used to endorse or promote products # derived from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO # EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT # OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING # IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY # OF SUCH DAMAGE. require 'rbconfig' require 'optparse' require 'pathname' def expand_require(out, filename, dirs, main, included={}) open(filename) {|f| comment = false test = false f.each {|line| if /^=begin/ =~ line comment = true out.print line elsif /^=end/ =~ line comment = false out.print line elsif comment out.print line elsif !main && (/^if __FILE__ == \$0/ =~ line || /^if \$0 == __FILE__/ =~ line) test = true out.print "#", line elsif test && /^end/ =~ line test = false out.print "#", line elsif test out.print "#", line elsif /^require '([^']*)'/ =~ line && %r{^/} !~ (req = $1) if included[req] out.print "#", line else dir = dirs.find {|d| (d + "#{req}.rb").exist? } if dir out.print "#", line filename = dir + "#{req}.rb" included[req] = filename #endmark = 'End_' + [req].pack("m*").delete("\n") #out.print "eval <<'#{endmark}', TOPLEVEL_BINDING, #{"[#{filename}]".dump}, #{out.output_line+1}\n" expand_require(out, filename, dirs, false, included) #out.print "#{endmark}\n" else out.print line end end elsif /^__END__$/ =~ line break else out.print line end } } end module CountOutputLine def output_line @output_line = 1 unless defined? @output_line @output_line end def write(str) @output_line = output_line + str.count("\n") super end end def parse_options $output_filename = nil $dep_output_filename = nil ARGV.options {|q| q.banner = 'rb-link [opts] script-file [library-directories...]' q.def_option('--help', 'show this message') {puts q; exit(0)} q.def_option('--output=filename', '-o', 'specify output file') {|filename| $output_filename = filename} q.def_option('--dependency=filename', '-d', 'specify dependency output file') {|filename| $dep_output_filename = filename} q.parse! } end def open_output if $output_filename File.open($output_filename, 'w') {|f| yield f f.chmod 0755 } else yield STDOUT end end def main parse_options script = ARGV.shift if ARGV.empty? libdirs = [Pathname.new('.')] else libdirs = ARGV.map {|f| Pathname.new(f) } end open_output {|out| out.extend CountOutputLine interpreter_path = File.join(Config::CONFIG["bindir"], Config::CONFIG["ruby_install_name"]) out.print "#!#{interpreter_path}\n" included = {} expand_require(out, script, libdirs, true, included) if $dep_output_filename open($dep_output_filename, 'w') {|f| incs = included.values.sort if incs.empty? f.puts "#{$output_filename} : #{script}" else f.puts "#{$output_filename} : #{script} #{incs.join(' ')}" incs.each {|inc| f.puts "#{inc} :" } end } end } end main samidare-0.7/rb2rm0000755000000000000000000000175711042075667012637 0ustar rootroot#!/usr/bin/env ruby # rb2rm - status.rb to status.rm converter # # Copyright (C) 2003 Tanaka Akira # # 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 require 'amarshal' require 'autofile' system("cp status.rm status.rm-") open("status.rb") {|input| open("status.rm", "w") {|output| Marshal.dump(AMarshal.load(input),output) } } samidare-0.7/rm2rb0000755000000000000000000000171511042075667012631 0ustar rootroot#!/usr/bin/env ruby # rm2rb - status.rm to status.rb converter # # Copyright (C) 2003 Tanaka Akira # # 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 require 'amarshal' require 'autofile' open("status.rm") {|input| open("status.rb", "w") {|output| AMarshal.dump(Marshal.load(input),output) } } samidare-0.7/samidare.man0000644000000000000000000000542311042075667014141 0ustar rootroot.TH SAMIDARE 1 "July 2008" "samidare 0.7" "User Commands" .SH NAME samidare \- web page update checker .SH SYNOPSIS .B samidare .RI [ OPTION ]... .RI [ URL ]... .SH DESCRIPTION .PP Samidare checks web page updates. It takes a list of URLs in a configuration file, config.yml, and checks last update time of them. A HTML file, latest.html, is generated to show the updates. .SH OPTIONS .TP --help show help message. .TP -v, --verbose specify verbose mode. .TP -n, --no-check don't check web. output generation only. .TP -f, --force force check (avoid timing control mechanism) .TP -o, --output=filename specify output html filename. .TP --output-lirs=filename specify output lirs filename. .TP -T, --template=filename specify template filename. .TP -t, --timing show check time of pages. .TP --dump-config dump flatten configuration. .TP --dump-status dump status. If URLs is specified, the status of specified pages are shown. .TP --dump-template-data dump data for expand template. The "data" variable in template file refer this. .TP --dump-filenames dumps locally stored filenames of pages specified by URLs. .TP --dump-filenames2 dumps locally stored recent two filenames of pages specified by URLs. .TP --remove-entry remove entry of pages specified by URLs. .TP --diff-content show difference of recent two files of specified URLs. .SH USAGE samidare is configured by "config.yml" and "t.latest.html" by default. samidare generates "latest.html" and "sites.lirs.gz" samidare uses "status.rm" and "tmp" to record status of pages. "config.yml" is a configuration file in YAML format. See EXAMPLES section for its content. "t.latest.html" is a template file. In the file, "data" variable can be used. See the document of htree library for template directives. So you can run samidare as follows. % cd $HOME % mkdir samidare % cd samidare % vi config.yml % vi t.latest.html # optional % samidare % w3m latest.html # view the result If you want to publish the result, use symbolic link to latest.html and sites.lirs.gz as follows. % mkdir public_html % mkdir public_html/samidare % cd public_html/samidare % ln -s ../../samidare/latest.html . % ln -s ../../samidare/sites.lirs.gz . .SH EXAMPLES The configuration file is described in YAML format. The simplest configuration is list of URLs as follows. - http://www.example.org/blog/ - http://www.example.net/ .SH FILES "config.yml" and "t.latest.html" is configuration file. "latest.html" and "sites.lirs.gz" is output. "status.rm" and "tmp" is used by samidare internally. .SH SECURITY samidare stores pages in tmp directory. If it is published via your web server, XSS (cross site scripting) is possible. So the directory should not be published. .SH AUTHOR Tanaka Akira .SH SEE ALSO htree samidare-0.7/string-util.rb0000644000000000000000000000212011042075667014454 0ustar rootroot# string-util.rb - string utilities # # Copyright (C) 2003 Tanaka Akira # # 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 require 'zlib' require 'stringio' class String def decode_gzip Zlib::GzipReader.new(StringIO.new(self)).read || "" end def encode_gzip out = "" Zlib::GzipWriter.wrap(StringIO.new(out)) {|gz| gz << self } out end def decode_deflate Zlib::Inflate.inflate(self) end end samidare-0.7/t.latest.html0000644000000000000000000000342211042075667014300 0ustar rootroot samidare template sample

五月雨サンプルアンテナ

category

  1. date title (author) [info]