⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 html.pm

📁 Punjab is a jabber XMLRPC/SOAP/REST client. It is a xmlrpc, soap, or REST server that allows for p
💻 PM
📖 第 1 页 / 共 2 页
字号:
package PunJab::HTML;use strict;use warnings;use POE;use POE::Filter::XML;use POE::Filter::XML::Node;use POE::Filter::XML::NS qw/ :JABBER :IQ /;use POE::Filter::XML::Utils;use PunJab::Util;use PunJab::Session;use PunJab::Server::HTML;use POSIX qw(strftime);use Digest::SHA1;use Digest::MD5 qw(md5 md5_hex md5_base64);use Data::Uniqid qw ( suniqid uniqid luniqid );use CGI;my %help;sub new {    shift;    my $config = shift;    $config->{'type'} = "html_shell";          PunJab::Server::HTML->new($config,'html_server');        POE::Session->create	( inline_states =>	  { _start => sub {	      my $kernel = $_[KERNEL];	      if ($config->{debug}>0) {		  &debug("HTML Interface Session Started\n");	      }	     	      $kernel->alias_set("html_shell");	      # need a file handler	      $kernel->yield('get_help');	  },	    session_register => sub {                my $sid = $_[ARG0];		                $punjab_session->register($sid);                $punjab_session->logged_in($sid,1);                $punjab_session->activity($sid,time());                if ($_[HEAP]->{'CONFIG'}->{debug} > 1) {                    &debug("HTML Session $sid registered");                }            },            session_unregister => sub {                my $sid = $_[ARG0];                $punjab_session->unregister($sid);                if ($_[HEAP]->{'CONFIG'}->{debug} > 1) {                    &debug("HTML Session $sid unregistered");                }            },	                # -------------------------- #            # html calls            # -------------------------- #	    login     => \&login,	    logout    => \&logout,	    help      => \&help,	    presence  => \&presence,	    message   => \&message,	    iqs       => \&iqs,            roster    => \&roster,            vcard     => \&vcard,	    register  => \&register,	    browse    => \&browse,	    disco     => \&disco,	    pubsub    => \&pubsub,	    send_message  => \&send_message,	    send_html     => \&send_html,	    #stream_html   => \&stream_html,	    get_help      => \&get_help,	    get_presence  => \&get_presence,            get_roster    => \&get_roster,	    send_roster   => \&send_roster,	    return_browse => \&return_browse,	    return_pubsub => \&return_pubsub,	    	    check_timeout => \&check_timeout,	    check_timeout_continue => \&check_timeout_continue,	},	  heap => { CONFIG => $config },	  options => { debug => $config->{'debug'}, trace => $config->{'debug'} }	  );        return undef;}sub login {    # this will need to be overwritten or changed into a redifinable tool    my ($kernel,$heap,$session,$html_transaction) = @_[KERNEL, HEAP, SESSION, ARG0];        my ($jid,$pass,$options,$content,$session_id,$error);    my $params = $html_transaction->params();    my $port = $params->{'port'};    my $input = new CGI($html_transaction->stdin());    my $output;    my ($username,$hostname,$resource);    $port = $input->param('port') if defined $input->param('port');    $pass = $input->param('pass') if defined $input->param('pass');    $jid  = $input->param('jid') if defined $input->param('jid');        if (not defined $jid and not defined $pass) {		if (not defined $html_transaction->request()->authorization()) {	    # if it is a get do an http basic auth 		    $html_transaction->auth("Bad Authentication");	    return;	} 		($jid,$pass) = $html_transaction->request()->authorization_basic();    }    # TODO : this needs to be fixed    if (not defined($jid) or not defined($pass)) {	$html_transaction->error("you need a username and password",200) if not defined $html_transaction->request()->authorization();	$html_transaction->auth("you need a username and password") if defined $html_transaction->request()->authorization();		return FALSE;    }    ### Grab hostname     #my $hostname = &get_host($jid);    if ($jid =~ /\@/) {	($username,$hostname,$resource) = &parse_jid($jid);    } else {	$username = $jid;    }    if (not defined($username)) {	$html_transaction->auth("Bad Authentication") if defined $html_transaction->request()->authorization();		$html_transaction->error("Bad Authentication",200) if not defined $html_transaction->request()->authorization();		return FALSE;    }    $hostname = $heap->{'CONFIG'}->{'hostname'} if not defined $hostname;    #my $port_num = '5222' if not defined $port;    if (not defined($port) or $port eq "") {	$port = 5222;    }    $port =~ s/\D//gi; # get rid of crap        $resource = "PunJab" if not defined $resource or $resource eq "";    ### Create the session    # put this in a html header?    my $ip = $html_transaction->request()->{remote_ip};        $ip = $port if not defined $ip; # give a value if missing remote_ip    my $shaobj  = new Digest::SHA1;        $shaobj->add($jid.$pass.$resource.$ip);    $session_id = $shaobj->hexdigest();        ### Start the jabber client.      if ($heap->{'CONFIG'}->{debug} > 1) {	&debug('Connecting : ' .$jid." : ". $session_id . " : " .$port."");    }    $output->{'sid'} = $session_id;    if ($punjab_session->check_session($session_id)) {        $html_transaction->return($session_id);        return;    }    	    PunJab::JabberConnection->new($session_id,				  $jid,				  $pass,				  $username,				  $resource,				  $hostname,				  $port,				  $heap->{'CONFIG'},				  $html_transaction,				  'session_register',				  'session_unregister');        $kernel->delay('check_timeout', $heap->{'CONFIG'}->{'idle_check'});        }sub logout {    my ($kernel,$heap,$session,$html_transaction) = @_[KERNEL, HEAP, SESSION, ARG0];    my $params = $html_transaction->params();    my $stdin= $html_transaction->stdin();        my $sid = $params->{'sid'};     $sid = _sid($html_transaction) if not defined $sid;     return if not defined $sid;        if ($punjab_session->check_session($sid)) {	$kernel->post($sid,'disconnect');    } else {	$html_transaction->error("Session does not exist");	return;    }    $html_transaction->return(&str_to_node("<logout><sid>".$sid."</sid></logout>"));}sub message {    my ($kernel,$heap,$session,$html_transaction) = @_[KERNEL, HEAP, SESSION, ARG0];    my $params = $html_transaction->params();     my $sid  = $params->{'sid'};    my $to   = $params->{'to'};    my $from = $params->{'from'};    my $id   = $params->{'id'};     my $type = $params->{'type'};    my $c    = $params->{'check'};    my $s    = $params->{'stream'};    my $input = new CGI($html_transaction->stdin());    $to   =~ s/\s//gi if defined $to; # trim space    $from =~ s/\s//gi if defined $from; # trim space    my ($pc,$messages);    $sid = _sid($html_transaction) if not defined $sid;     return if not defined $sid;        if ($punjab_session->check_session($sid)) {        $punjab_session->activity($sid,time());		if ($html_transaction->method() eq "GET") {	    # grab the message		  	    $kernel->post('Manager'.$sid,'start_message_event','send_message',$html_transaction) if $s;	    if (defined $c and $c==1) {		$kernel->post('Manager'.$sid,'check_managed_message',$to,$from,'send_html',$html_transaction);	    } else {		$kernel->post('Manager'.$sid,'get_managed_message',$to,$from,$id,$type,'send_html',$html_transaction);	    }	    return;	} elsif ($html_transaction->method() eq "POST") {	    my $m = POE::Filter::XML::Node->new('message');            $m->attr('to',$to) if defined $to;            $m->attr('from',$from) if defined $from;            $m->attr('type',$type) if defined $type;	    my $m_data = $input->param('message') if defined $input->param('message');	    my $s_data = $input->param('subject') if defined $input->param('subject'); 	    $m_data =~ s/\s*$//gm if defined $m_data;	    $s_data =~ s/\s*$//gm if defined $s_data;	    	    $m->insert_tag('subject')->data($s_data) if defined $input->param('subject');            $m->insert_tag('body')->data($m_data) if defined $input->param('message');                        $kernel->post($sid,'send_xml',$m);	} 	$html_transaction->return($messages);	        } else {		$html_transaction->error("Session does not exist");	return;    }     }sub presence{    my ($kernel,$heap,$session,$html_transaction) = @_[KERNEL, HEAP, SESSION, ARG0];    my $params = $html_transaction->params();    my $input = new CGI($html_transaction->stdin());    my ($output,$pc,$presences);     my $sid  = $params->{'sid'};     my $to   = $params->{'to'};    my $from = $params->{'from'};    my $s    = $params->{'stream'};    &debug($to);    $sid = _sid($html_transaction) if not defined $sid;     return if not defined $sid;    if ($punjab_session->check_session($sid)) {        $punjab_session->activity($sid,time());		if ($html_transaction->method() eq "GET") {	    # grab the presence	    #$html_transaction->request()->{'html_type'} = 'presences';	    $kernel->post('Manager'.$sid,'start_presence_event','send_html',$html_transaction) if $s;	    $kernel->post('Manager'.$sid,'get_managed_presence',$to,$from,'send_html',$html_transaction);  	    return;	} elsif ($html_transaction->method() eq "POST") {	    # create and send presence	    my $p = POE::Filter::XML::Node->new('presence');	    $p->attr('to',$to) if defined $to;	    $p->attr('from',$from) if defined $from;	    my $type = $input->param('type') if defined $input->param('type'); 	    $type    =~ s/\s*$//gm if defined $type;	   	    $p->attr('type',$type) if defined $type and $type ne "";	    my $st_data = $input->param('status') if defined $input->param('status');	    my $s_data  = $input->param('show') if defined $input->param('show');	    my $p_data  = $input->param('priority') if defined $input->param('priority'); 	    $st_data =~ s/\s*$//gm if defined $st_data;	    $s_data =~ s/\s*$//gm if defined $s_data;	    $p_data =~ s/\s*$//gm if defined $p_data;	    $p->insert_tag('status')->data($st_data) if defined $input->param('status');	    $p->insert_tag('show')->data($s_data) if defined $input->param('show');	    $p->insert_tag('priority')->data($p_data) if defined $input->param('priority');	    	    $kernel->post($sid,'send_xml',$p);	} 	$html_transaction->return($presences);	        } else {	$html_transaction->error("Session does not exist");    }}sub roster{    my ($kernel,$heap,$session,$html_transaction) = @_[KERNEL, HEAP, SESSION, ARG0];    my $params = $html_transaction->params();    my $s    = $params->{'stream'};       my $sid = $params->{'sid'};     $sid = _sid($html_transaction) if not defined $sid;     return if not defined $sid;    my ($item,$stdin); # get rid of stdin    my $id = luniqid;    if ($punjab_session->check_session($sid)) {	$punjab_session->activity($sid,time());	$html_transaction->request()->{'html_type'} = 'roster';	if ($html_transaction->method() eq "GET") {	    &debug("\n\n\nGET ROSTER\n\n\n");	    # should this go on the heap? It may be a bit to crazy	    $html_transaction->request()->{'start_roster'} = $sid;	    $kernel->post('Manager'.$sid,'start_roster', 'get_roster', 			  $html_transaction,$id,$sid,'JABBER'.$sid);	    return;	} elsif ($html_transaction->method() eq "POST") {	    my $iq = POE::Filter::XML::Node->new('iq');	    $iq->attr('type',+IQ_SET);	    $iq->attr('id',$id);		    &debug("SEND ROSTER");	    my $query = $iq->insert_tag('query',['xmlns',+NS_JABBER_ROSTER]);	    if (ref($stdin) eq "POE::Filter::XML::Node") {		my $items        = $stdin->get_children();		foreach my $i (@$items) {		    my $p = POE::Filter::XML::Node->new('presence');		    $p->attr('type','subscribe');		    $p->attr('to',$i->attr('jid'));		    $kernel->post($sid,'send_xml',$p);		    $query->insert_tag($i);		}	    } else {		$item  = $query->insert_tag('item');		$item->attr('name',$params->{'name'}) if defined $params->{'name'};		$item->attr('jid',$params->{'jid'}) if defined $params->{'jid'};		$item->insert_tag('group')->data($params->{'group'}) if defined $params->{'group'};	    }	    $kernel->post($sid,'send_xml',$iq);	    	    	    $kernel->post('Manager'.$sid,'manage_events', 'send_html', 			  $html_transaction,$iq,$sid);	    return;	}	    } else {	$html_transaction->error("Session does not exist");	return;    }}sub get_roster() {    my ($kernel,$session,$heap,$ret_val, $html_transaction,$node,$sid) = 	@_[KERNEL, SESSION, HEAP, ARG0 .. ARG3];        if ($punjab_session->check_session($sid)) {		if (defined($html_transaction->request()->{'start_roster'})) {	    # we want to combine presence with our roster	    $kernel->post('Manager'.$sid,'get_managed_roster','get_presence',$html_transaction,$sid);	} else {	    $kernel->post('Manager'.$sid,'get_managed_roster','send_html',$html_transaction);	}	    } else {	$html_transaction->error("Session does not exist");    }}sub get_presence() {    my ($kernel,$session,$heap,$ret_val, $html_transaction,$node,$sid) = 	@_[KERNEL, SESSION, HEAP, ARG0 .. ARG3];    $sid = $html_transaction->request()->{'start_roster'} if defined $html_transaction->request()->{'start_roster'};        if ($punjab_session->check_session($sid)) {		if (defined($html_transaction->request()->{'start_roster'})) {	    # should this go on the heap? It may be a bit to crazy	    $html_transaction->request()->{'roster'} = $ret_val;	    	    $kernel->post('Manager'.$sid,'get_managed_presence',undef,undef,'send_roster',$html_transaction);	} else {	    $kernel->post('Manager'.$sid,'get_managed_presence',undef,undef,'send_html',$html_transaction);	}	    } else {	$html_transaction->error("Session does not exist");    }}sub send_roster {    my ($kernel,$session,$heap,$ret_val,$html_trans) = 	@_[KERNEL, SESSION, HEAP, ARG0, ARG1];    # should we do something else    $html_trans->return($html_trans->request()->{'roster'});    #$html_trans->return($ret_val);}sub vcard{    my ($kernel,$heap,$session,$html_transaction) = @_[KERNEL, HEAP, SESSION, ARG0];    my $params = $html_transaction->params();     my $id = luniqid;    my $sid = $params->{'sid'};     my $jid = $params->{'jid'};      $sid = _sid($html_transaction) if not defined $sid;     return if not defined $sid;    if ($punjab_session->check_session($sid)) {	$punjab_session->activity($sid,time());	$html_transaction->request()->{'html_type'} = 'vcard';	if ($html_transaction->method() eq "GET") {	    $kernel->post($sid,'start_vcard', 'send_html',			     $html_transaction,$jid,$id);	    return;	} elsif ($html_transaction->method() eq "POST") {	    #$kernel->post($sid,'set_vcard', 'send_html',		#	     $html_transaction,$stdin,$id);	    return;	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -