[Added SIP trace for SIP Thor datasource Adrian Georgescu **20070719095414] hunk ./cdrlib.phtml 21 + var $skipNormalize = false; hunk ./cdrlib.phtml 198 + if ($this->DATASOURCES[$this->cdr_source]['skipNormalize']) { + $this->skipNormalize = $this->DATASOURCES[$this->cdr_source]['skipNormalize']; + } + hunk ./cdrlib.phtml 684 + if ($this->skipNormalize) { + dprint("Normalize is disabled for this data source"); + return 0; + } + hunk ./cdrlib.phtml 768 + if ($this->skipNormalize) { + dprint("Normalize is disabled for this data source"); + return 0; + } + hunk ./cdrlib.phtml 817 + if ($this->skipNormalize) { + dprint("Normalize is disabled for this data source"); + return 0; + } + hunk ./cdrlib_ser.phtml 2460 - $this->callIdPrint=" callIdPrint=" SipProxyServer', 'Trace', hunk ./cdrlib_ser.phtml 4190 -class SER_trace { - function SER_trace ($cdr_source) { +class SIP_trace { + var $enableThor = false; + var $trace_array = array(); + + function SIP_trace ($cdr_source) { hunk ./cdrlib_ser.phtml 4198 - $this->table = $DATASOURCES[$cdr_source]['table']; - $db_class = $DATASOURCES[$cdr_source]['db_class']; - $this->purgeRecordsAfter = $DATASOURCES[$cdr_source]['purgeRecordsAfter']; + global $soapEngines; + $this->soapEngines = $soapEngines; hunk ./cdrlib_ser.phtml 4201 - if ($db_class && $this->table) { - $this->db = new $db_class; + if (strlen($DATASOURCES[$cdr_source]['enableThor'])) { + $this->enableThor = $DATASOURCES[$cdr_source]['enableThor']; + } hunk ./cdrlib_ser.phtml 4205 - $query="select count(*) as c, - min(date) as min, - max(date) as max - from $this->table"; - dprint($query); - if ($this->db->query($query)) { - if ($this->db->next_record()) { - $this->summary=array( - "count" => $this->db->f('c'), - "startDate" => $this->db->f('min'), - "endDate" => $this->db->f('max') - ); - } else { - print "

No trace found. "; - return 0; - } - } else { - printf ("

Error: database error %s %s",$this->db->Error,$query); + if ($this->enableThor) { + if ($DATASOURCES[$cdr_source]['soapEngineId']) { + $this->soapEngineId=$DATASOURCES[$cdr_source]['soapEngineId']; + + require_once("provisioning_lib.phtml"); + + $this->SOAPlogin = array( + "username" => $this->soapEngines[$this->soapEngineId]['username'], + "password" => $this->soapEngines[$this->soapEngineId]['password'], + "admin" => true + ); + + $this->SOAPurl=$this->soapEngines[$this->soapEngineId]['url']; + + $this->SoapAuth = array('auth', $this->SOAPlogin , 'urn:AGProjects:NGNPro', 0, ''); + + // Instantiate the SOAP client + $this->soapclient = new WebService_NGNPro_SipPort($this->SOAPurl); + + $this->soapclient->setOpt('curl', CURLOPT_TIMEOUT, 5); + $this->soapclient->setOpt('curl', CURLOPT_SSL_VERIFYPEER, 0); + $this->soapclient->setOpt('curl', CURLOPT_SSL_VERIFYHOST, 0); + + } else { + print "Error: soapEngineID not defined in datasource $cdr_source"; hunk ./cdrlib_ser.phtml 4233 - $this->initOK=1; + } else { + $this->table = $DATASOURCES[$cdr_source]['table']; + $db_class = $DATASOURCES[$cdr_source]['db_class']; + $this->purgeRecordsAfter = $DATASOURCES[$cdr_source]['purgeRecordsAfter']; + + $this->db = new $db_class; + hunk ./cdrlib_ser.phtml 4244 - } else { - print "

