[Moved TrustedPeers to seperate file Tijmen de Mes **20240214092909 Ignore-this: 26d21c0049bdfb5e7902c2d7b5b8eea8200cf802a3e8b75cd7e2f5980ec843f0e608331ad6694116 ] addfile ./library/NGNPro/Records/TrustedPeers.php hunk ./library/NGNPro/Records/TrustedPeers.php 1 + 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 " +
$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; + } + + $i=0; + + if ($this->rows) { + while ($i < $maxrows) { + + if (!$result->peers[$i]) break; + + $peer = $result->peers[$i]; + + $index=$this->next+$i+1; + + $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)) + ); + + $update_url = $this->url.sprintf("&service=%s&ip_filter=%s&msteams_filter=%s", + urlencode($this->SoapEngine->service), + urlencode($peer->ip), + urlencode($peer->msteams) + ); + + if ($_REQUEST['action'] == 'Delete' && + $_REQUEST['ip_filter'] == $peer->ip) { + $delete_url .= "&confirm=1"; + $actionText = "Confirm"; + } else { + $actionText = "Delete"; + } + 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 + ); + + $i++; + } + } + + print "
Id + OwnerTrusted peerPrepaidCapacityMS TeamsTenantDescriptionBlockedChange dateActions
%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 " + + +
+ "; + 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']; + } else { + $item_name=ucfirst($item); + } + + if ($this->FieldsAdminOnly[$item]['type'] == 'text') { + printf (" + + + ", + $item_name, + $item, + $peer->$item + ); + } else if ($this->FieldsAdminOnly[$item]['type'] == 'boolean') { + if ($peer->$item == 1) { + $checked = "checked"; + } else { + $checked = ""; + } + + printf (" + + + ", + $item_name, + $item, + $checked + ); + } else { + printf (" + + + ", + $item_name, + $item, + $peer->$item + ); + } + } + } + + foreach (array_keys($this->Fields) as $item) { + if ($this->Fields[$item]['name']) { + $item_name=$this->Fields[$item]['name']; + } else { + $item_name=ucfirst($item); + } + + if ($this->Fields[$item]['type'] == 'text') { + printf (" + + + ", + $item_name, + $item, + $peer->$item + ); + } else if ($this->Fields[$item]['type'] == 'boolean') { + if ($peer->$item == 1) { + $checked = "checked"; + } else { + $checked = ""; + } + + printf (" + + + ", + $item_name, + $item, + $checked + ); + } else { + printf (" + + + ", + $item_name, + $item, + $peer->$item + ); + } + } + + print " + "; + + printf ("",$peer->ip); + $this->printFiltersToForm(); + + $this->printHiddenFormElements(); + + print ""; + print " +
%s
%s
%s
%s
%s
%s
+
+ "; + } + + function showAddForm() { + //if ($this->selectionActive) return; + + printf ("
",$_SERVER['PHP_SELF']); + print " +
+ "; + + print " + + "; + $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); + + $this->printHiddenFormElements(); + + print "
+
+
+ "; + } + + 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); + + if (!strlen($ipaddress)) { + printf ("

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

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 () { + print "
Owner"; + $this->showResellerForm('reseller'); + print "
"; + } + + function showTextBeforeCustomerSelection() { + print "Owner"; + } + + function showCustomerForm($name='customer_filter') { + } +} + hunk ./library/ngnpro_client.php 2784 -class TrustedPeers extends Records -{ - 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']) - ); - - 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 " -
$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; - } - - $i=0; - - if ($this->rows) { - while ($i < $maxrows) { - - if (!$result->peers[$i]) break; - - $peer = $result->peers[$i]; - - $index=$this->next+$i+1; - - $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)) - ); - - $update_url = $this->url.sprintf("&service=%s&ip_filter=%s&msteams_filter=%s", - urlencode($this->SoapEngine->service), - urlencode($peer->ip), - urlencode($peer->msteams) - ); - - if ($_REQUEST['action'] == 'Delete' && - $_REQUEST['ip_filter'] == $peer->ip) { - $delete_url .= "&confirm=1"; - $actionText = "Confirm"; - } else { - $actionText = "Delete"; - } - 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 - ); - - $i++; - } - } - - print "
Id - OwnerTrusted peerPrepaidCapacityMS TeamsTenantDescriptionBlockedChange dateActions
%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 " - - -
- "; - 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']; - } else { - $item_name=ucfirst($item); - } - - if ($this->FieldsAdminOnly[$item]['type'] == 'text') { - printf (" - - - ", - $item_name, - $item, - $peer->$item - ); - } else if ($this->FieldsAdminOnly[$item]['type'] == 'boolean') { - if ($peer->$item == 1) { - $checked = "checked"; - } else { - $checked = ""; - } - - printf (" - - - ", - $item_name, - $item, - $checked - ); - } else { - printf (" - - - ", - $item_name, - $item, - $peer->$item - ); - } - } - } - - foreach (array_keys($this->Fields) as $item) { - if ($this->Fields[$item]['name']) { - $item_name=$this->Fields[$item]['name']; - } else { - $item_name=ucfirst($item); - } - - if ($this->Fields[$item]['type'] == 'text') { - printf (" - - - ", - $item_name, - $item, - $peer->$item - ); - } else if ($this->Fields[$item]['type'] == 'boolean') { - if ($peer->$item == 1) { - $checked = "checked"; - } else { - $checked = ""; - } - - printf (" - - - ", - $item_name, - $item, - $checked - ); - } else { - printf (" - - - ", - $item_name, - $item, - $peer->$item - ); - } - } - - print " - "; - - printf ("",$peer->ip); - $this->printFiltersToForm(); - - $this->printHiddenFormElements(); - - print ""; - print " -
%s
%s
%s
%s
%s
%s
-
- "; - } - - function showAddForm() { - //if ($this->selectionActive) return; - - printf ("
",$_SERVER['PHP_SELF']); - print " -
- "; - - print " - - "; - $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); - - $this->printHiddenFormElements(); - - print "
-
-
- "; - } - - 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); - - if (!strlen($ipaddress)) { - printf ("

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

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 () { - print "
Owner"; - $this->showResellerForm('reseller'); - print "
"; - } - - function showTextBeforeCustomerSelection() { - print "Owner"; - } - - function showCustomerForm($name='customer_filter') { - } -} - +require_once 'NGNPro/Records/TrustedPeers.php';