[Moved gateways to seperate file Tijmen de Mes **20240219101149 Ignore-this: 7ce46ca6effb27d03d8b4751aafe0b2a32e988ca08ff2bdab0a5f8b4ef9dca9d4a5615851432d130 ] addfile ./library/NGNPro/Records/Gateways.php hunk ./library/NGNPro/Records/Gateways.php 1 + array('type'=>'integer', + 'readonly' => true), + 'name' => array('type'=>'string'), + 'carrier_id' => array('type'=>'integer'), + 'transport' => array('type'=>'string'), + 'ip' => array('name'=>'IP or hostname', + 'type'=>'string'), + 'port' => array('type'=>'integer') + ); + + //var $transports=array('udp','tcp','tls'); + var $transports=array('udp'); + + public function __construct($SoapEngine) + { + $this->filters = array( + 'id' => trim($_REQUEST['id_filter']), + 'name' => trim($_REQUEST['name_filter']), + 'carrier_id' => trim($_REQUEST['carrier_id_filter']) + ); + + $this->sortElements=array( + 'changeDate' => 'Change date', + 'name' => 'Gateway', + 'carrier_id' => 'Carrier', + 'ip' => 'Address' + ); + + parent::__construct($SoapEngine); + } + + function listRecords() { + $this->getCarriers(); + + $this->showSeachForm(); + + // Insert credetials + $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); + + // Filter + $filter=array('id' => intval($this->filters['id']), + 'name' => $this->filters['name'], + 'carrier_id'=> intval($this->filters['carrier_id']), + '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 + ); + + // Call function + $this->log_action('getGateways'); + $result = $this->SoapEngine->soapclient->getGateways($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; + + print " +
$this->rows records found
+

+ + "; + + print " + + + + + + + + + + + + + + "; + + 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->gateways[$i]) break; + + $gateway = $result->gateways[$i]; + + $index=$this->next+$i+1; + + $_delete_url = $this->url.sprintf("&service=%s&action=Delete&id_filter=%s", + urlencode($this->SoapEngine->service), + urlencode($gateway->id) + ); + + if ($_REQUEST['action'] == 'Delete' && + $_REQUEST['id_filter'] == $gateway->id) { + $_delete_url .= "&confirm=1"; + $actionText = "Confirm"; + } else { + $actionText = "Delete"; + } + + $_url = $this->url.sprintf("&service=%s&id_filter=%s", + urlencode($this->SoapEngine->service), + urlencode($gateway->id) + ); + + $_customer_url = $this->url.sprintf("&service=customers@%s&customer_filter=%s", + urlencode($this->SoapEngine->customer_engine), + urlencode($gateway->reseller) + ); + + $_carrier_url = $this->url.sprintf("&service=pstn_carriers@%s&id_filter=%s&reseller_filter=%s", + urlencode($this->SoapEngine->soapEngine), + urlencode($gateway->carrier_id), + urlencode($gateway->reseller) + ); + + $_rules_url = $this->url.sprintf("&service=gateway_rules@%s&gateway_id_filter=%s&reseller_filter=%s", + urlencode($this->SoapEngine->soapEngine), + urlencode($gateway->id), + urlencode($gateway->reseller) + ); + + $_r=0; + + printf(" + + + + + + + + + + + ", + $index, + $_customer_url, + $gateway->reseller, + $_url, + $gateway->id, + $_carrier_url, + $gateway->carrier, + $gateway->name, + $gateway->transport, + $gateway->ip, + $gateway->port, + $_rules_url, + $gateway->changeDate, + $_delete_url, + $actionText + ); + + printf(" + + "); + + $i++; + + } + + } + + print "
IdOwnerGatewayCarrierNameAddressRulesChange dateActions
%s%s%s%s%s%s:%s:%sRules%s%s
"; + + if ($this->rows == 1) { + $this->showRecord($gateway); + } else { + $this->showPagination($maxrows); + } + + return true; + } + } + + function showAddForm() { + //if ($this->selectionActive) return; + + $this->getCarriers(); + + if (!count($this->carriers)) { + print "

Create a carrier first"; + return false; + } + + printf ("

