[Reorganize code for better readability Adrian Georgescu **20070906165042] hunk ./provisioning_logic.phtml 102 - printf ("Connection to NGN-Pro at %s ",$this->SOAPurl,$this->SOAPurl); + printf ("

Connection to NGN-Pro at %s ",$this->SOAPurl,$this->SOAPurl); hunk ./provisioning_logic.phtml 586 +class Domains extends Records { + + var $maxrowsperpage= 200; + + function Domains(&$SOAPEngine,$adminonly) { + $this->filters = array( + 'domain' => trim($_REQUEST['domain_filter']) + ); + + $this->Records(&$SOAPEngine,$adminonly); + } + + function listRecords() { + + $this->showSeachForm(); + + // Insert credetials + $this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth); + + $filter=$this->filters['domain']; + // Call function + $result = $this->SOAPEngine->soapclient->getDomains($filter); + + 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 = count($result); + + 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) { + + $domain = $result[$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&domain_filter=%s", + urlencode($this->SOAPEngine->service), + urlencode($domain) + ); + + if ($_REQUEST['action'] == 'Delete' && + $_REQUEST['domain_filter'] == $domain) { + $_url .= "&confirm=1"; + $actionText = "Confirm"; + } else { + $actionText = "Delete"; + } + + printf(" + + + + + + ", + $bgcolor, + $index, + $domain, + $domain->customer, + $domain->reseller, + $_url, + $actionText + ); + + $i++; + } + } + + print "
Id + DomainOperatorAction
%s%s%s.%s%s
"; + + $this->showPagination($maxrows); + + return true; + } + } + + function showSeachFormCustom() { + + printf (" Domain: ",$this->filters['domain']); + + } + + function deleteRecord() { + if (!$_REQUEST['confirm']) { + print "

Please press on Confirm to confirm the delete. "; + return 1; + } + + if (!strlen($this->filters['domain']) || !strlen($this->filters['domain'])) { + print "

Error: missing SIP domain. "; + return 0; + } + + $this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth); + + $result = $this->SOAPEngine->soapclient->deleteDomain($this->filters['domain']); + + 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 { + printf ("

SIP domain %s has been deleted. ",$this->filters['domain']); + unset($this->filters); + return 1; + } + } + + function showAddForm() { + if ($this->selectionActive) return; + print " +

+ + + "; + printf ("",$_SERVER['PHP_SELF']); + print " + + + "; + $this->printHiddenFormElements(); + + print " + + +
+ "; + + print " + + "; + + printf (" Domain: "); + + if ($this->adminonly) { + $this->showResellerForm('reseller'); + $this->showCustomerForm('customer'); + } else { + $this->showCustomerForm('customer'); + } + + print " + + "; + print " +
+ "; + } + + function addRecord() { + + $domain = trim($_REQUEST['domain']); + + if ($this->adminonly) { + $reseller = trim($_REQUEST['reseller']); + $customer = trim($_REQUEST['customer']); + } else { + $reseller = $this->reseller; + $customer = trim($_REQUEST['customer']); + if (!$customer || !in_array($customer,array_keys($this->customers))) { + $customer=$reseller; + } + } + + $this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth); + + $result = $this->SOAPEngine->soapclient->addDomain($domain); + + 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 { + printf ("

SIP domain %s has been added. ",$domain); + return 1; + } + } +} + +class SIPAccounts extends Records { + var $sortElements=array('changeDate' => 'Change date', + 'username' => 'Username', + 'domain' => 'Domain' + ); + + function SIPAccounts(&$SOAPEngine,$adminonly) { + + $this->filters = array('username' => trim($_REQUEST['username_filter']), + 'domain' => trim($_REQUEST['domain_filter']), + 'fullname' => trim($_REQUEST['fullname_filter']) + ); + + $this->Records(&$SOAPEngine,$adminonly); + + } + + function getRecordKeys() { + + if (preg_match("/^(.*)@(.*)$/",$this->filters['username'],$m)) { + $this->filters['username'] = $m[1]; + $this->filters['domain'] = $m[2]; + } + + if ($this->filters['domain'] && $this->allowedDomains && !in_array($this->filters['domain'],$this->allowedDomains)) { + $this->filters['domain'] = $this->allowedDomains[0]; + } + + // Filter + $filter=array('username' => $this->filters['username'], + 'domain' => $this->filters['domain'], + 'name' => $this->filters['fullname'] + ); + + // Range + $range=array('start' => 0, + 'count' => 1000 + ); + + // 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 + ); + + // Insert credetials + $this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth); + + // Call function + $result = $this->SOAPEngine->soapclient->getAccounts($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 { + foreach ($result->accounts as $account) { + $this->selectionKeys[]=$account->id->username.'@'.$account->id->domain; + } + + return true; + } + + return false; + + } + + function listRecords() { + + $this->getAllowedDomains(); + + if (preg_match("/^(.*)@(.*)$/",$this->filters['username'],$m)) { + $this->filters['username'] = $m[1]; + $this->filters['domain'] = $m[2]; + } + + // Make sure we apply the domain filter from the login credetials + if ($this->allowedDomains && !$this->filters['domain']) { + //$this->filters['domain'] = $this->allowedDomains[0]; + } + + if ($this->filters['domain'] && $this->allowedDomains && !in_array($this->filters['domain'],$this->allowedDomains)) { + $this->filters['domain'] = $this->allowedDomains[0]; + } + + $this->showSeachForm(); + + // Filter + $filter=array('username' => $this->filters['username'], + 'domain' => $this->filters['domain'], + 'name' => $this->filters['fullname'] + ); + + // 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 + ); + + if (strlen($this->filters['username'])) $this->url .= sprintf("&username_filter=%s",urlencode($this->filters['username'])); + if (strlen($this->filters['domain'])) $this->url .= sprintf("&domain_filter=%s",urlencode($this->filters['domain'])); + if (strlen($this->filters['fullname'])) $this->url .= sprintf("&fullname_filter=%s",urlencode($this->filters['fullname'])); + + // Insert credetials + $this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth); + + // Call function + $result = $this->SOAPEngine->soapclient->getAccounts($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
+

