[Added DeleteBalance and DeleteBalance History commands to rating engine Adrian Georgescu **20080223104521 Use colors in mysql replication status ] hunk ./mysql_replication_lib.phtml 78 - + $this->slave_of = $clusters[$host]['slave_of']; + $this->color = $clusters[$host]['color']; hunk ./mysql_replication_lib.phtml 157 - print " - - - - "; - print ""; - print " - - "; - - print " - -
Slave statusMaster status
- "; - + print ""; + hunk ./mysql_replication_lib.phtml 170 - - print "
"; + + printf (""); + + printf ("",$this->status[$key]->color,$this->status[$key]->master_log_file); + printf ("",$this->status[$key]->master_position); + + printf (""); + hunk ./mysql_replication_lib.phtml 180 - printf ("",$this->status[$key]->slave_log_file); + printf ("",$this->status[$this->status[$key]->slave_of]->color,$this->status[$key]->slave_log_file); hunk ./mysql_replication_lib.phtml 187 - print "
Master status
Log file%s
Position%s
Slave status
Log file%s
Log file%s
"; - print " -
- "; - print ""; - printf ("",$this->status[$key]->master_log_file); - printf ("",$this->status[$key]->master_position); - print "
Log file%s
Position%s
"; - - print " -
+ + print " hunk ./mysql_replication_lib.phtml 247 -# write down the file and possition %s.file %s.pos +# write down file a& possition %s.file %s.pos hunk ./mysql_replication_lib.phtml 259 -# wait until same file/pos as %s is displayed) +# wait until same file/pos as %s is displayed hunk ./rating_lib.phtml 3916 - syslog(LOG_NOTICE, "DebitBalance() error: missing BillingPartyId"); + syslog(LOG_NOTICE, "DebitBalance() error: missing account"); hunk ./rating_lib.phtml 3920 - if (strlen($account) > 254) { - syslog(LOG_NOTICE, "DebitBalance() error: BillingPartyId > 254 chars"); - return 0; - } - - if (!$account || !strlen($balance)) { - syslog(LOG_NOTICE, "DebitBalance() error: missing BillingPartyId or balance"); + if (!is_numeric($balance)) { + syslog(LOG_NOTICE, "DebitBalance() error: balance"); hunk ./rating_lib.phtml 3983 - if (strlen($account) > 128) { - syslog(LOG_NOTICE, "CreditBalance() error: account > 128 chars"); - return 0; - } + list($prepaidUser,$prepaidDomain)=explode("@",$account); hunk ./rating_lib.phtml 3995 - dprint($query); - hunk ./rating_lib.phtml 3997 - list($prepaidUser,$prepaidDomain)=explode("@",$account); - hunk ./rating_lib.phtml 4012 - dprint($query); hunk ./rating_lib.phtml 4034 - dprint($query); - hunk ./rating_lib.phtml 4040 + hunk ./rating_lib.phtml 4052 - dprint($query); - $this->db->query($query); - hunk ./rating_lib.phtml 4066 + function DeleteBalance($account) { + + $account=trim($account); + if (preg_match("/^(.*):(.*)$/",$account,$m)) { + $account=$m[2]; + } + + if (!$account) { + syslog(LOG_NOTICE, "DeleteBalance() error: missing account"); + return 0; + } + + $query=sprintf("delete from %s where account = '%s'", + addslashes($this->table),addslashes($account) + ); + + if (!$this->db->query($query)) { + $log=sprintf("DeleteBalance error for query %s: %s (%s)",$query,$this->db->Error,$this->db->Errno); + syslog(LOG_NOTICE, $log); + return 0; + } + + unset($this->balance[$account]); + + $log=sprintf ("Prepaid account %s has been deleted",$account); + syslog(LOG_NOTICE, $log); + + return 1; + } + + function DeleteBalanceHistory($account) { + + $account=trim($account); + if (preg_match("/^(.*):(.*)$/",$account,$m)) { + $account=$m[2]; + } + + if (!$account) { + syslog(LOG_NOTICE, "DeleteBalanceHistory() error: missing account"); + return 0; + } + + list($username,$domain)=explode('@',$account); + + $query=sprintf("delete from prepaid_history where username = '%s' and domain = '%s'", + addslashes($username), + addslashes($domain) + ); + + if (!$this->db->query($query)) { + $log=sprintf("DeleteBalanceHistory error for query %s: %s (%s)",$query,$this->db->Error,$this->db->Errno); + syslog(LOG_NOTICE, $log); + return 0; + } + + $log=sprintf ("History of prepaid account %s has been deleted",$account); + syslog(LOG_NOTICE, $log); + + return 1; + } + hunk ./rating_lib.phtml 4132 - "MaxSessionTime From=sip:123@example.com To=sip:0031650222333 Duration=7200 Lock=1\n". - "ShowPrice From=sip:123@example.com To=sip:0031650222333 Duration=59\n". + "MaxSessionTime From=sip:123@example.com To=sip:0031650222333 Duration=7200 Lock=1\n". + "ShowPrice From=sip:123@example.com To=sip:0031650222333 Duration=59\n". hunk ./rating_lib.phtml 4140 - "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". + "AddBalance From=123@example.com Value=10.00\n". + "GetBalance From=123@example.com\n". + "GetBalanceHistory From=123@example.com\n". + "DeleteBalance From=123@example.com\n". + "DeleteBalanceHistory From=123@example.com\n". + "DebitBalance From=sip:123@example.com To=sip:0031650222333 Duration=59\n". hunk ./rating_lib.phtml 4147 - "ShowPrepaidAccounts Filter=123@example.com\n" + "ShowPrepaidAccounts Filter=123@example.com\n" hunk ./rating_lib.phtml 4484 + /* hunk ./rating_lib.phtml 4486 - syslog(LOG_NOTICE, $log); + syslog(LOG_NOTICE, $log); + */ hunk ./rating_lib.phtml 4573 + } else if ($NetFields['action'] == "deletebalance") { + + if (!$NetFields['from']) { + dprint("Missing From parameter."); + $log=sprintf ("Error: Missing From parameter"); + syslog(LOG_NOTICE, $log); + return 0; + } + + return $this->DeleteBalance($NetFields['from']); + + } else if ($NetFields['action'] == "deletebalancehistory") { + + if (!$NetFields['from']) { + dprint("Missing From parameter."); + $log=sprintf ("Error: Missing From parameter"); + syslog(LOG_NOTICE, $log); + return 0; + } + + return $this->DeleteBalanceHistory($NetFields['from']); + hunk ./rating_lib.phtml 4688 - $log=sprintf ("Customer : %s",$NetFields['from']); - syslog(LOG_NOTICE, $log); - $log=sprintf ("Balance : %s",$this->balance[$NetFields['from']]); - syslog(LOG_NOTICE, $log); - hunk ./rating_lib.phtml 4689 - $balance="0.00"; + $balance=sprintf("%0.4f",0);