[Added gateway rules and fixed LCR provisioning Adrian Georgescu **20090410154614] hunk ./library/ngnpro_client.php 185 - 'dns_zones' => array( + 'dns_zones' => array( hunk ./library/ngnpro_client.php 213 - 'trusted_peers' => array( + 'trusted_peers' => array( hunk ./library/ngnpro_client.php 221 - 'pstn_carriers' => array( + 'pstn_carriers' => array( hunk ./library/ngnpro_client.php 229 - 'pstn_gateways' => array( + 'pstn_gateways' => array( hunk ./library/ngnpro_client.php 237 - 'pstn_routes' => array( + 'pstn_routes' => array( hunk ./library/ngnpro_client.php 244 + ), + 'gateway_rules' => array( + 'records_class' => 'GatewayRules', + 'name' => 'PSTN rules', + 'soap_class' => 'WebService_NGNPro_SipPort', + 'category' => 'pstn', + 'description' => 'Manage rules for outbound gateways. ', + 'resellers_only'=> true hunk ./library/ngnpro_client.php 412 + // disable some version dependent ports hunk ./library/ngnpro_client.php 414 - if ($this->version <= 1 && $_p = 'customers') continue; + if ($this->version < 2 && $_p == 'customers') continue; + if ($this->version < 4.1 && $_p == 'gateway_rules') continue; hunk ./library/ngnpro_client.php 727 - if ($_port == 'customers' && $this->SoapEngine->soapEngines[$_engine]['version'] <= 1) continue; - if ($this->SoapEngine->ports[$_port]['resellers_only']) { - if ($this->login_credentials['login_type']=='admin' || $this->loginAccount->resellerActive ) { + + // disable some version dependent ports + + if ($_port == 'customers' && $this->SoapEngine->soapEngines[$_engine]['version'] < 2) continue; + if ($_port == 'gateway_rules' && $this->SoapEngine->soapEngines[$_engine]['version'] < 4.1) continue; + + if ($this->SoapEngine->ports[$_port]['resellers_only']) { + if ($this->login_credentials['login_type']=='admin' || $this->loginAccount->resellerActive ) { hunk ./library/ngnpro_client.php 8591 + Gateways hunk ./library/ngnpro_client.php 8657 - %s + %s + Gateways hunk ./library/ngnpro_client.php 8666 - $_carrier_url, hunk ./library/ngnpro_client.php 8667 + $_carrier_url, hunk ./library/ngnpro_client.php 9258 - Prefix - Strip - Prepend - Min - Max + Rules hunk ./library/ngnpro_client.php 9339 - urlencode($carrier->name), - urlencode($carrier->reseller) + urlencode($gateway->name), + urlencode($gateway->reseller) + ); + + $_rules_url = $this->url.sprintf("&service=gateway_rules@%s&gateway_filter=%s&reseller_filter=%s", + urlencode($this->SoapEngine->soapEngine), + urlencode($gateway->name), + urlencode($gateway->reseller) hunk ./library/ngnpro_client.php 9357 - if (count($gateway->rules)) { - foreach ($gateway->rules as $_rule) { - $_r++; - if ($_r == 1) { - printf(" - - %s - %s - %s - %s - %s:%s:%s - %s - %s - %s - %s - %s - %s - %s - ", - $bgcolor, - $index, - $_customer_url, - $gateway->reseller, - $name_link, - $gateway->name, - $gateway->carrier, - $gateway->transport, - $gateway->ip, - $gateway->port, - $_rule->prefix, - $_rule->strip, - $_rule->prepend, - $_rule->min_length, - $_rule->max_length, - $gateway->changeDate, - $_url, - $actionText - ); - - } else { + printf(" + + %s + %s + %s + %s + %s:%s:%s + Rules + %s + %s + ", + $bgcolor, + $index, + $_customer_url, + $gateway->reseller, + $name_link, + $gateway->name, + $gateway->carrier, + $gateway->transport, + $gateway->ip, + $gateway->port, + $_rules_url, + $gateway->changeDate, + $_url, + $actionText + ); hunk ./library/ngnpro_client.php 9384 - printf(" - - - %s - %s - %s - %s - %s - - ", - $bgcolor, - $_rule->prefix, - $_rule->strip, - $_rule->prepend, - $_rule->min_length, - $_rule->max_length - ); - - } - } - - } else { - - printf(" - - %s - %s - %s - %s - %s:%s:%s - - %s - %s - ", - $bgcolor, - $index, - $_customer_url, - $gateway->reseller, - $name_link, - $gateway->name, - $gateway->carrier, - $gateway->transport, - $gateway->ip, - $gateway->port, - $gateway->changeDate, - $_url, - $actionText - ); - - printf(" - - "); - } + printf(" + + "); hunk ./library/ngnpro_client.php 9678 - print ""; - print "

Rules

"; hunk ./library/ngnpro_client.php 9750 - print ""; - - print ""; - print ""; - print ""; - print ""; - print ""; - print ""; - print ""; - print ""; - print ""; - - $j=0; - foreach ($gateway->rules as $_rule) { - $j++; - print ""; - print ""; - printf (" - - - - - - ", - $_rule->prefix, - $_rule->strip, - $_rule->prepend, - $_rule->min_length, - $_rule->max_length - ); - print ""; - } - - $j++; - print ""; - print ""; - - printf (" - - - - - - - - " - ); - - print "
IdPrefixStrip digitsPrependMin digitsMax digits
$j
"; - hunk ./library/ngnpro_client.php 9770 - if (!$gateway = $this->getRecord($name_filter)) { + if (!$gateway = $this->getRecord($_REQUEST['name_filter'])) { hunk ./library/ngnpro_client.php 9774 - $new_rules=array(); - - $j=0; - while ($j < count($_REQUEST['rule_prefix'])) { - - $prefix = $_REQUEST['rule_prefix'][$j]; - $strip = $_REQUEST['rule_strip'][$j]; - $prepend = $_REQUEST['rule_prepend'][$j]; - $min_length = $_REQUEST['rule_min_length'][$j]; - $max_length = $_REQUEST['rule_max_length'][$j]; - - if (strlen($prefix) || - strlen($strip) || - strlen($prepend) || - strlen($min_length) || - strlen($max_length) - ) { - $new_rules[]=array( 'prefix' => $prefix, - 'strip' => intval($strip), - 'prepend' => $prepend, - 'min_length' => intval($min_length), - 'max_length' => intval($max_length) - ); - } - $j++; - } - - $gateway->rules=$new_rules; - hunk ./library/ngnpro_client.php 9790 - 'logs' => array('success' => sprintf('Gateway %s has been updated',$name))) + 'logs' => array('success' => sprintf('Gateway %s has been updated',$_REQUEST['name_filter']))) hunk ./library/ngnpro_client.php 9854 +class GatewayRules extends Records { + var $gatewayGroups=array(); + var $FieldsReadOnly=array( + 'reseller', + 'changeDate' + ); + + var $Fields=array( + 'gateway' => array('type'=>'string'), + 'carrier' => array('type'=>'string'), + 'prefix' => array('type'=>'string'), + 'strip' => array('type'=>'integer'), + 'prepend' => array('type'=>'string'), + 'maxLength' => array('type'=>'integer'), + 'maxLength' => array('type'=>'integer') + ); + + function GatewayRules(&$SoapEngine) { + $this->filters = array('id' => trim($_REQUEST['id_filter']), + 'gateway' => trim($_REQUEST['gateway_filter']), + 'carrier' => trim($_REQUEST['carrier_filter']), + 'prefix' => trim($_REQUEST['prefix_filter']), + ); + + $this->sortElements=array( + 'gateway' => 'Gateway', + 'carrier' => 'Carrier', + 'prefix' => 'Prefix', + 'changeDate' => 'Change date' + ); + $this->Records(&$SoapEngine); + } + + function listRecords() { + $this->getGatewayGroups(); + + $this->showSeachForm(); + + // Insert credetials + $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); + + // Filter + $filter=array('id' => intval($this->filters['id']), + 'gateway' => $this->filters['gateway'], + 'carrier' => $this->filters['carrier'], + 'prefix' => $this->filters['prefix'], + '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'] = 'ASC'; + + $orderBy = array('attribute' => $this->sorting['sortBy'], + 'direction' => $this->sorting['sortOrder'] + ); + + // Compose query + $Query=array('filter' => $filter, + 'orderBy' => $orderBy, + 'range' => $range + ); + + $result = $this->SoapEngine->soapclient->getGatewayRules($Query); + + if (PEAR::isError($result)) { + $error_msg = $result->getMessage(); + $error_fault= $result->getFault(); + $error_code = $result->getCode(); + printf ("

Error from %s: %s (%s): %s",$this->SoapEngine->SOAPurl,$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring); + 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->gateway_rules[$i]) break; + + $gateway_rule = $result->gateway_rules[$i]; + + $index=$this->next+$i+1; + + $rr=floor($index/2); + $mod=$index-$rr*2; + + if ($mod ==0) { + $bgcolor="lightgrey"; + } else { + $bgcolor="white"; + } + + $_url = $this->url.sprintf("&service=%s&action=Delete&id_filter=%s&reseller_filter=%s", + urlencode($this->SoapEngine->service), + urlencode($gateway_rule->id), + urlencode($gateway_rule->reseller) + ); + + if ($_REQUEST['action'] == 'Delete' && + $_REQUEST['id_filter'] == $gateway_rule->id && + $_REQUEST['reseller_filter'] == $gateway_rule->reseller) { + $_url .= "&confirm=1"; + $actionText = "Confirm"; + } else { + $actionText = "Delete"; + } + + $_rule_url = $this->url.sprintf("&service=%s&id_filter=%s&reseller_filter=%s", + urlencode($this->SoapEngine->service), + urlencode($gateway_rule->id), + urlencode($gateway_rule->reseller) + ); + + $_customer_url = $this->url.sprintf("&service=customers@%s&customer_filter=%s", + urlencode($this->SoapEngine->customer_engine), + urlencode($gateway_rule->reseller) + ); + + $_carrier_url = $this->url.sprintf("&service=pstn_carriers@%s&name_filter=%s&reseller_filter=%s", + urlencode($this->SoapEngine->soapEngine), + urlencode($gateway_rule->carrier), + urlencode($gateway_rule->reseller) + ); + + $_gateway_url = $this->url.sprintf("&service=pstn_gateways@%s&name_filter=%s&reseller_filter=%s", + urlencode($this->SoapEngine->soapEngine), + urlencode($gateway_rule->gateway), + urlencode($gateway_rule->reseller) + ); + + printf(" + + + + + + + + + + + + + + ", + $bgcolor, + $index, + $_rule_url, $gateway_rule->id, + $_customer_url,$gateway_rule->reseller, + $_carrier_url, $gateway_rule->carrier, + $_gateway_url, $gateway_rule->gateway, + $gateway_rule->prefix, + $gateway_rule->strip, + $gateway_rule->prepend, + $gateway_rule->maxLength, + $gateway_rule->maxLength, + $gateway_rule->changeDate, + $_url, + $actionText + ); + + printf(" + + "); + + $i++; + + } + + } + + print "
+ Rule + ResellerCarrierGatewayPrefixStripPrependMinLengthMaxLengthChange dateActions
%s%s%s%s%s%s%s%s%s%s%s%s
"; + + if ($this->rows == 1 && $this->version > 3) { + $this->showRecord($gateway_rule); + } else { + $this->showPagination($maxrows); + } + + return true; + } + } + + function showAddForm() { + if ($this->selectionActive) return; + + $this->getGatewayGroups(); + + if (!count($this->carriers)) { + print "

Create a carrier first"; + return false; + } + + print " +

+ + + "; + printf ("",$_SERVER['PHP_SELF']); + print " + + "; + $this->printHiddenFormElements(); + + print " + + +
+ "; + + print " + + + "; + + printf (" Gateway "); + + printf (" Carrier: "); + + print ""); + + printf (" Prefix "); + printf (" Strip "); + printf (" Prepend "); + printf (" Min length "); + printf (" Max length "); + + print " +
+ "; + } + + function addRecord($dictionary=array()) { + if ($dictionary['gateway']) { + $gateway = $dictionary['gateway']; + } else { + $gateway = trim($_REQUEST['gateway']); + } + if ($dictionary['carrier']) { + $carrier = $dictionary['carrier']; + } else { + $carrier = trim($_REQUEST['carrier']); + } + + if ($dictionary['prefix']) { + $prefix = $dictionary['prefix']; + } else { + $prefix = trim($_REQUEST['prefix']); + } + + if ($dictionary['strip']) { + $strip = $dictionary['strip']; + } else { + $strip = trim($_REQUEST['strip']); + } + + if ($dictionary['prepend']) { + $prepend = $dictionary['prepend']; + } else { + $prepend = trim($_REQUEST['prepend']); + } + + if ($dictionary['maxLength']) { + $maxLength = $dictionary['maxLength']; + } else { + $maxLength = trim($_REQUEST['maxLength']); + } + + if ($dictionary['maxLength']) { + $maxLength = $dictionary['maxLength']; + } else { + $maxLength = trim($_REQUEST['maxLength']); + } + + if (!strlen($gateway) || !strlen($carrier)) { + printf ("

Error: Missing gateway or carrier"); + return false; + } + + $rule=array( + 'gateway' => $gateway, + 'carrier' => $carrier, + 'prefix' => $prefix, + 'prepend' => $prepend, + 'strip' => intval($strip), + 'maxLength' => intval($maxLength), + 'maxLength' => intval($maxLength) + ); + + $function=array('commit' => array('name' => 'addGatewayRule', + 'parameters' => array($rule), + 'logs' => array('success' => sprintf('Gateway rule has been added'))) + ); + + 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 rule id "; + return false; + } + + $function=array('commit' => array('name' => 'deleteGatewayRule', + 'parameters' => array(intval($id)), + 'logs' => array('success' => sprintf('Gateway rule %d has been deleted',$id))) + ); + unset($this->filters); + return $this->SoapEngine->execute($function,$this->html); + + } + + function showSeachFormCustom() { + printf (" Rule ",$this->filters['id']); + printf (" Gateway ",$this->filters['gateway']); + print " + "); + } + + function showCustomerForm() { + } + function showTextBeforeCustomerSelection() { + print "Reseller"; + } + + function showRecord($rule) { + + print ""; + print ""; + print ""; + print ""; + + print ""; + print ""; + print ""; + + print " + + + + "; + print ""; + print "
"; + print "

Ruley

"; + print "
"; + + print ""; + + 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, + $rule->$item, + $rule->$item + ); + } else { + if ($item == 'carrier') { + printf (""; + + } else { + printf ("", + $item, + $rule->$item + ); + } + } + print " + "; + + + } + + printf ("name); + printf ("reseller); + + $this->printFiltersToForm(); + $this->printHiddenFormElements(); + + print " +
%s", + $item_name + ); + + if ($this->Fields[$item]['readonly']) { + printf ("%s
+ "; + + + print "
+ +
"; + + } + + function updateRecord () { + //print "

Updating rule ..."; + + if (!$_REQUEST['id_filter'] || !strlen($_REQUEST['reseller_filter'])) return; + + if (!$rule = $this->getRecord($_REQUEST['id_filter'])) { + return false; + } + + foreach (array_keys($this->Fields) as $item) { + $var_name=$item.'_form'; + if ($this->Fields[$item]['type'] == 'integer') { + $rule->$item = intval($_REQUEST[$var_name]); + } else { + $rule->$item = trim($_REQUEST[$var_name]); + } + } + + $function=array('commit' => array('name' => 'updateGatewayRule', + 'parameters' => array($rule), + 'logs' => array('success' => sprintf('Rule %d has been updated',$_REQUEST['id_filter']))) + ); + + $result = $this->SoapEngine->execute($function,$this->html); + + dprint_r($result) ; + if (PEAR::isError($result)) { + $error_msg = $result->getMessage(); + $error_fault= $result->getFault(); + $error_code = $result->getCode(); + printf ("

Error from %s: %s (%s): %s",$this->SOAPurl,$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring); + + 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 + $this->sorting['sortBy'] = 'gateway'; + $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 + $result = $this->SoapEngine->soapclient->getGatewayRules($Query); + + if (PEAR::isError($result)) { + $error_msg = $result->getMessage(); + $error_fault= $result->getFault(); + $error_code = $result->getCode(); + printf ("

Error from %s: %s (%s): %s",$this->SoapEngine->SOAPurl,$error_msg, $error_fault->detail->exception->errorcode,$error_fault->detail->exception->errorstring); + return false; + } else { + if ($result->gateway_rules[0]){ + return $result->gateway_rules[0]; + } else { + return false; + } + } + } + +} + hunk ./library/ngnpro_client.php 10606 - $_group_url = $this->url.sprintf("&service=pstn_gateways@%s&carrier_filter=%s", + $_group_url = $this->url.sprintf("&service=pstn_carriers@%s&name_filter=%s", hunk ./library/ngnpro_soap_library.php 726 + } + function &addGatewayRule($rule) + { + // rule is a ComplexType GatewayRule, + // refer to wsdl for more info + $rule = new SOAP_Value('rule', '{urn:AGProjects:NGNPro}GatewayRule', $rule); + $result = $this->call('addGatewayRule', + $v = array('rule' => $rule), + array('namespace' => 'urn:AGProjects:NGNPro:Sip', + 'soapaction' => '', + 'style' => 'rpc', + 'use' => 'encoded')); + return $result; + } + function &updateGatewayRule($rule) + { + // rule is a ComplexType GatewayRule, + // refer to wsdl for more info + $rule = new SOAP_Value('rule', '{urn:AGProjects:NGNPro}GatewayRule', $rule); + $result = $this->call('updateGatewayRule', + $v = array('rule' => $rule), + array('namespace' => 'urn:AGProjects:NGNPro:Sip', + 'soapaction' => '', + 'style' => 'rpc', + 'use' => 'encoded')); + return $result; + } + function &deleteGatewayRule($id) + { + $result = $this->call('deleteGatewayRule', + $v = array('id' => $id), + array('namespace' => 'urn:AGProjects:NGNPro:Sip', + 'soapaction' => '', + 'style' => 'rpc', + 'use' => 'encoded')); + return $result; + } + function &getGatewayRules($query) + { + $result = $this->call('getGatewayRules', + $v = array('query' => $query), + array('namespace' => 'urn:AGProjects:NGNPro:Sip', + 'soapaction' => '', + 'style' => 'rpc', + 'use' => 'encoded')); + return $result;