Changeset 776
- Timestamp:
- 10/28/07 14:46:57 (6 years ago)
- Location:
- lang/perl/mobirc/trunk/mobirc
- Files:
-
- 1 added
- 7 modified
-
Makefile.PL (modified) (1 diff)
-
config.yaml (modified) (1 diff)
-
lib/Mobirc/HTTPD.pm (modified) (3 diffs)
-
lib/Mobirc/HTTPD/Authorizer/Cookie.pm (modified) (2 diffs)
-
lib/Mobirc/HTTPD/Controller.pm (modified) (5 diffs)
-
lib/Mobirc/HTTPD/Router.pm (added)
-
lib/Mobirc/IRCClient.pm (modified) (4 diffs)
-
mobirc (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/perl/mobirc/trunk/mobirc/Makefile.PL
r770 r776 4 4 5 5 requires 'CGI'; 6 requires 'CGI::Cookie'; 6 7 requires 'Carp'; 7 8 requires 'Encode'; -
lang/perl/mobirc/trunk/mobirc/config.yaml
r775 r776 15 15 title: mobirc 16 16 lines: 40 17 cookie_expires: +3d 17 18 authorizer: 18 19 - module: Mobirc::HTTPD::Authorizer::Cookie -
lang/perl/mobirc/trunk/mobirc/lib/Mobirc/HTTPD.pm
r771 r776 23 23 use Mobirc::Util; 24 24 use Mobirc::HTTPD::Controller; 25 use Mobirc::HTTPD::Router; 25 26 26 27 our $GLOBAL_CONFIG; # TODO: should use HEAP. … … 99 100 croak 'uri missing' unless $uri; 100 101 101 my ($meth, @args) = route($c, $uri);102 my ($meth, @args) = Mobirc::HTTPD::Router->route($c, $uri); 102 103 103 104 if (blessed $meth && $meth->isa('HTTP::Response')) { … … 112 113 } 113 114 114 sub route {115 my ($c, $uri) = @_;116 croak 'uri missing' unless $uri;117 118 if ( $uri eq '/' ) {119 return 'index';120 }121 elsif ( $uri eq '/topics' ) {122 return 'topics';123 }124 elsif ( $uri eq '/recent' ) {125 return 'recent';126 }127 elsif ($uri =~ m{^/channels(-recent)?/([^?]+)(?:\?time=\d+)?$}) {128 my $recent_mode = $1 ? true : false;129 my $channel_name = $2;130 return 'show_channel', $recent_mode, uri_unescape($channel_name);131 } else {132 warn "dan the 404 not found: $uri";133 my $response = HTTP::Response->new(404);134 $response->content("Dan the 404 not found: $uri");135 return $response;136 }137 }138 139 115 1; 140 116 -
lang/perl/mobirc/trunk/mobirc/lib/Mobirc/HTTPD/Authorizer/Cookie.pm
r770 r776 4 4 use boolean ':all'; 5 5 use Carp; 6 use CGI::Cookie; 6 7 7 8 sub authorize { … … 12 13 } 13 14 14 my %cookie; 15 for ( split( /; */, $c->{req}->header('Cookie') ) ) { 16 my ( $name, $value ) = split(/=/); 17 $value =~ s/%([0-9A-Fa-f][0-9A-Fa-f])/pack('C', hex($1))/eg; 18 $cookie{$name} = $value; 19 } 15 my %cookie = CGI::Cookie->parse($c->{req}->header('Cookie')); 20 16 21 if ( $cookie{username} eq $conf->{username}22 && $cookie{passwd} eq $conf->{password} )17 if ( $cookie{username}->value eq $conf->{username} 18 && $cookie{passwd}->value eq $conf->{password} ) 23 19 { 24 20 return true; -
lang/perl/mobirc/trunk/mobirc/lib/Mobirc/HTTPD/Controller.pm
r770 r776 15 15 use Scalar::Util qw/blessed/; 16 16 use List::Util qw/first/; 17 use CGI::Cookie; 17 18 18 19 use Mobirc; … … 88 89 89 90 if ($message) { 90 $c->{poe}->kernel->post( ' keitairc_irc', privmsg => $channel => $message );91 $c->{poe}->kernel->post( 'mobirc_irc', privmsg => $channel => $message ); 91 92 92 93 add_message( … … 166 167 167 168 my $response = HTTP::Response->new(200); 168 $response->push_header( 'Content-type' , 'text/html; charset=Shift_JIS' ); # TODO: should be configurable169 $response->push_header( 'Content-type' => $c->{config}->{httpd}->{content_type} ); 169 170 $response->push_header('Content-Length' => length($content) ); 170 171 … … 180 181 my $c = shift; 181 182 my $response = shift; 182 183 my ( $sec, $min, $hour, $mday, $mon, $year, $wday ) =184 localtime( time + $c->{httpd}->{cookie_ttl} );185 183 186 184 my ( $user_info, ) = … … 190 188 croak "Can't get user_info" unless $user_info; 191 189 192 my $expiration = sprintf(193 '%.3s, %.2d-%.3s-%.4s %.2d:%.2d:%.2d',194 qw(Sun Mon Tue Wed Thu Fri Sat) [$wday],195 $mday,196 qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec) [$mon],197 $year + 1900,198 $hour,199 $min,200 $sec201 );202 190 $response->push_header( 203 'Set-Cookie' ,204 sprintf(205 "username=%s; expires=%s; \n",206 $user_info->{username}, $expiration191 'Set-Cookie' => CGI::Cookie->new( 192 -name => 'username', 193 -value => $user_info->{username}, 194 -expires => $c->{config}->{httpd}->{cookie_expires} 207 195 ) 208 196 ); 209 197 $response->push_header( 210 'Set-Cookie' ,211 sprintf(212 "passwd=%s; expires=%s; \n",213 $user_info->{password}, $expiration198 'Set-Cookie' => CGI::Cookie->new( 199 -name => 'passwd', 200 -value => $user_info->{username}, 201 -expires => $c->{config}->{httpd}->{cookie_expires} 214 202 ) 215 203 ); -
lang/perl/mobirc/trunk/mobirc/lib/Mobirc/IRCClient.pm
r755 r776 18 18 # irc component 19 19 POE::Component::IRC->spawn( 20 Alias => ' keitairc_irc',20 Alias => 'mobirc_irc', 21 21 Nick => $config->{irc}->{nick}, 22 22 Username => $config->{irc}->{username}, … … 67 67 $poe->kernel->alias_set('irc_session'); 68 68 69 my $irc = $poe->kernel->alias_resolve(' keitairc_irc');69 my $irc = $poe->kernel->alias_resolve('mobirc_irc'); 70 70 $poe->kernel->post( $irc, register => 'all' ); 71 71 $poe->kernel->post( $irc, connect => {} ); … … 208 208 my $poe = sweet_args; 209 209 210 $poe->kernel->post( keitairc_irc => connect => {} );210 $poe->kernel->post( mobirc_irc => connect => {} ); 211 211 } 212 212 … … 214 214 my $poe = sweet_args; 215 215 216 $poe->kernel->post( keitairc_irc => time ) unless $poe->heap->{seen_traffic};216 $poe->kernel->post( mobirc_irc => time ) unless $poe->heap->{seen_traffic}; 217 217 $poe->heap->{seen_traffic} = false; 218 218 $poe->kernel->delay( autoping => $poe->heap->{config}->{ping_delay} ); -
lang/perl/mobirc/trunk/mobirc/mobirc
r770 r776 10 10 use Carp; 11 11 use YAML::Syck; 12 use Getopt::Long; 12 13 13 14 use lib File::Spec->catfile( $FindBin::Bin, 'lib'); … … 20 21 $SIG{INT} = sub { die "SIGINT!\n" }; 21 22 22 DEBUG "NOW LOADING"; 23 my $daemonize_fg = false; 24 my $conffname = File::Spec->catfile($FindBin::Bin, 'config.yaml'); 25 my $version = false; 26 GetOptions( 27 'daemonize' => \$daemonize_fg, 28 'config=s' => \$conffname, 29 'version' => \$version, 30 ) or die "Usage: $0 -c config.yaml"; 31 Getopt::Long::Configure("bundling"); # allows -c -v 23 32 24 my $conffname = File::Spec->catfile($FindBin::Bin, 'config.ini'); 25 if ($ARGV[0]) { 26 $conffname = $ARGV[0];33 if ($version) { 34 print "Mobirc/$Mobirc::VERSION\n"; 35 exit; 27 36 } 37 28 38 die "file does not exist: $conffname" unless -f $conffname; 29 39 … … 38 48 $config->{httpd}->{root} ||= '/'; 39 49 $config->{global}->{assets_dir} ||= File::Spec->catfile($FindBin::Bin, 'assets'); 40 $config->{httpd}->{cookie_ttl} ||= 86400 * 3; # 3 days 50 $config->{httpd}->{cookie_expires} ||= '+3d'; 51 $config->{httpd}->{content_type} ||= 'text/html; charset=Shift_JIS'; 41 52 42 53 # daemonize 43 if ( $ config->{global}->{daemonize}) {54 if ( $daemonize_fg ) { 44 55 daemonize($config->{global}->{pid_fname}); 45 56 } … … 76 87 use YAML instead of AppConfig 77 88 dispatcher likes Sledge(HTTPD) 89 TT should in the assets dir? 90 cool uri 91 use TT at dispatch_index 92 templates should be configurable 93 use poe's heap instead of global variables ;-( 94 Makefile.PL 78 95 79 96 =head1 TODO 80 97 81 98 avoid warnings. 82 use poe's heap instead of global variables ;-(83 templates should configurable84 use TT at dispatch_index85 TT should in the assets dir?86 cool uri87 Makefile.PL88 99 89 100 =head1 supported phones
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)