",$_SERVER['PHP_SELF']); + print " +
+ "; + + print " + + "; + + printf (" Carrier "); + + print ""); + + printf ("
Name
"); + + printf ("
Transport"); + + print "
"); + + printf ("
Address
"); + + $this->printHiddenFormElements(); + + print "
+
+ "; + } + + function addRecord($dictionary=array()) { + if ($dictionary['name']) { + $name = $dictionary['name']; + } else { + $name = trim($_REQUEST['name']); + } + + if ($dictionary['carrier_id']) { + $carrier_id = $dictionary['carrier_id']; + } else { + $carrier_id = trim($_REQUEST['carrier_id']); + } + + if ($dictionary['address']) { + $address = $dictionary['address']; + } else { + $address = trim($_REQUEST['address']); + } + + if ($dictionary['transport']) { + $transport = $dictionary['transport']; + } else { + $transport = trim($_REQUEST['transport']); + } + + if (!strlen($name) || !strlen($carrier_id) || !strlen($address)) { + printf ("

Error: Missing gateway name, carrier_id or address"); + return false; + } + + $address_els=explode(':',$address); + + if (count($address_els) == 1) { + $ip = $address_els[0]; + $port ='5060'; + } else if (count($address_els) == 2) { + $ip = $address_els[0]; + $port = $address_els[1]; + } + + if (!$port) $port = 5060; + + if (!in_array($transport,$this->transports)) { + $transport=$this->transports[0]; + } + + $gateway=array( + 'name' => $name, + 'carrier_id' => intval($carrier_id), + 'ip' => $ip, + 'port' => intval($port), + 'transport' => $transport + ); + + $function=array('commit' => array('name' => 'addGateway', + 'parameters' => array($gateway), + 'logs' => array('success' => sprintf('Gateway %s has been added',$name))) + ); + + unset($this->filters); + 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 ($dictionary['id']) { + $id = $dictionary['id']; + } else { + $id = trim($this->filters['id']); + } + + if (!strlen($id)) { + print "

Error: missing gateway id. "; + return false; + } + + $function=array('commit' => array('name' => 'deleteGateway', + 'parameters' => array(intval($id)), + 'logs' => array('success' => sprintf('Gateway %d has been deleted',$id))) + ); + unset($this->filters); + return $this->SoapEngine->execute($function,$this->html); + + } + + function showSeachFormCustom() { + printf ("

Gateway
",$this->filters['id']); + + print " + "); + printf ("
Name
",$this->filters['name']); + + } + + function showCustomerForm($name='customer_filter') { + } + + function showTextBeforeCustomerSelection() { + print "Owner"; + } + + function showRecord($gateway) { + + print "

Gateway

"; + + printf ("
",$_SERVER['PHP_SELF']); + print ""; + + foreach (array_keys($this->Fields) as $item) { + if ($this->Fields[$item]['name']) { + $item_name=$this->Fields[$item]['name']; + } else { + $item_name=ucfirst($item); + } + + printf ("
+ + ", + $item_name + ); + + if ($this->Fields[$item]['readonly']) { + printf ("
%s
", + $item, + $gateway->$item, + $gateway->$item + ); + } else { + if ($item == 'carrier_id') { + printf ("
"); + + } else if ($item == 'transport') { + printf ("
"; + + } else { + printf ("
", + $item, + $gateway->$item + ); + } + } + print " +
"; + } + + printf ("",$gateway->id); + + $this->printFiltersToForm(); + $this->printHiddenFormElements(); + + print " +
+ +
+ "; + print "
"; + + } + + function updateRecord () { + //print "

