OSDN Git Service

1.28
authormorimoto <morimoto@180c8125-5b33-4295-ad04-72a68a15b4cc>
Sat, 11 Sep 2004 16:18:24 +0000 (16:18 +0000)
committermorimoto <morimoto@180c8125-5b33-4295-ad04-72a68a15b4cc>
Sat, 11 Sep 2004 16:18:24 +0000 (16:18 +0000)
ChangeLog
doc/index.html
keitairc

index 49c4ab9..22ce4ab 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2004-09-12  Jun Morimoto  <morimoto@xantia.citroen.org>
+
+       * keitairc 1.28: Cookie \e$BBP1~\e(B
+
 2004-09-07  Jun Morimoto  <morimoto@xantia.citroen.org>
 
        * keitairc 1.27: \e$BL$FI%P%C%U%!$N07$$$,$*$+$7$+$C$?\e(B
index 29b1119..40d4f51 100644 (file)
@@ -10,7 +10,7 @@
 
 <p class="flushleft">
 morimoto@xantia.citroen.org<br>
-$Id: index.html,v 1.22 2004-09-11 15:53:42 morimoto Exp $
+$Id: index.html,v 1.23 2004-09-11 16:18:24 morimoto Exp $
 </p>
 
 <h2>ÀâÌÀ</h2>
@@ -93,6 +93,10 @@ web_title = keitairc
 # ¥Á¥ã¥Í¥ë¤´¤È¤Ë¡¢¤³¤Î¹Ô¿ô¤Þ¤Çµ­²±
 web_lines = 20
 
+# È¯¸À¸å Ì¤ÆÉ¥á¥Ã¥»¡¼¥¸¤Î¤ß¤òɽ¼¨¤¹¤ë¤« Á´È¯¸À¤òɽ¼¨¤¹¤ë¤«?
+# ¥Ç¥£¥Õ¥©¥ë¥È¤ÏÁ´È¯¸Àɽ¼¨
+# show_newmsgonly = yes
+
 # ¥¢¥¯¥»¥¹Ç§¾Ú. ¤³¤³¤ò¾Êά¤·¤Æ¤·¤Þ¤¦¤È
 # ¥Ñ¥¹¥ï¡¼¥Éǧ¾Ú¤·¤Ê¤¤¤Î¤Ç¡¢Àܳ¤Ï´Êñ¤Ç¤¹¤¬¡¢URL ¤¬¤Ð¤ì¤Æ¤·¤Þ¤¦¤È
 # Ã¯¤Ç¤âÆɤá¤Þ¤¹¤·¡¢Ã¯¤Ç¤â¤¢¤Ê¤¿¤ËÀ®¤ê¤¹¤Þ¤·¤Æȯ¸À¤Ç¤­¤Þ¤¹¡£
@@ -100,6 +104,12 @@ web_username = andre
 web_password = 2055
 
 ################################################################
+# options for AirH" Phone
+################################################################
+# AirH" Phone ¤Ê¤É Cookie ÂбþüËö¤Ç¥¯¥Ã¥­¡¼¤ò»È¤¦¾ì¹ç
+# use_cookie = yes
+
+################################################################
 # options for au (ezweb)
 ################################################################
 # au_subscriber_id = 050999999999999_mb.ezweb.ne.jp
@@ -108,10 +118,9 @@ web_password = 2055
 # (subscriber_id ¤Çǧ¾Ú¤Ç¤­¤Ê¤«¤Ã¤¿¾ì¹ç¤Ï Ä̾ï¤Î basic auth ¤ò
 # ¹Ô¤¤¤Þ¤¹)
 
-# È¯¸À¸å Ì¤ÆÉ¥á¥Ã¥»¡¼¥¸¤Î¤ß¤òɽ¼¨¤¹¤ë¤« Á´È¯¸À¤òɽ¼¨¤¹¤ë¤«?
-# ¥Ç¥£¥Õ¥©¥ë¥È¤ÏÁ´È¯¸Àɽ¼¨
-# show_newmsgonly = yes
-
+################################################################
+# options for Vodafone live!
+################################################################
 # ¤â¤· Vodafone live! (J-Phone) ¤Ê¤É¤Î http port ¤ò»ØÄê¤Ç¤­¤Ê¤¤Ã¼Ëö¤Ç¡¢port 80 ¤ò
 # ÀêÍ­¤»¤º keitairc ¤ò»È¤¤¤¿¤¤¤Ê¤é¡¢¤¿¤È¤¨¤Ð keitairc ¤ò port 8765 ¤Ç
 # Î©¤Á¤¢¤²¡¢apache ¤Î httpd.conf ¤Î
@@ -136,9 +145,12 @@ web_password = 2055
 
 <p>
 keitairc ¤òµ¯Æ°¤·¤Æ·ÈÂÓ¤«¤é¥¢¥¯¥»¥¹¤¹¤ë¤È¡¢
+web_username ¤È web_password ¤Ç»ØÄꤷ¤¿¥æ¡¼¥¶Ì¾¤È¥Ñ¥¹¥ï¡¼¥É¤Çǧ¾Ú¤ò¹Ô¤Ê¤Ã¤¿¤Î¤Á¡¢
 ¤¤¤Þ»²²Ã¤·¤Æ¤¤¤ëÁ´¤Æ¤Î¥Á¥ã¥Í¥ë¤Î¥ê¥¹¥È¤¬½Ð¤Þ¤¹¡£
 È¯¸ÀÆâÍƤ¬¿·¤·¤¤¥Á¥ã¥Í¥ë¤«¤é½ç¤ËʤӤޤ¹¡£
-¥Á¥ã¥Í¥ë¤Î¥ê¥¹¥È¤ÏÅÅÏõ¡¤Î 0 ¤ò²¡¤¹¤È¹¹¿·¤Ç¤­¤Þ¤¹¡£
+¥Á¥ã¥Í¥ë¤Î¥ê¥¹¥È¤ÏÅÅÏõ¡¤Î 0 ¤ò²¡¤¹¤È¹¹¿·¤Ç¤­¤Þ¤¹¡£<br>
+¤Ê¤ª¡¢AirH" Phone¤Ê¤ÉCookieÂбþµ¡¼ï¤Ç¤Ï¡¢
+use_cookie = yes »ØÄê¤ò¤¹¤ì¤Ð¡¢°Ê¹ß¤Î¥æ¡¼¥¶Ì¾¡¦¥Ñ¥¹¥ï¡¼¥Éǧ¾Ú¤ò¾Êά¤Ç¤­¤Þ¤¹¡£
 </p>
 
 <p>
@@ -179,9 +191,26 @@ OK 
 ¤Ë cvs ¥ê¥Ý¥¸¥È¥ê, BTS ¤Ê¤É¤¬¤¢¤ê¤Þ¤¹¡£
 </p>
 
+<h2>¥»¥­¥å¥ê¥Æ¥£</h2>
+<ul>
+<li><tt>use_cookie = yes</tt> ¤ÇüËö¤ËÊݸ¤µ¤ì¤ë¥¯¥Ã¥­¡¼¤ÎÆâÍƤÏ
+°Å¹æ²½¤µ¤ì¤Æ¤¤¤Ê¤¤¤Î¤Ç¡¢¥¯¥Ã¥­¡¼ÆâÍƤ¬Ï³±Ì¤¹¤ë¤È¥æ¡¼¥¶Ì¾¥Ñ¥¹¥ï¡¼¥É¤âϳ±Ì¤·¤Þ¤¹¡£
+<li>¤½¤â¤½¤â¤³¤³¤Ç»È¤ï¤ì¤Æ¤¤¤ë¥æ¡¼¥¶Ì¾¥Ñ¥¹¥ï¡¼¥Éǧ¾Ú¤Ï http basic Ç§¾Ú¤Ê¤Î¤Ç
+ÄÌ¿®Ï©¤òʿʸ¤Çή¤ì¤Þ¤¹¡£
+</ul>
+
 <h2>Changes</h2>
 <dl>
 
+<dt>1.28
+<dd>AirH" Phone¤Ê¤ÉCookieÂбþüËö¤Î¤¿¤á¤Ë¡¢CookieÂбþ¤·¤Þ¤·¤¿¡£
+°ìÅ٥桼¥¶Ì¾¡¢¥Ñ¥¹¥ï¡¼¥Éǧ¾Ú¤ò¹Ô¤Ê¤¨¤Ð¡¢Cookie¤Ëµ­²±¤µ¤ì¤ë¤Î¤Ç¡¢
+¼¡¤«¤é¤Ï¥æ¡¼¥¶Ì¾¡¢¥Ñ¥¹¥ï¡¼¥É¤òÆþÎϤ¹¤ëɬÍפ¬¤¢¤ê¤Þ¤»¤ó¡£
+~/.keitairc¤Ë<tt>use_cookie = yes<tt>¤ÎÄɲä¬É¬ÍפǤ¹¡£
+(thanks to
+<a href="http://naimune.com/keitairc/">http://naimune.com/keitairc/</a>:
+¤Ò¤Á¤µ¤È¤¸¤å¤ó»á)
+
 <dt>1.27
 <dd>̤ÆɥХåե¡¤Î°·¤¤¤¬¤ª¤«¤·¤«¤Ã¤¿
 
index cee1e04..d275869 100755 (executable)
--- a/keitairc
+++ b/keitairc
@@ -1,6 +1,6 @@
 #!/usr/bin/perl
 # keitairc
-# $Id: keitairc,v 1.27 2004-09-07 04:20:58 morimoto Exp $
+# $Id: keitairc,v 1.28 2004-09-11 16:18:24 morimoto Exp $
 #
 # Copyright (c) 2003 Jun Morimoto <morimoto@xantia.citroen.org>
 # This program is covered by the GNU General Public License 2
@@ -8,7 +8,7 @@
 # Depends: libjcode-pm-perl, libpoe-component-irc-perl,
 #   liburi-perl, libwww-perl, libappconfig-perl
 
-my $rcsid = q$Id: keitairc,v 1.27 2004-09-07 04:20:58 morimoto Exp $;
+my $rcsid = q$Id: keitairc,v 1.28 2004-09-11 16:18:24 morimoto Exp $;
 my ($version) = $rcsid =~ m#,v ([0-9.]+)#;
 
 use strict;
@@ -23,6 +23,7 @@ use AppConfig qw(:argcount);
 
 use constant true => 1;
 use constant false => 0;
+use constant cookie_ttl => 86400*3;  # 3 days
 
 my $config = AppConfig->new(
                            {
@@ -33,7 +34,7 @@ my $config = AppConfig->new(
                            },
                            qw(irc_nick irc_username irc_desc
                               irc_server irc_port irc_password
-                              au_subscriber_id
+                              au_subscriber_id use_cookie
                               web_port web_title web_lines web_root
                               web_username web_password show_newmsgonly)
                            );
@@ -62,6 +63,8 @@ my %unread_lines;
 # chk
 my ($message_added);
 
+my $user_agent;
+
 # irc component
 POE::Component::IRC->new('keitairc');
 POE::Session->new(
@@ -343,20 +346,38 @@ sub on_web_request{
        return;
     }
 
+    # cookie
+    my $cookie_authorized;
+    if($config->use_cookie){
+      my %cookie;
+      for(split(/; */, $request->header('Cookie'))){
+       my ($name, $value) = split(/=/);
+       $value =~ s/%([0-9A-Fa-f][0-9A-Fa-f])/pack('C', hex($1))/eg;
+        $cookie{$name} = $value;
+      }
+
+      if($cookie{username} eq $config->web_username &&
+        $cookie{passwd} eq $config->web_password){
+       $cookie_authorized = true;
+      }
+    }
+
     # authorization
-    unless(defined($config->au_subscriber_id) &&
-          ($request->header('x-up-subno') eq $config->au_subscriber_id)) {
+    unless($cookie_authorized){
+      unless(defined($config->au_subscriber_id) &&
+            $request->header('x-up-subno') eq $config->au_subscriber_id){
        if(defined($config->web_username)){
-           unless($request->headers->authorization_basic eq
-                  $config->web_username . ':' . $config->web_password){
-               my $response = HTTP::Response->new(401);
-               $response->push_header(WWW_Authenticate =>
-                                      qq(Basic Realm="keitairc"));
-               $heap->{client}->put($response);
-               $kernel->yield('shutdown');
-               return;
-           }
+         unless($request->headers->authorization_basic eq
+                $config->web_username . ':' . $config->web_password){
+           my $response = HTTP::Response->new(401);
+           $response->push_header(WWW_Authenticate =>
+                                  qq(Basic Realm="keitairc"));
+           $heap->{client}->put($response);
+           $kernel->yield('shutdown');
+           return;
+         }
        }
+      }
     }
 
     my $uri = $request->uri;
@@ -448,7 +469,6 @@ sub on_web_request{
        $content .= '<input type="text" name="m" size="10">';
        $content .= '<input type="submit" accesskey="1" value="OK[1]">';
         $content .= qq(<a accesskey="8" href="$docroot">ch list[8]</a><br>);
-       # $content .= '<input type="submit" accesskey="1" value="&#63920;">';
        $content .= '</form>';
 
        my $canon_channel = &canon_name($channel);
@@ -485,6 +505,27 @@ sub on_web_request{
     $content .= '</body></html>';
 
     my $response = HTTP::Response->new(200);
+
+    if($config->use_cookie){
+      my ($sec, $min, $hour, $mday, $mon, $year, $wday) =
+       localtime(time + cookie_ttl);
+      my $expiration =
+       sprintf('%.3s, %.2d-%.3s-%.4s %.2d:%.2d:%.2d',
+               qw(Sun Mon Tue Wed Thu Fri Sat)[$wday],
+               $mday,
+               qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)[$mon],
+               $year + 1900,
+               $hour,
+               $min,
+               $sec);
+      $response->push_header('Set-Cookie',
+                            sprintf("username=%s; expires=%s; \n",
+                                    $config->web_username, $expiration));
+      $response->push_header('Set-Cookie',
+                            sprintf("passwd=%s; expires=%s; \n",
+                                    $config->web_password, $expiration));
+    }
+
     $response->push_header('Content-type', 'text/html; charset=Shift_JIS');
     $response->content(Jcode->new($content)->sjis);
     $heap->{client}->put($response);