Error: missing database or table definition in $cdr_source datasource). "; - return 0; + if (is_array($DATASOURCES[$cdr_source]['SIPProxies'])) { + $this->SIPProxies=$DATASOURCES[$cdr_source]['SIPProxies']; + } hunk ./cdrlib_ser.phtml 4248 + } hunk ./cdrlib_ser.phtml 4250 - if (is_array($DATASOURCES[$cdr_source]['SIPProxies'])) { - $this->SIPProxies=$DATASOURCES[$cdr_source]['SIPProxies']; - } + function getTrace ($callid,$fromtag,$proxyIP) { hunk ./cdrlib_ser.phtml 4252 + if ($this->enableThor) { + // get trace using soap request + if (!is_object($this->soapclient)) { + //return 0; + } + + $this->soapclient->addHeader($this->SoapAuth); + $result = $this->soapclient->getTrace($proxyIP,$callid,$fromtag); + + if (PEAR::isError($result)) { + $error_msg = $result->getMessage(); + $error_fault = $result->getFault(); + $error_code = $result->getCode(); + + $log=sprintf("%s: %s",$error_fault->faultstring,$error_fault->faultcode); + syslog(LOG_NOTICE, "SOAP error: $log1"); + return 0; + } + + foreach ($result as $_trace) { + + if (preg_match("/^(udp|tcp|tls):(.*)$/",$_trace->toip,$m)) { + $toip=$m[2]; + $protocol=$m[1]; + } + + preg_match("/^(\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+)$/",$_trace->date,$m); + $timestamp = mktime($m[4],$m[5],$m[6],$m[2],$m[3],$m[1]); + + $this->trace_array[$_trace->id]= + array ( + 'id' => $_trace->id, + 'direction' => $_trace->direction, + 'fromip' => $_trace->fromip, + 'toip' => $_trace->toip, + 'method' => $_trace->method, + 'protocol' => $protocol, + 'date' => $_trace->date, + 'status' => $_trace->status, + 'timestamp' => $timestamp, + 'msg' => $_trace->msg, + 'md5' => md5($_trace->msg) + ); + } + + + } else { + $query="select *,UNIX_TIMESTAMP(date) as timestamp + from $this->table where callid = '$callid' + and traced_user = ''"; + + dprint($query); + + if (!$this->db->query($query)) { + printf ("

Error: database error %s %s",$this->db->Error,$query); + return 0; + } + + $rows=$this->db->num_rows(); + + dprint("Found $rows rows"); + + $columns=0; + + while ($this->db->next_record()) { + + if (preg_match("/^(udp|tcp|tls):(.*)$/",$this->db->f('toip'),$m)) { + $toip=$m[2]; + $protocol=$m[1]; + } + + if (!$this->column[$this->db->f('fromip')]) { + $this->column[$this->db->f('fromip')]=$columns+1; + $columns++; + } + + if (!$this->column[$toip]) { + $this->column[$toip]=$columns+1; + $columns++; + } + + $this->trace_array[$this->db->f('id')]= + array ( + 'id' => $this->db->f('id'), + 'direction' => $this->db->f('direction'), + 'fromip' => $this->db->f('fromip'), + 'toip' => $toip, + 'method' => $this->db->f('method'), + 'protocol' => $protocol, + 'date' => $this->db->f('date'), + 'status' => $this->db->f('status'), + 'timestamp' => $this->db->f('timestamp'), + 'msg' => $this->db->f('msg'), + 'md5' => md5($this->db->f('msg')) + ); + } + } hunk ./cdrlib_ser.phtml 4351 - function show($callid,$method,$status,$fromtag,$trace_url="") { + function show($callid,$fromtag,$proxyIP) { hunk ./cdrlib_ser.phtml 4360 - $query="select *,UNIX_TIMESTAMP(date) as timestamp - from $this->table where callid = '$callid' - and traced_user = ''"; - - if ($status) $query.=" and status = '$status' "; - if ($method) $query.=" and method = '$method'"; - - $query.=" order by id limit 1000"; - - dprint($query); - - $this->db->query($query); - $rows=$this->db->num_rows(); - hunk ./cdrlib_ser.phtml 4366 - if ($this->db->num_rows()) { - - print " -