Updating gateway ..."; + + if (!$_REQUEST['id_filter']) return; + + if (!$gateway = $this->getRecord($_REQUEST['id_filter'])) { + return false; + } + + foreach (array_keys($this->Fields) as $item) { + $var_name=$item.'_form'; + if ($this->Fields[$item]['type'] == 'integer') { + $gateway->$item = intval($_REQUEST[$var_name]); + } else { + $gateway->$item = trim($_REQUEST[$var_name]); + } + } + + if (!in_array($gateway->transport,$this->transports)) { + printf ("Invalid transport '%s'",$gateway->transport); + return false; + } + + $function=array('commit' => array('name' => 'updateGateway', + 'parameters' => array($gateway), + 'logs' => array('success' => sprintf('Gateway %s has been updated',$_REQUEST['name_filter']))) + ); + + $result = $this->SoapEngine->execute($function,$this->html); + + dprint_r($result) ; + 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 { + return true; + } + } + + function getRecord($id) { + // Insert credetials + $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); + + // Filter + $filter=array('id' => intval($id)); + + // Range + $range=array('start' => 0, + 'count' => 1 + ); + + // Order + if (!$this->sorting['sortBy']) $this->sorting['sortBy'] = 'name'; + 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('getGateways'); + $result = $this->SoapEngine->soapclient->getGateways($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 { + if ($result->gateways[0]){ + return $result->gateways[0]; + } else { + return false; + } + } + } +} + hunk ./library/ngnpro_client.php 2786 - -class Gateways extends Records -{ - var $carriers=array(); - var $FieldsReadOnly=array( - 'reseller', - 'changeDate' - ); - - var $Fields=array( - 'id' => array('type'=>'integer', - 'readonly' => true), - 'name' => array('type'=>'string'), - 'carrier_id' => array('type'=>'integer'), - 'transport' => array('type'=>'string'), - 'ip' => array('name'=>'IP or hostname', - 'type'=>'string'), - 'port' => array('type'=>'integer') - ); - - //var $transports=array('udp','tcp','tls'); - var $transports=array('udp'); - - public function __construct($SoapEngine) - { - $this->filters = array( - 'id' => trim($_REQUEST['id_filter']), - 'name' => trim($_REQUEST['name_filter']), - 'carrier_id' => trim($_REQUEST['carrier_id_filter']) - ); - - $this->sortElements=array( - 'changeDate' => 'Change date', - 'name' => 'Gateway', - 'carrier_id' => 'Carrier', - 'ip' => 'Address' - ); - - parent::__construct($SoapEngine); - } - - function listRecords() { - $this->getCarriers(); - - $this->showSeachForm(); - - // Insert credetials - $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); - - // Filter - $filter=array('id' => intval($this->filters['id']), - 'name' => $this->filters['name'], - 'carrier_id'=> intval($this->filters['carrier_id']), - '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 - ); - - // Call function - $this->log_action('getGateways'); - $result = $this->SoapEngine->soapclient->getGateways($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; - - print " -

$this->rows records found
-

- - "; - - print " - - - - - - - - - - - - - - "; - - 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->gateways[$i]) break; - - $gateway = $result->gateways[$i]; - - $index=$this->next+$i+1; - - $_delete_url = $this->url.sprintf("&service=%s&action=Delete&id_filter=%s", - urlencode($this->SoapEngine->service), - urlencode($gateway->id) - ); - - if ($_REQUEST['action'] == 'Delete' && - $_REQUEST['id_filter'] == $gateway->id) { - $_delete_url .= "&confirm=1"; - $actionText = "Confirm"; - } else { - $actionText = "Delete"; - } - - $_url = $this->url.sprintf("&service=%s&id_filter=%s", - urlencode($this->SoapEngine->service), - urlencode($gateway->id) - ); - - $_customer_url = $this->url.sprintf("&service=customers@%s&customer_filter=%s", - urlencode($this->SoapEngine->customer_engine), - urlencode($gateway->reseller) - ); - - $_carrier_url = $this->url.sprintf("&service=pstn_carriers@%s&id_filter=%s&reseller_filter=%s", - urlencode($this->SoapEngine->soapEngine), - urlencode($gateway->carrier_id), - urlencode($gateway->reseller) - ); - - $_rules_url = $this->url.sprintf("&service=gateway_rules@%s&gateway_id_filter=%s&reseller_filter=%s", - urlencode($this->SoapEngine->soapEngine), - urlencode($gateway->id), - urlencode($gateway->reseller) - ); - - $_r=0; - - printf(" - - - - - - - - - - - ", - $index, - $_customer_url, - $gateway->reseller, - $_url, - $gateway->id, - $_carrier_url, - $gateway->carrier, - $gateway->name, - $gateway->transport, - $gateway->ip, - $gateway->port, - $_rules_url, - $gateway->changeDate, - $_delete_url, - $actionText - ); - - printf(" - - "); - - $i++; - - } - - } - - print "
IdOwnerGatewayCarrierNameAddressRulesChange dateActions
%s%s%s%s%s%s:%s:%sRules%s%s
"; - - if ($this->rows == 1) { - $this->showRecord($gateway); - } else { - $this->showPagination($maxrows); - } - - return true; - } - } - - function showAddForm() { - //if ($this->selectionActive) return; - - $this->getCarriers(); - - if (!count($this->carriers)) { - print "

Create a carrier first"; - return false; - } - - printf ("

",$_SERVER['PHP_SELF']); - print " -
- "; - - print " - - "; - - printf (" Carrier "); - - print ""); - - printf ("
Name
"); - - printf ("
Transport"); - - print "
"); - - printf ("
Address
"); - - $this->printHiddenFormElements(); - - print "
-
- "; - } - - function addRecord($dictionary=array()) { - if ($dictionary['name']) { - $name = $dictionary['name']; - } else { - $name = trim($_REQUEST['name']); - } - - if ($dictionary['carrier_id']) { - $carrier_id = $dictionary['carrier_id']; - } else { - $carrier_id = trim($_REQUEST['carrier_id']); - } - - if ($dictionary['address']) { - $address = $dictionary['address']; - } else { - $address = trim($_REQUEST['address']); - } - - if ($dictionary['transport']) { - $transport = $dictionary['transport']; - } else { - $transport = trim($_REQUEST['transport']); - } - - if (!strlen($name) || !strlen($carrier_id) || !strlen($address)) { - printf ("

