Skip to content

Commit

Permalink
add max call duration option
Browse files Browse the repository at this point in the history
  • Loading branch information
callcenter-magnus committed Jan 23, 2024
1 parent 16f86e7 commit d0f4db8
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 50 deletions.
Binary file modified build/MagnusBilling-current.tar.gz
Binary file not shown.
10 changes: 10 additions & 0 deletions protected/commands/UpdateMysqlCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -1988,6 +1988,16 @@ public function run($args)
$version = '7.8.4.4';
$this->update($version);
}
//2024-01-22
if ($version == '7.8.4.4') {
$sql = "INSERT INTO pkg_configuration VALUES
(NULL, 'Max call duration', 'max_call_duration', '3600', 'Maximum call duration in seconds', 'global', '1');
";
$this->executeDB($sql);

$version = '7.8.4.5';
$this->update($version);
}

}

Expand Down
32 changes: 31 additions & 1 deletion protected/commands/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,31 @@ if [[ -e /var/www/html/mbilling/protected/commands/update2.sh ]]; then
exit;
fi


get_linux_distribution ()
{
if [ -f /etc/debian_version ]; then
DIST="DEBIAN"
HTTP_DIR="/etc/apache2/"
HTTP_CONFIG=${HTTP_DIR}"apache2.conf"
MYSQL_CONFIG="/etc/mysql/mariadb.conf.d/50-server.cnf"
elif [ -f /etc/redhat-release ]; then
DIST="CENTOS"
HTTP_DIR="/etc/httpd/"
HTTP_CONFIG=${HTTP_DIR}"conf/httpd.conf"
MYSQL_CONFIG="/etc/my.cnf"
else
DIST="OTHER"
echo 'Installation does not support your distribution'
exit 1
fi
}



get_linux_distribution


cd /var/www/html/mbilling
rm -rf MagnusBilling-current.tar.gz
wget --no-check-certificate https://raw.githubusercontent.com/magnussolution/magnusbilling7/source/build/MagnusBilling-current.tar.gz
Expand Down Expand Up @@ -62,7 +87,12 @@ chmod -R 700 /var/www/html/mbilling/resources/sounds
chmod -R 700 /var/www/html/mbilling/resources/images
chmod +x /var/www/html/mbilling/resources/asterisk/mbilling.php
chmod -R 555 /var/www/html/mbilling/resources/asterisk/