CDRTool SIP session trace $callid $authorize

+ $this->getTrace($callid,$fromtag,$proxyIP); hunk ./cdrlib_ser.phtml 4368 - - - - "; - if ($this->isAuthorized) { - $key="callid-".trim($callid).trim($fromtag); + if (!count($this->trace_array)) { + print "

+ SIP trace for session id $callid is not available."; + return; + } hunk ./cdrlib_ser.phtml 4374 - $query=sprintf("select * from memcache where `key` = '%s'",addslashes($key)); - dprint($query); - $this->cdrtool->query($query); + print " +

CDRTool SIP session trace $callid $authorize

hunk ./cdrlib_ser.phtml 4377 - $basicURL=$protocolURL.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; +
+ + + "; + if ($this->isAuthorized) { + $key="callid-".trim($callid).trim($fromtag); hunk ./cdrlib_ser.phtml 4384 - if ($this->cdrtool->num_rows()) { - $selected_toggleVisibility['public']="selected"; - $fullURL=$basicURL."&public=1"; - $color2="lightblue"; - } else { - $selected_toggleVisibility['private']="selected"; - $fullURL=$basicURL; - } + $query=sprintf("select * from memcache where `key` = '%s'",addslashes($key)); + dprint($query); + $this->cdrtool->query($query); hunk ./cdrlib_ser.phtml 4388 - print " - "; + if ($this->cdrtool->num_rows()) { + $selected_toggleVisibility['public']="selected"; + $fullURL=$basicURL."&public=1"; + $color2="lightblue"; hunk ./cdrlib_ser.phtml 4395 - print " - - - -
+ $basicURL=$protocolURL.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; hunk ./cdrlib_ser.phtml 4390 - Trace is visible - - - "; - print "URL for this trace"; + $selected_toggleVisibility['private']="selected"; + $fullURL=$basicURL; hunk ./cdrlib_ser.phtml 4399 + print " + hunk ./cdrlib_ser.phtml 4402 - print " - Click on each trace entry to see the full message. -
- "; - + Trace is visible + + + "; + print "
URL for this trace"; hunk ./cdrlib_ser.phtml 4411 - print "