Error: Missing gateway name, carrier_id or address"); - return false; - } - - $address_els=explode(':',$address); - - if (count($address_els) == 1) { - $ip = $address_els[0]; - $port ='5060'; - } else if (count($address_els) == 2) { - $ip = $address_els[0]; - $port = $address_els[1]; - } - - if (!$port) $port = 5060; - - if (!in_array($transport,$this->transports)) { - $transport=$this->transports[0]; - } - - $gateway=array( - 'name' => $name, - 'carrier_id' => intval($carrier_id), - 'ip' => $ip, - 'port' => intval($port), - 'transport' => $transport - ); - - $function=array('commit' => array('name' => 'addGateway', - 'parameters' => array($gateway), - 'logs' => array('success' => sprintf('Gateway %s has been added',$name))) - ); - - unset($this->filters); - 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 ($dictionary['id']) { - $id = $dictionary['id']; - } else { - $id = trim($this->filters['id']); - } - - if (!strlen($id)) { - print "

Error: missing gateway id. "; - return false; - } - - $function=array('commit' => array('name' => 'deleteGateway', - 'parameters' => array(intval($id)), - 'logs' => array('success' => sprintf('Gateway %d has been deleted',$id))) - ); - unset($this->filters); - return $this->SoapEngine->execute($function,$this->html); - - } - - function showSeachFormCustom() { - printf ("

Gateway
",$this->filters['id']); - - print " - "); - printf ("
Name
",$this->filters['name']); - - } - - function showCustomerForm($name='customer_filter') { - } - - function showTextBeforeCustomerSelection() { - print "Owner"; - } - - function showRecord($gateway) { - - print "

Gateway

"; - - printf ("
",$_SERVER['PHP_SELF']); - print ""; - - foreach (array_keys($this->Fields) as $item) { - if ($this->Fields[$item]['name']) { - $item_name=$this->Fields[$item]['name']; - } else { - $item_name=ucfirst($item); - } - - printf ("
- - ", - $item_name - ); - - if ($this->Fields[$item]['readonly']) { - printf ("
%s
", - $item, - $gateway->$item, - $gateway->$item - ); - } else { - if ($item == 'carrier_id') { - printf ("
"); - - } else if ($item == 'transport') { - printf ("
"; - - } else { - printf ("
", - $item, - $gateway->$item - ); - } - } - print " -
"; - } - - printf ("",$gateway->id); - - $this->printFiltersToForm(); - $this->printHiddenFormElements(); - - print " -
- -
- "; - print "
"; - - } - - function updateRecord () { - //print "

Updating gateway ..."; - - if (!$_REQUEST['id_filter']) return; - - if (!$gateway = $this->getRecord($_REQUEST['id_filter'])) { - return false; - } - - foreach (array_keys($this->Fields) as $item) { - $var_name=$item.'_form'; - if ($this->Fields[$item]['type'] == 'integer') { - $gateway->$item = intval($_REQUEST[$var_name]); - } else { - $gateway->$item = trim($_REQUEST[$var_name]); - } - } - - if (!in_array($gateway->transport,$this->transports)) { - printf ("Invalid transport '%s'",$gateway->transport); - return false; - } - - $function=array('commit' => array('name' => 'updateGateway', - 'parameters' => array($gateway), - 'logs' => array('success' => sprintf('Gateway %s has been updated',$_REQUEST['name_filter']))) - ); - - $result = $this->SoapEngine->execute($function,$this->html); - - dprint_r($result) ; - 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 { - return true; - } - } - - function getRecord($id) { - // Insert credetials - $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); - - // Filter - $filter=array('id' => intval($id)); - - // Range - $range=array('start' => 0, - 'count' => 1 - ); - - // Order - if (!$this->sorting['sortBy']) $this->sorting['sortBy'] = 'name'; - 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('getGateways'); - $result = $this->SoapEngine->soapclient->getGateways($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 { - if ($result->gateways[0]){ - return $result->gateways[0]; - } else { - return false; - } - } - } -} - +require_once 'NGNPro/Records/Gateways.php';