rm -rf /var/lib/asterisk/sbin/*
if [ ${DIST} = "DEBIAN" ]; then
CRONPATH='/var/spool/cron/crontabs/asterisk'
elif [ ${DIST} = "CENTOS" ]; then
CRONPATH='/var/spool/cron/asterisk'
fi

if [[ -e /var/www/html/mbilling/resources/images/lock-screen-background.jpg ]]; then
for color in black blue gray orange purple red yellow green
Expand Down
2 changes: 1 addition & 1 deletion protected/models/Sip.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function rules()
['defaultuser, cid_number, outboundproxy, sippasswd', 'length', 'max' => 40],
['defaultuser', 'checkusername'],
['secret', 'checksecret'],
['secret', 'length', 'min' => 4, 'max' => 20],
['secret', 'length', 'min' => 4, 'max' => 30],
['defaultuser', 'unique', 'caseSensitive' => 'false'],
['techprefix, cnl', 'length', 'max' => 6],
['techprefix', 'checktechprefix'],
Expand Down
76 changes: 37 additions & 39 deletions resources/asterisk/CalcAgi.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ class CalcAgi
public $sessionbill = 0;
public $sipiax = 0;
public $id_campaign = '';
public $tariffObj = array();
public $freetimetocall_left = array();
public $freecall = array();
public $offerToApply = array();
public $didAgi = array();
public $tariffObj = [];
public $freetimetocall_left = [];
public $freecall = [];
public $offerToApply = [];
public $didAgi = [];
public $dialstatus_rev_list;
public $id_prefix;
public $id_provider;
Expand All @@ -67,7 +67,7 @@ public function init()

public function calculateAllTimeout(&$MAGNUS, $agi)
{
if (!is_array($this->tariffObj) || count($this->tariffObj) == 0) {
if ( ! is_array($this->tariffObj) || count($this->tariffObj) == 0) {
return false;
}

Expand Down Expand Up @@ -115,14 +115,14 @@ public function calculateTimeout(&$MAGNUS, $agi)
$agi->verbose("offer Unlimited calls");
$this->freecall[0] = true;
$package_selected = true;
$this->offerToApply[0] = array(
$this->offerToApply[0] = [
"id" => $id_offer,
"label" => "Unlimited calls",
"type" => $packagetype,
"billingblock" => $modelOffer->billingblock,
"initblock" => $modelOffer->initblock,
"minimal_time_charge" => $modelOffer->minimal_time_charge,
);
];
break;
case 1:

Expand All @@ -133,14 +133,14 @@ public function calculateTimeout(&$MAGNUS, $agi)
if ($number_calls_used < $freetimetocall) {
$this->freecall[0] = true;
$package_selected = true;
$this->offerToApply[0] = array(
$this->offerToApply[0] = [
"id" => $id_offer,
"label" => "Number of Free calls",
"type" => $packagetype,
"billingblock" => $modelOffer->billingblock,
"initblock" => $modelOffer->initblock,
"minimal_time_charge" => $modelOffer->minimal_time_charge,
);
];
$agi->verbose(print_r($this->offerToApply[0], true), 6);
}
}
Expand All @@ -156,14 +156,14 @@ public function calculateTimeout(&$MAGNUS, $agi)

if ($this->freetimetocall_left[0] > 0) {
$package_selected = true;
$this->offerToApply[0] = array(
$this->offerToApply[0] = [
"id" => $id_offer,
"label" => "Free minutes",
"type" => $packagetype,
"billingblock" => $modelOffer->billingblock,
"initblock" => $modelOffer->initblock,
"minimal_time_charge" => $modelOffer->minimal_time_charge,
);
];
$agi->verbose(print_r($this->offerToApply[0], true), 6);
}
}
Expand All @@ -174,34 +174,30 @@ public function calculateTimeout(&$MAGNUS, $agi)

$credit -= $connectcharge;
$this->tariffObj[0]['timeout'] = 0;
$this->tariffObj[0]['timeout_without_rules'] = 0;
$this->tariffObj[0]['freetime_include_in_timeout'] = $this->freetimetocall_left[0];
$agi->verbose("Credit $credit", 20);
if ($credit < 0 && !$this->freecall[0] && $this->freetimetocall_left[0] <= 0) {
if ($credit < 0 && ! $this->freecall[0] && $this->freetimetocall_left[0] <= 0) {
return "ERROR CT1";
/*NO CREDIT TO CALL */
}

$TIMEOUT = 0;
$answeredtime_1st_leg = 0;
if ($rateinitial <= 0) /*Se o preço for 0, entao retornar o timeout em 3600 s*/ {
$this->tariffObj[0]['timeout'] = 3600;
$this->tariffObj[0]['timeout_without_rules'] = 3600;
$TIMEOUT = 3600;
if ($rateinitial <= 0) /*Se o preço for 0, entao retornar o timeout em 3600 s*/{
$this->tariffObj[0]['timeout'] = $MAGNUS->config['global']['max_call_duration'];
$TIMEOUT = $MAGNUS->config['global']['max_call_duration'];
return $TIMEOUT;
}

if ($this->freecall[0]) /*usado para planos gratis*/ {
$this->tariffObj[0]['timeout'] = 3600;
$TIMEOUT = 3600;
$this->tariffObj[0]['timeout_without_rules'] = 3600;
$this->tariffObj[0]['freetime_include_in_timeout'] = 3600;
if ($this->freecall[0]) /*usado para planos gratis*/{
$this->tariffObj[0]['timeout'] = $MAGNUS->config['global']['max_call_duration'];
$TIMEOUT = $MAGNUS->config['global']['max_call_duration'];
$this->tariffObj[0]['freetime_include_in_timeout'] = $MAGNUS->config['global']['max_call_duration'];
return $TIMEOUT;
}
if ($credit < 0 && $this->freetimetocall_left[0] > 0) {
$this->tariffObj[0]['timeout'] = $this->freetimetocall_left[0];
$TIMEOUT = $this->freetimetocall_left[0];
$this->tariffObj[0]['timeout_without_rules'] = $this->freetimetocall_left[0];
$this->tariffObj[0]['timeout'] = $this->freetimetocall_left[0];
$TIMEOUT = $this->freetimetocall_left[0];
return $TIMEOUT;
}

Expand All @@ -215,19 +211,21 @@ public function calculateTimeout(&$MAGNUS, $agi)
}

$num_sec = intval($num_min * 60) - $answeredtime_1st_leg; /*numero de segundos - o tempo que gastou para completar*/

if ($billingblock > 0) {
$mod_sec = $num_sec % $billingblock;
$num_sec = $num_sec - $mod_sec;
}
$TIMEOUT = $num_sec;

/*Call time to speak without rate rules... idiot rules*/
$num_min_WR = $initial_credit / $rateinitial;
$num_sec_WR = intval($num_min_WR * 60);
$this->tariffObj[0]['timeout_without_rules'] = $num_sec_WR + $this->freetimetocall_left[0];
$this->tariffObj[0]['timeout'] = $TIMEOUT + $this->freetimetocall_left[0];

return $TIMEOUT + $this->freetimetocall_left[0];
if ($TIMEOUT > $MAGNUS->config['global']['max_call_duration']) {
$agi->verbose('TIMEOUT1 use max_call_duration ' . $MAGNUS->config['global']['max_call_duration'], 5);
$TIMEOUT = $MAGNUS->config['global']['max_call_duration'];
}
$this->tariffObj[0]['timeout'] = $TIMEOUT + $this->freetimetocall_left[0];
return $TIMEOUT;
}

