diff --git a/library/NGNPro/Records/TrustedPeers.php b/library/NGNPro/Records/TrustedPeers.php new file mode 100644 index 0000000..c7b364b --- /dev/null +++ b/library/NGNPro/Records/TrustedPeers.php @@ -0,0 +1,498 @@ + array('type'=>'boolean', 'name' => 'MS Teams'), + 'prepaid' => array('type'=>'boolean'), + 'tenant' => array('type'=>'string'), + 'callLimit' => array('type'=>'integer', 'name' => 'Capacity'), + 'blocked' => array('type'=>'integer') + ); + var $Fields=array( + 'description' => array('type'=>'string'), + 'authToken' => array('type'=>'string', 'name' => 'Authentication token') + ); + + public function __construct($SoapEngine) + { + + $this->filters = array('ip' => trim($_REQUEST['ip_filter']), + 'tenant' => trim($_REQUEST['tenant_filter']), + 'description' => trim($_REQUEST['description_filter']), + 'msteams' => trim($_REQUEST['msteams_filter']) + ); + + parent::__construct($SoapEngine); + + $this->sortElements=array( + 'changeDate' => 'Change date', + 'description' => 'Description', + 'ip' => 'Address' + ); + } + + function listRecords() { + + $this->showSeachForm(); + + // Insert credetials + $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); + + // Filter + $filter=array('ip' => $this->filters['ip'], + 'description' => $this->filters['description'], + 'tenant' => $this->filters['tenant'], + 'msteams' => 1 == intval($this->filters['msteams']) + ); + + // Range + $range=array('start' => intval($this->next), + 'count' => intval($this->maxrowsperpage) + ); + + // Order + if (!$this->sorting['sortBy']) $this->sorting['sortBy'] = 'description'; + if (!$this->sorting['sortOrder']) $this->sorting['sortOrder'] = 'ASC'; + + $orderBy = array('attribute' => $this->sorting['sortBy'], + 'direction' => $this->sorting['sortOrder'] + ); + + // Compose query + $Query=array('filter' => $filter, + 'orderBy' => $orderBy, + 'range' => $range + ); + + // Call function + $this->log_action('getTrustedPeers'); + + $result = $this->SoapEngine->soapclient->getTrustedPeers($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); + return false; + } else { + $this->rows = $result->total; + + if ($this->rows && $_REQUEST['action'] != 'PerformActions' && $_REQUEST['action'] != 'Delete') { + $this->showActionsForm(); + } + + print " +
Id + | Owner | +Trusted peer | +Prepaid | +Capacity | +MS Teams | +Tenant | +Description | +Blocked | +Change date | +Actions | +
%s | +%s | +%s | +%s | +%s | +%s | +%s | +%s | +%s | +%s | +%s | +
+ |
Error: Missing IP or description. "); + return false; + } + + $peer=array( + 'ip' => $ipaddress, + 'description' => $description, + 'callLimit' => intval($callLimit), + 'msteams' => 1 == $msteams, + 'tenant' => $tenant, + 'blocked' => 0, + 'owner' => intval($_REQUEST['owner']), + 'customer' => intval($customer), + 'reseller' => intval($reseller) + ); + + $function=array('commit' => array('name' => 'addTrustedPeer', + 'parameters' => array($peer), + 'logs' => array('success' => sprintf('Trusted peer %s has been added',$ipaddress))) + ); + + return $this->SoapEngine->execute($function,$this->html); + } + + function updateRecord() { + list($customer,$reseller)=$this->customerFromLogin($dictionary); + + if (!strlen($this->filters['ip'])) { + print "
Error: missing peer address. "; + return false; + } + $peer=array( + 'ip' => $this->filters['ip'], + 'description' => $_REQUEST['description_form'], + 'authToken' => $_REQUEST['authToken_form'], + 'tenant' => $_REQUEST['tenant_form'], + 'callLimit' => intval($_REQUEST['callLimit_form']), + 'prepaid' => 1 == $_REQUEST['prepaid_form'], + 'blocked' => intval($_REQUEST['blocked_form']), + 'msteams' => 1 == $_REQUEST['msteams_form'], + 'customer' => intval($customer), + 'reseller' => intval($reseller) + ); + + $function=array('commit' => array('name' => 'updateTrustedPeer', + 'parameters' => array($peer), + 'logs' => array('success' => sprintf('Trusted peer %s has been updated',$this->filters['ip']))) + ); + + return $this->SoapEngine->execute($function,$this->html); + } + + function deleteRecord($dictionary=array()) { + if (!$dictionary['confirm'] && !$_REQUEST['confirm']) { + print "
Please press on Confirm to confirm the delete. "; + return true; + } + + if (!strlen($this->filters['ip'])) { + print "
Error: missing IP address. "; + return false; + } + + $function=array('commit' => array('name' => 'deleteTrustedPeer', + 'parameters' => array($this->filters['ip']), + 'logs' => array('success' => sprintf('Trusted peer %s has been deleted',$this->filters['ip']))) + ); + + unset($this->filters); + return $this->SoapEngine->execute($function,$this->html); + } + + function showSeachFormCustom() { + if (intval($this->filters['msteams']) == 1) { + $checked_msteams = 'checked'; + } else { + $checked_msteams = ''; + } + + printf ("
%s at %s as %s ", $this->soap_class, $this->SOAPurl, $this->SOAPurl, $this->soapUsername ); dprint($log); $this->SoapAuth = array('auth', $this->SOAPlogin , 'urn:AGProjects:NGNPro', 0, ''); $this->SoapAuthAdmin = array('auth', $this->SOAPloginAdmin , 'urn:AGProjects:NGNPro', 0, ''); // Instantiate the SOAP client if (!class_exists($this->soap_class)) return ; $this->soapclient = new $this->soap_class($this->SOAPurl); $this->soapclient->setOpt('curl', 'CURLOPT_SSL_VERIFYPEER', 0); $this->soapclient->setOpt('curl', 'CURLOPT_SSL_VERIFYHOST', 0); // set the timeout $this->soapclient->_options['timeout'] = $this->timeout; if ($this->customer_engine) { $this->SOAPloginCustomers = array( "username" => $this->soapEngines[$this->customer_engine]['username'], "password" => $this->soapEngines[$this->customer_engine]['password'], "admin" => true, "impersonate" => intval($this->reseller) ); $this->SoapAuthCustomers = array('auth', $this->SOAPloginCustomers , 'urn:AGProjects:NGNPro', 0, ''); $this->SOAPurlCustomers = $this->soapEngines[$this->customer_engine]['url']; $this->soapclientCustomers = new WebService_NGNPro_CustomerPort($this->SOAPurlCustomers); $this->soapclientCustomers->setOpt('curl', 'CURLOPT_SSL_VERIFYPEER', 0); $this->soapclientCustomers->setOpt('curl', 'CURLOPT_SSL_VERIFYHOST', 0); if (strlen($this->soapEngines[$this->customer_engine]['timeout'])) { $this->soapclientCustomers->_options['timeout'] = intval($this->soapEngines[$this->customer_engine]['timeout']); } else { $this->soapclientCustomers->_options['timeout'] = $this->timeout; } } if ($this->voicemail_engine) { $this->SOAPloginVoicemail = array( "username" => $this->soapEngines[$this->voicemail_engine]['username'], "password" => $this->soapEngines[$this->voicemail_engine]['password'], "admin" => true, "impersonate" => intval($this->reseller) ); $this->SoapAuthVoicemail = array('auth', $this->SOAPloginVoicemail , 'urn:AGProjects:NGNPro', 0, ''); $this->SOAPurlVoicemail = $this->soapEngines[$this->voicemail_engine]['url']; $this->soapclientVoicemail = new WebService_NGNPro_VoicemailPort($this->SOAPurlVoicemail); $this->soapclientVoicemail->setOpt('curl', 'CURLOPT_SSL_VERIFYPEER', 0); $this->soapclientVoicemail->setOpt('curl', 'CURLOPT_SSL_VERIFYHOST', 0); if (strlen($this->soapEngines[$this->voicemail_engine]['timeout'])) { $this->soapclientVoicemail->_options['timeout'] = intval($this->soapEngines[$this->voicemail_engine]['timeout']); } else { $this->soapclientVoicemail->_options['timeout'] = $this->timeout; } } } else { print "Error: No SOAP credentials defined."; } $this->url = $_SERVER['PHP_SELF']."?1=1"; foreach (array_keys($this->extraFormElements) as $element) { if (!strlen($this->extraFormElements[$element])) continue; $this->url .= sprintf( '&%s=%s', $element, urlencode($this->extraFormElements[$element]) ); } $this->support_email = $this->soapEngines[$this->soapEngine]['support_email']; $this->support_web = $this->soapEngines[$this->soapEngine]['support_web']; $this->welcome_message = $this->soapEngines[$this->soapEngine]['welcome_message']; } /** * returns a list of allowed engines based on a filter * the filter format is: * engine1:port1,port2 engine2 engine3:port1 */ public function getSoapEngineAllowed($soapEngines, $filter) { if (!$filter) { $soapEngines_checked = $soapEngines; } else { $_filter_els = explode(" ", $filter); foreach (array_keys($soapEngines) as $_engine) { foreach ($_filter_els as $_filter) { unset($_allowed_engine); $_allowed_ports = array(); list($_allowed_engine, $_allowed_ports_els) = explode(":", $_filter); if ($_allowed_ports_els) { $_allowed_ports = explode(",", $_allowed_ports_els); } if (count($_allowed_ports) == 0) { $_allowed_ports = array_keys($this->ports); } if ($_engine == $_allowed_engine) { $soapEngines_checked[$_engine] = $soapEngines[$_engine]; $this->allowedPorts[$_engine] = $_allowed_ports; continue; } } } } return $soapEngines_checked; } /** * $function = array( * 'commit' => array( * 'name' => 'addAccount', * 'parameters' => array( * $param1, * $param2 * ), * 'logs' => array( * 'success' => 'The function was a success', * 'failure' => 'The function has failed' * ) * ) * ); */ public function execute($function, $html = true, $adminonly = false) { if (!$function['commit']['name']) { if ($html) { print "Error: no function name supplied"; } else { print "Error: no function name supplied\n"; } return false; } if ($adminonly) { $this->soapclient->addHeader($this->SoapAuthAdmin); } else { $this->soapclient->addHeader($this->SoapAuth); } $result = call_user_func_array( array( $this->soapclient, $function['commit']['name'] ), $function['commit']['parameters'] ); if ((new PEAR)->isError($result)) { $this->error_msg = $result->getMessage(); $this->error_fault = $result->getFault(); $this->error_code = $result->getCode(); $this->exception = $this->error_fault->detail->exception; $log = sprintf( "SOAP request error from %s: %s (%s): %s", $this->SOAPurl, $this->error_msg, $this->error_fault->detail->exception->errorcode, $this->error_fault->detail->exception->errorstring ); syslog(LOG_NOTICE, $log); if ($html) { $log = sprintf( "SOAP query failed: %s (%s): %s", $this->error_msg, $this->error_fault->detail->exception->errorcode, $this->error_fault->detail->exception->errorstring ); print "$log"; } return false; } else { $this->result = $result; if ($function['commit']['logs']['success']) { if ($html) { printf( "
%s \n", htmlentities($function['commit']['logs']['success']) ); } } if (is_object($result) || strlen($result)) { return $result; } else { return true; } } } } class Records { public $maxrowsperpage = '20'; public $sip_settings_page = 'sip_settings.phtml'; public $allowedDomains = array(); public $selectionActive = false; public $selectionKeys = array(); public $resellers = array(); public $customers = array(); public $record_generator = false; public $customer_properties = array(); public $loginProperties = array(); public $errorMessage = ''; public $html = true; public $filters = array(); public $selectionActiveExceptions = array(); public function log_action($action = 'Unknown') { global $CDRTool; $location = "Unknown"; $_loc = geoip_record_by_name($_SERVER['REMOTE_ADDR']); if ($_loc['country_name']) { $location = $_loc['country_name']; } $log = sprintf( "CDRTool login username=%s, type=%s, impersonate=%s, IP=%s, location=%s, action=%s:%s, script=%s", $this->login_credentials['username'], $this->login_credentials['login_type'], $CDRTool['impersonate'], $_SERVER['REMOTE_ADDR'], $location, $this->SoapEngine->port, $action, $_SERVER['PHP_SELF'] ); syslog(LOG_NOTICE, $log); } public function soapHasError($result) { return (new PEAR)->isError($result); } public function checkLogSoapError($result, $syslog = false, $print = false) { if (!$this->soapHasError($result)) { return false; } $error_msg = $result->getMessage(); $error_fault= $result->getFault(); $error_code = $result->getCode(); if ($syslog) { $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); if ($print) { printf("
Error: $log"); } } else { printf( "Error: %s (%s): %s", $error_msg, $error_fault->detail->exception->errorcode, $error_fault->detail->exception->errorstring ); } return true; } public function buildUrl($data) { return sprintf( "%s&%s", $this->url, http_build_query($data) ); } public function __construct($SoapEngine) { $this->SoapEngine = $SoapEngine; $this->version = $this->SoapEngine->version; $this->login_credentials = $this->SoapEngine->login_credentials; $this->sorting['sortBy'] = trim($_REQUEST['sortBy']); $this->sorting['sortOrder'] = trim($_REQUEST['sortOrder']); $this->next = $_REQUEST['next']; $this->adminonly = $this->SoapEngine->adminonly; $this->reseller = $this->SoapEngine->reseller; $this->customer = $this->SoapEngine->customer; $this->impersonate = $this->SoapEngine->impersonate; $this->url = $this->SoapEngine->url; foreach (array_keys($this->filters) as $_filter) { if (strlen($this->filters[$_filter]) && !in_array($_filter, $this->selectionActiveExceptions)) { $this->selectionActive = true; break; } } if ($this->adminonly) { $this->url .= sprintf('&adminonly=%s', $this->adminonly); if ($this->login_credentials['reseller']) { $this->filters['reseller'] = $this->login_credentials['reseller']; } else { $this->filters['reseller'] = trim($_REQUEST['reseller_filter']); } } $this->filters['customer'] = trim($_REQUEST['customer_filter']); //$this->getResellers(); $this->getCustomers(); $this->getLoginAccount(); if (strlen($this->SoapEngine->sip_settings_page)) { $this->sip_settings_page = $this->SoapEngine->sip_settings_page; } if (strlen($this->SoapEngine->digest_settings_page)) { $this->digest_settings_page = $this->SoapEngine->digest_settings_page; } $this->support_email = $this->SoapEngine->support_email; $this->support_web = $this->SoapEngine->support_web; } function showEngineSelection() { $selected_soapEngine[$this->SoapEngine->service] =' selected'; $pstn_access = $this->getCustomerProperty('pstn_access'); printf(""); printf( "", $this->url ); } function showAfterEngineSelection() { } function showCustomerSelection() { $this->showCustomerForm(); } function showResellerSelection() { if ($this->adminonly) { $this->showResellerForm(); } else { printf("%s", $this->reseller); } } function showPagination($maxrows) { $url .= $this->url.'&'.$this->addFiltersToURL().sprintf( "&service=%s&sortBy=%s&sortOrder=%s", urlencode($this->SoapEngine->service), urlencode($this->sorting['sortBy']), urlencode($this->sorting['sortOrder']) ); print "
%s", $this->SoapEngine->ports[$this->SoapEngine->port]['description'] ); printf( "