Tadashi Okoshi
slash****@users*****
2006年 3月 7日 (火) 23:39:10 JST
Index: affelio/lib/Affelio/App/Standalone/Public/Bin/get_content.pm
diff -u /dev/null affelio/lib/Affelio/App/Standalone/Public/Bin/get_content.pm:1.1
--- /dev/null Tue Mar 7 23:39:10 2006
+++ affelio/lib/Affelio/App/Standalone/Public/Bin/get_content.pm Tue Mar 7 23:39:10 2006
@@ -0,0 +1,291 @@
+# Copyright (C) 2005 FishGrove Inc.
+#
+# 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.
+#
+# $Id: get_content.pm,v 1.1 2006/03/07 14:39:10 slash5234 Exp $
+
+package Affelio::App::Standalone::Public::Bin::get_content;
+{
+ use strict;
+
+ use lib("../../../../../../extlib/");
+ use lib("../../../../../../lib/");
+ use Affelio::misc::CGIError;
+ use Affelio::misc::Debug qw(debug_print);
+
+ use Exporter;
+ @Affelio::App::Standalone::Public::Bin::get_content::ISA = "Exporter";
+ @Affelio::App::Standalone::Public::Bin::get_content::EXPORT = qw (run);
+
+ #######################################################################
+ #run
+ #######################################################################
+ sub run{
+ $| = 1;
+
+use CGI qw(-unique_headers);
+use CGI::Session; #qw(-ip_match);
+use Error qw(:try);
+
+use Affelio;
+use Affelio::App::Standalone::Env;
+use Affelio::App::Standalone::FriendRoutines qw(get_summed_permission_list);
+use Affelio::misc::MyCrypt qw(url_decode msg_decrypt);
+use Affelio::misc::Time qw(get_timestamp);
+use Affelio::misc::NetMisc qw(get_remote_host);
+use Affelio::misc::WebInput;
+
+#Load Affelio and CGI
+my $q = new CGI;
+my $cfg_dir = "../config/";
+my $af = new Affelio(ConfigDir => $cfg_dir,
+ CGI => $q);
+my $wi = new Affelio::misc::WebInput();
+
+#Retrieve args
+my $module = $wi->PTN_word($q->param("module"));
+if($module eq "" || !defined($module)){
+ error($q,"Input parameters are not defined.(module)");
+}
+
+my $content = $wi->PTN_getcontent_content($q->param("content"));
+if($content eq "" || !defined($content)){
+ error($q,"Input parameters are not defined.(content)");
+}
+
+my $ck_visitor_type=0;
+my $ck_visitor_type_str="pb";
+my $ck_visitor_afid = "";
+
+############################################################################
+#Load session from cookie
+############################################################################
+my $session = $af->getSM()->get_session();
+
+if(!$session){
+ debug_print("StandAlone::get_content: session not found.");
+ $ck_visitor_type=0;
+ $ck_visitor_type_str="pb";
+ $ck_visitor_afid = "";
+}else{
+ my $type = $session->param("type");
+
+ if($type eq "self"){
+ debug_print("StandAlone::get_content: session found. [self]");
+ $ck_visitor_type=3;
+ $ck_visitor_type_str="self";
+ $ck_visitor_afid = $session->param("user_afid");
+ }elsif($type eq "f1"){
+ debug_print("StandAlone::get_content: session found. [f1]");
+ $ck_visitor_type=2;
+ $ck_visitor_type_str="f1";
+ $ck_visitor_afid = $session->param("user_afid");
+ }elsif($type eq "f2"){
+ debug_print("StandAlone::get_content: session found. [f2]");
+ $ck_visitor_type=1;
+ $ck_visitor_type_str="f2";
+ $ck_visitor_afid = $session->param("user_afid");
+ }
+}
+
+
+#CFID check
+my $CFID_timestamp;
+my $CFID_expire;
+my $CFID_remotehost;
+my $CFID_visitor_afid;
+my $CFID_visitor_type=0;
+my $CFID_visitor_type_str="pb";
+
+if( ($ck_visitor_type <= 2)
+ && ( $q->param("referrer") ne "")
+ && ( $q->param("cfid") ne "" )
+ ){
+
+ my $referrer = $wi->PTN_URL($q->param("referrer"));
+ if($referrer =~ /(.*)\/$/){
+ $referrer = $1;
+ }
+
+ my $passAB = $af->getFM->get_attribute_by_afid($referrer, "password");
+ if($passAB eq "" || !defined($passAB)){
+ error($q,"Parameters are not defined. (1): Your peer does not have shared password with you...");
+ }
+
+ my $cfid = msg_decrypt( url_decode($q->param("cfid") ) , $passAB) ;
+ if($cfid eq "" || !defined($cfid)){
+ error($q,"Parameters are not defined. (2): Invalid encryption: After decryption, we could not valid your encrypted message...");
+ }
+
+ #######################################################################
+ #Check cfid
+ ($CFID_timestamp, $CFID_expire, $CFID_remotehost, $CFID_visitor_afid, $CFID_visitor_type_str) = split('\*', $cfid);
+
+ #check timestamp
+ #check expire
+ #check remotehost
+ #check visitor_afid
+ debug_print("StandAlone::get_content: Information extracted from CFID");
+ debug_print("StandAlone::get_content: \ttimestamp =$CFID_timestamp\n");
+ debug_print("StandAlone::get_content: \texpire =$CFID_expire\n");
+ debug_print("StandAlone::get_content: \tremote_host =$CFID_remotehost\n");
+ debug_print("StandAlone::get_content: \tvisitor_afid =$CFID_visitor_afid\n");
+ debug_print("StandAlone::get_content: \tvisitor_type(original) =$CFID_visitor_type_str\n");
+
+ #check visitor_type_str
+ if($CFID_visitor_type_str eq "self") {
+ $CFID_visitor_type_str = "f1";
+ $CFID_visitor_type =2;
+ }elsif($CFID_visitor_type_str eq "f1") {
+ $CFID_visitor_type_str = "f2";
+ $CFID_visitor_type =1;
+ }else{
+ $CFID_visitor_type_str = "pb";
+ $CFID_visitor_type =0;
+ }
+ debug_print("StandAlone::get_content: \tvisitor_type(decreased) =$CFID_visitor_type_str\n");
+
+}
+
+
+############################################################################
+#Well, after all, who is it?
+############################################################################
+my $visitor_type=0; #3=self 2=f1 1=f2 0=pb
+my $visitor_type_str="pb";
+my $visitor_afid="";
+
+if($ck_visitor_type == 3){
+
+ $visitor_type = $ck_visitor_type;
+ $visitor_type_str = $ck_visitor_type_str;
+ $visitor_afid = $ck_visitor_afid;
+
+}elsif($ck_visitor_type > $CFID_visitor_type){
+
+ $visitor_type = $ck_visitor_type;
+ $visitor_type_str = $ck_visitor_type_str;
+ $visitor_afid = $ck_visitor_afid;
+
+}else{
+
+ $visitor_type = $CFID_visitor_type;
+ $visitor_type_str = $CFID_visitor_type_str;
+ $visitor_afid = $CFID_visitor_afid;
+}
+
+#######################################
+#Is this visitor a friend of this site?
+
+if($visitor_type < 3){
+ my $tmp1 = $af->getFM->get_attribute_by_afid($visitor_afid, "password");
+
+ if($tmp1 ne ""){
+ $visitor_type = 2;
+ $visitor_type_str="f1";
+ $visitor_afid = $CFID_visitor_afid;
+ }
+}
+
+debug_print("StandAlone::get_content: Finally...");
+debug_print("StandAlone::get_content: \tvisitor_type = [$visitor_type] [$visitor_type_str]");
+debug_print("StandAlone::get_content: \tvisitor_type = [$visitor_afid]");
+debug_print("StandAlone::get_content: \tmodule = [$module]\n");
+debug_print("StandAlone::get_content: \tcontent = [$content]\n");
+
+
+############################################################################
+#Output content
+############################################################################
+if($module eq "core"){
+
+ if($content =~ /^\/profile\/profile\_face([0-9a-zA-Z\_]*)\.jpg$/){
+
+ debug_print("StandAlone::get_content: image!");
+
+ #Get summarized permission list for the given user
+ my @list
+ = get_summed_permission_list($af,
+ $visitor_afid,
+ $visitor_type_str);
+
+ debug_print("StandAlone::get_content: Got summarized permission...");
+ debug_print("StandAlone::get_content: \t[@list]");
+
+ my $permission = $list[5] ;
+ debug_print("StandAlone::get_content: Pic perm: $permission");
+
+ my $real_filename = $content;
+ $real_filename =~ s|/profile/||;
+
+ my $actual_file="";
+ if( $permission ==1)
+ {
+ $actual_file = "$af->{site__user_dir}/$real_filename";
+ }else{
+ $actual_file = "$af->{site__fs_root}/skins/$af->{userpref__skin}/0_face.jpg";
+ }
+ open(IMG, "< $actual_file");
+ print "Content-type: image/jpeg\n";
+ print "Pragma: no-cache\n\n";
+ binmode (IMG);
+ binmode (STDOUT);
+ print <IMG>;
+ close IMG;
+ }
+
+ if($content eq "/profile/mystatus"){
+
+ debug_print("StandAlone::get_content: mystatus!");
+ my $mystatus=" ";
+ if( $visitor_type >= 2){
+ $mystatus = $af->{user__currentstatus};
+ }
+ print "Content-type:application/x-javascript\n\n";
+ print "document.write(\"$mystatus\");";
+ print "\n\n";
+ exit(1);
+ }
+
+ if($content eq "/profile/mystatus_iframe"){
+
+ debug_print("StandAlone::get_content: mystatus!");
+ my $mystatus=" ";
+ if( $visitor_type >= 2){
+ $mystatus = $af->{user__currentstatus};
+ }
+ print "Content-type: text/html; charset=UTF-8\n";
+ print "Pragma: no-cache\n\n";
+
+ # " ni kiwo tsukero!!!! escape! escape! " --> \"
+ print "<HTML><body TOPMARGIN=0 LEFTMARGIN=0 MARGINHEIGHT=0 MARGINWIDTH=0><div style=\"margin:0px; padding:0px; font-family:sans-serif; font-size:xx-small;\">$mystatus</div></body></HTML>";
+ debug_print("StandAlone::get_content: mystatus!");
+ exit(1);
+ }
+
+ print "Content-type: text/html; charset=UTF-8\n";
+ print "Pragma: no-cache\n\n";
+ print "<HTML></HTML>";
+ exit(1);
+
+}
+exit(1);
+
+
+
+ }#method
+ #######################################################################
+}
+1;
Index: affelio/lib/Affelio/App/Standalone/Public/Bin/loginexec.pm
diff -u /dev/null affelio/lib/Affelio/App/Standalone/Public/Bin/loginexec.pm:1.1
--- /dev/null Tue Mar 7 23:39:10 2006
+++ affelio/lib/Affelio/App/Standalone/Public/Bin/loginexec.pm Tue Mar 7 23:39:10 2006
@@ -0,0 +1,374 @@
+# Copyright (C) 2005 FishGrove Inc.
+#
+# 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.
+#
+# $Id: loginexec.pm,v 1.1 2006/03/07 14:39:10 slash5234 Exp $
+
+package Affelio::App::Standalone::Public::Bin::loginexec;
+{
+ use strict;
+
+ use lib("../../../../../../extlib/");
+ use lib("../../../../../../lib/");
+ use Affelio::misc::CGIError;
+ use Affelio::misc::Debug qw(debug_print);
+
+ use Exporter;
+ @Affelio::App::Standalone::Public::Bin::loginexec::ISA = "Exporter";
+ @Affelio::App::Standalone::Public::Bin::loginexec::EXPORT = qw (run);
+
+ #######################################################################
+ #run
+ #######################################################################
+ sub run{
+
+use CGI qw(-unique_headers);
+use CGI::Session;
+use HTML::Template;
+use Error qw(:try);
+use Affelio;
+use Affelio::App::Standalone::Env;
+use Affelio::misc::Time;
+use Affelio::misc::NetMisc;
+use Affelio::misc::MyCrypt;
+use Affelio::misc::WebInput;
+use Affelio::SNS::Handshaker_c;
+
+my $q = new CGI;
+
+debug_print("StandAlone::loginexec.cgi: **start.");
+
+############################################################################
+#Load Affelio
+############################################################################
+my $cfg_dir = "../config/";
+my $af;
+try{
+ $af = new Affelio(ConfigDir => $cfg_dir,
+ CGI => $q);
+}catch Error with{
+ my $e = shift;
+ error($q, "Affelio load error.\n" . $e);
+};
+my $wi = new Affelio::misc::WebInput;
+debug_print("StandAlone::loginexec.cgi: loaded Affelio.");
+
+############################################################################
+#Prep (1) input args
+############################################################################
+#mode
+my $mode = $wi->PTN_mode($q->url_param("mode"));
+
+#username or affelio_url
+my $affelio_url = $wi->PTN_through($q->param("affelio_url"));
+my $username = $wi->PTN_word($q->param("username"));
+
+#password
+my $password = $wi->PTN_through($q->param("password"));
+
+#forward_URL
+# After authentication, browser must be forwarded to $forward_URL
+# Usually, $forward_URL is the user's AFLink person's page.
+my $forward_URL = $wi->PTN_URL($q->url_param("forward_URL"));
+#aftergo_URL
+# After browser is forwarded to $forward_URL (after auth.),
+# $aftergo_URL is one more further URL that the browser needs
+# to be fowarded to.
+my $aftergo_URL = $wi->PTN_URL($q->url_param("aftergo_URL"));
+
+#type from FORM
+my $submit_type = $wi->PTN_mode($q->param("submittype"));
+debug_print("StandAlone::loginexec.cgi: checked input args.");
+
+############################################################################
+#Prep (2) misc
+############################################################################
+#farm_users_root
+# This Affelio's 1-step parent URL.
+# e.g. this Affelio : http://my.affelio.jp/user/foo
+# e.g. farm_users_root : http://my.affelio.jp/user/
+my $farm_users_root = $af->{site__user_afid};
+$farm_users_root =~ s|/$||;
+$farm_users_root =~ s|/([A-Za-z0-9\-\_]+)$|/|;
+
+#output data
+my $issued_cookie="";
+my $next_url;
+
+debug_print("StandAlone::\t\tmode = $mode");
+debug_print("StandAlone::\t\taffelio_url= $affelio_url");
+debug_print("StandAlone::\t\tusername = $username");
+debug_print("StandAlone::\t\tpassword = $password");
+debug_print("StandAlone::\t\tforward = $forward_URL");
+debug_print("StandAlone::\t\taftergo = $aftergo_URL");
+debug_print("StandAlone::\t\tfarm_users_root = $farm_users_root");
+
+############################################################################
+#Already logined?
+############################################################################
+if($af->getSM->get_userclass() eq "self"){
+ #Yes, the user is already logged in as the owner.
+
+}else{
+ #No, this user has to be authenticated.
+
+ if($mode eq ""){
+ ###################################################################
+ #Protocol V1
+ ###################################################################
+ if( (verify_password($password, $af->{site__password}) > 0)
+ && ($username eq $af->{site__username}) ){
+ debug_print("StandAlone::loginexec.cgi: AUTH OK.\n");
+ #login OK
+ }else{
+ #login failed.
+ debug_print("StandAlone::loginexec.cgi: AUTH NG.\n");
+
+ my $TMPL_FILE = "$af->{site__tmpl_dir}/owner_side/loginfailed.tmpl";
+ my $tmpl = new HTML::Template( filename => $TMPL_FILE);
+ $tmpl->param("forward_URL" => $af->{site__user_afid});
+ $tmpl->param("tmpl_path" => "$af->{site__tmpl_web_path}");
+ print "Content-type: text/html; charset=UTF-8\n\n";
+ print $af->translate_templateL10N($tmpl->output);
+
+ debug_print("StandAlone::loginexec.cgi: exit(1).\n");
+ exit(1);
+ }
+
+ }elsif($mode eq "s0"){
+ ####################################################################
+ #Phase V2: Phase S0
+ ####################################################################
+ if($affelio_url eq $af->{site__username}){
+ ##################################
+ #input URL = site owner's nickname
+ ##################################
+ show_checkpassword_screen(af => $af,
+ forward_URL => $forward_URL,
+ aftergo_URL => $aftergo_URL,
+ mode => "login_as_owner");
+ exit(1);
+
+ }else{
+ ##################################
+ #Else
+ ##################################
+ $affelio_url =~ /^([A-Za-z0-9\-\_]*)$/;
+ if ($1 eq $affelio_url){
+ $affelio_url = $farm_users_root . $affelio_url;
+ }
+
+ if($affelio_url !~ /^(http:\/\/)/){
+ $affelio_url = "http://" . $affelio_url;
+ }
+ if($affelio_url =~ /(.*)\/$/){
+ $affelio_url = $1;
+ }
+ debug_print("StandAlone::loginexec.cgi($mode): formated Affelio URL= [$affelio_url]");
+
+ if($affelio_url eq $af->{site__user_afid}){
+
+ show_checkpassword_screen(af => $af,
+ forward_URL => $forward_URL,
+ aftergo_URL => $aftergo_URL,
+ mode => "login_as_owner");
+
+ exit(1);
+ }
+
+ ##################################
+ #Determine aftergo_URL
+ ##################################
+ #aftergo_URL is a URL to which the user will be forwarded after auth.
+ if($aftergo_URL eq ""){
+ $aftergo_URL= $ENV{HTTP_REFERER};
+ }
+
+ ##################################
+ #Determine forward_URL
+ ##################################
+ if($forward_URL eq ""){
+ $forward_URL= $af->{site__user_afid};
+ }
+
+ ##################################
+ #Go to "s1" phase...
+ ##################################
+ my $next_URL
+ = "$affelio_url/bin/loginexec.cgi?mode=s1&forward_URL=$forward_URL&aftergo_URL=$aftergo_URL";
+ debug_print("StandAlone::\t\tnext_URL= $next_URL");
+ debug_print("StandAlone::loginexec.cgi($mode): end.");
+ print $q->redirect( -url => $next_URL);
+ exit(1);
+ }
+
+ }elsif($mode eq "s1"){
+ ####################################################################
+ #Phase V2: Phase S1
+ # (password input phase)
+ ####################################################################
+ show_checkpassword_screen(af => $af,
+ forward_URL => $forward_URL,
+ aftergo_URL => $aftergo_URL,
+ mode => "back_from_friend");
+ debug_print("StandAlone::loginexec.cgi($mode): end.");
+ exit(1);
+
+ }elsif($mode eq "s2"){
+ ####################################################################
+ #Phase V2: Phase S2
+ # (auth check phase)
+ ####################################################################
+ debug_print("StandAlone::loginexec.cgi($mode): submit_type= $submit_type");
+ if($submit_type eq "Cancel"){
+ if($aftergo_URL eq ""){
+ print $q->redirect( -url => $af->{site__user_afid});
+ exit;
+ }else{
+ print $q->redirect( -url => $aftergo_URL);
+ exit;
+ }
+
+ }
+
+ if( (verify_password($password, $af->{site__password}) > 0) ){
+ debug_print("StandAlone::loginexec.cgi: AUTH Ok.\n");
+ }else{
+ #login failed.
+ debug_print("StandAlone::loginexec.cgi: AUTH NG.\n");
+
+ my $loginfailed=
+ $af->translate_templateL10N('<AF_M text="Login failed.">');
+
+ if($affelio_url eq $af->{site__username}){
+ sleep(3);
+ show_checkpassword_screen(af => $af,
+ forward_URL => $forward_URL,
+ aftergo_URL => $aftergo_URL,
+ mode => "login_as_owner",
+ error => $loginfailed);
+ }else{
+ sleep(3);
+ show_checkpassword_screen(af => $af,
+ forward_URL => $forward_URL,
+ aftergo_URL => $aftergo_URL,
+ mode => "back_from_friend",
+ error => $loginfailed);
+ }
+
+ debug_print("StandAlone::loginexec.cgi: exit(1).\n");
+ exit(1);
+ }
+ }
+
+ #######################################################################
+ #Startup new session
+ #######################################################################
+ $af->getSM->startup_session(user_afid => $af->{site__user_afid},
+ user_nickname => $af->{user__nickname},
+ type => "self");
+ $af->getSM->get_session->expire("+3d");
+ $af->getSM->get_session->flush();
+
+ debug_print("StandAlone::loginexec.cgi: startup_session finished.\n");
+
+ #Prepare a cookie with the session_id
+ $issued_cookie = $af->getSM->issue_cookie();
+}
+
+############################################################################
+#Check if forward_URL is my friend
+############################################################################
+if($forward_URL ne ""){
+ if($forward_URL =~ /(.*)\/$/){
+ $forward_URL = $1;
+ }
+ debug_print("StandAlone::loginexec.cgi: ForwardURL= $forward_URL");
+
+ my $passAB="";
+ try{
+ $passAB = $af->getFM->get_attribute_by_afid($forward_URL, "password");
+ }catch Error with{
+ my $e = shift;
+ error($q, "Error from FriendManager.\n" . $e);
+ };
+
+ if($passAB eq ""){
+ show_askmakefriend_screen($af, $forward_URL);
+ exit;
+ }else{
+ $next_url= "$af->{site__user_afid}/outgoing.cgi?dest_url=$forward_URL&dest_url2=$aftergo_URL";
+ }
+}else{
+ $next_url= "$af->{site__user_afid}/admin.cgi";
+}
+
+if($issued_cookie){
+ print $q->redirect( -url => $next_url, -cookie => $issued_cookie);
+}else{
+ print $q->redirect( -url => $next_url);
+}
+
+exit(1);
+
+ }#method
+ #######################################################################
+
+############################################################################
+# sub show_askmakefriend_screen
+############################################################################
+sub show_askmakefriend_screen{
+ my $af =shift;
+ my $forward_URL =shift;
+
+ my $TMPL_FILE = "$af->{site__tmpl_dir}/owner_side/ask_makefriend.tmpl";
+ my $tmpl = new HTML::Template( filename => $TMPL_FILE,
+ die_on_bad_params => 0);
+ $tmpl->param("owner_nickname" => $af->{user__nickname});
+ $tmpl->param("tmpl_path" => "$af->{site__tmpl_web_path}");
+ $tmpl->param("admin_path" => "$af->{site__user_afid}/admin.cgi?mode=makefriend&dest_url=$forward_URL");
+ $tmpl->param("dest_affelio_URL" => $forward_URL);
+
+ print "Content-type: text/html; charset=UTF-8\n\n";
+ print $af->translate_templateL10N($tmpl->output);
+}
+
+############################################################################
+# sub show_checkpassword_screen
+############################################################################
+sub show_checkpassword_screen{
+ my %args = @_;
+
+ my $af = $args{af};
+ my $forward_URL = $args{forward_URL};
+ my $aftergo_URL = $args{aftergo_URL};
+
+ my $TMPL_FILE = "$af->{site__tmpl_dir}/owner_side/login_s1.tmpl";
+ my $tmpl = new HTML::Template( filename => $TMPL_FILE,
+ die_on_bad_params => 0);
+ $tmpl->param("owner_nickname" => $af->{user__nickname});
+ $tmpl->param("tmpl_path" => "$af->{site__tmpl_web_path}");
+ $tmpl->param("cgi_path" => "$af->{site__user_afid}/bin/loginexec.cgi?mode=s2&forward_URL=$forward_URL&aftergo_URL=$aftergo_URL");
+ $tmpl->param($args{mode} => "true");
+ $tmpl->param(error => $args{error});
+
+ print "Content-type: text/html; charset=UTF-8\n\n";
+ print $af->translate_templateL10N($tmpl->output);
+}
+############################################################################
+
+
+}
+1;
Index: affelio/lib/Affelio/App/Standalone/Public/Bin/logoutexec.pm
diff -u /dev/null affelio/lib/Affelio/App/Standalone/Public/Bin/logoutexec.pm:1.1
--- /dev/null Tue Mar 7 23:39:10 2006
+++ affelio/lib/Affelio/App/Standalone/Public/Bin/logoutexec.pm Tue Mar 7 23:39:10 2006
@@ -0,0 +1,90 @@
+# Copyright (C) 2005 FishGrove Inc.
+#
+# 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.
+#
+# $Id: logoutexec.pm,v 1.1 2006/03/07 14:39:10 slash5234 Exp $
+
+package Affelio::App::Standalone::Public::Bin::logoutexec;
+{
+ use strict;
+
+ use lib("../../../../../../extlib/");
+ use lib("../../../../../../lib/");
+ use Affelio::misc::CGIError;
+ use Affelio::misc::Debug qw(debug_print);
+
+ use Exporter;
+ @Affelio::App::Standalone::Public::Bin::logoutexec::ISA = "Exporter";
+ @Affelio::App::Standalone::Public::Bin::logoutexec::EXPORT = qw (run);
+
+ #######################################################################
+ #run
+ #######################################################################
+ sub run{
+use CGI qw(-unique_headers);
+use CGI::Session; #qw(-ip_match);
+use HTML::Template;
+use Error qw(:try);
+use Affelio;
+use Affelio::App::Standalone::Env;
+use Affelio::SNS::Handshaker_c;
+use Affelio::misc::NetMisc;
+use Affelio::misc::MyCrypt;
+use Affelio::misc::Time;
+
+debug_print("StandAlone::logoutexec.cgi: start.");
+
+my $q = new CGI;
+############################################################################
+#Load Affelio
+############################################################################
+my $cfg_dir = "../config/";
+my $af;
+try{
+ $af = new Affelio(ConfigDir => $cfg_dir,
+ CGI => $q);
+}catch Error with{
+ my $e = shift;
+ error($q, "Affelio load error.\n" . $e);
+};
+my $wi = new Affelio::misc::WebInput;
+
+############################################################################
+#Check session w/ cookie
+############################################################################
+my $sid = $q->cookie("affelio-$af->{user__nickname}");
+my $session = $af->getSM->get_session();
+
+if($session){
+ #Output expired cookie and redirect the user to index.
+ $session->delete();
+ $session->flush();
+ undef($session);
+
+ #Output expired cookie and redirect the user to index.
+}
+
+print $q->redirect( -url => $af->{site__user_afid});
+
+debug_print("StandAlone::logoutexec.cgi: end.");
+exit(1);
+
+
+
+
+ }#method
+ #######################################################################
+}
+1;
Index: affelio/lib/Affelio/App/Standalone/Public/Bin/recv_mail_ack.pm
diff -u /dev/null affelio/lib/Affelio/App/Standalone/Public/Bin/recv_mail_ack.pm:1.1
--- /dev/null Tue Mar 7 23:39:10 2006
+++ affelio/lib/Affelio/App/Standalone/Public/Bin/recv_mail_ack.pm Tue Mar 7 23:39:10 2006
@@ -0,0 +1,223 @@
+# Copyright (C) 2005 FishGrove Inc.
+#
+# 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.
+#
+# $Id: recv_mail_ack.pm,v 1.1 2006/03/07 14:39:10 slash5234 Exp $
+
+package Affelio::App::Standalone::Public::Bin::recv_mail_ack;
+{
+ use strict;
+
+ use lib("../../../../../../extlib/");
+ use lib("../../../../../../lib/");
+ use Affelio::misc::CGIError;
+ use Affelio::misc::Debug qw(debug_print);
+
+ use Exporter;
+ @Affelio::App::Standalone::Public::Bin::recv_mail_ack::ISA = "Exporter";
+ @Affelio::App::Standalone::Public::Bin::recv_mail_ack::EXPORT = qw (run);
+
+ #######################################################################
+ #run
+ #######################################################################
+ sub run{
+
+use CGI qw(-unique_headers);
+$CGI::DISABLE_UPLOADS = 1;
+$CGI::POST_MAX = 102_400;
+use CGI::Session; #qw(-ip_match);
+use HTML::Template;
+use File::Copy;
+use Crypt::DH;
+use Error qw(:try);
+
+use Affelio;
+use Affelio::misc::MyCrypt;
+use Affelio::SNS::Handshaker_c;
+use Affelio::SNS::Handshaker_tmpDB;
+use Affelio::exception::Exception;
+use Affelio::exception::IOException;
+use Affelio::misc::WebInput;
+
+my $q = new CGI;
+
+############################################################################
+#Load Affelio
+my $cfg_dir = "../config/";
+my $af;
+try{
+ $af = new Affelio(ConfigDir => $cfg_dir);
+}catch Error with{
+ my $e = shift;
+ error($q, "Affelio load error.\n" . $e);
+};
+my $wi = new Affelio::misc::WebInput;
+
+############################################################################
+#Sesion check (as admin)
+my $sid = $q->cookie("affelio-$af->{user__nickname}");
+my $session = new CGI::Session(undef,
+ $sid,
+ {Directory=> $af->{site__session_dir}});
+
+my $TMPL_FILE="";
+if( (!$session) || ($session->param("type") ne "self") ){
+ # Is the session alive?
+ # Is the user the admin of this site?
+ # if not....
+ debug_print("StandAlone::recv_mail_ack.cgi: login is needed.");
+
+ $TMPL_FILE
+ = "$af->{site__tmpl_dir}/owner_side/login.tmpl";
+ my $tmpl = new HTML::Template( filename => $TMPL_FILE,
+ die_on_bad_params => 0);
+ $tmpl->param(reason_msg => "You haven't been authenticated.");
+ $tmpl->param("tmpl_path" => "$af->{site__tmpl_web_path}/owner_side/");
+ print "Content-type: text/html; charset=UTF-8\n\n";
+ print $af->translate_templateL10N($tmpl->output);
+ exit(1);
+}
+debug_print("StandAlone::recv_mail_ack.cgi: Session as the admin is OK.");
+
+
+############################################################################
+#Read CGI input
+my $session_id="";
+$session_id = $wi->PTN_word($q->param("id"));
+if(!$session_id){
+ die "id is not defined. [$session_id]";
+}
+debug_print("StandAlone::recv_mail_ack: $session_id\n");
+
+
+############################################################################
+#Read temporarily-saved session
+my $dummy;
+my $timestamp;
+my $peer_af_id;
+my $peer_name;
+my $peer_nickname;
+my $peer_DH_pub_key_str;
+my $peer_DH_pub_key;
+
+############################################################################
+#remove a record from tmpDB
+my $tmpdb= new Affelio::SNS::Handshaker_tmpDB($af);
+my @ret= $tmpdb->remove_received_Handshake($session_id);
+
+if(!defined(@ret)){
+ #No such session exists!!
+ debug_print("StandAlone::recv_mail_ack: session not found.\n");
+ error($q, "Affelio load error.\nNo such session exists!");
+}else{
+ ($dummy, $timestamp, $peer_af_id,
+ $peer_nickname, $peer_DH_pub_key_str) = @ret;
+
+ $peer_DH_pub_key = Math::BigInt->new($peer_DH_pub_key_str);
+}
+debug_print("StandAlone::recv_mail_ack: $session_id, $timestamp, $peer_af_id, $peer_nickname, $peer_DH_pub_key_str\n");
+
+############################################################################
+#DH key generation
+my $mydh = Crypt::DH->new;
+#RFC 2412 - The OAKLEY Key Determination Protocol
+#Group 1: A 768 bit prime
+my $DH_g="2";
+my $DH_p="1552518092300708935130918131258481755631334049434514313202351194902966239949102107258669453876591642442910007680288864229150803718918046342632727613031282983744380820890196288509170691316593175367469551763119843371637221007210577919";
+$mydh->g($DH_g);
+$mydh->p($DH_p);
+#
+#Step (1): create my public_key
+$mydh->generate_keys;
+my $my_DH_pub_key = $mydh->pub_key;
+my $my_DH_pub_key_str = $mydh->pub_key->bstr;
+
+
+############################################################################
+#send FriendshipReply
+my $ret="";
+try{
+ $ret = reply_HandShake(dest_uri => "$peer_af_id",
+ timestamp => $timestamp,
+ my_nickname => $af->{user__nickname},
+ my_domain => $af->{user__domain},
+ my_AFID => $af->{site__user_afid},
+ DH_pub_key_str => $my_DH_pub_key_str
+ );
+}catch Error with {
+ my $E = shift;
+ error($q, "HandShake reply output an error!\n$E");
+};
+
+debug_print("StandAlone::recv_mail_ack: reply_HandShake finished.");
+
+############################################################################
+#generate Password
+my $pass = $mydh->compute_key($peer_DH_pub_key)->bstr;
+debug_print("StandAlone::recv_mail_ack: PASSWORD=[$pass]\n");
+
+############################################################################
+#Add peer to my friends list.
+try{
+ $af->getFM->add_friend($peer_af_id,
+ $peer_nickname,
+ $timestamp,
+ $pass);
+}catch Error with{
+ my $E = shift;
+ error($q, "Error from FriendManager\n$E\n");
+};
+debug_print("StandAlone::recv_mail_ack: added to my friends list.");
+sleep(2);
+
+############################################################################
+#Get peer's friends list.
+try{
+ $ret = get_F2List(dest_uri => "$peer_af_id",
+ timestamp => 0);
+}catch Error with {
+ my $E = shift;
+ error($q, "HandShake was successful!\n But, get_F2List reply output an error!\n$E");
+};
+debug_print("StandAlone::recv_mail_ack: get_F2List finished.");
+debug_print("StandAlone::recv_mail_ack: List I've got is [$ret]");
+#
+#
+##################################################
+#Save the F2 list into my DB
+#$af->{fm}->save_F2List($ret, $peer_af_id);
+
+my $urlencoded_title = url_encode($af->translate_templateL10N('<AF_M text="_HandshakeReply_SentBack_message_title">'));
+
+############################################################################
+#print output HTML
+my $TMPL_FILE = "$af->{site__tmpl_dir}/owner_side/mail_ack_recved.tmpl";
+my $tmpl = new HTML::Template( filename => $TMPL_FILE);
+$tmpl->param(peer_af_id => $af->{site__user_afid} . "/outgoing.cgi?dest=".$peer_af_id);
+$tmpl->param(peer_nickname => $peer_nickname);
+
+$tmpl->param(next_url => $af->{site__user_afid} . "/admin.cgi?mode=messages&action=compose&to_url=" . $peer_af_id . "&title=" . $urlencoded_title);
+
+$tmpl->param("tmpl_path" => "$af->{site__tmpl_web_path}");
+
+print "Content-type: text/html; charset=UTF-8\n\n";
+print $af->translate_templateL10N($tmpl->output);
+
+
+
+ }#method
+
+}
+1;
Index: affelio/lib/Affelio/App/Standalone/Public/Bin/xml_rpc_serv.pm
diff -u /dev/null affelio/lib/Affelio/App/Standalone/Public/Bin/xml_rpc_serv.pm:1.1
--- /dev/null Tue Mar 7 23:39:10 2006
+++ affelio/lib/Affelio/App/Standalone/Public/Bin/xml_rpc_serv.pm Tue Mar 7 23:39:10 2006
@@ -0,0 +1,55 @@
+# Copyright (C) 2005 FishGrove Inc.
+#
+# 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.
+#
+# $Id: xml_rpc_serv.pm,v 1.1 2006/03/07 14:39:10 slash5234 Exp $
+
+package Affelio::App::Standalone::Public::Bin::xml_rpc_serv;
+{
+ use strict;
+
+ use lib("../../../../../../extlib/");
+ use lib("../../../../../../lib/");
+ use Cwd;
+ use Affelio::misc::CGIError;
+ use Affelio::misc::Debug qw(debug_print);
+
+ use Exporter;
+ @Affelio::App::Standalone::Public::Bin::xml_rpc_serv::ISA = "Exporter";
+ @Affelio::App::Standalone::Public::Bin::xml_rpc_serv::EXPORT = qw (run);
+
+ #######################################################################
+ #run
+ #######################################################################
+ sub run{
+ }
+
+ BEGIN{
+ use Affelio::App::Standalone::Env;
+ use XMLRPC::Transport::HTTP;
+ use Affelio::SNS::Handshaker_s;
+
+ $Affelio::SNS::Handshaker_s::Util::AF_DIR = cwd() . "/../";
+
+ local $SIG{__WARN__} = sub { };
+ my $server = XMLRPC::Transport::HTTP::CGI->new;
+ $server->dispatch_to('affelio');
+ $server->handle;
+ }
+}
+
+
+
+1;