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 "
$this->rows records found

"; if (!$this->next) $this->next=0; if ($this->rows > $this->maxrowsperpage) { $maxrows = $this->maxrowsperpage + $this->next; if ($maxrows > $this->rows) $maxrows = $this->maxrowsperpage; } else { - $maxrows=$this->rows; + $maxrows = $this->rows; } $i=0; if ($this->rows) { - while ($i < $maxrows) { + while ($i < $maxrows) { if (!$result->domains[$i]) break; $domain = $result->domains[$i]; $index = $this->next+$i+1; - $delete_url = $this->url.sprintf( - "&service=%s&action=Delete&domain_filter=%s", - urlencode($this->SoapEngine->service), - urlencode($domain->domain) + $base_url_data = array( + 'service' => $this->SoapEngine->service, + 'domain_filter' => $domain->domain ); - if ($_REQUEST['action'] == 'Delete' && - $_REQUEST['domain_filter'] == $domain->domain) { - $delete_url .= "&confirm=1"; - $deleteText = "Confirm"; - } else { - $deleteText = "Delete"; - } + $delete_url_data = array_merge( + $base_url_data, + array( + 'action' => 'Delete' + ) + ); + + $customer_url_data = array( + 'service' => sprintf('customers@%s', $this->SoapEngine->customer_engine), + 'customer_filter' => $domain->customer + ); + + $sip_domains_url_data = array_merge( + $base_url_data, + array( + 'service' => sprintf('sip_domains@%s', $this->SoapEngine->soapEngine) + ) + ); + + $sip_accounts_url_data = array_merge( + $base_url_data, + array( + 'service' => sprintf('sip_accounts@%s', $this->SoapEngine->soapEngine) + ), + ); + + $sip_aliasses_url_data = array( + 'service' => sprintf('sip_aliases@%s', $this->SoapEngine->soapEngine), + 'alias_domain_filter' => $domain->domain, + ); if ($_REQUEST['action'] == 'Delete' && $_REQUEST['domain_filter'] == $domain->domain) { - $delete_url .= "&confirm=1"; + $delete_url_data['confirm'] = 1; $deleteText = "Confirm"; } else { $deleteText = "Delete"; } - $_customer_url = $this->url.sprintf( - "&service=customers@%s&customer_filter=%s", - urlencode($this->SoapEngine->customer_engine), - urlencode($domain->customer) - ); - - $_sip_domains_url = $this->url.sprintf( - "&service=sip_domains@%s&domain_filter=%s", - urlencode($this->SoapEngine->soapEngine), - urlencode($domain->domain) - ); - - $_sip_accounts_url = $this->url.sprintf( - "&service=sip_accounts@%s&domain_filter=%s", - urlencode($this->SoapEngine->soapEngine), - urlencode($domain->domain) - ); + $delete_url = $this->buildUrl($delete_url_data); + $_customer_url = $this->buildUrl($customer_url_data); + $_sip_domains_url = $this->buildUrl($sip_domains_url_data); + $_sip_accounts_url = $this->buildUrl($sip_accounts_url_data); + $_sip_aliases_url = $this->buildUrl($sip_aliasses_url_data); - $_sip_aliases_url = $this->url.sprintf( - "&service=sip_aliases@%s&alias_domain_filter=%s", - urlencode($this->SoapEngine->soapEngine), - urlencode($domain->domain) - ); if ($this->adminonly) { - $export_url = $this->url.sprintf( - "&service=%s&action=Export&domain_filter=%s", - urlencode($this->SoapEngine->service), - urlencode($domain->domain) + $export_url_data = array_merge( + $base_url_data, + array( + 'action' => 'Export' + ) ); + $export_url = $this->buildUrl($export_url_data); printf( " ", $index, $_customer_url, $domain->customer, $domain->reseller, $_sip_domains_url, $domain->domain, $_sip_accounts_url, $_sip_aliases_url, $domain->changeDate, $delete_url, $deleteText, $export_url ); } else { printf( " ", $index, $_customer_url, $domain->customer, $domain->reseller, $_sip_domains_url, $domain->domain, $_sip_accounts_url, $_sip_aliases_url, $domain->changeDate, $delete_url, $deleteText ); } $i++; } } 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
"; if ($this->rows == 1) { $this->showRecord($domain); } else { $this->showPagination($maxrows); } return true; } } function showSeachFormCustom() { - printf ("

