diff --git a/library/media_sessions.php b/library/media_sessions.php index 1f71953..4a9a564 100644 --- a/library/media_sessions.php +++ b/library/media_sessions.php @@ -1,741 +1,764 @@ dispatcher = $dispatcher; $this->filters = $filters; $this->allowedDomains = $allowedDomains; $this->getUserAgentPictures(); } public function getUserAgentPictures() { global $userAgentImages; global $userAgentImagesFile; if (!isset($userAgentImagesFile)) { $userAgentImagesFile = "phone_images.php"; } require_once($userAgentImagesFile); $this->userAgentImages = $userAgentImages; } private function connectSocket() { if (!strlen($this->dispatcher)) { return false; } if (preg_match("/^(tls|tcp):(.*):(.*)$/", $this->dispatcher, $m)) { $hostname = $m[1].'://'.$m[2]; $port = $m[3]; $target= 'tcp://'.$m[2].':'.$m[3]; $transport= $m[1]; $this->mp_tls_cert_file = '/etc/cdrtool/mediaproxy.'.$m[2].'.pem'; if ($m[1] == 'tls') { if (!file_exists($this->mp_tls_cert_file)) { printf("

Error: mediaproxy certificate file %s does not exist. \n", $this->mp_tls_cert_file); return false; } $tls_options=array('ssl' => array('local_cert' => $this->mp_tls_cert_file)); $context=stream_context_create($tls_options); } else { $context=stream_context_create(array()); } } else { printf("

Error: MediaProxy dispatcher '%s' must be in the form: tls:hostname:port or tcp:hostname:port", $this->dispatcher); return false; } if ($fp = stream_socket_client($target, $errno, $errstr, $this->timeout, STREAM_CLIENT_CONNECT, $context)) { if ($transport == "tls") { if (!stream_socket_enable_crypto($fp, true, STREAM_CRYPTO_METHOD_SSLv3_CLIENT)) { printf("

Error connecting to %s: (Could not enable crypto) \n", $target); return false; } } return $fp; } else { printf("

Error connecting to %s: %s (%s) \n", $target, $errstr, $errno); return false; } } public function fetchSessionFromNetwork() { // get sessions from MediaProxy2 dispatcher if (!$fp = $this->connectSocket()) { return array(); } fputs($fp, "sessions\r\n"); $line = fgets($fp); return json_decode($line); } public function fetchSummaryFromNetwork() { // get summary from MediaProxy2 dispatcher if (count($this->allowedDomains)) { return array(); } if (!$fp = $this->connectSocket()) { return array(); } fwrite($fp, "summary\r\n"); $line = fgets($fp); fclose($fp); return json_decode($line, true); } public function getSessions() { $_sessions = $this->fetchSessionFromNetwork(); if (count($this->allowedDomains)) { $this->domain_statistics['total'] = array( 'sessions' => 0, 'caller' => 0, 'callee' => 0 ); + foreach ($_sessions as $_session) { list($user1, $domain1) = explode("@", $_session->from_uri); list($user2, $domain2) = explode("@", $_session->to_uri); if (preg_match("/^(.*):/", $domain1, $m)) { $domain1 = $m[1]; } - if (!in_array($domain1, $this->allowedDomains) && !in_array($domain2, $this->allowedDomains)) { + $may_display = false; + foreach ($this->allowedDomains as $allow_domain) { + if ($this->endsWith($domain1, $allow_domain)) { + $may_display = true; + break; + } + if ($this->endsWith($domain2, $allow_domain)) { + $may_display = true; + break; + } + } + if (!$may_display) { continue; } if (!array_key_exists($domain1, $this->domain_statistics)) { $this->domain_statistics[$domain1] = array( 'sessions' => 0, 'caller' => 0, 'callee' => 0 ); } $this->domain_statistics[$domain1]['sessions']++; $this->domain_statistics['total']['sessions']++; foreach ($_session->streams as $streamInfo) { list($relay_ip, $relay_port) = explode(":", $streamInfo->caller_local); $_relay_statistics[$relay_ip]['stream_count'][$streamInfo->media_type]++; if ($_session->duration) { $session_bps =($streamInfo->caller_bytes + $streamInfo->callee_bytes) / $_session->duration * 8; $_relay_statistics[$relay_ip]['bps_relayed'] = $_relay_statistics[$relay_ip]['bps_relayed'] + $session_bps; } $this->domain_statistics[$domain1]['caller'] = $this->domain_statistics[$domain1]['caller'] + intval($streamInfo->caller_bytes / $_session->duration * 2); $this->domain_statistics['total']['caller'] = $this->domain_statistics['total']['caller'] + intval($streamInfo->caller_bytes / $_session->duration * 2); $this->domain_statistics[$domain1]['callee'] = $this->domain_statistics[$domain1]['callee'] + intval($streamInfo->callee_bytes / $_session->duration * 2); $this->domain_statistics['total']['callee'] = $this->domain_statistics['total']['callee'] + intval($streamInfo->callee_bytes/$_session->duration * 2); } $_relay_statistics[$relay_ip]['session_count']++; $_sessions2[] = $_session; } } else { $this->domain_statistics['total'] = array( 'sessions' => 0, 'caller' => 0, 'callee' => 0 ); foreach ($_sessions as $_session) { list($user1, $domain1) = explode("@", $_session->from_uri); list($user2, $domain2) = explode("@", $_session->to_uri); if (preg_match("/^(.*):/", $domain1, $m)) { $domain1=$m[1]; } if (!array_key_exists($domain1, $this->domain_statistics)) { $this->domain_statistics[$domain1]= array( 'sessions' => 0, 'caller' => 0, 'callee' => 0 ); } $this->domain_statistics[$domain1]['sessions']++; $this->domain_statistics['total']['sessions']++; foreach ($_session->streams as $streamInfo) { if ($_session->duration) { $this->domain_statistics[$domain1]['caller'] = $this->domain_statistics[$domain1]['caller']+intval($streamInfo->caller_bytes/$_session->duration*2); $this->domain_statistics['total']['caller'] = $this->domain_statistics['total']['caller']+intval($streamInfo->caller_bytes/$_session->duration*2); $this->domain_statistics[$domain1]['callee'] = $this->domain_statistics[$domain1]['callee']+intval($streamInfo->callee_bytes/$_session->duration*2); $this->domain_statistics['total']['callee'] = $this->domain_statistics['total']['callee']+intval($streamInfo->callee_bytes/$_session->duration*2); } } } $_sessions2 = $_sessions; } if (count($this->allowedDomains)) { foreach (array_keys($_relay_statistics) as $_ip) { $this->relay_statistics[]=array('ip' => $_ip, 'bps_relayed' => $_relay_statistics[$_ip]['bps_relayed'], 'session_count' => $_relay_statistics[$_ip]['session_count'], 'stream_count' => $_relay_statistics[$_ip]['stream_count'], 'status' => 'ok', 'uptime' => 'unknown' ); } } if (strlen($this->filters['user'])) { foreach ($_sessions2 as $_session) { $user=$this->filters['user']; if (preg_match("/$user/", $_session->from_uri) || preg_match("/$user/", $_session->to_uri)) { $this->sessions[] = $_session; } } } else { $this->sessions = $_sessions2; } } public function getSummary() { if (count($this->allowedDomains)) { if (is_array($this->relay_statistics)) { $this->summary = $this->relay_statistics; } } else { $this->summary = $this->fetchSummaryFromNetwork(); } } public function showSearch() { printf( "

", $_SERVER['PHP_SELF'], isset($_REQUEST['user']) ? $_REQUEST['user'] : '' ); print ""; } public function showHeader() { print " Media sessions "; } public function showFooter() { } public function showAll() { $this->showHeader(); - $this->showSummary(); + if (!$this->allowedDomains) { + $this->showSummary(); + } $this->showSearch(); $this->showSessions(); $this->showFooter(); } public function showSummary() { $this->getSummary(); if (!count($this->summary)) { return; } if (count($this->allowedDomains)) { print "
"; } else { print "
Address Relayed traffic Sessions Streams Status
"; } $i = 1; foreach ($this->summary as $relay) { unset($media_types); unset($streams); $streams = ''; $media_types=count($relay['stream_count']); if ($media_types > 1) { foreach (array_keys($relay['stream_count']) as $key) { $streams .= sprintf("%s %s, ", $key, $relay['stream_count'][$key]); } $streams=chop($streams, ', '); } else { foreach (array_keys($relay['stream_count']) as $key) { $streams=sprintf("%s %s", $key, $relay['stream_count'][$key]); } } $rClass= 'label-success'; if ($relay['status'] == 'halting') { $rClass = 'label-warning'; } $relayStatus = sprintf("%s", $rClass, ucfirst($relay['status'])); if (count($this->allowedDomains)) { printf( " ", $i, $this->ip2host($relay['ip']), $this->normalizeTraffic($relay['bps_relayed']), $relay['session_count'], $streams, $relayStatus ); } else { printf( " ", $i, $this->ip2host($relay['ip']), $relay['version'], $this->normalizeTime($relay['uptime']), $this->normalizeTraffic($relay['bps_relayed']), $relay['session_count'], $streams, $relayStatus ); } $i++; } print "
Address Version Uptime Relayed traffic Sessions Streams Status
%d %s %s %d %s %s
%d %s %s %s %s %d %s %s
"; } public function showSessions() { print "

Sessions

"; if (!count($this->sessions)) { return; } print " "; $i = 1; foreach ($this->sessions as $session) { $from = $session->from_uri; $to = $session->to_uri; $fromAgent = $session->caller_ua; $toAgent = $session->callee_ua; $fromImage = $this->getImageForUserAgent($fromAgent); $toImage = $this->getImageForUserAgent($toAgent); $sc = count($session->streams); print " "; $duration = $this->normalizeTime($session->duration); if (count($session->streams) > 0) { foreach ($session->streams as $streamInfo) { $status = $streamInfo->status; $statusClass = ""; if ($status=="idle" || $status=='hold') { $idletime = $this->normalizeTime($streamInfo->timeout_wait); $status = sprintf("%s %s", $status, $idletime); } else if ($status == "closed") { $statusClass = "muted"; } $caller = $streamInfo->caller_remote; $callee = $streamInfo->callee_remote; $relay_caller = $streamInfo->caller_local; $relay_callee = $streamInfo->callee_local; if (substr_count($relay_caller, ":") == 1) { // Probaly ipv4 $relay_caller_data = explode(":", $relay_caller); $relay_caller = $this->ip2host($relay_caller_data[0]).":".$relay_caller_data[1]; } if (substr_count($relay_callee, ":") == 1) { // Probaly ipv4 $relay_callee_data = explode(":", $relay_callee); $relay_callee = $this->ip2host($relay_callee_data[0]).":".$relay_callee_data[1]; } $codec = $streamInfo->caller_codec; $type = $streamInfo->media_type; if ($caller == '?.?.?.?:?') { $caller = '–'; // a dash $align1 = 'center'; } else { $align1 = 'left'; } if ($callee == '?.?.?.?:?') { $callee = '–'; // a dash $align2 = 'center'; } else { $align2 = 'left'; } if ($codec == 'Unknown') { $codec = '–'; // a dash } else { $codec = "$codec"; } if ($type == 'Unknown') { $type = '–'; // a dash } else if ($type == 'video') { $type = "$type"; } else if ($type == 'audio') { $type = "$type"; } else { $type = "$type"; } $bytes_in1 = $this->normalizeBytes($streamInfo->caller_bytes); $bytes_in2 = $this->normalizeBytes($streamInfo->callee_bytes); print " "; } } else { print ""; } $i++; } print "
Callers (".count($this->sessions).") Phones Media Streams
Caller address Relay caller Relay callee Callee address Status Type/Codec Duration Bytes
Caller
Bytes
Called
From: $from
To: $to
"; if ($fromImage == 'unknown.png') { print ""; } else if ($fromImage == 'asterisk.png') { print ""; } else { print " \"$fromAgent\""; } print " "; if ($toImage == 'unknown.png') { print ""; } else if ($toImage == 'asterisk.png') { print ""; } else { print " \"$toAgent\""; } print "$caller $relay_caller $relay_callee $callee $status $type $codec $duration $bytes_in1 $bytes_in2
 

"; } private function normalizeBytes($bytes) { $mb = $bytes /1024 /1024.0; $kb = $bytes /1024.0; if ($mb >= 0.95) { return sprintf("%.2fM", $mb); } else if ($kb >= 1) { return sprintf("%.2fk", $kb); } else { return sprintf("%d", $bytes); } } private function normalizeTime($period) { $sec = $period % 60; $min = floor($period / 60); $h = floor($min / 60); $d = floor($h / 24); $min = $min % 60; $h = $h % 24; if ($d >= 1) { return sprintf('%dd %dh %02d\' %02d"', $d, $h, $min, $sec); } else if ($h >= 1) { return sprintf('%dh %02d\' %02d"', $h, $min, $sec); } else { return sprintf('%d\' %02d"', $min, $sec); } } private function normalizeTraffic($traffic) { // input is in bits/second $mb = $traffic / 1024 / 1024.0; $gb = $traffic/ 1024 / 1024 / 1024; $kb = $traffic / 1024.0; if ($gb >= 0.95) { return sprintf("%.2f Gbit/s", $gb); } else if ($mb >= 0.95) { return sprintf("%.2f Mbit/s", $mb); } else if ($kb >= 1) { return sprintf("%.2f Kbit/s", $kb); } else if ($traffic == 0) { return $traffic; } else { return sprintf("%d bit/s", $traffic); } } public function getImageForUserAgent($agent) { foreach ($this->userAgentImages as $agentRegexp => $image) { if (preg_match("/$agentRegexp/i", $agent)) { return $image; } } return "unknown.png"; } public function ip2host($ip) { return $ip; } } class MediaSessionsNGNPro extends MediaSessions { // get Media session from NGNPro public function MediaSessionsNGNPro($engineId, $allowedDomains=array(), $filters=array()) { if (!strlen($engineId)) { return false; } $this->soapEngineId = $engineId; $this->filters = $filters; $this->allowedDomains = $allowedDomains; $this->getUserAgentPictures(); require("/etc/cdrtool/ngnpro_engines.inc"); require_once("ngnpro_soap_library.php"); if (!strlen($this->soapEngineId)) { return false; } if (!$soapEngines[$this->soapEngineId]) { return false; } $this->SOAPlogin = array( "username" => $soapEngines[$this->soapEngineId]['username'], "password" => $soapEngines[$this->soapEngineId]['password'], "admin" => true ); $this->SOAPurl=$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); if (is_array($soapEngines[$this->soapEngineId]['hostnames'])) { $this->hostnames=$soapEngines[$this->soapEngineId]['hostnames']; } else { $this->hostnames=array(); } } public function fetchSessionFromNetwork() { if (!is_object($this->soapclient)) { return false; } $this->soapclient->addHeader($this->SoapAuth); $result = $this->soapclient->getMediaSessions(); if ((new PEAR)->isError($result)) { $error_msg = $result->getMessage(); $error_fault = $result->getFault(); $error_code = $result->getCode(); printf("Error from %s: %s: %s", $this->SOAPurl, $error_fault->detail->exception->errorcode, $error_fault->detail->exception->errorstring); return false; } return json_decode($result); } public function fetchSummaryFromNetwork() { if (!is_object($this->soapclient)) { return array(); } $this->soapclient->addHeader($this->SoapAuth); $result = $this->soapclient->getMediaSummary(); if ((new PEAR)->isError($result)) { $error_msg = $result->getMessage(); $error_fault = $result->getFault(); $error_code = $result->getCode(); printf("Error from %s: %s: %s", $this->SOAPurl, $error_fault->detail->exception->errorcode, $error_fault->detail->exception->errorstring); return array(); } return json_decode($result, true); } public function ip2host($ip) { if ($this->hostnames[$ip]) { return $this->hostnames[$ip]; } else { return $ip; } } + + public function endsWith($string, $endString) + { + $len = strlen($endString); + if ($len == 0) { + return true; + } + return (substr($string, -$len) === $endString); + } } ?> diff --git a/network_status.phtml b/network_status.phtml index a8321a0..bf6db5f 100644 --- a/network_status.phtml +++ b/network_status.phtml @@ -1,86 +1,86 @@ "CDRTool_Session", "auth" => "CDRTool_Auth", "perm" => "CDRTool_Perm" ) ); require("sip_statistics.php"); require("media_sessions.php"); -$perm->check("statistics"); +$perm->check("admin"); $title = "SIP network status"; include("header.phtml"); global $CDRTool; $allowedDomains = array(); if (strlen($CDRTool['filter']['domain'])) { $allowedDomains = explode(' ', $CDRTool['filter']['domain']); } $layout = new pageLayoutLocal(); $layout->showTopMenu($title); foreach (array_keys($DATASOURCES) as $datasource) { print "
"; if (in_array($datasource, $CDRTool['dataSourcesAllowed']) && !$DATASOURCES[$datasource]['invisible']) { if ($DATASOURCES[$datasource]['networkStatus']) { print "
"; printf("

%s

", $DATASOURCES[$datasource]['name']); $SipThorNetworkImage = new SipThorNetworkImage($DATASOURCES[$datasource]['networkStatus'], $allowedDomains); //printf ("",$DATASOURCES[$datasource]['networkStatus']); print "
"; print "
"; print "
"; } else if ($DATASOURCES[$datasource]['db_registrar']) { print "
"; printf("

%s

", $DATASOURCES[$datasource]['name']); require_once("cdr_generic.php"); $online = new SIPonline($datasource, $DATASOURCES[$datasource]['db_registrar']); $online->showAll(); print "
"; print "
"; } if (array_key_exists('mediaSessions', $DATASOURCES[$datasource])) { $MediaSessions = new MediaSessionsNGNPro($DATASOURCES[$datasource]['mediaSessions'], $allowedDomains); $MediaSessions->getSessions(); $MediaSessions->getSummary(); print "

Media relays

"; $MediaSessions->showSummary(); } else if (array_key_exists('mediaDispatcher', $DATASOURCES[$datasource])) { $MediaSessions = new MediaSessions($DATASOURCES[$datasource]['mediaDispatcher'], $allowedDomains); $MediaSessions->getSessions(); $MediaSessions->getSummary(); print "

Media relays

"; $MediaSessions->showSummary(); } if (array_key_exists('networkStatus', $DATASOURCES[$datasource])) { $NetworkStatistics = new NetworkStatistics($DATASOURCES[$datasource]['networkStatus'], $allowedDomains); print "

SIP accounts

"; $NetworkStatistics->showStatistics(); print "

Network topology

"; $NetworkStatistics->showStatus(); } print "
"; } print "
"; } $layout->showFooter(); print " "; page_close(); ?> diff --git a/phplib/local.inc b/phplib/local.inc index d7fc85f..2e7f432 100644 --- a/phplib/local.inc +++ b/phplib/local.inc @@ -1,1618 +1,1618 @@ register("challenge"); if (!$challenge) { $challenge = md5(uniqid($this->magic)); } $query=sprintf("select * from spam where ip = '%s'", addslashes($_SERVER['REMOTE_ADDR'])); $this->db->query($query); if ($this->db->num_rows()) { $this->db->next_record(); $spam_login_ip = $this->db->f('ip'); $spam_login_tries = $this->db->f('tries'); $spam_login_stamp = $this->db->f('stamp'); $next_try = $spam_login_stamp+120; $remains = $next_try-time(); $next_try = Date("Y-m-d H:i:s", $next_try); $now = Date("Y-m-d H:i:s", time()); } if ($remains < 0) { $query=sprintf("delete from spam where ip = '%s'", addslashes($spam_login_ip)); if ($this->db->query($query)) { unset($spam_login_tries); } } if ($spam_login_tries < $max_login_attempts) { $title="Login"; if (is_readable("/etc/cdrtool/local/header.phtml")) { include("/etc/cdrtool/local/header.phtml"); } else { include("$CDRTool[Path]/header.phtml"); } $layout = new pageLayoutLocal(); $layout->showLoginForm($this); $layout->showFooter(); } else { if ($spam_login_tries == $max_login_attempts) { $log_time=Date("Y-m-d H:i:s", time()); $log_query=sprintf( "insert into log (date,login,ip,description,results) values ('%s','%s','%s','%s attempts to wrong login', 'IP blocked until %s')", addslashes($log_time), addslashes($username), addslashes($_SERVER['REMOTE_ADDR']), addslashes($spam_login_tries), addslashes($next_try) ); $this->db->query($log_query); } $new_stamp=time(); $query=sprintf( "update spam set tries = tries + 1 where ip = '%s' ", addslashes($_SERVER['REMOTE_ADDR']) ); $this->db->query($query); print "

The current time on this system is $now.

Too many wrong attempts to login, wait until $next_try (over $remains seconds) and try again.

If you forgot your password please contact your system administrator for obtaining a new one.

"; exit; } } function auth_validatelogin() { global $d_cli, $d_card, $prepaid_login, $cust_form, $codeFilter, $aNumberFilter,$login_for; global $CDRTool; global $otp_error, $otpasswd; global $verbose; global $DATASOURCES; $username = isset($_POST["username"]) ? $_POST["username"] : ''; $sendotp = isset($_POST["sendotp"]) ? $_POST["sendotp"] : ''; $password = isset($_POST["password"]) ? $_POST["password"] : ''; $challenge = isset($_POST["challenge"]) ? $_POST["challenge"] : ''; $response = isset($_POST["response"]) ? $_POST["response"] : ''; $response_ha1 = isset($_POST["response_ha1"]) ? $_POST["response_ha1"] : ''; $REMOTE_ADDR = $_SERVER["REMOTE_ADDR"]; //dprint_r("response: $response"); $otp_yubikey = isset($_POST["yubikey"]) ? $_POST["yubikey"] : ''; $yubi_id = substr($otp_yubikey, 0, 12); $use_yubikey=0; if (stream_resolve_include_path('Auth/Yubico.php')) { require_once 'Auth/Yubico.php'; $use_yubikey=1; } else { require_once 'PEAR.php'; } if ($username) { $this->auth["uname"]=$username; ## This provides access for "loginform.ihtml" } $uid = false; if ($username || $use_yubikey ) { $username = trim($username); if (preg_match ("/\@/",$username)) { $a = explode("@", $username); $domainAuth = new DomainAuthLocal(); $ret=$domainAuth->validate($a[0], $a[1], $password, $response_ha1, $otp_yubikey); //dprint("here"); //dprint_r($ret); if ($ret[0]) { foreach ($ret[2] as $allowedDS) { $CDRTool[dataSourcesAllowed][]=$allowedDS; } if ($ret[1] == "subscriber") { $CDRTool[filter][aNumber] = $username; $this->auth["perm"] = "callsearch,statistics,showPrice,showCallerId"; } else { $CDRTool[filter][domain] = $a[1]; $this->auth["perm"] = "callsearch,statistics,showPrice,showCallerId"; } } return $ret[0]; } else { $query = sprintf( "select * from auth_user where (username = '%s' or (yubikey='%s' and yubikey !='')) and expire > NOW()", addslashes($username), addslashes($yubi_id) ); $this->db->query($query); $this->db->next_record(); $otp_enabled_db = $this->db->f('otp_enable'); $otp_email = $this->db->f('email'); $otp_tel = $this->db->f('tel'); $otp_passwd = $this->db->f('otp_passwd'); $otp_passwd_md5 = md5($this->db->f('otp_passwd')); if ($sendotp) { if ($otp_email || $otp_tel) { $interval="15"; print "

Sending OneTimePassword "; $random_otp = random_passwd_gen(); $expire_otp = date("Y-m-d H:i:s", mktime(date("H"), date("i") + $interval, 0, date("m") ,date("d"), date("Y"))); $update = sprintf( "UPDATE auth_user SET otp_passwd='%s', otp_expire = '%s' WHERE username = '%s'", addslashes($random_otp), addslashes($expire_otp), addslashes($username) ); if ($this->db->query($update)) { if ($otp_email) { $body=sprintf("%s valid until %s CET (GMT+1) requested from %s", $random_otp, $expire_otp, $_SERVER['REMOTE_ADDR']); mail($otp_email, "OTP for CDRTool", $body, "From: support@ag-projects.com"); } if ($otp_tel) { $body = sprintf("Password is %s valid until %s CET (GMT+1) from %s", $random_otp, $expire_otp, $_SERVER['REMOTE_ADDR']); $otp_tel=preg_replace("/[^0-9+]/", "", $otp_tel); otp_sms($otp_tel, $body, "1"); } print "

Password will expire at: $expire_otp (in $interval minutes)

"; } } else { print "

No OTP recipient exists for this account. "; } } $this->db->query( sprintf( "SELECT *,UNIX_TIMESTAMP(otp_expire) as timestamp_otp, UNIX_TIMESTAMP() as timestamp_now FROM %s WHERE (username = '%s' OR (yubikey='%s' AND yubikey != '')) AND expire > NOW()", addslashes($this->database_table), addslashes($username), addslashes($yubi_id) ) ); $this->db->next_record(); $uid = $this->db->f("user_id"); $perm = $this->db->f("perms"); $yubikey = $this->db->f("yubikey"); $auth_method = $this->db->f("auth_method"); $user_db = $this->db->f("username"); $aclFilter = array(); foreach (explode(" ", $this->db->f("aclFilter")) as $ip) { $ip = trim($ip); if ($ip) { $aclFilter[] = $ip; } } $acl_filter = false; if ($aclFilter) { $acl_filter = true; foreach ($aclFilter as $f) { if (startsWith($_SERVER['REMOTE_ADDR'], $f)) { $acl_filter = false; break; } } } if ($acl_filter) { $log = sprintf("CDRTool login with username %s using method %s from IP %s denied by ACL", $username, $auth_method, $_SERVER['REMOTE_ADDR']); syslog(LOG_NOTICE, $log); return false; } if ($CDRTool['provider']['clear_text_passwords'] != 1) { // Update hashed pass if none set and we need hashed ones if ($this->db->f("password_hashed") == '' && $this->db->f("password") != '') { $newpassmd5=md5($this->db->f("password")); $this->db->query( sprintf( "UPDATE %s SET password_hashed='%s', password='' WHERE username='%s'", addslashes($this->database_table), addslashes($newpassmd5), addslashes($username) ) ); $pass = $newpassmd5; $pass_md5 = $newpassmd5; } else { $pass = $this->db->f("password_hashed"); $pass_md5 = $this->db->f("password_hashed"); } } else { $pass = $this->db->f("password"); $pass_md5 = md5($this->db->f("password")); } $otp_passwd = $this->db->f("otp_passwd"); if (strlen($this->db->f('otp_passwd'))) { $otp_passwd_md5 = md5($this->db->f('otp_passwd')); } else { $otp_passwd_md5 = "garbage"; } $timestamp_otp = $this->db->f("timestamp_otp"); $timestamp_now = $this->db->f("timestamp_now"); $CDRTool['loginName'] = $this->db->f("name"); $CDRTool['loginEmail'] = $this->db->f("email"); $_dataSourcesAllowed = explode(",", $this->db->f("sources")); $_datasourceDefined = array_keys($DATASOURCES); $CDRTool['dataSourcesAllowed'] = array_intersect($_dataSourcesAllowed, $_datasourceDefined); // limits per CDRTool login account $CDRTool['filter']['user_id'] = $this->db->f("user_id"); $CDRTool['filter']['aNumber'] = $this->db->f('aNumberFilter'); $CDRTool['filter']['displayA'] = $this->db->f('display_cli'); $CDRTool['filter']['domain'] = $this->db->f('domainFilter'); $CDRTool['filter']['gateway'] = $this->db->f('gatewayFilter'); $CDRTool['filter']['compid'] = $this->db->f('compidFilter'); $CDRTool['filter']['cscode'] = $this->db->f('cscodeFilter'); if (preg_match("/^(\d+)\.(\d+)$/", $this->db->f('impersonate'), $m)) { $CDRTool['filter']['customer'] = $m[1]; $CDRTool['filter']['reseller'] = $m[2]; } else if (preg_match("/^(\d+)$/", $this->db->f('impersonate'), $m)) { $CDRTool['filter']['customer'] = $m[1]; $CDRTool['filter']['reseller'] = $m[1]; } else { $CDRTool['filter']['customer'] = ''; $CDRTool['filter']['reseller'] = ''; } $CDRTool['impersonate'] = $this->db->f('impersonate'); if ($this->db->f('afterDateFilter') && $this->db->f('afterDateFilter') != "0000-00-00") { $CDRTool['filter']['after_date']=$this->db->f('afterDateFilter'); } if ($CDRTool['filter']['customer']) { // get soap credentials from NGNPro database global $soapEngines ; require_once('SOAP/Client.php'); require("/etc/cdrtool/ngnpro_engines.inc"); require_once("ngnpro_soap_library.php"); $this->SOAPlogin=array( "username" => $soapEngines[$CDRTool['ngnpro_reseller_engine']]['username'], "password" => $soapEngines[$CDRTool['ngnpro_reseller_engine']]['password'], "admin" => true ); $this->SoapAuth = array('auth', $this->SOAPlogin , 'urn:AGProjects:NGNPro', 0, ''); $this->CustomerPort = new WebService_NGNPro_CustomerPort($soapEngines[$CDRTool['ngnpro_reseller_engine']]['url']); $this->CustomerPort->setOpt('curl', CURLOPT_TIMEOUT, 5); $this->CustomerPort->setOpt('curl', CURLOPT_SSL_VERIFYPEER, 0); $this->CustomerPort->setOpt('curl', CURLOPT_SSL_VERIFYHOST, 0); $filter = array('customer' => intval($CDRTool['filter']['customer'])); $range = array('start' => 0,'count' => 1); $orderBy = array('attribute' => 'customer', 'direction' => 'ASC'); $Query=array('filter' => $filter,'orderBy' => $orderBy,'range' => $range); // Call function $this->CustomerPort->addHeader($this->SoapAuth); $result = $this->CustomerPort->getCustomers($Query); if ((new PEAR)->isError($result)) { $error_msg = $result->getMessage(); $error_fault= $result->getFault(); $error_code = $result->getCode(); $log = sprintf( "SOAP request error from %s: %s (%s): %s", $this->SoapEngine->SOAPurl, $error_msg, $error_fault->detail->exception->errorcode, $error_fault->detail->exception->errorstring ); syslog(LOG_NOTICE, $log); } else { if (count($result->accounts) == 1) { if ($result->accounts[0]->impersonate) { // get the credentials of the impersonate field $filter = array('customer' => intval($result->accounts[0]->impersonate), 'reseller' => intval($result->accounts[0]->reseller)); $range = array('start' => 0,'count' => 1); $orderBy = array('attribute' => 'customer', 'direction' => 'ASC'); $Query=array('filter' => $filter,'orderBy' => $orderBy,'range' => $range); // Call function $this->CustomerPort->addHeader($this->SoapAuth); $result = $this->CustomerPort->getCustomers($Query); if ((new PEAR)->isError($result)) { $error_msg = $result->getMessage(); $error_fault= $result->getFault(); $error_code = $result->getCode(); $log = sprintf( "SOAP request error from %s: %s (%s): %s", $this->SoapEngine->SOAPurl, $error_msg, $error_fault->detail->exception->errorcode, $error_fault->detail->exception->errorstring ); syslog(LOG_NOTICE, $log); } else { if (count($result->accounts) == 1) { $CDRTool["soap_username"] = $result->accounts[0]->username; $CDRTool["soap_password"] = $result->accounts[0]->password; } else { print "

Error retrieving customer data from the provisioning server, there is no such impersonate id. "; } } } else { $CDRTool["soap_username"] = $result->accounts[0]->username; $CDRTool["soap_password"] = $result->accounts[0]->password; } } else { print "

Error retrieving customer data from the provisioning server, there is no such customer id. "; } } } $expected_response = md5("$username:$pass_md5:$challenge"); $expect_otp=md5("$username:$otp_passwd_md5:$challenge"); if ($use_yubikey == 1) { $yubi = new Auth_Yubico('11334', 'NDSXQN1QpwUvqtR5v5sYbwhPQ70='); $auth = $yubi->verify($otp_yubikey); } //print_r($result); ## True when JS is disabled if ($response == "") { if ($CDRTool['provider']['clear_text_passwords']!= 1) { $password=md5($password); } if ($password == $pass || (!(new PEAR)->isError($auth) && $yubikey == $yubi_id && $username == $user_db && $expected_response == $response && $auth_method=='7' && $use_yubikey) || (!(new PEAR)->isError($auth) && $yubikey == $yubi_id && $username == $user_db && $auth_method=='5' && $use_yubikey) || (!(new PEAR)->isError($auth) && $auth_method =='4' && $use_yubikey) || ($password == $otp_passwd && $timestamp_otp > $timestamp_now) ) { $log=sprintf("CDRTool login with username %s using method %s from IP %s", $username, $auth_method, $_SERVER['REMOTE_ADDR']); syslog(LOG_NOTICE, $log); if ($this->db->f("yubikey") == '' && $otp_yubikey != '') { $this->db->query( sprintf( "UPDATE %s SET yubikey='%s' WHERE username='%s'", addslashes($this->database_table), addslashes($otp_yubikey), addslashes($username) ) ); } $this->auth["perm"] = $perm; return $uid; } else { return false; } } else { ## Response is set, JS is enabled // we check if either otp or normal password match //print "

$response == $expected_response

$response == $expect_otp"; if ($expected_response == $response || (!(new PEAR)->isError($auth) && $yubikey == $yubi_id && $username == $user_db && $expected_response == $response && $auth_method=='7' && $use_yubikey) || (!(new PEAR)->isError($auth) && $yubikey == $yubi_id && $username == $user_db && $auth_method=='5' && $use_yubikey) || (!(new PEAR)->isError($auth) && $auth_method =='4' && $use_yubikey) || ($response == $expect_otp && $timestamp_otp > $timestamp_now) ) { $log=sprintf("CDRTool login with username %s using method %s from IP %s", $username, $auth_method, $_SERVER['REMOTE_ADDR']); syslog(LOG_NOTICE, $log); if ($this->db->f("yubikey") == '' && $otp_yubikey != '') { $this->db->query( sprintf( "UPDATE %s SET yubikey='%s' WHERE username='%s'", addslashes($this->database_table), addslashes($otp_yubikey), addslashes($username) ) ); } $this->auth["perm"] = $perm; return $uid; } else { return false; } } } } else { if ($use_yubikey == 1){ $yubi = new Auth_Yubico('11334', 'NDSXQN1QpwUvqtR5v5sYbwhPQ70='); $auth = $yubi->verify($otp_yubikey); $yubi_id = substr($otp_yubikey, 0, 12); if (!(new PEAR)->isError($auth)) { $this->db->query( sprintf( "SELECT *,UNIX_TIMESTAMP(otp_expire) as timestamp_otp, UNIX_TIMESTAMP() as timestamp_now FROM %s WHERE yubikey = '%s' AND expire > NOW()", addslashes($this->database_table), addslashes($yubi_id) ) ); $this->db->next_record(); $username = $this->db->f("username"); $this->auth["uname"]=$username; $uid = $this->db->f("user_id"); $perm = $this->db->f("perms"); $auth_method = $this->db->f("auth_method"); $log=sprintf("CDRTool login with username %s using method %s from IP %s", $username, $auth_method, $_SERVER['REMOTE_ADDR']); syslog(LOG_NOTICE, $log); $this->auth["perm"] = $perm; return $uid; } } } } } class CDRTool_Perm extends Perm { public $classname = "CDRTool_Perm"; public $permissions = array( "admin" => 1, "callsearch" => 2, "statistics" => 4, "sqlquery" => 8, "soapclient" => 16, "rates" => 32, "showCallerId" => 64, "showPrice" => 128, "provisioning" => 256, - "readonly" => 512 + "readonly" => 512, + "sessions" => 1024 ); function perm_invalid($does_have, $must_have) { global $perm, $auth, $sess; global $_PHPLIB; include($_PHPLIB["libdir"] . "perminvalid.phtml"); } } class SIP_Subscriber_Session extends Session { public $classname = "SIP_Subscriber_Session"; public $auto_init = "SIP_setup.inc"; public $cookiename = "SIPCookie2"; ## defaults to classname public $magic = "3333jhjjjss13"; ## ID seed public $mode = "cookie"; ## We propagate session IDs with cookies public $fallback_mode = "get"; public $allowcache = "public"; public $lifetime = 0; ## 0 = do session cookies, else minutes public $that_class = "CDRTool_CT_Sql"; ## name of data storage container public $gc_probability = 5; } class SIP_Subscriber_Auth extends Auth { // use this auth for SIP accounts public $classname = "SIP_Subscriber_Auth"; public $lifetime = 0; public $magic = "d66mmmg111dsgzz"; ## Challenge seed function auth_loginform() { global $sess; global $max_login_attempts; $username = $_POST["username"]; $password = $_POST["password"]; $challenge = $_POST["challenge"]; $step = $_POST["step"]; $REMOTE_ADDR = $_SERVER["REMOTE_ADDR"]; $yubikey_p = $_POST['yubikey']; $sess->register("challenge"); if (!$challenge) { $challenge = md5(uniqid($this->magic)); } include("sip_login.phtml"); } function auth_validatelogin() { global $SIP; $username = isset($_POST["username"]) ? $_POST["username"] : ''; $password = isset($_POST["password"]) ? $_POST["password"] : ''; $challenge = isset($_POST["challenge"]) ? $_POST["challenge"] : ''; $response = isset($_POST["response"]) ? $_POST["response"] : ''; $response_ha1= isset($_POST["response_ha1"]) ? $_POST["response_ha1"] : ''; $yubikey_p = isset($_POST['yubikey']) ? $_POST['yubikey'] : ''; $use_yubikey = 0; if (stream_resolve_include_path('Auth/Yubico.php')) { require_once 'Auth/Yubico.php'; $use_yubikey=1; } else { require_once 'PEAR.php'; } if ($username) { $this->auth["uname"]=$username; } $a = explode("@", $username); $domain = $a[1]; if (count($a) != 2) { return false; } global $domainFilters, $resellerFilters, $soapEngines ; require_once('SOAP/Client.php'); require("/etc/cdrtool/ngnpro_engines.inc"); require_once("ngnpro_soap_library.php"); $SIP['account'] = $username; if ($domainFilters[$domain]['sip_engine']) { $SIP['engine'] = $domainFilters[$domain]['sip_engine']; } else if ($domainFilters['default']['sip_engine']) { $SIP['engine']=$domainFilters['default']['sip_engine']; } else { print "Error: cannot authenticate SIP subscriber, no domainFilter defined in ngnpro_engines.inc"; return false; } $this->SOAPlogin=array( "username" => $soapEngines[$SIP['engine']]['username'], "password" => $soapEngines[$SIP['engine']]['password'], "admin" => true ); $this->SoapAuth = array('auth', $this->SOAPlogin , 'urn:AGProjects:NGNPro', 0, ''); $this->SipPort = new WebService_NGNPro_SipPort($soapEngines[$SIP['engine']]['url']); $this->SipPort->setOpt('curl', CURLOPT_TIMEOUT, 5); $this->SipPort->setOpt('curl', CURLOPT_SSL_VERIFYPEER, 0); $this->SipPort->setOpt('curl', CURLOPT_SSL_VERIFYHOST, 0); $this->SipPort->addHeader($this->SoapAuth); $result = $this->SipPort->getAccount(array("username" =>$a[0],"domain" =>$domain)); if ((new PEAR)->isError($result)) { $error_msg = $result->getMessage(); $error_fault= $result->getFault(); $error_code = $result->getCode(); $log = printf( "SOAP error from %s (SipPort): %s (%s): %s", $soapEngines[$SIP['engine']]['url'], $error_msg, $error_fault->detail->exception->errorcode, $error_fault->detail->exception->errorstring ); syslog(LOG_NOTICE, $log); return false; } //dprint_r($result->properties); $web_password=''; foreach ($result->properties as $_property) { if ($_property->name == 'web_password') { $web_password=$_property->value; break; } if ($_property->name == 'yubikey') { $yubikey=$_property->value; break; } } if (!$web_password) $web_password=$result->password; $pass_md5 = md5($web_password); $expected_response = md5("$username:$pass_md5:$challenge"); $SIP['customer'] = $result->customer; $SIP['reseller'] = $result->reseller; $parts=explode(':', $pass_md5); dprint_r($result); dprint($expected_response); dprint($parts['0']); if ($result->ha1 && $result->ha1 == $response_ha1) { $log=sprintf("SIP settings page: %s logged in from %s", $username, $_SERVER['REMOTE_ADDR']); syslog(LOG_NOTICE, $log); return true; } if ($use_yubikey == 1) { $yubi = new Auth_Yubico('11334', 'NDSXQN1QpwUvqtR5v5sYbwhPQ70='); $auth = $yubi->verify($yubikey_p); $yubi_id = substr($yubikey_p, 0, 12); } if (!(new PEAR)->isError($auth) && $yubikey == $yubi_id && $use_yubikey == 1) { $log=sprintf("SIP settings page: %s logged in with yubikey from %s", $username, $_SERVER['REMOTE_ADDR']); syslog(LOG_NOTICE, $log); return true; } if ($pass_md5 && $parts[0] == $response_ha1) { $log=sprintf("SIP settings page: %s logged in from %s", $username, $_SERVER['REMOTE_ADDR']); syslog(LOG_NOTICE, $log); return true; } if ($expected_response == $response) { $log=sprintf("SIP settings page: %s logged in from %s", $username, $_SERVER['REMOTE_ADDR']); syslog(LOG_NOTICE, $log); return true; } return false; } } function otp_sms($tel, $message, $hideoutput) { $tel=preg_replace("/[^0-9]/", "", $tel); $tel="+".$tel; $message = substr($message, 0, 135); if (!$tel || !$message) { return 0; } $cmd="/usr/bin/sms --destination $tel --message \"$message\""; exec($cmd, $output, $returnCode); if ($returnCode == "0") { if (!$hideoutput) { print "

"; printf(_("SMS sent succesfully to %s. "), $tel); } } else { print "

"; print ""; print "OTP "; print _("Error"); } } function random_passwd_gen() { # Calculating random password $alf=array("a","b","c","d","e","f", "h","i","j","k","l","m", "n","p","r","s","t","w", "x","y","1","2","3","4", "5","6","7","8","9"); while ($i < 5) { srand((double)microtime() * 1000000); $randval = rand(0, 28); $random_otp="$random_otp"."$alf[$randval]"; $i++; } return $random_otp; } function dprint($msg = "") { global $verbose; if ($verbose) { print "
$msg\n"; } } function dprint_r($obj) { global $verbose; if ($verbose) { print "

\n";
         print_r($obj);
         print "
\n"; } } function dprint_sql($sql = "") { global $verbose; require_once('SqlFormatter.php'); if ($verbose) { echo SqlFormatter::format($sql); } } function checkEmail($email) { global $verbose; dprint("checkEmail($email)"); if (stristr($email, "-.") || !preg_match("/^[a-zA-Z0-9][a-zA-Z0-9_.-]*@([a-zA-Z0-9][a-zA-Z0-9-]*\.)+[a-zA-Z]{2,}$/i", $email) ) { return 0; } return 1; } class OpenSIPS_DomainAuth { function OpenSIPS_DomainAuth() { $this->userDB = new DB_opensips; $this->allowedDataSourcesSubscriber = array('opensips_radius','sip_trace','media_trace'); } function validate($user, $domain, $password) { $ha1 = md5($user. ':' . $domain . ':' . $password); $query = sprintf( "SELECT * FROM subscriber WHERE username = '%s' AND domain = '%s' AND (password = '%s' or ha1 = '%s') ", addslashes($user), addslashes($domain), addslashes($password), addslashes($ha1) ); if ($this->userDB->query($query)) { $this->userDB->next_record(); $uid = $this->userDB->f('username'); if ($uid) { return array($uid, "subscriber", $this->allowedDataSourcesSubscriber); } } } } class SipThor_DomainAuth { function SipThor_DomainAuth() { $this->userDB = new DB_sipthor; $this->allowedDataSourcesSubscriber = array('sipthor','sip_trace_thor','media_trace_thor'); } function validate($user, $domain, $password, $response, $otp_yubikey) { $query = sprintf( "SELECT * FROM sip_accounts WHERE username = '%s' AND domain = '%s'", addslashes($user), addslashes($domain) ); $use_yubikey=0; if (stream_resolve_include_path('Auth/Yubico.php')) { require_once 'Auth/Yubico.php'; $use_yubikey=1; } else { require_once 'PEAR.php'; } if ($this->userDB->query($query)) { $this->userDB->next_record(); $profile = json_decode($this->userDB->f('profile'), 'true'); $check_password = $profile['password']; $check_password_ha1=$profile['ha1']; if ($profile['properties']['web_password']) { $web_pass=$profile['properties']['web_password']; if (strstr($web_pass, ":")) { $split = explode(":", $web_pass); //if (preg_match('/^[a-f0-9]{32}$/', split[0])) { $check_web_password=$split[0]; //} } else { $check_web_password = $profile['properties']['web_password']; } } if ($use_yubikey == 1 && $profile['properties']['yubikey']) { $yubi = new Auth_Yubico('11334', 'NDSXQN1QpwUvqtR5v5sYbwhPQ70='); $yubikey=$profile['properties']['yubikey']; $auth = $yubi->verify($otp_yubikey); $yubi_id = substr($otp_yubikey, 0, 12); } $check_password_md5 = md5("$check_password"); $expected_response_pass = md5("$user:$domain:$check_password"); $expected_response_pass_ha1 = md5("$user:$domain:$check_password_ha1"); $expected_response_web = $check_password; //dprint($expected_response_pass_ha1); if ($expected_response_pass == $response) { $uid = $this->userDB->f('username'); if ($uid) { return array($uid, "subscriber", $this->allowedDataSourcesSubscriber); } } else if ($check_password == $password) { $uid = $this->userDB->f('username'); if ($uid) { return array($uid, "subscriber", $this->allowedDataSourcesSubscriber); } } else if ($expected_response_web == $response) { $uid = $this->userDB->f('username'); if ($uid) { return array($uid, "subscriber", $this->allowedDataSourcesSubscriber); } } else if ($expected_response_pass_ha1 == $response) { $uid = $this->userDB->f('username'); if ($uid) { return array($uid, "subscriber", $this->allowedDataSourcesSubscriber); } } else if (!(new PEAR)->isError($auth) && $yubikey == $yubi_id && $use_yubikey) { $uid = $this->userDB->f('username'); if ($uid) { return array($uid, "subscriber", $this->allowedDataSourcesSubscriber); } } } } } class pageLayout { function showLoginForm(&$parentAuth) { global $username, $otp_error, $CDRTool; $auth=$parentAuth; $use_yubikey=0; if (stream_resolve_include_path('Auth/Yubico.php')) { require_once 'Auth/Yubico.php'; $use_yubikey=1; } $username = $auth->auth["uname"]; print " "; $url = $auth->url(); print "

"; $this->hasAGProjectslogo = 1; $logo = $CDRTool['tld']."/images/CDRTool.png"; print "

"; print "

"; if ($CDRTool['provider']['sampleLoginSubscriber']) { $sampleLoginSubscriber = $CDRTool['provider']['sampleLoginSubscriber']; } else { $sampleLoginSubscriber = "account@sip2sip.info"; } if ($CDRTool['provider']['sampleLoginDomain']) { $sampleLoginDomain = $CDRTool['provider']['sampleLoginDomain']; } else { $sampleLoginDomain = "sip2sip.info"; } $web_username = $auth->auth["uname"]; print "

"; //dprint_r($CDRTool); if ($use_yubikey == 1) { print "
If you login the first time with a CDRTool account and the username, password and OTP key filled in, the key identifier is stored into you account.
For info and purchase of this key see http://www.yubico.com \" type=text name=yubikey size=40>
"; } print "

"; if (isset($username)) { if (!$sendotp || $username) { print "

Invalid username/password combination.
$otp_error

"; $spam = new DB_CDRTool; $query = sprintf("select * from spam where ip = '%s'", addslashes($_SERVER['REMOTE_ADDR'])); $spam->query($query); if (!$spam->num_rows()) { $query = sprintf( "insert into spam (ip,tries,login,stamp) values ('%s','1','%s','%s') ", $_SERVER['REMOTE_ADDR'], addslashes($username), time() ); } else { $query = sprintf( "update spam set tries = tries +1 where ip = '%s'", addslashes($_SERVER['REMOTE_ADDR']) ); } $spam->query($query); } else { print "Please fill in your One Time Password!"; } } print "
"; print ""; print ""; print " "; } function showHeader($title = '') { } function showTopMenu($title = '') { global $DATASOURCES, $CDRTool, $cdr_source, $perm; $version = trim(file_get_contents('version')); print ' '; print "
"; print "
"; print "

"; print "$title"; if (isset($DATASOURCES[$cdr_source]['name'])) { print $DATASOURCES[$cdr_source]['name']; } // Dirty hack if ($title == 'Provisioning' && $perm->have_perm("provisioning")) { print "
Usage statistics"; } print "

"; // print " // // "; // if (is_readable($CDRTool['Path']."/images/logo.gif")) { // printf ("",$CDRTool['tld']); // } else if (is_readable($CDRTool['Path']."/images/logo.jpg")) { // printf ("",$CDRTool['tld']); // } else if (is_readable($CDRTool['Path']."/images/logo.png")) { // printf ("",$CDRTool['tld']); // } else { // $this->hasAGProjectslogo=1; // print ""; // } // print " // // //
"; // printf ("",$CDRTool['tld']); // print " // // // //
"; // print "

$title"; // print " "; // print $DATASOURCES[$cdr_source]['name']; // print "

"; // print "

"; // print "
// "; // print " // // // //
// // // "; // if ($perm->have_perm("callsearch")) { // print " "; // } // if ($perm->have_perm("rates")) { // print " "; // print " "; // print " "; // } // if ($perm->have_perm("statistics")) { // print " "; // print " "; // print " "; // } // if ($perm->have_perm("admin")) { // print " "; // } // if ($perm->have_perm("provisioning")) { // print " "; // } // print " "; // print " "; // $now_print=Date("Y-m-d H:i:s",time()); // $tz=$CDRTool['provider']['timezone']; // //print " "; // print " "; // print " // //
CDRsRatingPrepaidQuotaNetworkSessionsUsageReplicationProvisioningAccountsLogs$now_print | v. $versionv. $version
//
// "; // printf ("Logout %s",$CDRTool['loginName']); // print " //
//
//

//"; } function showTopMenuSubscriber($title = "") { global $DATASOURCES, $CDRTool, $cdr_source, $perm; $version=trim(file_get_contents(version)); $now_print=Date("Y-m-d H:i:s", time()); $tz=getenv('TZ'); print '

'; print "
"; print "
"; print "

"; print "$title"; print $DATASOURCES[$cdr_source]['name']; print "

"; } function showLegalNotice() { global $loginname, $CDRTool; $CDRTool_company = $CDRTool['provider']['name']; $legalNotice="Legal Notice". "\n\n". "This software is intended for the use of $CDRTool_company, ". "resellers of $CDRTool_company and the customers of $CDRTool_company. ". "The use of this software by any natural or legal person that does ". "not belong to $CDRTool_company, its Resellers or is a not a ". "customer of $CDRTool_company or its resellers is therefore ". "expressly prohibited.". "\n\n". "All the information stored on, and accessible through this software ". "are personal data protected as such by international and domestic ". "legislation relating to the processing of personal data and ". "the protection of the right to privacy. For these reasons: ". "1. This software shall exclusively be used to the extent that it ". "is necessary for the provision of services to $CDRTool_company ". "customers and its resellers; ". "2. No information displayed on, and accessible through this software ". "shall be communicated to any natural or legal person outside ". "$CDRTool_company and its resellers, without prejudice to the ". "possibility for competent authorities (namely government bodies, ". "courts, regulatory authorities) to be informed of billing or ". "traffic data in conformity with the applicable legislation. ". "\n\n"; $loginName=$CDRTool['loginName']; $this->hasAGProjectslogo=1; print "

You are currently logged in as $loginname

If you agree with the Terms and Conditions,
press on I agree button to continue.

"; } function showFooter() { global $CDRTool; if (!$CDRTool['filter']['aNumber'] && !$this->hasAGProjectslogo) { $thisYear = date("Y", time()); print "

"; } } function showLogout($loginname) { print "


Logout

You have been logged in as $loginname.

You have been logged out.

Login again

"; } } function unLockTables($dbid) { $dbid->query("unlock tables"); } function changeLanguage($lang = 'en', $domain = 'cdrtool') { // run dpkg-reconfigure locales and select support languages .utf8 $lang = languageCodeFor(isset($lang) ? $lang : 'en'); $lang.='.utf8'; setlocale(LC_ALL, $lang); bindtextdomain($domain, '/var/www/CDRTool/po/locale'); bind_textdomain_codeset($domain, 'UTF-8'); textdomain($domain); } // return full language code for given 2 letter language code function languageCodeFor($lang='en') { $lang = isset($lang) ? strtolower($lang) : 'en'; switch ($lang) { case 'en': return 'en_US'; // this can be C or en_US case 'ja': return 'ja_JP'; default : return ($lang . '_' . strtoupper($lang)); } return 'C'; // this will never be reached } function RandomString($len=11) { $alf=array("a","b","c","d","e","f", "h","i","j","k","l","m", "n","p","r","s","t","w", "x","y","1","2","3","4", "5","6","7","8","9"); $i=0; $string = ''; while($i < $len) { srand((double)microtime()*1000000); $randval = rand(0,28); $string = "$string"."$alf[$randval]"; $i++; } return $string; } function RandomNumber($len=5,$skipzero=false) { $alf=array("1","2","3","4","5", "9","8","7","6"); if (!$skipzero) $alf[]="0"; $i=0; while($i < $len) { srand((double)microtime()*1000000); $randval = rand(0,9); $string="$string"."$alf[$randval]"; $i++; } return $string; } function microtime_float() { list($usec, $sec) = explode(" ", microtime()); return ((float)$usec + (float)$sec); } function sec2hms($duration) { // return seconds in HH:MM:SS format $sum1=$duration; $duration_print=""; $duration_hour=floor($sum1/3600); if ($duration_hour > 0) { $sum1=$sum1-($duration_hour*3600); $duration_print="$duration_hour:"; } $duration_min=floor($sum1/60); if ($duration_min > 0) { $sum1=$sum1-($duration_min*60); if ($duration_min < 10) { $duration_min="0"."$duration_min"; } $duration_print="$duration_print"."$duration_min:"; } else { $duration_print="$duration_print"."00:"; } if ($sum1< 10) { $duration_sec="0"."$sum1"; } else { $duration_sec=$sum1; } $duration_print="$duration_print"."$duration_sec"; return $duration_print; } function get_location($ip) { $geo_location=array(); $geo_location['country'] = ''; $geo_location['city'] = '' ; $geo_location['code'] = ''; $geo_location['region'] = ''; if ($_loc=geoip_record_by_name($ip)) { if ($_loc['city']) { $geo_location['city'] = $_loc['city']; } $geo_location['country'] = $_loc['country_name']; $geo_location['code'] = $_loc['country_code']; $geo_location['region'] = $_loc['region']; } return json_encode($geo_location); } function startsWith($haystack, $needle, $case=true) { if ($case) { return strpos($haystack, $needle, 0) === 0; } return stripos($haystack, $needle, 0) === 0; } ?>