diff --git a/library/NGNPro/Records/TrustedPeers.php b/library/NGNPro/Records/TrustedPeers.php index c7b364b..4e901f8 100644 --- a/library/NGNPro/Records/TrustedPeers.php +++ b/library/NGNPro/Records/TrustedPeers.php @@ -1,498 +1,602 @@ 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') - ); + var $FieldsAdminOnly = array( + 'msteams' => 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']) - ); + $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' - ); + $this->sortElements = array( + 'changeDate' => 'Change date', + 'description' => 'Description', + 'ip' => 'Address' + ); } - function listRecords() { + 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']) - ); + $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) - ); + $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'] - ); + $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 + ); // Call function $this->log_action('getTrustedPeers'); - $result = $this->SoapEngine->soapclient->getTrustedPeers($Query); + $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); + if ($this->checkLogSoapError($result, true)) { return false; } else { $this->rows = $result->total; if ($this->rows && $_REQUEST['action'] != 'PerformActions' && $_REQUEST['action'] != 'Delete') { $this->showActionsForm(); } - print " -
$this->rows records found
- - - - - - - - - - - - - - - - - "; + print <<< END +
$this->rows records found
+
Id - OwnerTrusted peerPrepaidCapacityMS TeamsTenantDescriptionBlockedChange dateActions
+ + + + + + + + + + + + + + +END; 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) { if (!$result->peers[$i]) break; $peer = $result->peers[$i]; - $index=$this->next+$i+1; + $index = $this->next+$i+1; + + $base_url_data = array( + 'service' => $this->SoapEngine->service, + 'ip_filter' => $peer->ip + 'msteams_filter' => $peer->msteams + ); - $delete_url = $this->url.sprintf("&service=%s&action=Delete&ip_filter=%s&msteams_filter=%s", - urlencode($this->SoapEngine->service), - urlencode($peer->ip), - urlencode(intval($peer->msteams)) + $delete_url_data = array_merge( + $base_url_data, + array( + 'action' => 'Delete' + ) ); - $update_url = $this->url.sprintf("&service=%s&ip_filter=%s&msteams_filter=%s", - urlencode($this->SoapEngine->service), - urlencode($peer->ip), - urlencode($peer->msteams) + $update_url_data = $base_url_data; + + $customer_url_data = array( + 'service' => sprintf('customers@%s', $this->SoapEngine->customer_engine), + 'customer_filter' => $peer->reseller ); if ($_REQUEST['action'] == 'Delete' && $_REQUEST['ip_filter'] == $peer->ip) { - $delete_url .= "&confirm=1"; + $delete_url_data['confirm'] = 1; $actionText = "Confirm"; } else { $actionText = "Delete"; } + + $delete_url = $this->buildUrl($delete_url_data); + $update_url = $this->buildUrl($_url_data); + $_customer_url = $this->buildUrl($customer_url_data); + if ($peer->msteams) { $msteams = 'Yes'; } else { $msteams = 'No'; } if ($peer->prepaid) { $prepaid = 'Yes'; } else { $prepaid = 'No'; } - $_customer_url = $this->url.sprintf("&service=customers@%s&customer_filter=%s", - urlencode($this->SoapEngine->customer_engine), - urlencode($peer->reseller) - ); - - printf(" - - - - - - - - - - - - - ", - $index, - $_customer_url, - $peer->reseller, - $update_url, - $peer->ip, - $prepaid, - $peer->callLimit, - $msteams, - $peer->tenant, - $peer->description, - $peer->blocked, - $peer->changeDate, - $delete_url, - $actionText + printf( + " + + + + + + + + + + + + + + ", + $index, + $_customer_url, + $peer->reseller, + $update_url, + $peer->ip, + $prepaid, + $peer->callLimit, + $msteams, + $peer->tenant, + $peer->description, + $peer->blocked, + $peer->changeDate, + $delete_url, + $actionText ); $i++; } } print "
Id + OwnerTrusted peerPrepaidCapacityMS TeamsTenantDescriptionBlockedChange dateActions
%s%s%s%s%s%s%s%s%s%s%s
%s%s%s%s%s%s%s%s%s%s%s
"; if ($result->total == 1) { $this->showRecord($peer); } $this->showPagination($maxrows); return true; } } - function showRecord($peer) { - print ""; - print " - + function showRecord($peer) + { + print <<< END +
+
- "; - printf ("",$_SERVER['PHP_SELF']); +
+END; + printf("", $_SERVER['PHP_SELF']); print ""; 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=ucfirst($item); + $item_name = ucfirst($item); } if ($this->FieldsAdminOnly[$item]['type'] == 'text') { - printf (" - - - ", - $item_name, - $item, - $peer->$item + printf( + " + + + + + ", + $item_name, + $item, + $peer->$item ); - } else if ($this->FieldsAdminOnly[$item]['type'] == 'boolean') { + } elseif ($this->FieldsAdminOnly[$item]['type'] == 'boolean') { if ($peer->$item == 1) { - $checked = "checked"; + $checked = "checked"; } else { $checked = ""; } - - printf (" - - - ", - $item_name, - $item, - $checked + + printf( + " + + + + + ", + $item_name, + $item, + $checked ); } else { - printf (" - - - ", - $item_name, - $item, - $peer->$item + printf( + " + + + + + ", + $item_name, + $item, + $peer->$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=ucfirst($item); + $item_name = ucfirst($item); } if ($this->Fields[$item]['type'] == 'text') { - printf (" - - - ", - $item_name, - $item, - $peer->$item + printf( + " + + + + + ", + $item_name, + $item, + $peer->$item ); - } else if ($this->Fields[$item]['type'] == 'boolean') { + } elseif ($this->Fields[$item]['type'] == 'boolean') { if ($peer->$item == 1) { - $checked = "checked"; + $checked = "checked"; } else { $checked = ""; } - - printf (" - - - ", - $item_name, - $item, - $checked + + printf( + " + + + + + ", + $item_name, + $item, + $checked ); } else { - printf (" - - - ", - $item_name, - $item, - $peer->$item + printf( + " + + + + + ", + $item_name, + $item, + $peer->$item ); } } - print " - "; - - printf ("",$peer->ip); + print <<< END + + + +END; + printf("", $peer->ip); $this->printFiltersToForm(); $this->printHiddenFormElements(); - print ""; - print " -
%s
%s
%s
%s
%s
%s
%s
%s
%s
%s
%s
%s
-
- "; + print <<< END + +
+END; } - function showAddForm() { + function showAddForm() + { //if ($this->selectionActive) return; - printf ("
",$_SERVER['PHP_SELF']); - print " -
- "; - - print " - - "; + printf("", $_SERVER['PHP_SELF']); + print <<< END +
+ +END; $this->showCustomerTextBox(); if ($this->filters['msteams']) { $checked = 'checked'; } else { $checked = ''; } - printf ("
Address
"); - printf ("
Call limit
"); - printf ("
Description
"); - printf ("
Tenant
", $this->filters['tenant']); - printf ("
MS Teams
", $checked); + print <<< END +
+ Address +
+
+ Call limit +
+
+ Description +
+END; + printf( + " +
+ Tenant +
+ ", + $this->filters['tenant'] + ); + printf( + " +
+ MS Teams +
+ ", + $checked + ); $this->printHiddenFormElements(); - print "
- - - - "; + print <<< END +
+ + + +END; } - function addRecord($dictionary=array()) { - + function addRecord($dictionary = array()) + { if ($dictionary['ipaddress']) { $ipaddress = $dictionary['ipaddress']; } else { $ipaddress = trim($_REQUEST['ipaddress']); } if ($dictionary['msteams']) { $msteams = $dictionary['msteams']; } else { $msteams = trim($_REQUEST['msteams']); } - + $this->filters['msteams'] = $msteams; if ($dictionary['description']) { $description = $dictionary['description']; } else { $description = trim($_REQUEST['description']); } if ($dictionary['tenant']) { $tenant = $dictionary['tenant']; } else { $tenant = trim($_REQUEST['tenant']); } if ($dictionary['callLimit']) { $callLimit = $dictionary['callLimit']; } else { $callLimit = trim($_REQUEST['callLimit']); } if ($dictionary['owner']) { $owner = $dictionary['owner']; } else { $owner = trim($_REQUEST['owner']); } - list($customer,$reseller)=$this->customerFromLogin($dictionary); + list($customer, $reseller)=$this->customerFromLogin($dictionary); if (!strlen($ipaddress)) { - printf ("

Error: Missing IP or description. "); + print "

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); + $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); + 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); + $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()) { + 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']))) - ); + $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); + return $this->SoapEngine->execute($function, $this->html); } - function showSeachFormCustom() { + function showSeachFormCustom() + { if (intval($this->filters['msteams']) == 1) { $checked_msteams = 'checked'; } else { $checked_msteams = ''; } - printf ("

Address
",$this->filters['ip']); - printf ("
Description
",$this->filters['description']); - printf ("
Tenant
",$this->filters['tenant']); - printf ("
Blocked
",$this->filters['blocked']); - printf ("
MS Teams
",$checked_msteams); - + printf( + " +
+ Address +
+ ", + $this->filters['ip'] + ); + printf( + " +
+ Description +
+ ", + $this->filters['description'] + ); + printf( + " +
+ Tenant +
+ ", + $this->filters['tenant'] + ); + printf( + " +
+ Blocked +
+ ", + $this->filters['blocked'] + ); + printf( + "
+ MS Teams +
+ ", + $checked_msteams + ); } - function showCustomerTextBox () { + function showCustomerTextBox() + { print "
Owner"; $this->showResellerForm('reseller'); print "
"; } - function showTextBeforeCustomerSelection() { + function showTextBeforeCustomerSelection() + { print "Owner"; } - function showCustomerForm($name='customer_filter') { + function showCustomerForm($name = 'customer_filter') + { } } -