+ + + + + + + + + + + + + + "; + + 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->accounts[$i]) break; + + $account = $result->accounts[$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&username_filter=%s&domain_filter=%s", + urlencode($this->SOAPEngine->service), + urlencode($account->id->username), + urlencode($account->id->domain) + ); + + if ($_REQUEST['action'] == 'Delete' && + $_REQUEST['username_filter'] == $account->id->username && + $_REQUEST['domain_filter'] == $account->id->domain) { + $_url .= "&confirm=1"; + $actionText = "Confirm"; + } else { + $actionText = "Delete"; + } + + if ($this->SipSettingsPage) { + + $url=sprintf('%s?account=%s@%s&rId=%s&soapEngineIdSipPort=%s',$this->SipSettingsPage,$account->id->username,$account->id->domain, + $this->reseller,$this->SOAPEngine->soapEngineIdSettingsPage); + + if ($this->adminonly) { + $url .= sprintf('&adminonly=%s',$this->adminonly); + } + + foreach (array_keys($this->SOAPEngine->extraFormElements) as $element) { + if (!strlen($this->SOAPEngine->extraFormElements[$element])) continue; + $url .= sprintf('&%s=%s',$element,urlencode($this->SOAPEngine->extraFormElements[$element])); + } + + $sip_account=sprintf(" + + %s@%s",$url,$account->id->username,$account->id->domain); + } else { + $sip_account=sprintf("%s@%s",$account->id->username,$account->id->domain); + } + + unset($groups); + foreach ($account->groups as $_grp) { + $groups.=$_grp.' '; + } + + printf(" + + + + + + + + + + + + + + ", + + $bgcolor, + $index, + $sip_account, + $account->reseller, + $account->customer, + $account->firstName, + $account->lastName, + $account->email, + $account->email, + $account->rpid, + $account->quota, + $groups, + $account->changeDate, + $account->owner, + $_url, + $actionText + ); + + $i++; + } + + } + + print "
Id + SIP accountOperatorNameEmailCaller IdQuotaGroupsLast changeOwnerAction
%s %s%s.%s%s %s%s%s%s%s%s%s%s
"; + + $this->showPagination($maxrows); + + return true; + } + } + + function showSeachFormCustom() { + printf ("User: ",$this->filters['username']); + printf ("@"); + + if ($this->allowedDomains) { + $selected_domain[$this->filters['domain']]='selected'; + printf (""); + } else { + printf ("",$this->filters['domain']); + } + + printf (" Name: ",$this->filters['fullname']); + } + + function deleteRecord() { + if (!$_REQUEST['confirm']) { + print "

Please press on Confirm to confirm the delete. "; + return 1; + } + + if (!strlen($this->filters['username']) || !strlen($this->filters['domain'])) { + print "