SIP domain
",$this->filters['domain']); + printf( + " +
+ SIP domain + +
+ ", + $this->filters['domain'] + ); } function exportRecord($dictionary = array()) { } function deleteRecord($dictionary = array()) { if (!$dictionary['confirm'] && !$_REQUEST['confirm']) { print "

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 ("

",$_SERVER['PHP_SELF']); - print " -
- "; - - print " - - "; + printf("", $_SERVER['PHP_SELF']); + print <<< END +
+ +END; $this->showCustomerTextBox(); - printf ("
SIP domain
"); - + print <<< END +
+
+ SIP domain + +
+END; $this->printHiddenFormElements(); - printf (" Import SIP domain from file: - -
-
-
- -
- - Select file - Change - - Remove - -
+ + print <<< END + Import SIP domain from file: + +
+
+
+
- " - ); - print "
- - "; + + Select file + Change + + Remove + +
+
+ + +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 ""; - print " - + print <<< END +
+
- "; - printf ("",$_SERVER['PHP_SELF']); +
+END; + printf("", $_SERVER['PHP_SELF']); print ""; print ""; if ($cert_data) { // Parse the resource and print out the contents. - $ts = $cert_data['validTo_time_t']; - $expire = new DateTime("@$ts"); - printf("", $cert_data['subject']['CN']); - printf("", $cert_data['issuer']['C'], $cert_data['issuer']['O'], $cert_data['issuer']['CN']);; - printf("", $expire->format('Y-m-d')); + $ts = $cert_data['validTo_time_t']; + $expire = new DateTime("@$ts"); + printf( + "", + $cert_data['subject']['CN'] + ); + printf( + "", + $cert_data['issuer']['C'], + $cert_data['issuer']['O'], + $cert_data['issuer']['CN'] + ); + printf("", $expire->format('Y-m-d')); } if ($this->adminonly) { foreach (array_keys($this->FieldsAdminOnly) as $item) { if ($this->FieldsAdminOnly[$item]['name']) { - $item_name=$this->FieldsAdminOnly[$item]['name']; + $item_name = $this->FieldsAdminOnly[$item]['name']; } else { - $item_name=preg_replace("/_/"," ",ucfirst($item)); + $item_name = preg_replace("/_/", " ", ucfirst($item)); } if ($this->FieldsAdminOnly[$item]['type'] == 'text') { - printf (" - - - ", - $item_name, - $item, - $domain->$item + printf( + " + + + + ", + $item_name, + $item, + $domain->$item ); - } else if ($this->FieldsAdminOnly[$item]['type'] == 'boolean') { + } elseif ($this->FieldsAdminOnly[$item]['type'] == 'boolean') { if ($domain->$item == 1) { - $checked = "checked"; + $checked = "checked"; } else { $checked = ""; } - - printf (" - - - ", - $item_name, - $item, - $checked + + printf( + " + + + + ", + $item_name, + $item, + $checked ); } else { - printf (" - - - ", - $item_name, - $item, - $domain->$item + printf( + " + + + + ", + $item_name, + $item, + $domain->$item ); } } } foreach (array_keys($this->Fields) as $item) { if ($this->Fields[$item]['name']) { - $item_name=$this->Fields[$item]['name']; + $item_name = $this->Fields[$item]['name']; } else { - $item_name = preg_replace("/_/"," ",ucfirst($item)); + $item_name = preg_replace("/_/", " ", ucfirst($item)); } if ($this->Fields[$item]['type'] == 'text') { printf( - " + " + - ", + + ", $item_name, $item, $domain->$item ); } elseif ($this->Fields[$item]['type'] == 'boolean') { if ($domain->$item == 1) { $checked = "checked"; } else { $checked = ""; } printf( - " + " + - ", + + ", $item_name, $item, $checked ); } else { printf( - " + " + - ", + + ", $item_name, $item, $domain->$item ); } } printf("", $domain->domain); $this->printFiltersToForm(); $this->printHiddenFormElements(); print ""; print "
TLS CN%s
CA Issuer%s %s %s
Expire date%s
TLS CN%s
CA Issuer%s %s %s
Expire date%s
%s
%s
%s
%s
%s
%s
%s
%s
%s
"; } function updateRecord() { //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 ("
%s=%s",$var_name,$_REQUEST[$var_name]); + $var_name = $item.'_form'; + //printf("
%s=%s", $var_name,$_REQUEST[$var_name]); if ($this->Fields[$item]['type'] == 'integer') { $domain->$item = intval($_REQUEST[$var_name] == 1); - } else if ($this->Fields[$item]['type'] == 'boolean') { + } elseif ($this->Fields[$item]['type'] == 'boolean') { $domain->$item = intval($_REQUEST[$var_name]); } else { $domain->$item = trim($_REQUEST[$var_name]); } } if ($this->adminonly) { foreach (array_keys($this->FieldsAdminOnly) as $item) { - $var_name=$item.'_form'; - //printf ("
%s=%s",$var_name,$_REQUEST[$var_name]); + $var_name = $item.'_form'; + //printf("
%s=%s", $var_name,$_REQUEST[$var_name]); if ($this->FieldsAdminOnly[$item]['type'] == 'integer') { $domain->$item = intval($_REQUEST[$var_name]); - } else if ($this->Fields[$item]['type'] == 'boolean') { + } elseif ($this->Fields[$item]['type'] == 'boolean') { $domain->$item = intval($_REQUEST[$var_name]); } else { $domain->$item = trim($_REQUEST[$var_name]); } } } - $function=array('commit' => array('name' => 'updateDomain', - 'parameters' => array($domain), - 'logs' => array('success' => sprintf('Domain %s has been updated',$domain->domain))) - ); + $function = array( + 'commit' => array( + 'name' => 'updateDomain', + 'parameters' => array($domain), + 'logs' => array('success' => sprintf('Domain %s has been updated', $domain->domain)) + ) + ); return $this->SoapEngine->execute($function, $this->html); } - function hide_html() { + function hide_html() + { if ($_REQUEST['action'] == 'Export') { return true; } else { return false; } } - function exportDomain($domain) { + function exportDomain($domain) + { $exported_data= array(); // Filter - $filter=array( + $filter = array( 'domain' => $domain, 'customer' => intval($this->filters['customer']), 'reseller' => intval($this->filters['reseller']) ); // Range - $range=array('start' => 0, + $range = array('start' => 0, 'count' => 1000 ); // Compose query - $Query=array('filter' => $filter, + $Query = array('filter' => $filter, 'range' => $range ); $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); $this->log_action('getDomains'); $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 { $i = 0 ; while ($i < $result->total) { $domain = $result->domains[$i]; if (!in_array($domain->customer, $export_customers)) { - $export_customers[]=$domain->customer; + $export_customers[] = $domain->customer; } if (!in_array($domain->reseller, $export_customers)) { - $export_customers[]=$domain->reseller; + $export_customers[] = $domain->reseller; } $i+=1; $exported_data['sip_domains'][] = objectToArray($domain); } } $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); $this->log_action('getAccounts'); // Call function - $result = call_user_func_array(array($this->SoapEngine->soapclient,'getAccounts'),array($Query)); + $result = call_user_func_array(array($this->SoapEngine->soapclient, 'getAccounts'), array($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['sip_accounts'] = objectToArray($result->accounts); foreach ($result->accounts as $account) { if (!in_array($account->owner, $export_customers)) { - $export_customers[]=$account->owner; + $export_customers[] = $account->owner; } - $sipId=array("username" => $account->id->username, + $sipId = array("username" => $account->id->username, "domain" => $account->id->domain ); $this->SoapEngine->soapclientVoicemail->addHeader($this->SoapEngine->SoapAuthVoicemail); $result = $this->SoapEngine->soapclientVoicemail->getAccount($sipId); - 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 != "2000" && $error_fault->detail->exception->errorcode != "1010") { - 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)); } }