[Added posibility to replicate customer entries in Customer Port Adrian Georgescu **20080222124548 Added getPrepaidHistory function to the rating engine Replaced false with 0 and true with 1 for the return values from rating engine Show database ip address when replication monitor returns an error ] hunk ./mysql_replication_lib.phtml 52 - printf ("

MySQL error: %s (%s) for query: %s",$db->Error,$db->Errno,$this->slave_status_query); + printf ("

Error from MySQL server %s: %s (%s) for query: %s",$clusters[$host]['ip'],$db->Error,$db->Errno,$this->slave_status_query); hunk ./mysql_replication_lib.phtml 249 -$text="root ssh keys must be shared between machines"; +$text="The ssh public keys for user root must be shared
between machines. Test scp as root between machines."; hunk ./mysql_replication_lib.phtml 263 -# do not exit the mysql console +# do not exit the mysql console hunk ./provisioning/ngnpro_client_lib.phtml 260 - - port is an available NGNPro web service - - engine is a connection to remote NGNPro server + - port is an available NGNPro service + - engine is a connection to an NGNPro server hunk ./provisioning/ngnpro_client_lib.phtml 456 - if ($this->adminonly) { - //printf ("

%s at %s as %s ",$this->soap_class,$this->SOAPurl,$this->SOAPurl,$this->soapUsername); - } - + $log=sprintf ("

%s at %s as %s ",$this->soap_class,$this->SOAPurl,$this->SOAPurl,$this->soapUsername); + dprint($log); hunk ./provisioning/ngnpro_client_lib.phtml 469 - $this->soapDepends=$this->soapEngines[$this->soapEngine]['depends']; - - if (strlen($this->soapDepends) && in_array($this->soapDepends,array_keys($this->soapEngines))) { - $this->soapEngineRemote = $this->soapEngines[$this->soapDepends]; - $this->impersonateRemote = intval($this->soapEngines[$this->soapDepends]['impersonate']); - - $this->SOAPloginRemote = array( - "username" => $this->soapEngines[$this->soapDepends]['username'], - "password" => $this->soapEngines[$this->soapDepends]['password'], - "admin" => true, - "impersonate" => $this->impersonateRemote - ); + //dprint_r($this->login_credentials); hunk ./provisioning/ngnpro_client_lib.phtml 471 - dprint_r($this->SOAPloginRemote); - $this->SOAPurlRemote=$this->soapEngines[$this->soapDepends]['url']; + if (strlen($this->soapEngines[$this->soapEngine]['depends'])) { + $this->soapRemote=$this->soapEngines[$this->soapEngine]['depends']; hunk ./provisioning/ngnpro_client_lib.phtml 474 - if ($this->adminonly) { - //printf ("and syncronize changes to %s",$this->SOAPurlRemote,$this->SOAPurlRemote); + if (strlen($this->soapRemote) && in_array($this->soapRemote,array_keys($this->soapEngines))) { + $this->soapEngineRemote = $this->soapEngines[$this->soapRemote]; + $this->impersonateRemote = intval($this->soapEngines[$this->soapRemote]['impersonate']); + + $this->SOAPloginRemote = array( + "username" => $this->soapEngines[$this->soapRemote]['username'], + "password" => $this->soapEngines[$this->soapRemote]['password'], + "admin" => true, + "impersonate" => $this->impersonateRemote + ); + + dprint_r($this->SOAPloginRemote); + $this->SOAPurlRemote=$this->soapEngines[$this->soapRemote]['url']; + + if ($this->adminonly) { + //printf ("and syncronize changes to %s",$this->SOAPurlRemote,$this->SOAPurlRemote); + } + $this->SoapAuthRemote = array('auth', $this->SOAPloginRemote , 'urn:AGProjects:NGNPro', 0, ''); + + // Instantiate the SOAP client dependency + $this->soapclientRemote = new $this->soap_class($this->SOAPurlRemote); + + $this->soapclientRemote->setOpt('curl', CURLOPT_SSL_VERIFYPEER, 0); + $this->soapclientRemote->setOpt('curl', CURLOPT_SSL_VERIFYHOST, 0); hunk ./provisioning/ngnpro_client_lib.phtml 499 - $this->SoapAuthRemote = array('auth', $this->SOAPloginRemote , 'urn:AGProjects:NGNPro', 0, ''); - - // Instantiate the SOAP client dependency - $this->soapclientRemote = new $this->soap_class($this->SOAPurlRemote); - - $this->soapclientRemote->setOpt('curl', CURLOPT_SSL_VERIFYPEER, 0); - $this->soapclientRemote->setOpt('curl', CURLOPT_SSL_VERIFYHOST, 0); hunk ./provisioning/ngnpro_client_lib.phtml 538 + hunk ./provisioning/ngnpro_client_lib.phtml 1149 - dprint ("No customer available"); + //dprint ("No customer available"); hunk ./provisioning/ngnpro_client_lib.phtml 7492 + if ($_REQUEST['action'] == 'Add' || $_REQUEST['action'] == 'Copy' || + $_REQUEST['action'] == 'Delete' || $_REQUEST['action'] == 'Update') { + + if ($this->reseller) { + $customer_engine_remote=$this->SoapEngine->login_credentials['reseller_filters'][$this->reseller]['customer_engine_remote']; + + if (strlen($customer_engine_remote)) { + + if (in_array($customer_engine_remote,array_keys($this->SoapEngine->soapEngines))) { + $this->SOAPloginCustomerRemote = array( + "username" => $this->SoapEngine->soapEngines[$customer_engine_remote]['username'], + "password" => $this->SoapEngine->soapEngines[$customer_engine_remote]['password'], + "admin" => true, + "impersonate" => $this->reseller + ); + + //dprint_r($this->SOAPloginCustomerRemote); + $this->SOAPurlCustomerRemote=$this->SoapEngine->soapEngines[$customer_engine_remote]['url']; + + $log=sprintf ("and syncronize changes to %s",$this->SOAPurlCustomerRemote,$this->SOAPurlCustomerRemote); + dprint($log); + + $this->SoapAuthCustomerRemote = array('auth', $this->SOAPloginCustomerRemote , 'urn:AGProjects:NGNPro', 0, ''); + + $this->SoapEngineCustomerRemote = new $this->SoapEngine->soap_class($this->SOAPurlCustomerRemote); + $this->SoapEngineCustomerRemote->setOpt('curl', CURLOPT_SSL_VERIFYPEER, 0); + $this->SoapEngineCustomerRemote->setOpt('curl', CURLOPT_SSL_VERIFYHOST, 0); + } + } + } + } hunk ./provisioning/ngnpro_client_lib.phtml 7806 - return $this->SoapEngine->execute($function,$this->html); + if ($this->SoapEngine->execute($function,$this->html)) { + if (is_object($this->SoapEngineCustomerRemote)) { + // delete remote + $function=array('commit' => array('name' => 'deleteAccount', + 'parameters' => array(intval($this->filters['customer'])), + 'logs' => array('failure' => sprintf('Error deleting customer id %s remotely',$this->filters['customer']))) + ); + $this->SoapEngineCustomerRemote->execute($function,$this->html); + } + return true; + } else { + return false; + } hunk ./provisioning/ngnpro_client_lib.phtml 8379 + + // update remote + if (is_object($this->SoapEngineCustomerRemote)) { + $function=array('commit' => array('name' => 'updateAccount', + 'parameters' => array($customer), + 'logs' => array('failure' => sprintf('Error: customer id %s could not be remotely updated',$customer->id)) + ) + ); + + // we fail to update remote and we rollback local update too + if (!$this->SoapEngineCustomerRemote->execute($function,$this->html)) { + $function=array('commit' => array('name' => 'updateAccount', + 'parameters' => array($customer_old) + ) + ); + $this->SoapEngine->execute($function,$this->html); + + return false; + } + } + + hunk ./provisioning/ngnpro_client_lib.phtml 8771 - if ($dictionary['notify'] || $_REQUEST['notify']) $this->notify($customer); + if (is_object($this->SoapEngineCustomerRemote)) { + if ($_id = $this->getCustomerId($customer['username'])) { + $customerRemote=$customer; + $customerRemote['id'] = $_id; + $function=array('commit' => array('name' => 'addAccount', + 'parameters' => array($customerRemote), + 'logs' => array('failure' => sprintf('Failed to add remote login account %s %s',$customerRemote['firstName'],$customerRemote['lastName'])) + ) + ); + if (!$this->SoapEngineCustomerRemote->execute($function,$this->html)) { + $function=array('commit' => array('name' => 'deleteAccount', + 'parameters' => array(intval($_id)), + 'logs' => array('success' => sprintf('Customer id %s has been deleted',$this->filters['customer']))) + ); + + $this->SoapEngine->execute($function,$this->html); + + return false; + } + } + } hunk ./provisioning/ngnpro_client_lib.phtml 8793 + // We have succesfully added customer entry hunk ./provisioning/ngnpro_client_lib.phtml 8796 + if ($dictionary['notify'] || $_REQUEST['notify']) $this->notify($customer); + hunk ./provisioning/ngnpro_client_lib.phtml 8899 + + function getCustomerId($username) { + if (!strlen($username)) return false; + $filter = array('username' => $username); + $range = array('start' => 0,'count' => 1); + $orderBy = array('attribute' => 'customer', 'direction' => 'ASC'); + $Query=array('filter' => $filter,'orderBy' => $orderBy,'range' => $range); + + // Insert credetials + $this->SoapEngine->soapclient->addHeader($this->SoapEngine->SoapAuth); + + // Call function + $result = $this->SoapEngine->soapclient->getCustomers($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 (count($result->accounts) == 1) { + return $result->accounts[0]->id; + } else { + return false; + } + } + } hunk ./rating_lib.phtml 3780 - return false; + return 0; hunk ./rating_lib.phtml 3789 - return true; + return 1; hunk ./rating_lib.phtml 3793 - return false; + return 0; hunk ./rating_lib.phtml 3806 - return true; + return 1; hunk ./rating_lib.phtml 3832 - return true; + return 1; hunk ./rating_lib.phtml 3836 - return true; + return 1; hunk ./rating_lib.phtml 3841 - return true; + return 1; hunk ./rating_lib.phtml 3851 - return true; + return 1; hunk ./rating_lib.phtml 3871 + function getBalanceHistory($account,$limit=50) { + + list($username,$domain)=explode("@",$account); + if (!strlen($username) || !strlen($domain)) return 0; + $query=sprintf("select * from prepaid_history where username = '%s' and domain = '%s' order by id desc", + addslashes($username), + addslashes($domain) + ); + + if ($limit) $query.= sprintf (" limit %d",$limit); + + dprint($query); + + if (!$this->db->query($query)) { + $log=sprintf ("getBalanceHistory error: %s (%s)",$this->db->Error,$this->db->Errno); + syslog(LOG_NOTICE, $log); + return 0; + } + + unset($line); + $line .= sprintf("%s\n",$this->db->num_rows()); + + while ($this->db->next_record()) { + $line .= sprintf + ("Action='%s'\tSource='%s'\tValue='%s'\tDate='%s'\tBalance='%s'\n", + $this->db->f('action'), + $this->db->f('number'), + $this->db->f('value'), + $this->db->f('date'), + $this->db->f('balance') + ); + } + + return $line; + } + hunk ./rating_lib.phtml 3917 - return false; + return 0; hunk ./rating_lib.phtml 3922 - return false; + return 0; hunk ./rating_lib.phtml 3927 - return false; + return 0; hunk ./rating_lib.phtml 3958 - return true; + return 1; hunk ./rating_lib.phtml 3962 - return false; + return 0; hunk ./rating_lib.phtml 3975 - return false; + return 0; hunk ./rating_lib.phtml 3985 - return false; + return 0; hunk ./rating_lib.phtml 3988 - if (strlen($account) > 128) { + if (strlen($account) > 128) { hunk ./rating_lib.phtml 3990 - return false; + return 0; hunk ./rating_lib.phtml 3993 - if ($this->balance[$account]) { + if (strlen($this->balance[$account])) { hunk ./rating_lib.phtml 4031 - return true; + return 1; hunk ./rating_lib.phtml 4035 - return false; + return 0; hunk ./rating_lib.phtml 4074 - return true; + return 1; hunk ./rating_lib.phtml 4078 - return false; + return 0; hunk ./rating_lib.phtml 4089 - "DebitBalance From=sip:123@example.com To=sip:0031650222333 Duration=59\n". hunk ./rating_lib.phtml 4090 - "AddBalance From=123@example.com Value=10.00\n". - "GetBalance From=123@example.com\n". hunk ./rating_lib.phtml 4093 - "ReloadPrepaidAccounts Account=abc@example.com\n". - "ShowPrepaidAccounts Filter=123@example.com\n". hunk ./rating_lib.phtml 4095 - "ReloadDomains"; + "ReloadDomains\n". + "AddBalance From=123@example.com Value=10.00\n". + "GetBalance From=123@example.com\n". + "GetBalanceHistory From=123@example.com\n". + "DebitBalance From=sip:123@example.com To=sip:0031650222333 Duration=59\n". + "ReloadPrepaidAccounts Account=abc@example.com\n". + "ShowPrepaidAccounts Filter=123@example.com\n" + ; hunk ./rating_lib.phtml 4121 - if (!$_els[0]) return false; + if (!$_els[0]) return 0; hunk ./rating_lib.phtml 4138 - return false; + return 0; hunk ./rating_lib.phtml 4164 - return false; + return 0; hunk ./rating_lib.phtml 4171 - return false; + return 0; hunk ./rating_lib.phtml 4339 - return false; + return 0; hunk ./rating_lib.phtml 4345 - return false; + return 0; hunk ./rating_lib.phtml 4351 - return false; + return 0; hunk ./rating_lib.phtml 4385 - return false; + return 0; hunk ./rating_lib.phtml 4397 - return false; + return 0; hunk ./rating_lib.phtml 4497 - return false; + return 0; hunk ./rating_lib.phtml 4500 - if (!$NetFields['value']) { + if (!is_numeric($NetFields['value'])) { hunk ./rating_lib.phtml 4502 - $log=sprintf ("Error: Missing Value parameter"); + $log=sprintf ("Error: Missing Value parameter, it must be numeric"); hunk ./rating_lib.phtml 4504 - return false; + return 0; hunk ./rating_lib.phtml 4507 - $log=sprintf ("Customer : %s",$NetFields['from']); + $log=sprintf ("Account : %s",$NetFields['from']); hunk ./rating_lib.phtml 4514 - $log=sprintf ("New Balance : %s",$this->balance[$NetFields['from']]); + if (intval($NetFields['value']) != 0) { + $log=sprintf ("New Balance : %s",$this->balance[$NetFields['from']]); hunk ./rating_lib.phtml 4517 + } hunk ./rating_lib.phtml 4522 - return false; + return 0; hunk ./rating_lib.phtml 4531 - return false; + return 0; hunk ./rating_lib.phtml 4538 - return false; + return 0; hunk ./rating_lib.phtml 4545 - return false; + return 0; hunk ./rating_lib.phtml 4615 - return false; + return 0; hunk ./rating_lib.phtml 4630 + } else if ($NetFields['action'] == "getbalancehistory") { + if (!$NetFields['from']) { + dprint("Missing From parameter."); + $log=sprintf ("Error: Missing From parameter"); + syslog(LOG_NOTICE, $log); + return 0; + } + + $history=$this->getBalanceHistory($NetFields['from']); + return trim($history); + hunk ./rating_lib.phtml 4687 - return false; + return 0;