public function calculateCost(&$MAGNUS, $callduration, $agi)
Expand Down Expand Up @@ -464,7 +462,7 @@ public function updateSystem(&$MAGNUS, &$agi, $doibill = 1, $didcall = 0, $callb
$MAGNUS->credit = $MAGNUS->credit - $cost;
/*CALULATION CUSTO AND SELL RESELLER */

if (!is_null($MAGNUS->id_agent) && $MAGNUS->id_agent > 1) {
if ( ! is_null($MAGNUS->id_agent) && $MAGNUS->id_agent > 1) {
$agi->verbose('$MAGNUS->id_agent' . $MAGNUS->id_agent . ' ' . $MAGNUS->destination . ' - ' .
$calldestinationPortabilidade . ' - ' . $this->real_answeredtime . ' - ' . $cost, 1);

Expand Down Expand Up @@ -539,7 +537,7 @@ public function updateSystem(&$MAGNUS, &$agi, $doibill = 1, $didcall = 0, $callb
public function updateSystemAgent($agi, $MAGNUS, $calledstation, $cost, $sessiontime)
{

if (!isset($MAGNUS->modelRateAgent[0]['rateinitial'])) {
if ( ! isset($MAGNUS->modelRateAgent[0]['rateinitial'])) {
$agi->verbose('NOT FOUND AGENT TARRIF, USE AGENT COST PRICE');
$cost_customer = $cost;
} else {
Expand All @@ -565,7 +563,7 @@ public function updateSystemAgent($agi, $MAGNUS, $calledstation, $cost, $session

public function sendCall($agi, $destination, &$MAGNUS, $typecall = 0)
{
if (substr("$destination", 0, 4) == 1111) /*Retira o techprefix de numeros portados*/ {
if (substr("$destination", 0, 4) == 1111) /*Retira o techprefix de numeros portados*/{
$destination = str_replace(substr($destination, 0, 7), "", $destination);
}
$old_destination = $destination;
Expand All @@ -580,7 +578,7 @@ public function sendCall($agi, $destination, &$MAGNUS, $typecall = 0)
}
$modelTrunks = $agi->query($sql)->fetchAll(PDO::FETCH_OBJ);

if (!isset($modelTrunks[0]->id)) {
if ( ! isset($modelTrunks[0]->id)) {
$MAGNUS->hangup($agi, 34);
return;
}
Expand Down Expand Up @@ -634,7 +632,7 @@ public function sendCall($agi, $destination, &$MAGNUS, $typecall = 0)
}
}
if ($typecall == 1) {
$timeout = 3600;
$timeout = $MAGNUS->config['global']['max_call_duration'];
}

if ($modelTrunk->credit_control == 1 && $provider_credit <= 0) {
Expand Down Expand Up @@ -751,7 +749,7 @@ public function callShop($agi, $MAGNUS, $sessiontime, $id_prefix, $cost)
AND id_user= $MAGNUS->id_user ORDER BY LENGTH(dialprefix) DESC LIMIT 1";
$modelReteCallshop = $agi->query($sql)->fetch(PDO::FETCH_OBJ);

if (!isset($modelReteCallshop->id)) {
if ( ! isset($modelReteCallshop->id)) {
$agi->verbose('Not found CallShop rate => ' . $MAGNUS->destination . ' ' . $MAGNUS->id_user);
return;
}
Expand Down Expand Up @@ -799,11 +797,11 @@ public function saveCDR($agi, $MAGNUS, $returnID = false)
$CalcAgi->saveCDR($agi, $MAGNUS);
*/

if ($this->sipiax == 3 && !preg_match('/\_WT/', $MAGNUS->sip_account)) {
if ($this->sipiax == 3 && ! preg_match('/\_WT/', $MAGNUS->sip_account)) {
//if call is a DID, check is sipaccount is valid, else, set the callerid
$sql = "SELECT name FROM pkg_sip WHERE name = '" . $MAGNUS->sip_account . "' LIMIT 1";
$modelSipaccount = $agi->query($sql)->fetch(PDO::FETCH_OBJ);
if (!isset($modelSipaccount->name)) {
if ( ! isset($modelSipaccount->name)) {
$MAGNUS->sip_account = $MAGNUS->CallerID;
}
}
Expand Down
18 changes: 9 additions & 9 deletions resources/asterisk/Magnus.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ class Magnus
public $language;
public $sip_account;
public $user_calllimit = 0;
public $modelUser = array();
public $modelSip = array();
public $modelUserAgent = array();
public $modelUser = [];
public $modelSip = [];
public $modelUserAgent = [];
public $demo = false;
public $voicemail;
public $magnusFilesDirectory = '/usr/local/src/magnus/';
Expand All @@ -90,7 +90,7 @@ public function init()
}

/* load_conf */
public function load_conf(&$agi, $config = null, $webui = 0, $idconfig = 1, $optconfig = array())
public function load_conf(&$agi, $config = null, $webui = 0, $idconfig = 1, $optconfig = [])
{
$this->idconfig = 1;
$sql = "SELECT id, config_key , config_value , config_group_title FROM pkg_configuration";
Expand Down Expand Up @@ -188,7 +188,7 @@ public function hangup(&$agi, $code = '')

public static function getDialStatus_Revert_List()
{
$dialstatus_rev_list = array();
$dialstatus_rev_list = [];
$dialstatus_rev_list["ANSWER"] = 1;
$dialstatus_rev_list["BUSY"] = 2;
$dialstatus_rev_list["NOANSWER"] = 3;
Expand Down Expand Up @@ -303,7 +303,7 @@ public function checkNumber($agi, &$CalcAgi, $try_num, $call2did = false)
}
}

if (!$res_all_calcultimeout) {
if ( ! $res_all_calcultimeout) {
$this->executePlayAudio("prepaid-no-enough-credit", $agi);
return false;
}
Expand Down Expand Up @@ -477,7 +477,7 @@ public function sayRate($agi, $rate)
/* say 'the cost of the call is '*/
$agi->stream_file('prepaid-cost-call', '#');
$this->agiconfig['play_rate_cents_if_lower_one'] = 1;
if ($units == 0 && $cents == 0 && $this->agiconfig['play_rate_cents_if_lower_one'] == 0 && !($this->agiconfig['play_rate_cents_if_lower_one'] == 1 && $point == 0)) {
if ($units == 0 && $cents == 0 && $this->agiconfig['play_rate_cents_if_lower_one'] == 0 && ! ($this->agiconfig['play_rate_cents_if_lower_one'] == 1 && $point == 0)) {
$agi->say_number(0);
$agi->stream_file($unit_audio, '#');
} else {
Expand Down Expand Up @@ -738,7 +738,7 @@ public function checkRestrictPhoneNumber($agi, $type = 'outbound')
}
} else if ($this->restriction == 2) {
/* ALLOW TO CALL ONLY RESTRICTED NUMBERS */
if (!isset($modelRestrictedPhonenumber->id)) {
if ( ! isset($modelRestrictedPhonenumber->id)) {
/*NUMBER NOT AUHTORIZED*/
$agi->verbose("NUMBER NOT AUHTORIZED - ALLOW TO CALL ONLY RESTRICTED NUMBERS", 1);
if ($this->play_audio == 1) {
Expand Down Expand Up @@ -911,4 +911,4 @@ public function generatePassword($tamanho, $maiuscula, $minuscula, $numeros, $co
return $password;
}

};
}

0 comments on commit d0f4db8

Please sign in to comment.