- SIP trace for session id $callid is not available."; - return; + print ""; hunk ./cdrlib_ser.phtml 4414 - $columns=0; - - while ($this->db->next_record()) { hunk ./cdrlib_ser.phtml 4415 - if (preg_match("/^(udp|tcp|tls):(.*)$/",$this->db->f('toip'),$m)) { - $toip=$m[2]; - $protocol=$m[1]; - } - - if (!$column[$this->db->f('fromip')]) { - $column[$this->db->f('fromip')]=$columns+1; - $columns++; - } - - if (!$column[$toip]) { - $column[$toip]=$columns+1; - $columns++; - } - - $trace_array[$this->db->f('id')]= - array ( - 'id' => $this->db->f('id'), - 'direction' => $this->db->f('direction'), - 'fromip' => $this->db->f('fromip'), - 'toip' => $toip, - 'method' => $this->db->f('method'), - 'protocol' => $protocol, - 'date' => $this->db->f('date'), - 'status' => $this->db->f('status'), - 'timestamp' => $this->db->f('timestamp'), - 'msg' => $this->db->f('msg'), - 'md5' => md5($this->db->f('msg')) - ); - } + print " + + + Click on each trace entry to see the full message. + + + + "; hunk ./cdrlib_ser.phtml 4424 - foreach (array_keys($trace_array) as $key) { + foreach (array_keys($this->trace_array) as $key) { hunk ./cdrlib_ser.phtml 4426 - if ($trace_array[$key]['direction'] == 'in') { + if ($this->trace_array[$key]['direction'] == 'in') { hunk ./cdrlib_ser.phtml 4429 - $thisIP=explode(":",$trace_array[$key]['fromip']); + $thisIP=explode(":",$this->trace_array[$key]['fromip']); hunk ./cdrlib_ser.phtml 4431 - $trace_array[$key]['isProxy'] = 1; + $this->trace_array[$key]['isProxy'] = 1; hunk ./cdrlib_ser.phtml 4435 - if ($trace_array[$key]['fromip'] == $trace_array[$key]['toip']) { - $trace_array[$key]['arrow_align'] = "left"; + if ($this->trace_array[$key]['fromip'] == $this->trace_array[$key]['toip']) { + $this->trace_array[$key]['arrow_align'] = "left"; hunk ./cdrlib_ser.phtml 4438 - } else if ($column[$trace_array[$key]['fromip']] < $column[$trace_array[$key]['toip']]) { + } else if ($this->column[$this->trace_array[$key]['fromip']] < $this->column[$this->trace_array[$key]['toip']]) { hunk ./cdrlib_ser.phtml 4440 - $trace_array[$key]['arrow_align'] = "right"; + $this->trace_array[$key]['arrow_align'] = "right"; hunk ./cdrlib_ser.phtml 4443 - $trace_array[$key]['arrow_align'] = "left"; + $this->trace_array[$key]['arrow_align'] = "left"; hunk ./cdrlib_ser.phtml 4445 - $trace_array[$key]['msg_possition'] = $column[$trace_array[$key]['toip']]; - $trace_array[$key]['arrow_possition'] = $column[$trace_array[$key]['fromip']]; - $trace_array[$key]['arrow_direction'] = $arrow_direction; + $this->trace_array[$key]['msg_possition'] = $this->column[$this->trace_array[$key]['toip']]; + $this->trace_array[$key]['arrow_possition'] = $this->column[$this->trace_array[$key]['fromip']]; + $this->trace_array[$key]['arrow_direction'] = $arrow_direction; hunk ./cdrlib_ser.phtml 4450 - if ($trace_array[$key]['fromip'] == $trace_array[$key]['toip']) { - $trace_array[$key]['arrow_align'] = "left"; + if ($this->trace_array[$key]['fromip'] == $this->trace_array[$key]['toip']) { + $this->trace_array[$key]['arrow_align'] = "left"; hunk ./cdrlib_ser.phtml 4453 - } else if ($column[$trace_array[$key]['fromip']] < $column[$trace_array[$key]['toip']]) { - $trace_array[$key]['arrow_align'] = "left"; + } else if ($this->column[$this->trace_array[$key]['fromip']] < $this->column[$this->trace_array[$key]['toip']]) { + $this->trace_array[$key]['arrow_align'] = "left"; hunk ./cdrlib_ser.phtml 4457 - $trace_array[$key]['arrow_align'] = "right"; + $this->trace_array[$key]['arrow_align'] = "right"; hunk ./cdrlib_ser.phtml 4461 - $trace_array[$key]['msg_possition'] = $column[$trace_array[$key]['fromip']]; - $trace_array[$key]['arrow_possition'] = $column[$trace_array[$key]['toip']]; - $trace_array[$key]['arrow_direction'] = $arrow_direction; + $this->trace_array[$key]['msg_possition'] = $this->column[$this->trace_array[$key]['fromip']]; + $this->trace_array[$key]['arrow_possition'] = $this->column[$this->trace_array[$key]['toip']]; + $this->trace_array[$key]['arrow_direction'] = $arrow_direction; hunk ./cdrlib_ser.phtml 4467 - #print "