Error: missing SIP account username or domain. "; + return 0; + } + + $account=array('username' => $this->filters['username'], + 'domain' => $this->filters['domain'] + ); + + $function=array('commit' => array('name' => 'deleteAccount', + 'parameters' => array($account), + 'logs' => array('success' => sprintf('

  • SIP account %s@%s has been deleted',$this->filters['username'],$this->filters['domain']) + ) + ) + + ); + + if ($this->SOAPEngine->execute($function)) { + unset($this->filters); + } + + return true; + } + + function showAddForm() { + if ($this->selectionActive) return; + print " +

    + + + "; + printf ("",$_SERVER['PHP_SELF']); + print " + + + "; + $this->printHiddenFormElements(); + + print " + + +
    + "; + + print " + + "; + + printf (" User: ",$_REQUEST['account']); + if (is_array($this->allowedDomains)) { + print "@"; + + } + + printf (" Pass: ",$_REQUEST['password']); + printf (" Name: ",$_REQUEST['fullname']); + printf (" Email: ",$_REQUEST['email']); + //printf (" CallerId: ",$_REQUEST['rpid']); + if ($this->adminonly) { + $this->showResellerForm('reseller'); + $this->showCustomerForm('customer'); + } else { + $this->showCustomerForm('customer'); + } + printf (" Owner: ",$_REQUEST['owner']); + /* + print " TZ: "; + + $this->showTimezones(); + */ + + print " + + "; + print " +
    + "; + } + + function addRecord() { + $account_els = explode("@", trim($_REQUEST['account'])); + + if ($this->adminonly) { + $reseller = trim($_REQUEST['reseller']); + $customer = trim($_REQUEST['customer']); + if (!$customer) $customer=$reseller; + } else { + $reseller = $this->reseller; + $customer = trim($_REQUEST['customer']); + if (!$customer || !in_array($customer,array_keys($this->customers))) { + $customer=$reseller; + } + } + + $username=$account_els[0]; + + if (strlen($account_els[1])) { + $domain=$account_els[1]; + + } else if (trim($_REQUEST['domain'])) { + $domain=trim($_REQUEST['domain']); + + } else { + printf ("

    Error: Missing SIP domain"); + return false; + } + + if (is_array($this->allowedDomains) && !in_array($domain,$this->allowedDomains)) { + printf ("

    Error: SIP domain %s is not allowed",$domain); + return false; + } + + $name_els = explode(" ", trim($_REQUEST['fullname'])); + + if (strlen(trim($_REQUEST['timezone']))) { + $timezone=trim($_REQUEST['timezone']); + } else { + $timezone='Europe/Amsterdam'; + } + + if (strlen(trim($_REQUEST['password']))) { + $password=trim($_REQUEST['password']); + } else { + $password=$this->RandomPassword(6); + } + + $email=trim($_REQUEST['email']); + + $regexp = "/^([a-z0-9][a-z0-9_.-]*)@([a-z0-9][a-z0-9-]*\.)+([a-z0-9]{2,})$/i"; + if (!preg_match($regexp, $uri)) $email=$username.'@'.$domain; + + $account=array( + 'id' => array('username' => $username, + 'domain' => $domain), + 'firstName' => $name_els[0], + 'lastName' => $name_els[1], + 'password' => $password, + 'timezone' => $timezone, + 'email' => $email, + 'owner' => intval($_REQUEST['owner']), + 'customer' => intval($customer), + 'reseller' => intval($reseller) + ); + + //print_r($account); + $deleteAccount=array('username' => $username, + 'domain' => $domain); + + + $function=array('commit' => array('name' => 'addAccount', + 'parameters' => array($account), + 'logs' => array('success' => sprintf('

  • SIP account %s@%s has been added',$username,$domain))), + 'rollback' => array('name' => 'deleteAlias', + 'parameters' => array($deleteAccount)) + ); + + $this->SOAPEngine->execute($function); + + return true; + } + + function RandomPassword($len=11) { + $alf=array("a","b","c","d","e","f", + "h","i","j","k","l","m", + "n","p","r","s","t","w", + "x","y","1","2","3","4", + "5","6","7","8","9"); + $i=0; + while($i < $len) { + srand((double)microtime()*1000000); + $randval = rand(0,28); + $string="$string"."$alf[$randval]"; + $i++; + } + return $string; + } + + function getAllowedDomains() { + + $this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth); + //print_r($this->SOAPEngine->soapclient->headersOut); + + $result = $this->SOAPEngine->soapclient->getDomains(); + + if (PEAR::isError($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); + //return false; + } else { + $this->allowedDomains=$result; + } + } +} + +class SIPAliases extends Records { + var $sortElements=array( + 'aliasUsername' => 'Alias user', + 'aliasDomain' => 'Alias domain', + 'targetUsername' => 'Target user', + 'targetDomain' => 'Target domain' + ); + + function SIPAliases(&$SOAPEngine,$adminonly) { + $this->filters = array('aliasUsername' => trim($_REQUEST['alias_username_filter']), + 'aliasDomain' => trim($_REQUEST['alias_domain_filter']), + 'targetUsername' => trim($_REQUEST['target_username_filter']), + 'targetDomain' => trim($_REQUEST['target_domain_filter']) + ); + + + $this->Records(&$SOAPEngine,$adminonly); + + } + + function listRecords() { + $this->getAllowedDomains(); + + // Make sure we apply the domain filter from the login credetials + if ($this->allowedDomains && !$this->filters['aliasDomain']) { + //$this->filters['aliasDomain'] = $this->allowedDomains[0]; + } + + if ($this->filters['aliasDomain'] && $this->allowedDomains && !in_array($this->filters['aliasDomain'],$this->allowedDomains)) { + $this->filters['aliasDomain'] = $this->allowedDomains[0]; + } + + $this->showSeachForm(); + + // Filter + $filter=array('aliasUsername' => $this->filters['aliasUsername'], + 'aliasDomain' => $this->filters['aliasDomain'], + 'targetUsername' => $this->filters['targetUsername'], + 'targetDomain' => $this->filters['targetDomain'] + ); + + // Range + $range=array('start' => intval($this->next), + 'count' => intval($this->maxrowsperpage) + ); + + // Order + if (!$this->sorting['sortBy']) $this->sorting['sortBy'] = 'aliasUsername'; + 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 + ); + + if (strlen($this->filters['aliasUsername'])) $this->url .= sprintf("&alias_username_filter=%s",urlencode($this->filters['aliasUsername'])); + if (strlen($this->filters['aliasDomain'])) $this->url .= sprintf("&alias_domain_filter=%s",urlencode($this->filters['aliasDomain'])); + if (strlen($this->filters['targetUsername'])) $this->url .= sprintf("&target_username_filter=%s",urlencode($this->filters['targetUsername'])); + if (strlen($this->filters['targetDomain'])) $this->url .= sprintf("&target_domain_filter=%s",urlencode($this->filters['targetDomain'])); + + // Insert credetials + $this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth); + + // Call function + $result = $this->SOAPEngine->soapclient->getAliases($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 "

    ";
    +            //print_r($result);
    +
    +            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->aliases[$i]) break; + + $alias = $result->aliases[$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&alias_username_filter=%s&alias_domain_filter=%s", + urlencode($this->SOAPEngine->service), + urlencode($alias->id->username), + urlencode($alias->id->domain) + ); + + if ($_REQUEST['action'] == 'Delete' && + $_REQUEST['alias_username_filter'] == $alias->id->username && + $_REQUEST['alias_domain_filter'] == $alias->id->domain) { + $_url .= "&confirm=1"; + $actionText = "Confirm"; + } else { + $actionText = "Delete"; + } + + printf(" + + + + + + + + + ", + $bgcolor, + $index, + $alias->id->username, + $alias->id->domain, + $alias->customer, + $alias->reseller, + $alias->target->username, + $alias->target->domain, + $alias->owner, + $_url, + $actionText + ); + + $i++; + + } + + } + + print "
    Id + AliasOperatorTargetOwnerAction
    %s%s@%s%s.%s%s@%s%s%s
    "; + + $this->showPagination($maxrows); + + return true; + } + } + + function deleteRecord() { + if (!$_REQUEST['confirm']) { + print "

    Please press on Confirm to confirm the delete. "; + return 1; + } + + if (!strlen($this->filters['aliasUsername']) || !strlen($this->filters['aliasDomain'])) { + print "

    Error: missing SIP alias username or domain. "; + return 0; + } + + $alias=array('username' => $this->filters['aliasUsername'], + 'domain' => $this->filters['aliasDomain'] + ); + + $function=array('commit' => array('name' => 'deleteAlias', + 'parameters' => array($alias), + 'logs' => array('success' => sprintf('

  • SIP alias %s@%s has been deleted',$this->filters['aliasUsername'],$this->filters['aliasDomain']) + ) + ) + + ); + + if ($this->SOAPEngine->execute($function)) { + unset($this->filters); + } + + return true; + } + + function showSeachFormCustom() { + printf (" User: ",$this->filters['aliasUsername']); + printf ("@"); + + if ($this->allowedDomains) { + $selected_domain[$this->filters['aliasDomain']]='selected'; + printf (""); + } else { + printf ("",$this->filters['aliasDomain']); + } + + printf (" Target: ",$this->filters['targetUsername']); + printf (" @",$this->filters['targetDomain']); + + } + + function showAddForm() { + if ($this->selectionActive) return; + print " +

    + + + "; + printf ("",$_SERVER['PHP_SELF']); + print " + + + "; + $this->printHiddenFormElements(); + + print " + + +
    + "; + + print " + + "; + + printf (" Alias: "); + + if (is_array($this->allowedDomains)) { + print "@"; + } + + printf (" Target: "); + + if ($this->adminonly) { + $this->showResellerForm('reseller'); + $this->showCustomerForm('customer'); + } else { + $this->showCustomerForm('customer'); + } + + printf (" Owner: "); + + print " + + "; + print " +
    + "; + } + + function addRecord() { + $alias_els = explode("@", trim($_REQUEST['alias'])); + $target_els = explode("@", trim($_REQUEST['target'])); + + $username=$alias_els[0]; + + if (strlen($alias_els[1])) { + $domain=$alias_els[1]; + + } else if (trim($_REQUEST['domain'])) { + $domain=trim($_REQUEST['domain']); + + } else { + printf ("

    Error: Missing SIP domain"); + return false; + } + + if (is_array($this->allowedDomains) && !in_array($domain,$this->allowedDomains)) { + printf ("

    Error: SIP domain %s is not allowed",$domain); + return false; + } + + if ($this->adminonly) { + $reseller = trim($_REQUEST['reseller']); + $customer = trim($_REQUEST['customer']); + if (!$customer) $customer=$reseller; + } else { + $reseller = $this->reseller; + $customer = trim($_REQUEST['customer']); + if (!$customer || !in_array($customer,array_keys($this->customers))) { + $customer=$reseller; + } + } + + $alias=array( + 'id' => array('username' => $username, + 'domain' => $domain + ), + 'target' => array('username' => $target_els[0], + 'domain' => $target_els[1] + ), + 'owner' => intval($_REQUEST['owner']), + 'customer' => intval($customer), + 'reseller' => intval($reseller) + ); + + //print_r($alias); + + $deleteAlias=array('username' => $username, + 'domain' => $domain); + + $function=array('commit' => array('name' => 'addAlias', + 'parameters' => array($alias), + 'logs' => array('success' => sprintf('

  • SIP alias %s@%s has been added',$username,$domain))), + 'rollback' => array('name' => 'deleteAlias', + 'parameters' => array($deleteAlias)) + ); + + $this->SOAPEngine->execute($function); + + return true; + } + + function getAllowedDomains() { + // Insert credetials + $this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth); + $result = $this->SOAPEngine->soapclient->getDomains(); + + 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->allowedDomains=$result; + } + } + +} + +class ENUMranges extends Records { + var $sortElements=array('changeDate' => 'Change date', + 'number' => 'Number', + 'tld' => 'TLD' + ); + + function ENUMranges(&$SOAPEngine,$adminonly) { + $this->filters = array('prefix' => trim($_REQUEST['prefix_filter']), + 'tld' => trim($_REQUEST['tld_filter']) + ); + + $this->Records(&$SOAPEngine,$adminonly); + } + + function listRecords() { + + $this->showSeachForm(); + + // Insert credetials + $this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth); + + // Call function + $result = $this->SOAPEngine->soapclient->getRanges(); + + 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 = count($result); + + //print "

    ";
    +            //print_r($result);
    +
    +            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) { + + $range = $result[$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&prefix_filter=%s&tld_filter=%s", + urlencode($this->SOAPEngine->service), + urlencode($range->id->prefix), + urlencode($range->id->tld) + ); + + if ($_REQUEST['action'] == 'Delete' && + $_REQUEST['prefix_filter'] == $range->id->prefix && + $_REQUEST['tld_filter'] == $range->id->tld) { + $_url .= "&confirm=1"; + $actionText = "Confirm"; + } else { + $actionText = "Delete"; + } + printf(" + + + + + + + + + + + + + ", + $bgcolor, + $index, + $range->id->prefix, + $range->id->tld, + $range->customer, + $range->reseller, + $range->ttl, + $range->minDigits, + $range->maxDigits, + $range->used, + $range->owner, + $range->info, + $_url, + $actionText + ); + + printf(" + + "); + + $i++; + + } + + } + + print "
    Id + Prefix Top level domainOperatorTTLMin digitsMax digitsUsedOwnerInfoAction
    %s+%s%s%s.%s%s%s%s%s%s%s%s
    "; + + $this->showPagination($maxrows); + + return true; + } + } + + function deleteRecord() { + if (!$_REQUEST['confirm']) { + print "

    Please press on Confirm to confirm the delete. "; + return 1; + } + + if (!strlen($this->filters['prefix']) || !strlen($this->filters['tld'])) { + print "

    Error: missing ENUM range id "; + return 0; + } + + $rangeId=array('prefix'=>$this->filters['prefix'], + 'tld'=>$this->filters['tld']); + + $function=array('commit' => array('name' => 'deleteRange', + 'parameters' => array($rangeId), + 'logs' => array('success' => sprintf('

  • ENUM range %s under %s has been deleted',$this->filters['prefix'],$this->filters['tld']) + ) + ) + + ); + if ($this->SOAPEngine->execute($function)) { + unset($this->filters); + } + + return true; + + } + + function showAddForm() { + if ($this->selectionActive) return; + + print " +

    + + + "; + printf ("",$_SERVER['PHP_SELF']); + print " + + + "; + + $this->printHiddenFormElements(); + + print " + + +
    + "; + + print " + + "; + printf (" Prefix: +"); + printf (" Top level domain: "); + printf (" TTL: "); + printf (" Min Digits: "); + printf (" Max Digits: "); + if ($this->adminonly) { + $this->showResellerForm('reseller'); + $this->showCustomerForm('customer'); + } else { + $this->showCustomerForm('customer'); + } + printf (" Owner: "); + + print " + + "; + print " +
    + "; + } + + function addRecord() { + $tld = trim($_REQUEST['tld']); + $prefix = trim($_REQUEST['prefix']); + + if (!strlen($tld) || !strlen($prefix)) { + printf ("

    Error: Missing TLD or prefix. "); + return false; + } + + if ($this->adminonly) { + $reseller = trim($_REQUEST['reseller']); + $customer = trim($_REQUEST['customer']); + if (!$customer) $customer=$reseller; + } else { + $reseller = $this->reseller; + $customer = trim($_REQUEST['customer']); + if (!$customer || !in_array($customer,array_keys($this->customers))) { + $customer=$reseller; + } + } + + if (!trim($_REQUEST['ttl'])) { + $ttl=3600; + } else { + $ttl=intval(trim($_REQUEST['ttl'])); + } + + $range=array( + 'id' => array('prefix' => $prefix, + 'tld' => $tld), + 'ttl' => $ttl, + 'minDigits' => intval(trim($_REQUEST['minDigits'])), + 'maxDigits' => intval(trim($_REQUEST['maxDigits'])), + 'customer' => intval($customer), + 'reseller' => intval($reseller), + 'owner' => intval($_REQUEST['owner']) + ); + + $deleteRange=array('prefix'=>$prefix, + 'tld'=>$tld); + + $function=array('commit' => array('name' => 'addRange', + 'parameters' => array($range), + 'logs' => array('success' => sprintf('

  • ENUM range +%s under %s has been added',$this->filters['prefix'],$this->filters['tld']))), + 'rollback' => array('name' => 'deleteRange', + 'parameters' => array($deleteRange)) + ); + + $this->SOAPEngine->execute($function); + + return true; + + } + + function showSeachFormCustom() { + /* + printf (" Prefix: ",$this->filters['prefix']); + printf (" TLD: ",$this->filters['tld']); + printf (" Owner: ",$this->filters['owner']); + */ + } +} + + hunk ./provisioning_logic.phtml 2425 + if (!$customer) $customer=$reseller; hunk ./provisioning_logic.phtml 2501 -class ENUMranges extends Records { - var $sortElements=array('changeDate' => 'Change date', - 'number' => 'Number', - 'tld' => 'TLD' - ); - - function ENUMranges(&$SOAPEngine,$adminonly) { - $this->filters = array('prefix' => trim($_REQUEST['prefix_filter']), - 'tld' => trim($_REQUEST['tld_filter']) - ); - - $this->Records(&$SOAPEngine,$adminonly); - } - - function listRecords() { - - $this->showSeachForm(); - - // Insert credetials - $this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth); - - // Call function - $result = $this->SOAPEngine->soapclient->getRanges(); - - 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 = count($result); - - //print "

    ";
    -            //print_r($result);
    -
    -            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) { - - $range = $result[$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&prefix_filter=%s&tld_filter=%s", - urlencode($this->SOAPEngine->service), - urlencode($range->id->prefix), - urlencode($range->id->tld) - ); - - if ($_REQUEST['action'] == 'Delete' && - $_REQUEST['prefix_filter'] == $range->id->prefix && - $_REQUEST['tld_filter'] == $range->id->tld) { - $_url .= "&confirm=1"; - $actionText = "Confirm"; - } else { - $actionText = "Delete"; - } - printf(" - - - - - - - - - - - - - ", - $bgcolor, - $index, - $range->id->prefix, - $range->id->tld, - $range->customer, - $range->reseller, - $range->ttl, - $range->minDigits, - $range->maxDigits, - $range->used, - $range->owner, - $range->info, - $_url, - $actionText - ); - - printf(" - - "); - - $i++; - - } - - } - - print "
    Id - Prefix Top level domainOperatorTTLMin digitsMax digitsUsedOwnerInfoAction
    %s+%s%s%s.%s%s%s%s%s%s%s%s
    "; - - $this->showPagination($maxrows); - - return true; - } - } - - function deleteRecord() { - if (!$_REQUEST['confirm']) { - print "

    Please press on Confirm to confirm the delete. "; - return 1; - } - - if (!strlen($this->filters['prefix']) || !strlen($this->filters['tld'])) { - print "

    Error: missing ENUM range id "; - return 0; - } - - $rangeId=array('prefix'=>$this->filters['prefix'], - 'tld'=>$this->filters['tld']); - - $function=array('commit' => array('name' => 'deleteRange', - 'parameters' => array($rangeId), - 'logs' => array('success' => sprintf('

  • ENUM range %s under %s has been deleted',$this->filters['prefix'],$this->filters['tld']) - ) - ) - - ); - if ($this->SOAPEngine->execute($function)) { - unset($this->filters); - } - - return true; - - } - - function showAddForm() { - if ($this->selectionActive) return; - - print " -

    - - - "; - printf ("",$_SERVER['PHP_SELF']); - print " - - - "; - - $this->printHiddenFormElements(); - - print " - - -
    - "; - - print " - - "; - printf (" Prefix: +"); - printf (" Top level domain: "); - printf (" TTL: "); - printf (" Min Digits: "); - printf (" Max Digits: "); - if ($this->adminonly) { - $this->showResellerForm('reseller'); - $this->showCustomerForm('customer'); - } else { - $this->showCustomerForm('customer'); - } - printf (" Owner: "); - - print " - - "; - print " -
    - "; - } - - function addRecord() { - $tld = trim($_REQUEST['tld']); - $prefix = trim($_REQUEST['prefix']); - - if (!strlen($tld) || !strlen($prefix)) { - printf ("

    Error: Missing TLD or prefix. "); - return false; - } - - if ($this->adminonly) { - $reseller = trim($_REQUEST['reseller']); - $customer = trim($_REQUEST['customer']); - } else { - $reseller = $this->reseller; - $customer = trim($_REQUEST['customer']); - if (!$customer || !in_array($customer,array_keys($this->customers))) { - $customer=$reseller; - } - } - - if (!trim($_REQUEST['ttl'])) { - $ttl=3600; - } else { - $ttl=intval(trim($_REQUEST['ttl'])); - } - - $range=array( - 'id' => array('prefix' => $prefix, - 'tld' => $tld), - 'ttl' => $ttl, - 'minDigits' => intval(trim($_REQUEST['minDigits'])), - 'maxDigits' => intval(trim($_REQUEST['maxDigits'])), - 'customer' => intval($customer), - 'reseller' => intval($reseller), - 'owner' => intval($_REQUEST['owner']) - ); - - $deleteRange=array('prefix'=>$prefix, - 'tld'=>$tld); - - $function=array('commit' => array('name' => 'addRange', - 'parameters' => array($range), - 'logs' => array('success' => sprintf('

  • ENUM range +%s under %s has been added',$this->filters['prefix'],$this->filters['tld']))), - 'rollback' => array('name' => 'deleteRange', - 'parameters' => array($deleteRange)) - ); - - $this->SOAPEngine->execute($function); - - return true; - - } - - function showSeachFormCustom() { - /* - printf (" Prefix: ",$this->filters['prefix']); - printf (" TLD: ",$this->filters['tld']); - printf (" Owner: ",$this->filters['owner']); - */ - } -} - hunk ./provisioning_logic.phtml 2716 + if (!$customer) $customer=$reseller; hunk ./provisioning_logic.phtml 3691 -class SIPAccounts extends Records { - var $sortElements=array('changeDate' => 'Change date', - 'username' => 'Username', - 'domain' => 'Domain' - ); - - function SIPAccounts(&$SOAPEngine,$adminonly) { - - $this->filters = array('username' => trim($_REQUEST['username_filter']), - 'domain' => trim($_REQUEST['domain_filter']), - 'fullname' => trim($_REQUEST['fullname_filter']) - ); - - $this->Records(&$SOAPEngine,$adminonly); - - } - - function getRecordKeys() { - - if (preg_match("/^(.*)@(.*)$/",$this->filters['username'],$m)) { - $this->filters['username'] = $m[1]; - $this->filters['domain'] = $m[2]; - } - - if ($this->filters['domain'] && $this->allowedDomains && !in_array($this->filters['domain'],$this->allowedDomains)) { - $this->filters['domain'] = $this->allowedDomains[0]; - } - - // Filter - $filter=array('username' => $this->filters['username'], - 'domain' => $this->filters['domain'], - 'name' => $this->filters['fullname'] - ); - - // Range - $range=array('start' => 0, - 'count' => 1000 - ); - - // 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 - ); - - // Insert credetials - $this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth); - - // Call function - $result = $this->SOAPEngine->soapclient->getAccounts($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 { - foreach ($result->accounts as $account) { - $this->selectionKeys[]=$account->id->username.'@'.$account->id->domain; - } - - return true; - } - - return false; - - } - - function listRecords() { - - $this->getAllowedDomains(); - - if (preg_match("/^(.*)@(.*)$/",$this->filters['username'],$m)) { - $this->filters['username'] = $m[1]; - $this->filters['domain'] = $m[2]; - } - - // Make sure we apply the domain filter from the login credetials - if ($this->allowedDomains && !$this->filters['domain']) { - //$this->filters['domain'] = $this->allowedDomains[0]; - } - - if ($this->filters['domain'] && $this->allowedDomains && !in_array($this->filters['domain'],$this->allowedDomains)) { - $this->filters['domain'] = $this->allowedDomains[0]; - } - - $this->showSeachForm(); - - // Filter - $filter=array('username' => $this->filters['username'], - 'domain' => $this->filters['domain'], - 'name' => $this->filters['fullname'] - ); - - // 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 - ); - - if (strlen($this->filters['username'])) $this->url .= sprintf("&username_filter=%s",urlencode($this->filters['username'])); - if (strlen($this->filters['domain'])) $this->url .= sprintf("&domain_filter=%s",urlencode($this->filters['domain'])); - if (strlen($this->filters['fullname'])) $this->url .= sprintf("&fullname_filter=%s",urlencode($this->filters['fullname'])); - - // Insert credetials - $this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth); - - // Call function - $result = $this->SOAPEngine->soapclient->getAccounts($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
    -

    - - - - - - - - - - - - - - "; - - 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->accounts[$i]) break; - - $account = $result->accounts[$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&username_filter=%s&domain_filter=%s", - urlencode($this->SOAPEngine->service), - urlencode($account->id->username), - urlencode($account->id->domain) - ); - - if ($_REQUEST['action'] == 'Delete' && - $_REQUEST['username_filter'] == $account->id->username && - $_REQUEST['domain_filter'] == $account->id->domain) { - $_url .= "&confirm=1"; - $actionText = "Confirm"; - } else { - $actionText = "Delete"; - } - - if ($this->SipSettingsPage) { - - $url=sprintf('%s?account=%s@%s&rId=%s&soapEngineIdSipPort=%s',$this->SipSettingsPage,$account->id->username,$account->id->domain, - $this->reseller,$this->SOAPEngine->soapEngineIdSettingsPage); - - foreach (array_keys($this->SOAPEngine->extraFormElements) as $element) { - if (!strlen($this->SOAPEngine->extraFormElements[$element])) continue; - $url .= sprintf('&%s=%s',$element,urlencode($this->SOAPEngine->extraFormElements[$element])); - } - - $sip_account=sprintf(" - - %s@%s",$url,$account->id->username,$account->id->domain); - } else { - $sip_account=sprintf("%s@%s",$account->id->username,$account->id->domain); - } - - unset($groups); - foreach ($account->groups as $_grp) { - $groups.=$_grp.' '; - } - - if ($account->reseller) { - // Use the reseller of the record - $_reseller=$account->reseller; - } else { - // use the reseller from the soap engine - $_reseller=$this->reseller; - } - - printf(" - - - - - - - - - - - - - - ", - - $bgcolor, - $index, - $sip_account, - $_reseller, - $this->customer, - $account->firstName, - $account->lastName, - $account->email, - $account->rpid, - $account->quota, - $groups, - $account->changeDate, - $account->owner, - $_url, - $actionText - ); - - $i++; - } - - } - - print "
    Id - SIP accountOperatorNameEmailCaller IdQuotaGroupsLast changeOwnerAction
    %s %s%s.%s%s %s%s%s%s%s%s%s%s
    "; - - $this->showPagination($maxrows); - - return true; - } - } - - function showSeachFormCustom() { - printf (" Username: ",$this->filters['username']); - printf (" Domain: "); - - if ($this->allowedDomains) { - $selected_domain[$this->filters['domain']]='selected'; - printf (""); - } else { - printf ("",$this->filters['domain']); - } - - printf (" Name: ",$this->filters['fullname']); - } - - function deleteRecord() { - if (!$_REQUEST['confirm']) { - print "

    Please press on Confirm to confirm the delete. "; - return 1; - } - - if (!strlen($this->filters['username']) || !strlen($this->filters['domain'])) { - print "

    Error: missing SIP account username or domain. "; - return 0; - } - - $account=array('username' => $this->filters['username'], - 'domain' => $this->filters['domain'] - ); - - $function=array('commit' => array('name' => 'deleteAccount', - 'parameters' => array($account), - 'logs' => array('success' => sprintf('

  • SIP account %s@%s has been deleted',$this->filters['username'],$this->filters['domain']) - ) - ) - - ); - - if ($this->SOAPEngine->execute($function)) { - unset($this->filters); - } - - return true; - } - - function showAddForm() { - if ($this->selectionActive) return; - print " -

    - - - "; - printf ("",$_SERVER['PHP_SELF']); - print " - - - "; - $this->printHiddenFormElements(); - - print " - - -
    - "; - - print " - - "; - - printf (" SIP: ",$_REQUEST['account']); - if (is_array($this->allowedDomains)) { - print "@"; - - } - - printf (" Pass: ",$_REQUEST['password']); - printf (" Name: ",$_REQUEST['fullname']); - printf (" Email: ",$_REQUEST['email']); - //printf (" CallerId: ",$_REQUEST['rpid']); - if ($this->adminonly) { - $this->showResellerForm('reseller'); - $this->showCustomerForm('customer'); - } else { - $this->showCustomerForm('customer'); - } - printf (" Owner: ",$_REQUEST['owner']); - /* - print " TZ: "; - - $this->showTimezones(); - */ - - print " - - "; - print " -
    - "; - } - - function addRecord() { - $account_els = explode("@", trim($_REQUEST['account'])); - - if ($this->adminonly) { - $reseller = trim($_REQUEST['reseller']); - $customer = trim($_REQUEST['customer']); - } else { - $reseller = $this->reseller; - $customer = trim($_REQUEST['customer']); - if (!$customer || !in_array($customer,array_keys($this->customers))) { - $customer=$reseller; - } - } - - $username=$account_els[0]; - - if (strlen($account_els[1])) { - $domain=$account_els[1]; - - } else if (trim($_REQUEST['domain'])) { - $domain=trim($_REQUEST['domain']); - - } else { - printf ("

    Error: Missing SIP domain"); - return false; - } - - if (is_array($this->allowedDomains) && !in_array($domain,$this->allowedDomains)) { - printf ("

    Error: SIP domain %s is not allowed",$domain); - return false; - } - - $name_els = explode(" ", trim($_REQUEST['fullname'])); - - if (strlen(trim($_REQUEST['timezone']))) { - $timezone=trim($_REQUEST['timezone']); - } else { - $timezone='Europe/Amsterdam'; - } - - if (strlen(trim($_REQUEST['password']))) { - $password=trim($_REQUEST['password']); - } else { - $password=$this->RandomPassword(6); - } - - $account=array( - 'id' => array('username' => $username, - 'domain' => $domain - ), - 'firstName' => $name_els[0], - 'lastName' => $name_els[1], - 'password' => $password, - 'timezone' => $timezone, - 'email' => trim($_REQUEST['email']), - 'owner' => intval($_REQUEST['owner']), - 'customer' => intval($customer), - 'reseller' => intval($reseller) - ); - - //print_r($account); - $deleteAccount=array('username' => $username, - 'domain' => $domain); - - - $function=array('commit' => array('name' => 'addAccount', - 'parameters' => array($account), - 'logs' => array('success' => sprintf('

  • SIP account %s@%s has been added',$username,$domain))), - 'rollback' => array('name' => 'deleteAlias', - 'parameters' => array($deleteAccount)) - ); - - $this->SOAPEngine->execute($function); - - return true; - } - - function RandomPassword($len=11) { - $alf=array("a","b","c","d","e","f", - "h","i","j","k","l","m", - "n","p","r","s","t","w", - "x","y","1","2","3","4", - "5","6","7","8","9"); - $i=0; - while($i < $len) { - srand((double)microtime()*1000000); - $randval = rand(0,28); - $string="$string"."$alf[$randval]"; - $i++; - } - return $string; - } - - function getAllowedDomains() { - - $this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth); - //print_r($this->SOAPEngine->soapclient->headersOut); - - $result = $this->SOAPEngine->soapclient->getDomains(); - - if (PEAR::isError($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); - //return false; - } else { - $this->allowedDomains=$result; - } - } -} - -class SIPAliases extends Records { - var $sortElements=array( - 'aliasUsername' => 'Alias user', - 'aliasDomain' => 'Alias domain', - 'targetUsername' => 'Target user', - 'targetDomain' => 'Target domain' - ); - - function SIPAliases(&$SOAPEngine,$adminonly) { - $this->filters = array('aliasUsername' => trim($_REQUEST['alias_username_filter']), - 'aliasDomain' => trim($_REQUEST['alias_domain_filter']), - 'targetUsername' => trim($_REQUEST['target_username_filter']), - 'targetDomain' => trim($_REQUEST['target_domain_filter']) - ); - - - $this->Records(&$SOAPEngine,$adminonly); - - } - - function listRecords() { - $this->getAllowedDomains(); - - // Make sure we apply the domain filter from the login credetials - if ($this->allowedDomains && !$this->filters['aliasDomain']) { - //$this->filters['aliasDomain'] = $this->allowedDomains[0]; - } - - if ($this->filters['aliasDomain'] && $this->allowedDomains && !in_array($this->filters['aliasDomain'],$this->allowedDomains)) { - $this->filters['aliasDomain'] = $this->allowedDomains[0]; - } - - $this->showSeachForm(); - - // Filter - $filter=array('aliasUsername' => $this->filters['aliasUsername'], - 'aliasDomain' => $this->filters['aliasDomain'], - 'targetUsername' => $this->filters['targetUsername'], - 'targetDomain' => $this->filters['targetDomain'] - ); - - // Range - $range=array('start' => intval($this->next), - 'count' => intval($this->maxrowsperpage) - ); - - // Order - if (!$this->sorting['sortBy']) $this->sorting['sortBy'] = 'aliasUsername'; - 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 - ); - - if (strlen($this->filters['aliasUsername'])) $this->url .= sprintf("&alias_username_filter=%s",urlencode($this->filters['aliasUsername'])); - if (strlen($this->filters['aliasDomain'])) $this->url .= sprintf("&alias_domain_filter=%s",urlencode($this->filters['aliasDomain'])); - if (strlen($this->filters['targetUsername'])) $this->url .= sprintf("&target_username_filter=%s",urlencode($this->filters['targetUsername'])); - if (strlen($this->filters['targetDomain'])) $this->url .= sprintf("&target_domain_filter=%s",urlencode($this->filters['targetDomain'])); - - // Insert credetials - $this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth); - - // Call function - $result = $this->SOAPEngine->soapclient->getAliases($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 "

    ";
    -            //print_r($result);
    -
    -            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->aliases[$i]) break; - - $alias = $result->aliases[$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&alias_username_filter=%s&alias_domain_filter=%s", - urlencode($this->SOAPEngine->service), - urlencode($alias->id->username), - urlencode($alias->id->domain) - ); - - if ($_REQUEST['action'] == 'Delete' && - $_REQUEST['alias_username_filter'] == $alias->id->username && - $_REQUEST['alias_domain_filter'] == $alias->id->domain) { - $_url .= "&confirm=1"; - $actionText = "Confirm"; - } else { - $actionText = "Delete"; - } - - printf(" - - - - - - - - - ", - $bgcolor, - $index, - $alias->id->username, - $alias->id->domain, - $alias->customer, - $alias->reseller, - $alias->target->username, - $alias->target->domain, - $alias->owner, - $_url, - $actionText - ); - - $i++; - - } - - } - - print "
    Id - SIP aliasOperatorSIP targetOwnerAction
    %s%s@%s%s.%s%s@%s%s%s
    "; - - $this->showPagination($maxrows); - - return true; - } - } - - function deleteRecord() { - if (!$_REQUEST['confirm']) { - print "

    Please press on Confirm to confirm the delete. "; - return 1; - } - - if (!strlen($this->filters['aliasUsername']) || !strlen($this->filters['aliasDomain'])) { - print "

    Error: missing SIP alias username or domain. "; - return 0; - } - - $alias=array('username' => $this->filters['aliasUsername'], - 'domain' => $this->filters['aliasDomain'] - ); - - $function=array('commit' => array('name' => 'deleteAlias', - 'parameters' => array($alias), - 'logs' => array('success' => sprintf('

  • SIP alias %s@%s has been deleted',$this->filters['aliasUsername'],$this->filters['aliasDomain']) - ) - ) - - ); - - if ($this->SOAPEngine->execute($function)) { - unset($this->filters); - } - - return true; - } - - function showSeachFormCustom() { - printf (" User: ",$this->filters['aliasUsername']); - printf (" Domain: "); - - if ($this->allowedDomains) { - $selected_domain[$this->filters['aliasDomain']]='selected'; - printf (""); - } else { - printf ("",$this->filters['aliasDomain']); - } - - printf (" Target user: ",$this->filters['targetUsername']); - printf (" Target domain: ",$this->filters['targetDomain']); - - } - - function showAddForm() { - if ($this->selectionActive) return; - print " -

    - - - "; - printf ("",$_SERVER['PHP_SELF']); - print " - - - "; - $this->printHiddenFormElements(); - - print " - - -
    - "; - - print " - - "; - - printf (" SIP alias: "); - - if (is_array($this->allowedDomains)) { - print "@"; - } - - printf (" SIP target: "); - - if ($this->adminonly) { - $this->showResellerForm('reseller'); - $this->showCustomerForm('customer'); - } else { - $this->showCustomerForm('customer'); - } - - printf (" Owner: "); - - print " - - "; - print " -
    - "; - } - - function addRecord() { - $alias_els = explode("@", trim($_REQUEST['alias'])); - $target_els = explode("@", trim($_REQUEST['target'])); - - $username=$alias_els[0]; - - if (strlen($alias_els[1])) { - $domain=$alias_els[1]; - - } else if (trim($_REQUEST['domain'])) { - $domain=trim($_REQUEST['domain']); - - } else { - printf ("

    Error: Missing SIP domain"); - return false; - } - - if (is_array($this->allowedDomains) && !in_array($domain,$this->allowedDomains)) { - printf ("

    Error: SIP domain %s is not allowed",$domain); - return false; - } - - if ($this->adminonly) { - $reseller = trim($_REQUEST['reseller']); - $customer = trim($_REQUEST['customer']); - } else { - $reseller = $this->reseller; - $customer = trim($_REQUEST['customer']); - if (!$customer || !in_array($customer,array_keys($this->customers))) { - $customer=$reseller; - } - } - - $alias=array( - 'id' => array('username' => $username, - 'domain' => $domain - ), - 'target' => array('username' => $target_els[0], - 'domain' => $target_els[1] - ), - 'owner' => intval($_REQUEST['owner']), - 'customer' => intval($customer), - 'reseller' => intval($reseller) - ); - - //print_r($alias); - - $deleteAlias=array('username' => $username, - 'domain' => $domain); - - $function=array('commit' => array('name' => 'addAlias', - 'parameters' => array($alias), - 'logs' => array('success' => sprintf('

  • SIP alias %s@%s has been added',$username,$domain))), - 'rollback' => array('name' => 'deleteAlias', - 'parameters' => array($deleteAlias)) - ); - - $this->SOAPEngine->execute($function); - - return true; - } - - function getAllowedDomains() { - // Insert credetials - $this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth); - $result = $this->SOAPEngine->soapclient->getDomains(); - - 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->allowedDomains=$result; - } - } - -} - hunk ./provisioning_logic.phtml 3848 - $this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth); - - $result = $this->SOAPEngine->soapclient->addDomain($domain); - - 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 { - printf ("

    SIP domain %s has been added. ",$domain); - return 1; - } - } -} - -class Domains extends Records { - - var $maxrowsperpage= 200; - - function Domains(&$SOAPEngine,$adminonly) { - $this->filters = array( - 'domain' => trim($_REQUEST['domain_filter']) - ); - - $this->Records(&$SOAPEngine,$adminonly); - } - - function listRecords() { - - $this->showSeachForm(); - - // Insert credetials - $this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth); - - $filter=$this->filters['domain']; - // Call function - $result = $this->SOAPEngine->soapclient->getDomains($filter); - - 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 = count($result); - - 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) { - - $domain = $result[$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&domain_filter=%s", - urlencode($this->SOAPEngine->service), - urlencode($domain) - ); - - if ($_REQUEST['action'] == 'Delete' && - $_REQUEST['domain_filter'] == $domain) { - $_url .= "&confirm=1"; - $actionText = "Confirm"; - } else { - $actionText = "Delete"; - } - - printf(" - - - - - - ", - $bgcolor, - $index, - $domain, - $domain->customer, - $domain->reseller, - $_url, - $actionText - ); - - $i++; - } - } - - print "
    Id - DomainOperatorAction
    %s%s%s.%s%s
    "; - - $this->showPagination($maxrows); - - return true; - } - } - - function showSeachFormCustom() { - - printf (" Domain: ",$this->filters['domain']); - - } - - function deleteRecord() { - if (!$_REQUEST['confirm']) { - print "

    Please press on Confirm to confirm the delete. "; - return 1; - } - - if (!strlen($this->filters['domain']) || !strlen($this->filters['domain'])) { - print "

    Error: missing SIP domain. "; - return 0; - } - - $this->SOAPEngine->soapclient->addHeader($this->SOAPEngine->SoapAuth); - - $result = $this->SOAPEngine->soapclient->deleteDomain($this->filters['domain']); - - 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 { - printf ("

    SIP domain %s has been deleted. ",$this->filters['domain']); - unset($this->filters); - return 1; - } - } - - function showAddForm() { - if ($this->selectionActive) return; - print " -

    - - - "; - printf ("",$_SERVER['PHP_SELF']); - print " - - - "; - $this->printHiddenFormElements(); - - print " - - -
    - "; - - print " - - "; - - printf (" Domain: "); - - if ($this->adminonly) { - $this->showResellerForm('reseller'); - $this->showCustomerForm('customer'); - } else { - $this->showCustomerForm('customer'); - } - - print " - - "; - print " -
    - "; - } - - function addRecord() { - - $domain = trim($_REQUEST['domain']); - - if ($this->adminonly) { - $reseller = trim($_REQUEST['reseller']); - $customer = trim($_REQUEST['customer']); - } else { - $reseller = $this->reseller; - $customer = trim($_REQUEST['customer']); - if (!$customer || !in_array($customer,array_keys($this->customers))) { - $customer=$reseller; - } - } -