我正在为一家公司工作,该公司正在使用Google Chatback(与我公司案例中的支持员工进行匿名聊天)作为主要的聊天服务提供商.此服务使用XMPP(以前称为Jabber)协议来发送和接收消息.
我们公司有十个支持员工帐户,可以通过我们在我们网站上使用的聊天服务访问它们.员工同时使用Mac OSX和Windows,以及不同操作系统上的不同客户端.聊天也可以通过Android和iOS上的原生应用程序获得.
我们需要一种用于记录聊天会话的服务,我们一直在寻找专有的解决方案,但这些在移动平台上是不受支持的,而且这基本上就是交易破解者.
我决定的解决方案是在消息链中引入另一个链接,记录所有消息.这个想法是服务器通过这个代理发送,根据它的聊天会话记录消息,然后以适当的方式保存这些日志.目前,他们将所有日志存储在DropBox文件夹中,这是一个容易出错的活动.
理论上,这将允许我们的支持者使用他们选择的任何操作系统/客户端,并且日志将最终在同一个地方.
在使用Smack API进行了一些测试之后,我得出结论,我的XMPP客户端(Android和Windows上的Trillian)都回复了它上次收到消息的资源.这实际上意味着我实现的非常简单的聊天记录器被忽略了.
使用下面的代码与另一个并行运行的客户端进行了测试.只有一个客户端收到该消息.
ConnectionConfiguration config = new ConnectionConfiguration("talk.google.com",5222,"googlemail.com");
config.setSecurityMode(ConnectionConfiguration.SecurityMode.required);
config.setSASLAuthenticationEnabled(true);
XMPPConnection connection = new XMPPConnection(config);
connection.connect();
Presence presence = new Presence(Presence.Type.unavailable);
connection.login("android_client_username","android_client_pass");
Message message = new Message("my_test_email@gmail.com");
message.setBody("Hello World!");
connection.sendPacket(message);
connection.sendPacket(presence);
connection.addPacketListener(new PacketListener() {
public void processPacket(Packet packet) {
if (packet instanceof Message) {
Message message = (Message) packet;
System.out.println(message.getBody());
}
}
},new MessageTypeFilter(Message.Type.chat));
>是否可以使用Google Talk服务创建此类代理,即无需托管我们自己的XMPP服务器?
>是否可以远程监听服务器上的所有数据包?
>如果没有,那么使用开放协议(如XMPP)的匿名基于Web的聊天客户端有哪些替代方案?
感谢您的时间.
>书:http://professionalxmpp.com/
> HTTP服务器
> Jabber / XMPP服务器(例如ejabberd)
>每个支持座位的聊天室
>使用perl和Net :: Jabber(不是Net :: XMPP,因为它不支持MUC)来创建脚本/进程/守护进程,它将登录到XMPP服务器并加入相应的聊天室.聊天室的其他参与者将是你的支持者之一,并且是那个寻求支持的人.必须以这样的方式设置脚本,使其在收到MUC消息时(例如,存储在数据库中)做出任何想要的内容.从安装Net :: Jabber开始,工作就不那么重要了,有些示例脚本需要添加/修改部分代码.
>如果您想通过Web浏览器聊天,必须使用Strophe.js以通过适当的代理配置通过HTTP服务器与XMPP服务器建立BOSH连接.
所有这些东西都可以在书中找到,除了使用Net :: Jabber的Perl脚本.
我可能没什么帮助,但如果你决定走这条路,我会帮忙的.如果Google Chatback支持MUC,那么您只需要Perl / Net :: Jabber部分.
编辑:perl XMPP守护进程
#!/usr/bin/perl -w
use strict;
use Net::Jabber;
use threads;
use DBI;
my $server = shift @ARGV;
my $port = shift @ARGV;
my $username = shift @ARGV;
my $password = shift @ARGV;
my $resource = shift @ARGV;
my $chatroom = shift @ARGV;
my %img = ('URGENT' => 'urgent.png','HIGH' => 'high.png','MEDIUM' => 'medium.png','LOW' => 'low.png');
my $dbname_status= 'db';
my $dbuser_status= 'user';
my $dbpass_status= 'pass';
my $dbhost_status = 'localhost';
my $dbport_status = 5432;
my $dbh_status = DBI->connect("dbi:Pg:dbname=$dbname_status;host=$dbhost_status;port=$dbport_status",$dbuser_status,$dbpass_status,{AutoCommit => 0,RaiseError => 1});
my $sth_status = $dbh_status->prepare(qq{SELECT * FROM sosrhs_ticketstatus});
$sth_status->execute;
my %status = ();
while (my $res = $sth_status->fetchrow_hashref)
{
$status{$res->{status}} = $res->{id};
}
$sth_status->finish;
$dbh_status->disconnect;
print "\nSERVER: ",$server,"\n";
print 'PORT: ',$port,"\n";
print 'USERNAME: ',$username,"\n";
print 'RESOURCE: ',$resource,"\n";
$SIG{HUP} = \&Stop;
$SIG{KILL} = \&Stop;
$SIG{TERM} = \&Stop;
$SIG{INT} = \&Stop;
my $Connection = new Net::Jabber::Client();
$Connection->SetCallBacks(message => sub {threads->create('InMessage',(@_))->join()},presence => sub {threads->create('InPresence',iq => sub {threads->create('InIQ',(@_))->join()}
);
my $status = $Connection->Connect(hostname=>$server,port=>$port,);
if (!(defined($status)))
{
print "ERROR: Jabber server is down or connection was not allowed.\n";
print " ($!)\n";
exit(0);
}
my @result = $Connection->AuthSend(username=>$username,password=>$password,resource=>$resource);
if ($result[0] ne "ok")
{
print "ERROR: Authorization Failed: $result[0] - $result[1]\n";
exit(0);
}
print "Logged in to $server:$port...\n";
$Connection->RosterGet();
print "Getting Roster to tell server to send presence info...\n";
$Connection->PresenceSend();
print "Sending presence to tell world that we are logged in...\n";
$Connection->MUCJoin(room => $chatroom,server => 'conference.' . $server,nick => $username);
print 'Join ' . $chatroom . '@conference.sosrhs MUC room...';
print "\n";
while(defined($Connection->Process())) { }
print "ERROR: The connection was killed...\n";
exit(0);
sub Stop
{
print "Exiting...\n";
$Connection->Disconnect();
exit(0);
}
sub InMessage
{
my $sid = shift;
my $message = shift;
my $type = $message->GetType();
my $fromJID = $message->GetFrom("jid");
my $from = $fromJID->GetUserID();
my $resource = $fromJID->GetResource();
my $subject = $message->GetSubject();
my $body = $message->GetBody();
#print "===\n";
#print "Message ($type)\n";
#print " From: $from ($resource)\n";
#print " Subject: $subject\n";
#print " Body: $body\n";
#print "===\n";
#print $message->GetXML(),"\n";
#print "===\n";
if ($from eq 'ticket_distributor')
{
if ($body =~ /^ticketrelay /)
{
&to_group($body);
}
elsif ($body =~ /^ackrelay /)
{
&to_group_ack($body);
}
elsif ($body =~ /^ticketupdaterelay /)
{
&to_group_update($body);
}
elsif ($body =~ /^ticketwithdrawrelay /)
{
&to_group_withdraw($body);
}
elsif ($body =~ /^ticketclearrelay /)
{
&to_group_clear($body);
}
elsif ($body =~ /^ticketcloserelay /)
{
&to_group_close($body);
}
elsif ($body =~ /^ticketfwdrelay /)
{
&to_group_fwd($body);
}
}
else
{
if ($body =~ /^ticketnew /)
{
&to_group($body);
&to_ticket_distributor($body);
}
elsif ($body =~ /^ack /)
{
&to_ticket_distributor_ack($body);
}
elsif ($body =~ /^ticketupdate /)
{
&to_ticket_distributor_update($body);
}
elsif ($body =~ /^ticketwithdraw /)
{
&to_ticket_distributor_withdraw($body);
}
elsif ($body =~ /^ticketclear /)
{
&to_ticket_distributor_clear($body);
}
elsif ($body =~ /^ticketclose /)
{
&to_ticket_distributor_close($body);
}
elsif ($body =~ /^ticketfwd /)
{
&to_ticket_distributor_fwd($body);
}
}
}
sub InIQ
{
my $sid = shift;
my $iq = shift;
my $from = $iq->GetFrom();
my $type = $iq->GetType();
my $query = $iq->GetQuery();
my $xmlns = $query->GetXMLNS();
#print "===\n";
#print "IQ\n";
#print " From $from\n";
#print " Type: $type\n";
#print " XMLNS: $xmlns";
#print "===\n";
#print $iq->GetXML(),"\n";
#print "===\n";
}
sub InPresence
{
my $sid = shift;
my $presence = shift;
my $from = $presence->GetFrom();
my $type = $presence->GetType();
my $status = $presence->GetStatus();
#print "===\n";
#print "Presence\n";
#print " From $from\n";
#print " Type: $type\n";
#print " Status: $status\n";
#print "===\n";
#print $presence->GetXML(),"\n";
#print "===\n";
if ($type eq 'subscribe')
{
my @usrreq = split('@',$from);
my $usrreq = $usrreq[0] . '@' . $server;
$Connection->Subscription(type => 'subscribed',to => $usrreq
);
}
}
# Functions for actions taken upon ticket
sub to_ticket_distributor
{
my $msg = shift;
my @msg = split(' ',$msg);
print "\n$username : $msg[0] $msg[1]\n";
my $dbname= 'db';
my $dbuser= 'user';
my $dbpass= 'pass';
my $dbhost = 'localhost';
my $dbport = 5432;
my $dbh = DBI->connect("dbi:Pg:dbname=$dbname;host=$dbhost;port=$dbport",$dbuser,$dbpass,RaiseError => 1});
my $sth = $dbh->prepare(qq{SELECT * FROM sosrhs_tickets_v where ticket_id = ?});
$sth->execute($msg[1]);
my $group_assigned_groupnamechat = '';
while (my $res = $sth->fetchrow_hashref)
{
$group_assigned_groupnamechat = $res->{group_assigned_groupnamechat};
}
$sth->finish;
$dbh->disconnect;
$Connection->MessageSend(to => 'ticket_distributor@' . $server,type => 'chat',body => $msg[1] . ' ' . $group_assigned_groupnamechat);
}
sub to_ticket_distributor_ack
{
my $msg = shift;
my @msg = split(' ',$msg);
print "\n$username : $msg[0] $msg[1] $msg[2]\n";
my $dbname= 'db';
my $dbuser= 'user';
my $dbpass= 'pass';
my $dbhost = 'localhost';
my $dbport = 5432;
my $dbh = DBI->connect("dbi:Pg:dbname=$dbname;host=$dbhost;port=$dbport",RaiseError => 1});
my $sth = $dbh->do(qq{UPDATE sosrhs_tickets SET ticketstatus = $status{'WORK IN PROGRESS'},user_accepted = '$msg[2]',tmstmp_accepted = now() WHERE ticket_id = $msg[1]});
$dbh->commit;
$sth = $dbh->prepare(qq{SELECT * FROM sosrhs_tickets_v where ticket_id = ?});
$sth->execute($msg[1]);
my $user_creator_groups_id = '';
while (my $res = $sth->fetchrow_hashref)
{
$user_creator_groups_id = $res->{user_creator_groups_id};
}
$sth->finish;
$sth = $dbh->prepare(qq{SELECT groupnamechat FROM sosrhs_groups WHERE id = ?});
$sth->execute($user_creator_groups_id);
my $user_creator_groupchatname = '';
while (my $res = $sth->fetchrow_hashref)
{
$user_creator_groupchatname = $res->{groupnamechat};
}
$sth->finish;
$dbh->disconnect;
$Connection->MessageSend(to => 'ticket_distributor@' . $server,body => 'ackrelay ' . $msg[1] . ' ' . $user_creator_groupchatname);
$Connection->MessageSend(to => $chatroom . '@conference.' . $server,type => 'groupchat',body => 'ackfinish ' . $msg[1]);
}
sub to_ticket_distributor_update
{
my $msg = shift;
my @msg = split(' ',$msg);
print "\n$username : $msg[0] $msg[1] $msg[2]\n";
my $ticket_action = shift @msg;
my $ticket_id = shift @msg;
my $user_id_update = shift @msg;
my $ticket_comment = join(' ',@msg);
my $dbname= 'db';
my $dbuser= 'user';
my $dbpass= 'pass';
my $dbhost = 'localhost';
my $dbport = 5432;
my $dbh = DBI->connect("dbi:Pg:dbname=$dbname;host=$dbhost;port=$dbport",RaiseError => 1});
my $sth = $dbh->prepare(qq{INSERT INTO sosrhs_tickets_comments (ticket_id,users_id,comment) VALUES (?,?,?)});
$sth->execute($ticket_id,$user_id_update,$ticket_comment);
$dbh->commit;
$sth = $dbh->prepare(qq{SELECT * FROM sosrhs_tickets_v where ticket_id = ?});
$sth->execute($ticket_id);
my $user_creator_groups_id = '';
while (my $res = $sth->fetchrow_hashref)
{
$user_creator_groups_id = $res->{user_creator_groups_id};
}
$sth->finish;
$sth = $dbh->prepare(qq{SELECT groupnamechat FROM sosrhs_groups WHERE id = ?});
$sth->execute($user_creator_groups_id);
my $user_creator_groupchatname = '';
while (my $res = $sth->fetchrow_hashref)
{
$user_creator_groupchatname = $res->{groupnamechat};
}
$sth->finish;
$dbh->disconnect;
$Connection->MessageSend(to => 'ticket_distributor@' . $server,body => 'ticketupdaterelay ' . $ticket_id . ' ' . $user_creator_groupchatname);
$Connection->MessageSend(to => $chatroom . '@conference.' . $server,body => 'ticketupdatefinish ' . $ticket_id);
}
sub to_ticket_distributor_withdraw
{
my $msg = shift;
my @msg = split(' ',$msg);
print "\n$username : $msg[0] $msg[1]\n";
my $ticket_action = shift @msg;
my $ticket_id = shift @msg;
my $user_id_withdraw = shift @msg;
my $dbname= 'db';
my $dbuser= 'user';
my $dbpass= 'pass';
my $dbhost = 'localhost';
my $dbport = 5432;
my $dbh = DBI->connect("dbi:Pg:dbname=$dbname;host=$dbhost;port=$dbport",RaiseError => 1});
my $sth = $dbh->do(qq{UPDATE sosrhs_tickets SET ticketstatus = $status{'WITHDRAWN'},user_withdrawn = $user_id_withdraw,tmstmp_withdrawn = now() WHERE ticket_id = $ticket_id});
$dbh->commit;
$sth = $dbh->prepare(qq{SELECT * FROM sosrhs_tickets_v where ticket_id = ?});
$sth->execute($ticket_id);
my $user_creator_groups_id = '';
while (my $res = $sth->fetchrow_hashref)
{
$user_creator_groups_id = $res->{user_creator_groups_id};
}
$sth->finish;
$sth = $dbh->prepare(qq{SELECT groupnamechat FROM sosrhs_groups WHERE id = ?});
$sth->execute($user_creator_groups_id);
my $user_creator_groupchatname = '';
while (my $res = $sth->fetchrow_hashref)
{
$user_creator_groupchatname = $res->{groupnamechat};
}
$sth->finish;
$dbh->disconnect;
$Connection->MessageSend(to => 'ticket_distributor@' . $server,body => 'ticketwithdrawrelay ' . $ticket_id . ' ' . $user_creator_groupchatname);
$Connection->MessageSend(to => $chatroom . '@conference.' . $server,body => 'ticketwithdrawfinish ' . $ticket_id);
}
sub to_ticket_distributor_clear
{
my $msg = shift;
my @msg = split(' ',$msg);
print "\n$username : $msg[0] $msg[1]\n";
my $ticket_action = shift @msg;
my $ticket_id = shift @msg;
my $user_id_clear = shift @msg;
my $dbname= 'db';
my $dbuser= 'user';
my $dbpass= 'pass';
my $dbhost = 'localhost';
my $dbport = 5432;
my $dbh = DBI->connect("dbi:Pg:dbname=$dbname;host=$dbhost;port=$dbport",RaiseError => 1});
my $sth = $dbh->do(qq{UPDATE sosrhs_tickets SET ticketstatus = $status{'CLEARED'},user_cleared = $user_id_clear,tmstmp_cleared = now() WHERE ticket_id = $ticket_id});
$dbh->commit;
$sth = $dbh->prepare(qq{SELECT * FROM sosrhs_tickets_v where ticket_id = ?});
$sth->execute($ticket_id);
my $user_creator_groups_id = '';
while (my $res = $sth->fetchrow_hashref)
{
$user_creator_groups_id = $res->{user_creator_groups_id};
}
$sth->finish;
$sth = $dbh->prepare(qq{SELECT groupnamechat FROM sosrhs_groups WHERE id = ?});
$sth->execute($user_creator_groups_id);
my $user_creator_groupchatname = '';
while (my $res = $sth->fetchrow_hashref)
{
$user_creator_groupchatname = $res->{groupnamechat};
}
$sth->finish;
$dbh->disconnect;
$Connection->MessageSend(to => 'ticket_distributor@' . $server,body => 'ticketclearrelay ' . $ticket_id . ' ' . $user_creator_groupchatname);
$Connection->MessageSend(to => $chatroom . '@conference.' . $server,body => 'ticketclearfinish ' . $ticket_id);
}
sub to_ticket_distributor_close
{
my $msg = shift;
my @msg = split(' ',$msg);
print "\n$username : $msg[0] $msg[1]\n";
my $ticket_action = shift @msg;
my $ticket_id = shift @msg;
my $user_id_close = shift @msg;
my $dbname= 'db';
my $dbuser= 'user';
my $dbpass= 'pass';
my $dbhost = 'localhost';
my $dbport = 5432;
my $dbh = DBI->connect("dbi:Pg:dbname=$dbname;host=$dbhost;port=$dbport",RaiseError => 1});
my $sth = $dbh->do(qq{UPDATE sosrhs_tickets SET ticketstatus = $status{'CLOSED'},user_closed = $user_id_close,tmstmp_closed = now() WHERE ticket_id = $ticket_id});
$dbh->commit;
$sth = $dbh->prepare(qq{SELECT groupnamechat FROM sosrhs_users_v WHERE groups_id = (SELECT group_assigned_id FROM sosrhs_tickets_v WHERE ticket_id = ?)});
$sth->execute($ticket_id);
my $user_accepted_groupchatname = '';
while (my $res = $sth->fetchrow_hashref)
{
$user_accepted_groupchatname = $res->{groupnamechat};
}
$sth->finish;
$dbh->disconnect;
$Connection->MessageSend(to => 'ticket_distributor@' . $server,body => 'ticketcloserelay ' . $ticket_id . ' ' . $user_accepted_groupchatname);
$Connection->MessageSend(to => $chatroom . '@conference.' . $server,body => 'ticketclosefinish ' . $ticket_id);
}
sub to_ticket_distributor_fwd
{
my $msg = shift;
my @msg = split(' ',$msg);
print "\n$username : $msg[0] $msg[1] $msg[2]\n";
my $ticket_action = shift @msg;
my $ticket_id = shift @msg;
my $user_id_fwd = shift @msg;
my $group_id_fwd_to = shift @msg;
my $dbname= 'db';
my $dbuser= 'user';
my $dbpass= 'pass';
my $dbhost = 'localhost';
my $dbport = 5432;
my $dbh = DBI->connect("dbi:Pg:dbname=$dbname;host=$dbhost;port=$dbport",RaiseError => 1});
my $sth = $dbh->do(qq{UPDATE sosrhs_tickets SET ticketstatus = $status{'ASSIGNED'},user_accepted = NULL,tmstmp_accepted = NULL,group_assigned = $group_id_fwd_to WHERE ticket_id = $ticket_id});
$dbh->commit;
$sth = $dbh->prepare(qq{INSERT INTO sosrhs_tickets_comments (ticket_id,groups_id_fwd_to) VALUES (?,$user_id_fwd,$group_id_fwd_to);
$dbh->commit;
$sth = $dbh->prepare(qq{SELECT groupnamechat FROM sosrhs_groups WHERE id = (SELECT group_assigned_id FROM sosrhs_tickets_v WHERE ticket_id = ?)});
$sth->execute($ticket_id);
my $user_fwd_groupchatname = '';
while (my $res = $sth->fetchrow_hashref)
{
$user_fwd_groupchatname = $res->{groupnamechat};
}
$sth->finish;
$sth = $dbh->prepare(qq{SELECT groupnamechat FROM sosrhs_groups WHERE id = (SELECT user_creator_groups_id FROM sosrhs_tickets_v WHERE ticket_id = ?)});
$sth->execute($ticket_id);
my $user_creator_groupchatname = '';
while (my $res = $sth->fetchrow_hashref)
{
$user_creator_groupchatname = $res->{groupnamechat};
}
$sth->finish;
$dbh->disconnect;
$Connection->MessageSend(to => 'ticket_distributor@' . $server,body => 'ticketfwdrelay ' . $ticket_id . ' ' . $user_fwd_groupchatname);
$Connection->MessageSend(to => 'ticket_distributor@' . $server,body => 'ticketfwdrelay ' . $ticket_id . ' ' . $user_creator_groupchatname);
$Connection->MessageSend(to => $chatroom . '@conference.' . $server,body => 'ticketfwdfinish ' . $ticket_id);
}
# Functions for relayed actions from ticket_distributor
sub to_group
{
my $msg = shift;
my @msg = split(' ',$msg);
print "\n$username : $msg[0] $msg[1]\n";
$Connection->MessageSend(to => $chatroom . '@conference.' . $server,body => &build_new_ticket_message($msg[1]));
}
sub to_group_ack
{
my $msg = shift;
my @msg = split(' ',body => 'ackrelay ' . $msg[1]);
}
sub to_group_update
{
my $msg = shift;
my @msg = split(' ',body => 'ticketupdaterelay ' . $msg[1]);
}
sub to_group_withdraw
{
my $msg = shift;
my @msg = split(' ',body => 'ticketwithdrawrelay ' . $msg[1]);
}
sub to_group_clear
{
my $msg = shift;
my @msg = split(' ',body => 'ticketclearrelay ' . $msg[1]);
}
sub to_group_close
{
my $msg = shift;
my @msg = split(' ',body => 'ticketcloserelay ' . $msg[1]);
}
sub to_group_fwd
{
my $msg = shift;
my @msg = split(' ',body => 'ticketfwdrelay ' . $msg[1]);
sleep 2;
$Connection->MessageSend(to => $chatroom . '@conference.' . $server,body => &build_new_ticket_message($msg[1]));
}
sub build_new_ticket_message
{
my $ticket_id = shift;
my $dbname= 'db';
my $dbuser= 'user';
my $dbpass= 'pass';
my $dbhost = 'localhost';
my $dbport = 5432;
my $dbh = DBI->connect("dbi:Pg:dbname=$dbname;host=$dbhost;port=$dbport",RaiseError => 1});
my $sth = $dbh->prepare(qq{SELECT * FROM sosrhs_tickets_v where ticket_id = ?});
$sth->execute($ticket_id);
my %ticket = ();
while (my $res = $sth->fetchrow_hashref)
{
$ticket{ticket_id} = $res->{ticket_id};
$ticket{ticketcategory_category} = $res->{ticketcategory_category};
$ticket{ticketstatus_status} = $res->{ticketstatus_status};
$ticket{ticketpriority_severityname} = $res->{ticketpriority_severityname};
$ticket{tmstmp_assigned} = $res->{tmstmp_assigned};
$ticket{user_creator_firstname} = $res->{user_creator_firstname};
$ticket{user_creator_secondname} = $res->{user_creator_secondname};
$ticket{group_assigned_groupname} = $res->{group_assigned_groupname};
$ticket{ticket_text} = $res->{ticket_text};
$ticket{ticket_file} = $res->{ticket_file};
$ticket{subject} = $res->{subject};
$ticket{user_creator_groups_id} = $res->{user_creator_groups_id};
}
$sth->finish;
$dbh->disconnect;
my $html_msg = q!