";
-        #print_r($trace_array);
+        //print "
";
+        //print_r($this->trace_array);
hunk ./cdrlib_ser.phtml 4479
-        foreach (array_keys($column) as $_key) {
+        foreach (array_keys($this->column) as $_key) {
hunk ./cdrlib_ser.phtml 4500
-        foreach (array_keys($trace_array) as $key) {
+        foreach (array_keys($this->trace_array) as $key) {
hunk ./cdrlib_ser.phtml 4504
-            $id        = $trace_array[$key]['id'];
-            $msg       = $trace_array[$key]['msg'];
-            $fromip    = $trace_array[$key]['fromip'];
-            $toip      = $trace_array[$key]['toip'];
-            $date      = substr($trace_array[$key]['date'],11);
-            $status    = $trace_array[$key]['status'];
-            $direction = $trace_array[$key]['direction'];
-            $timestamp = $trace_array[$key]['timestamp'];
-            $method    = $trace_array[$key]['method'];
-            $isProxy   = $trace_array[$key]['isProxy'];
+            $id        = $this->trace_array[$key]['id'];
+            $msg       = $this->trace_array[$key]['msg'];
+            $fromip    = $this->trace_array[$key]['fromip'];
+            $toip      = $this->trace_array[$key]['toip'];
+            $date      = substr($this->trace_array[$key]['date'],11);
+            $status    = $this->trace_array[$key]['status'];
+            $direction = $this->trace_array[$key]['direction'];
+            $timestamp = $this->trace_array[$key]['timestamp'];
+            $method    = $this->trace_array[$key]['method'];
+            $isProxy   = $this->trace_array[$key]['isProxy'];
hunk ./cdrlib_ser.phtml 4515
-            $msg_possition   = $trace_array[$key]['msg_possition'];
-            $arrow_possition = $trace_array[$key]['arrow_possition'];
-            $arrow_direction = $trace_array[$key]['arrow_direction'];
-            $arrow_align     = $trace_array[$key]['arrow_align'];
-            $md5             = $trace_array[$key]['md5'];
+            $msg_possition   = $this->trace_array[$key]['msg_possition'];
+            $arrow_possition = $this->trace_array[$key]['arrow_possition'];
+            $arrow_direction = $this->trace_array[$key]['arrow_direction'];
+            $arrow_align     = $this->trace_array[$key]['arrow_align'];
+            $md5             = $this->trace_array[$key]['md5'];
hunk ./cdrlib_ser.phtml 4630
-            while ($column_current <= count($column)) {
+            while ($column_current <= count($this->column)) {
hunk ./cdrlib_ser.phtml 4696
-            $trace_span=count($column)+2;
+            $trace_span=count($this->column)+2;
hunk ./debian/changelog 1
+cdrtool (5.2.2) unstable; urgency=low
+
+  * Added SIP trace for SIP Thor datasource
+
+ -- Adrian Georgescu   Thu, 19 Jul 2007 11:53:24 +0200
+
hunk ./provisioning_lib.phtml 420
+    }
+    function &getTrace($nodeIP, $callID, $fromTag) {
+        return $this->call("getTrace", 
+                        $v = array("nodeIP"=>$nodeIP, "callID"=>$callID, "fromTag"=>$fromTag), 
+                        array('namespace'=>'urn:AGProjects:NGNPro:Sip',
+                            'soapaction'=>'',
+                            'style'=>'rpc',
+                            'use'=>'encoded' ));
hunk ./setup/global.inc.in 281
+                    ),
+"sip_trace_thor"   =>array(
+                    "name"               => "SIP trace Thor",
+                    "enableThor"         => true,
+                    "soapEngineId"       => "id",   
+                    "invisible"          => 1 
hunk ./setup/global.inc.in 288
-
+                    
hunk ./sip-trace.phtml 36
+//$verbose=1;
hunk ./sip-trace.phtml 39
-$method      = $_REQUEST['method'];
-$status      = $_REQUEST['status'];
hunk ./sip-trace.phtml 40
+$proxyIP     = $_REQUEST['proxyIP'];
hunk ./sip-trace.phtml 43
-if (!$authorize || in_array($cdr_source,$CDRTool[dataSourcesAllowed])) {
+if (!$authorize || in_array($cdr_source,$CDRTool['dataSourcesAllowed'])) {
hunk ./sip-trace.phtml 48
-    $serTrace = new SER_trace($cdr_source);
-    if ($serTrace->initOK) {
-        $serTrace->show($callid,$method,$status,$fromtag);
-    }
+    $sipTrace = new SIP_trace($cdr_source);
+    $sipTrace->show($callid,$fromtag,$proxyIP);
+
hunk ./version 1
-5.2.1
+5.2.2