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

📄 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 页
字号:
	    } else {	$html_transaction->error("Session does not exist");	return;    }}sub register{   # for in band registration    my ($kernel,$heap,$session,$html_transaction) = @_[KERNEL, HEAP, SESSION, ARG0];    my $params = $html_transaction->params();         my $id = luniqid;    my $iq;    my $sid = $params->{'sid'};     $sid = _sid($html_transaction) if not defined $sid;     return if not defined $sid;    if ($punjab_session->check_session($sid)) {	if ($html_transaction->method() eq "GET") {	    $iq = POE::Filter::XML::Node->new('iq');	    $iq->attr('type',+IQ_GET);	    $iq->attr('id',$id);	    $iq->attr('to',$params->{'to'}) if defined $params->{'to'};	    $iq->attr('from',$params->{'from'}) if defined $params->{'from'};	    $iq->insert_tag('query',['xmlns',+NS_JABBER_REGISTER]);	    $kernel->post($sid,'send_xml',$iq);	    	    $html_transaction->return("register");	} elsif ($html_transaction->method() eq "POST") {	    $html_transaction->return("register");	}    } else {	$html_transaction->error("Session does not exist");	return;    }    return;}sub browse{    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'};     my $auto  = $params->{'auto'}; # auto browse into objects    my $items = $params->{'items'}; # auto get item information    $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'} = 'browse';	$kernel->post($sid,'start_browse', 'return_browse',		      $html_transaction,$id,$jid,$auto,$items);	 return;    } else {	$html_transaction->error("Session does not exist");	return;    }}sub return_browse(){    my ($kernel,$session,$heap,$ret_val, $html_transaction,$id,$jid,$sid) =        @_[KERNEL, SESSION, HEAP, ARG0, ARG1 .. ARG6];        if ($punjab_session->check_session($sid)) {        $punjab_session->activity($sid,time());                if (not defined $heap->{'browse'}->{$sid}) {            $heap->{'browse'}->{$sid} = [];        }        if ($ret_val->attr('type') ne 'error') {            push(@{$heap->{'browse'}->{$sid}},$ret_val);        } else {            push(@{$heap->{'browse'}->{$sid}},undef);        }	if ($#{$heap->{'browse'}->{$sid}}>=2) {            # parse through the ret vals?            $kernel->yield('send_html',$heap->{'browse'}->{$sid},$html_transaction);            delete $heap->{'browse'}->{$sid};        }    } else {        $html_transaction->error("Session does not exist");    }}sub pubsub{    my ($kernel,$heap,$session,$html_transaction) = @_[KERNEL, HEAP, SESSION, ARG0];    my $params  = $html_transaction->params();    my $args;    my $id      = luniqid;    my $sid     = $params->{'sid'};     my $to      = $params->{'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());	$html_transaction->request()->{'html_type'} = 'pubsub';		if ($html_transaction->method() eq "GET") {	    my $piq = POE::Filter::XML::Node->new('iq');	    $piq->attr('type',+IQ_GET);	    $piq->attr('id',$id);	    	    	    if ($args->[0] eq "affiliations") {	    } elsif ($args->[0] eq "options") {	    	    } elsif ($args->[0] eq "items") {	    } elsif ($args->[0] eq "entities") {	    } elsif ($args->[0] eq "configure") {			    } else {		# send a disco for the node if node is set		#<query xmlns="http://jabber.org/protocol/disco#items" node="generic"/>	    }	    $html_transaction->error("Not implemented");	    return;	} elsif ($html_transaction->method() eq "POST") {	    	    my $piq = POE::Filter::XML::Node->new('iq');	    $piq->attr('type',+IQ_SET);	    $piq->attr('id',$id);	    	    	    if ($args->[0] eq "create") {	    } elsif ($args->[0] eq "publish") {	    } elsif ($args->[0] eq "retract") {	    } elsif ($args->[0] eq "subscribe") {	    } elsif ($args->[0] eq "unsubscribe") {	    } elsif ($args->[0] eq "command") {	    } elsif ($args->[0] eq "configure") {	    } elsif ($args->[0] eq "delete") {	    } elsif ($args->[0] eq "purge") {	    } elsif ($args->[0] eq "entities") {	    } elsif ($args->[0] eq "message") {		my $pm = POE::Filter::XML::Node->new('message');		$html_transaction->error("Not implemented");		return;	    } 	    	    &debug($piq->to_str());	    $html_transaction->error("Not implemented");	    return;	} else {	    #$kernel->post($sid,'start_pubsub', 'return_pubsub',	    #	      $html_transaction,$id,$jid,$auto,$items);	    	    $html_transaction->error("Not implemented");	}	return;    } else {	$html_transaction->error("Session does not exist");	return;    }}sub return_pubsub(){    my ($kernel,$session,$heap,$ret_val, $html_transaction,$id,$jid,$sid) =        @_[KERNEL, SESSION, HEAP, ARG0, ARG1 .. ARG6];        if ($punjab_session->check_session($sid)) {        $punjab_session->activity($sid,time());                if (not defined $heap->{'pubsub'}->{$sid}) {            $heap->{'pubsub'}->{$sid} = [];        }        if ($ret_val->attr('type') ne 'error') {            push(@{$heap->{'pubsub'}->{$sid}},$ret_val);        } else {            push(@{$heap->{'pubsub'}->{$sid}},undef);        }	if ($#{$heap->{'pubsub'}->{$sid}}>=2) {            # parse through the ret vals?            $kernel->yield('send_html',$heap->{'pubsub'}->{$sid},$html_transaction);            delete $heap->{'pubsub'}->{$sid};        }    } else {        $html_transaction->error("Session does not exist");    }}sub iqs{    my ($kernel,$heap,$session,$html_transaction) = @_[KERNEL, HEAP, SESSION, ARG0];    my $params = $html_transaction->params();       my $sid = $params->{'sid'};     my $iq_id = $params->{'id'};        $sid = _sid($html_transaction) if not defined $sid;      return if not defined $sid;     my ($pc,$iqs);     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'} = 'iqs';	    #if ($s) {		#$kernel->post('Manager'.$sid,'get_managed_iq',$iq_id,'stream_html',$html_transaction);	    #} else {		$kernel->post('Manager'.$sid,'get_managed_iq',$iq_id,'send_html',$html_transaction);			    #}	    return;	} elsif ($html_transaction->method() eq "POST") {	    if (defined($pc)) {		# need to do more checks		foreach my $n (@$pc) {		    if ($n->name() eq "iq") {			$kernel->post($sid,'send_xml',$n);			$iqs->insert_tag($n);		    }		}	    } else {		$html_transaction->error("Error in xml");		return;	    }	} 	$html_transaction->return($iqs);	        } else {	$html_transaction->error("Session does not exist");    } }sub get_help{    my ($kernel,$heap) = @_[KERNEL, HEAP];    my $path = $heap->{'CONFIG'}->{'help'};    my $file;        if(defined($path))    {	$file = IO::File->new($path);	    } else {		$file = IO::File->new('./help/help.xml');    }        my $filter = POE::Filter::XML->new();    my @lines = $file->getlines();    my $nodes = $filter->get(\@lines);    splice(@$nodes,0,1);    # help hash is global    foreach my $node (@$nodes)    {	$help{$node->attr('id')} = $node if defined $node->attr('id');    }                }sub help{    my ($kernel,$heap,$session,$html_transaction) = @_[KERNEL, HEAP, SESSION, ARG0];    my $tool;    # reload help    $kernel->yield('get_help');    if ($html_transaction->method() eq "GET") {	if (defined($tool)) {	    # query for the tool	    if (defined($help{$tool})) {		$html_transaction->return($help{$tool});	    } else {		$html_transaction->error("Help for $tool Not Found.");	    }	} else {	    # make this a PFX node?	    my $resources = "<resources>";	    #foreach (keys %{$public_interfaces{'html_shell'}}) {		#$resources .= "<resource xlink:href='".$html_transaction->uri(1)."/".$_."'>".$_."</resource>";	    #}	    $resources .= "</resources>";		    $html_transaction->return(&str_to_node(qq[<help xmlns:xlink="http://www.w3.org/1999/xlink"> <name>help - an interface to the on-line reference manuals (similar to man)</name> <synopsis> finish me </synopsis> <description>Help is used for the systems documentation. Put more here. A help page consists of several parts. The elements are  &lt;name/&gt;, &lt;synonpsis/&gt;, &lt;description/&gt;, &lt;option/&gt;, &lt;resourcess/&gt;, &lt;also/&gt;, &lt;bugs/&gt;, &lt;author/&gt;, and &lt;location/&gt;. </description>  <examples>      http://localhost/help/date  </examples>  $resources </help>]));	}	return;    }    }sub send_html {    my ($kernel,$session,$heap,$ret_val,$html_trans) =        @_[KERNEL, SESSION, HEAP, ARG0, ARG1];    if (ref $ret_val eq "POE::Filter::XML::Node") {	my $attrs = $ret_val->get_attrs();	my @ret;	my $children = $ret_val->get_children();	foreach my $child (@$children)	{	    my $data = $child->data();	    $data =~ s/'/\\'/gi;	    $attrs->{$child->name()} = $data;	}		$attrs->{iter} = 0;	push(@ret,$attrs);	$html_trans->return(\@ret);	return;    }        $html_trans->return($ret_val);}sub send_message {    my ($kernel,$session,$heap,$ret_val,$html_transaction) =        @_[KERNEL, SESSION, HEAP, ARG0, ARG1];    # grab params from html_trans    my $params = $html_transaction->params();    $params->{'to'} =~ s/\s//gi if defined $params->{'to'}; # trim space    $params->{'from'} =~ s/\s//gi if defined $params->{'from'}; # trim space    if (ref $ret_val eq "POE::Filter::XML::Node") {	my $attrs = $ret_val->get_attrs();	my @ret;	my $children = $ret_val->get_children();	foreach my $child (@$children)	{	    my $data = $child->data();	    $data =~ s/'/\\'/gi;	    $attrs->{$child->name()} = $data;	}		$attrs->{iter} = 0;	# check the to and from for our message	if (not defined $params->{'from'} and not defined $params->{'to'}) {	    push(@ret,$attrs);	} elsif (defined $params->{'from'} and ($attrs->{'to'} =~ /$params->{'from'}/)) {	    push(@ret,$attrs);	} elsif (defined $params->{'to'} and ($attrs->{'from'} =~ /$params->{'to'}/)) {	    push(@ret,$attrs);	}			$html_transaction->return(\@ret);	return;    }        $html_transaction->return($ret_val);}sub check_timeout(){    my ($kernel,$session,$heap) =        @_[KERNEL, SESSION, HEAP];    my @keys = keys %{$punjab_session->registry()};    $heap->{'session_keys'} = \@keys;    $kernel->yield('check_timeout_continue');}sub check_timeout_continue(){    my ($kernel,$session,$heap) =        @_[KERNEL, SESSION, HEAP];    my $ctime = time();    my $s = pop(@{$heap->{'session_keys'}});    if (not defined $s) {        my $count = keys %{$punjab_session->registry()};        if ($count > 0) {            $kernel->delay('check_timeout', $heap->{'CONFIG'}->{'idle_check'});        }        return;    }    if (($ctime - $punjab_session->activity($s))>=$heap->{'CONFIG'}->{'timeout'}) {        $kernel->post($s,'disconnect');        $punjab_session->unregister($s);    }    $kernel->yield('check_timeout_continue');}sub _sid(){    my $html_transaction = shift;        if (not defined $html_transaction->request()->authorization()) {	# if it is a get do an http basic auth 		$html_transaction->auth("Bad Authentication");		return;    }     my ($jid,$pass) = $html_transaction->request()->authorization_basic();        if (not defined $jid and not defined $pass) {	$html_transaction->auth("Error in authorization.");	return +FALSE;    }    my ($username,$hostname,$resource) = &parse_jid($jid);    ### Create the session    # put this in a html header?    my $id      = $html_transaction->request()->{remote_ip};    my $shaobj  = new Digest::SHA1;    $shaobj->add($jid.$pass.$resource.$id);    my $sid = $shaobj->hexdigest();        return $sid;}1;__END__

⌨️ 快捷键说明

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