diff --git a/library/NGNPro/Records/SipDomains.php b/library/NGNPro/Records/SipDomains.php index 6fd5bdd..34e670b 100644 --- a/library/NGNPro/Records/SipDomains.php +++ b/library/NGNPro/Records/SipDomains.php @@ -1,944 +1,991 @@ array('type'=>'integer'), ); - var $Fields=array( + var $Fields = array( 'customer' => array('type'=>'integer'), 'certificate' => array('type'=>'text'), 'private_key' => array('type'=>'text'), 'match_ip_address' => array('type'=>'text', 'name'=> 'Match IP addresses'), 'verify_cert' => array('type'=>'boolean'), 'require_cert' => array('type'=>'boolean') ); public function __construct($SoapEngine) { dprint("init Domains"); $this->filters = array( 'domain' => strtolower(trim($_REQUEST['domain_filter'])) ); parent::__construct($SoapEngine); // keep default maxrowsperpage $this->sortElements = array( 'changeDate' => 'Change date', 'domain' => 'Domain' ); } function listRecords() { $this->showSeachForm(); // Filter $filter = array( 'domain' => $this->filters['domain'], 'customer' => intval($this->filters['customer']), 'reseller' => intval($this->filters['reseller']) ); // Range $range = array( 'start' => intval($this->next), 'count' => intval($this->maxrowsperpage) ); // Order if (!$this->sorting['sortBy']) $this->sorting['sortBy'] = 'changeDate'; if (!$this->sorting['sortOrder']) $this->sorting['sortOrder'] = 'DESC'; $orderBy = array( 'attribute' => $this->sorting['sortBy'], 'direction' => $this->sorting['sortOrder'] ); // Compose query $Query = array( 'filter' => $filter, 'orderBy' => $orderBy, 'range' => $range ); dprint_r($Query); // Insert credetials $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); $this->log_action('getDomains'); // Call function $result = $this->SoapEngine->soapclient->getDomains($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); + if ($this->checkLogSoapError($result, true)) { return false; } else { $this->rows = $result->total; if ($_REQUEST['action'] == 'Export' and $this->rows) { $this->exportDomain($result->domains[0]->domain); return; } if ($this->rows && $_REQUEST['action'] != 'PerformActions' && $_REQUEST['action'] != 'Delete') { $this->showActionsForm(); } print "
Id | Owner | SIP domain | Change date | Actions | |||
---|---|---|---|---|---|---|---|
%s | %s.%s | %s | Sip accounts | Sip aliases | %s | %s | Export |
%s | %s.%s | %s | Sip accounts | Sip aliases | %s | %s |
Please press on Confirm to confirm the delete. "; return true; } if ($dictionary['domain']) { - $domain=$dictionary['domain']; + $domain = $dictionary['domain']; } else { - $domain=$this->filters['domain']; + $domain = $this->filters['domain']; } if (!strlen($domain)) { print "
Error: missing SIP domain. "; return false; } - $function=array('commit' => array('name' => 'deleteDomain', + $function = array('commit' => array('name' => 'deleteDomain', 'parameters' => array($domain), - 'logs' => array('success' => sprintf('SIP domain %s has been deleted',$domain)) + 'logs' => array('success' => sprintf('SIP domain %s has been deleted', $domain)) ) ); unset($this->filters); return $this->SoapEngine->execute($function, $this->html); } - function showAddForm() { + function showAddForm() + { if ($this->selectionActive) return; - printf ("
+END; } function addRecord($dictionary = array()) { if ($this->adminonly && $_FILES['import_file']['tmp_name']) { - $content=fread(fopen($_FILES['import_file']['tmp_name'], "r"), $_FILES['import_file']['size']); + $content = fread(fopen($_FILES['import_file']['tmp_name'], "r"), $_FILES['import_file']['size']); //print_r($content); - if (!$imported_data=json_decode($content, true)) { - printf ("Error: reading imported data. "); + if (!$imported_data = json_decode($content, true)) { + printf("
Error: reading imported data. "); return false; } //print_r($imported_data); if (!in_array('sip_domains', array_keys($imported_data))) { - printf ("
Error: Missing SIP domains in imported data. "); + printf("
Error: Missing SIP domains in imported data. "); return false; } if (!in_array('sip_accounts', array_keys($imported_data))) { return false; - printf ("
Error: Missing SIP accounts in imported data. "); + printf("
Error: Missing SIP accounts in imported data. "); } - foreach($imported_data['customers'] as $customer) { + foreach ($imported_data['customers'] as $customer) { // Insert credetials $this->SoapEngine->soapclientCustomers->addHeader($this->SoapEngine->SoapAuth); $this->log_action('addAccount'); $customer['credit'] = floatval($customer['credit']); $customer['balance'] = floatval($customer['balance']); // Call function $result = $this->SoapEngine->soapclientCustomers->addAccount($customer); - if ((new PEAR)->isError($result)) { + if ($this->soapHasError($result)) { $error_msg = $result->getMessage(); $error_fault= $result->getFault(); $error_code = $result->getCode(); if ($error_fault->detail->exception->errorcode == 5001) { - $result = $this->SoapEngine->soapclientCustomers->updateCustomer($customer); - 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); - printf ("
Error: $log"); - } else { - printf('
Customer %s has been updated',$customer['id']); + $result = $this->SoapEngine->soapclientCustomers->updateCustomer($customer); + if (!$this->checkLogSoapError($result, true, true)) { + printf('
Customer %s has been updated', $customer['id']); } } else { - $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); - printf ("
Error: $log"); + $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 + ); + printf("
Error: $log"); } } else { - printf('
Customer %s has been added',$customer['id']); + printf('
Customer %s has been added', $customer['id']); } } - foreach($imported_data['sip_domains'] as $domain) { + foreach ($imported_data['sip_domains'] as $domain) { flush(); $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); $this->log_action('addDomain'); $result = $this->SoapEngine->soapclient->addDomain($domain); - if ((new PEAR)->isError($result)) { + if ($this->soapHasError($result)) { $error_msg = $result->getMessage(); $error_fault= $result->getFault(); $error_code = $result->getCode(); if ($error_fault->detail->exception->errorcode == 1001) { $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); $this->log_action('updateDomain'); $result = $this->SoapEngine->soapclient->updateDomain($domain); - 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); - printf ("
Error: $log"); - } else { - printf('
SIP domain %s has been updated',$domain['domain']); - } + if (!$this->checkLogSoapError($result, true, true)) { + printf('
SIP domain %s has been updated', $domain['domain']); + } } else { - $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); - printf ("
Error: $log"); + $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 + ); + printf("
Error: $log"); } } else { - printf('
SIP domain %s has been added',$domain['domain']); + printf('
SIP domain %s has been added', $domain['domain']); } - } $i = 0; $added = 0; $updated = 0; $failed = 0; - foreach($imported_data['sip_accounts'] as $account) { + foreach ($imported_data['sip_accounts'] as $account) { $i+=1; flush(); $account['callLimit'] = intval($account['callLimit']); $account['prepaid'] = intval($account['prepaid']); $account['quota'] = intval($account['quota']); $account['owner'] = intval($account['owner']); $account['timeout'] = intval($account['timeout']); $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); $this->log_action('addAccount'); $result = $this->SoapEngine->soapclient->addAccount($account); - if ((new PEAR)->isError($result)) { + if ($this->soapHasError($result)) { $error_msg = $result->getMessage(); $error_fault= $result->getFault(); $error_code = $result->getCode(); if ($error_fault->detail->exception->errorcode == 1011) { $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); $result = $this->SoapEngine->soapclient->updateAccount($account); - 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); - printf ("
Error: $log"); + if ($this->checkLogSoapError($result, true, true)) { $failed += 1; } else { - printf('
%d SIP account %s@%s has been updated',$i, $account['id']['username'], $account['id']['domain']); + printf( + '
%d SIP account %s@%s has been updated
', + $i, + $account['id']['username'], + $account['id']['domain'] + ); $updated += 1; } } else { - $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); - printf ("Error: $log"); + $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 + ); + printf("
Error: $log"); $failed += 1; } } else { - printf('
%d SIP account %s@%s has been added',$i, $account['id']['username'], $account['id']['domain']); + printf( + '
%d SIP account %s@%s has been added', + $i, + $account['id']['username'], + $account['id']['domain'] + ); $added += 1; } } if ($added) { - printf('
%d SIP accounts added',$added); + printf('
%d SIP accounts added', $added); } if ($updated) { - printf('
%d SIP accounts updated',$updated); + printf('
%d SIP accounts updated', $updated); } if ($failed) { - printf('
%d SIP accounts failed',$failed); + printf('
%d SIP accounts failed', $failed); } $added = 0; - foreach($imported_data['sip_aliases'] as $alias) { + foreach ($imported_data['sip_aliases'] as $alias) { flush(); $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); $this->log_action('addAlias'); $result = $this->SoapEngine->soapclient->addAlias($alias); - 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); - printf ("
Error: $log"); - } else { - $added += 1; + if (!$this->checkLogSoapError($result, true, true)) { + $added += 1; } } if ($added) { - printf('
%d SIP aliases added',$added); + printf('
%d SIP aliases added', $added); } return true; } else { if ($dictionary['domain']) { $domain = $dictionary['domain']; } else { $domain = trim($_REQUEST['domain']); } list($customer, $reseller)=$this->customerFromLogin($dictionary); if (!$this->validDomain($domain)) { - print "Error: invalid domain name"; + print "Error: invalid domain name"; return false; } - $domainStructure = array('domain' => strtolower($domain), - 'customer' => intval($customer), - 'reseller' => intval($reseller) - ); - $function=array('commit' => array('name' => 'addDomain', - 'parameters' => array($domainStructure), - 'logs' => array('success' => sprintf('SIP domain %s has been added',$domain))) - ); + $domainStructure = array( + 'domain' => strtolower($domain), + 'customer' => intval($customer), + 'reseller' => intval($reseller) + ); + $function = array( + 'commit' => array( + 'name' => 'addDomain', + 'parameters' => array($domainStructure), + 'logs' => array('success' => sprintf('SIP domain %s has been added', $domain)) + ) + ); return $this->SoapEngine->execute($function, $this->html); } } function getRecordKeys() { // Filter - $filter=array( + $filter = array( 'domain' => $this->filters['domain'], 'customer' => intval($this->filters['customer']), 'reseller' => intval($this->filters['reseller']) ); // Range - $range=array('start' => intval($this->next), - 'count' => intval($this->maxrowsperpage) - ); + $range = array( + 'start' => intval($this->next), + 'count' => intval($this->maxrowsperpage) + ); // Order if (!$this->sorting['sortBy']) $this->sorting['sortBy'] = 'changeDate'; if (!$this->sorting['sortOrder']) $this->sorting['sortOrder'] = 'DESC'; - $orderBy = array('attribute' => $this->sorting['sortBy'], - 'direction' => $this->sorting['sortOrder'] - ); + $orderBy = array( + 'attribute' => $this->sorting['sortBy'], + 'direction' => $this->sorting['sortOrder'] + ); // Compose query - $Query=array('filter' => $filter, - 'orderBy' => $orderBy, - 'range' => $range - ); + $Query = array( + 'filter' => $filter, + 'orderBy' => $orderBy, + 'range' => $range + ); $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); $this->log_action('getDomains'); $result = $this->SoapEngine->soapclient->getDomains($Query); - if ((new PEAR)->isError($result)) { + if ($this->soapHasError($result)) { $error_msg = $result->getMessage(); $error_fault= $result->getFault(); $error_code = $result->getCode(); - printf ("
Error in getAllowedDomains from %s: %s (%s): %s",$this->SoapEngine->SOAPurl, $error_msg, $error_fault->detail->exception->errorcode, $error_fault->detail->exception->errorstring); + printf( + "
Error in getAllowedDomains from %s: %s (%s): %s", + $this->SoapEngine->SOAPurl, + $error_msg, + $error_fault->detail->exception->errorcode, + $error_fault->detail->exception->errorstring + ); //return false; } else { foreach ($result->domains as $_domain) { - $this->selectionKeys[]=$_domain->domain; + $this->selectionKeys[] = $_domain->domain; } } } function getRecord($domain) { // Filter - $filter=array( - 'domain' => $domain - ); + $filter = array( + 'domain' => $domain + ); // Range - $range=array('start' => 0, - 'count' => 1 - ); + $range = array( + 'start' => 0, + 'count' => 1 + ); - $orderBy = array('attribute' => 'changeDate', - 'direction' => 'DESC' - ); + $orderBy = array( + 'attribute' => 'changeDate', + 'direction' => 'DESC' + ); // Compose query - $Query=array('filter' => $filter, - 'orderBy' => $orderBy, - 'range' => $range - ); + $Query = array( + 'filter' => $filter, + 'orderBy' => $orderBy, + 'range' => $range + ); dprint_r($Query); // Insert credetials $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); $this->log_action('getDomains'); // Call function $result = $this->SoapEngine->soapclient->getDomains($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); + if ($this->checkLogSoapError($result, true)) { return false; } else { if ($result->domains[0]) { return $result->domains[0]; } else { return false; } } } function showRecord($domain) { if ($domain->certificate and $domain->private_key) { - $pemdata = sprintf("%s\n%s", $domain->certificate, $domain->private_key); - $cert = openssl_x509_read( $pemdata ); + $pemdata = sprintf("%s\n%s", $domain->certificate, $domain->private_key); + $cert = openssl_x509_read($pemdata); if ($cert) { - $cert_data = openssl_x509_parse( $cert ); - openssl_x509_free( $cert ); + $cert_data = openssl_x509_parse($cert); + openssl_x509_free($cert); $expire = mktime($cert_data['validTo_time_t']); } else { $cert_data = ""; } } #print("
"); #print_r($cert_data); #print(""); - print "
-
Updating domain ...";
if (!$_REQUEST['domain_filter']) return false;
if (!$domain = $this->getRecord($_REQUEST['domain_filter'])) {
return false;
}
- $domain_old=$domain;
+ $domain_old = $domain;
foreach (array_keys($this->Fields) as $item) {
- $var_name=$item.'_form';
- //printf (" Error (VoicemailPort): %s (%s): %s",$error_msg, $error_fault->detail->exception->errorcode, $error_fault->detail->exception->errorstring); + printf(" Error (VoicemailPort): %s (%s): %s", $error_msg, $error_fault->detail->exception->errorcode, $error_fault->detail->exception->errorstring); } } else { $exported_data['voicemail_accounts'][] = $result; } // Filter - $filter=array('targetUsername' => $account->id->username, + $filter = array('targetUsername' => $account->id->username, 'targetDomain' => $account->id->domain ); // Range - $range=array('start' => 0, + $range = array('start' => 0, 'count' => 20 ); // Compose query - $Query=array('filter' => $filter, + $Query = array('filter' => $filter, 'range' => $range ); // Call function $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); $this->log_action('getAliases'); $result = $this->SoapEngine->soapclient->getAliases($Query); - if ((new PEAR)->isError($result)) { + + if ($this->soapHasError($result)) { $error_msg = $result->getMessage(); $error_fault= $result->getFault(); $error_code = $result->getCode(); - printf (" Error (SipPort): %s (%s): %s",$error_msg, $error_fault->detail->exception->errorcode, $error_fault->detail->exception->errorstring); + printf( + " Error (SipPort): %s (%s): %s ", + $error_msg, + $error_fault->detail->exception->errorcode, + $error_fault->detail->exception->errorstring + ); } else { foreach ($result->aliases as $alias) { $exported_data['sip_aliases'][] = objectToArray($alias); } } } } foreach ($export_customers as $customer) { if (!$customer) { continue; } - $filter=array( + $filter = array( 'customer' => intval($customer), ); // Compose query - $Query=array('filter' => $filter + $Query = array('filter' => $filter ); // Insert credetials $this->SoapEngine->soapclientCustomers->addHeader($this->SoapEngine->SoapAuth); $this->log_action('getCustomers'); // Call function $result = $this->SoapEngine->soapclientCustomers->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); + if ($this->checkLogSoapError($result, true)) { return false; } else { $exported_data['customers'] = objectToArray($result->accounts); } } //print_r($exported_data['customers']); print_r(json_encode($exported_data)); } } |