Skip to content

Commit 776c466

Browse files
add max call duration option
1 parent 16f86e7 commit 776c466

File tree

5 files changed

+87
-49
lines changed

5 files changed

+87
-49
lines changed

build/MagnusBilling-current.tar.gz

230 Bytes
Binary file not shown.

protected/commands/UpdateMysqlCommand.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1988,6 +1988,16 @@ public function run($args)
19881988
$version = '7.8.4.4';
19891989
$this->update($version);
19901990
}
1991+
//2024-01-22
1992+
if ($version == '7.8.4.4') {
1993+
$sql = "INSERT INTO pkg_configuration VALUES
1994+
(NULL, 'Max call duration', 'max_call_duration', '3600', 'Maximum call duration in seconds', 'global', '1');
1995+
";
1996+
$this->executeDB($sql);
1997+
1998+
$version = '7.8.4.5';
1999+
$this->update($version);
2000+
}
19912001

19922002
}
19932003

protected/commands/update.sh

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,31 @@ if [[ -e /var/www/html/mbilling/protected/commands/update2.sh ]]; then
2323
exit;
2424
fi
2525

26+
27+
get_linux_distribution ()
28+
{
29+
if [ -f /etc/debian_version ]; then
30+
DIST="DEBIAN"
31+
HTTP_DIR="/etc/apache2/"
32+
HTTP_CONFIG=${HTTP_DIR}"apache2.conf"
33+
MYSQL_CONFIG="/etc/mysql/mariadb.conf.d/50-server.cnf"
34+
elif [ -f /etc/redhat-release ]; then
35+
DIST="CENTOS"
36+
HTTP_DIR="/etc/httpd/"
37+
HTTP_CONFIG=${HTTP_DIR}"conf/httpd.conf"
38+
MYSQL_CONFIG="/etc/my.cnf"
39+
else
40+
DIST="OTHER"
41+
echo 'Installation does not support your distribution'
42+
exit 1
43+
fi
44+
}
45+
46+
47+
48+
get_linux_distribution
49+
50+
2651
cd /var/www/html/mbilling
2752
rm -rf MagnusBilling-current.tar.gz
2853
wget --no-check-certificate https://raw.githubusercontent.com/magnussolution/magnusbilling7/source/build/MagnusBilling-current.tar.gz
@@ -62,7 +87,12 @@ chmod -R 700 /var/www/html/mbilling/resources/sounds
6287
chmod -R 700 /var/www/html/mbilling/resources/images
6388
chmod +x /var/www/html/mbilling/resources/asterisk/mbilling.php
6489
chmod -R 555 /var/www/html/mbilling/resources/asterisk/
65-
90+
rm -rf /var/lib/asterisk/sbin/*
91+
if [ ${DIST} = "DEBIAN" ]; then
92+
CRONPATH='/var/spool/cron/crontabs/asterisk'
93+
elif [ ${DIST} = "CENTOS" ]; then
94+
CRONPATH='/var/spool/cron/asterisk'
95+
fi
6696

6797
if [[ -e /var/www/html/mbilling/resources/images/lock-screen-background.jpg ]]; then
6898
for color in black blue gray orange purple red yellow green

resources/asterisk/CalcAgi.php

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ class CalcAgi
4040
public $sessionbill = 0;
4141
public $sipiax = 0;
4242
public $id_campaign = '';
43-
public $tariffObj = array();
44-
public $freetimetocall_left = array();
45-
public $freecall = array();
46-
public $offerToApply = array();
47-
public $didAgi = array();
43+
public $tariffObj = [];
44+
public $freetimetocall_left = [];
45+
public $freecall = [];
46+
public $offerToApply = [];
47+
public $didAgi = [];
4848
public $dialstatus_rev_list;
4949
public $id_prefix;
5050
public $id_provider;
@@ -67,7 +67,7 @@ public function init()
6767

6868
public function calculateAllTimeout(&$MAGNUS, $agi)
6969
{
70-
if (!is_array($this->tariffObj) || count($this->tariffObj) == 0) {
70+
if ( ! is_array($this->tariffObj) || count($this->tariffObj) == 0) {
7171
return false;
7272
}
7373

@@ -115,14 +115,14 @@ public function calculateTimeout(&$MAGNUS, $agi)
115115
$agi->verbose("offer Unlimited calls");
116116
$this->freecall[0] = true;
117117
$package_selected = true;
118-
$this->offerToApply[0] = array(
118+
$this->offerToApply[0] = [
119119
"id" => $id_offer,
120120
"label" => "Unlimited calls",
121121
"type" => $packagetype,
122122
"billingblock" => $modelOffer->billingblock,
123123
"initblock" => $modelOffer->initblock,
124124
"minimal_time_charge" => $modelOffer->minimal_time_charge,
125-
);
125+
];
126126
break;
127127
case 1:
128128

@@ -133,14 +133,14 @@ public function calculateTimeout(&$MAGNUS, $agi)
133133
if ($number_calls_used < $freetimetocall) {
134134
$this->freecall[0] = true;
135135
$package_selected = true;
136-
$this->offerToApply[0] = array(
136+
$this->offerToApply[0] = [
137137
"id" => $id_offer,
138138
"label" => "Number of Free calls",
139139
"type" => $packagetype,
140140
"billingblock" => $modelOffer->billingblock,
141141
"initblock" => $modelOffer->initblock,
142142
"minimal_time_charge" => $modelOffer->minimal_time_charge,
143-
);
143+
];
144144
$agi->verbose(print_r($this->offerToApply[0], true), 6);
145145
}
146146
}
@@ -156,14 +156,14 @@ public function calculateTimeout(&$MAGNUS, $agi)
156156

157157
if ($this->freetimetocall_left[0] > 0) {
158158
$package_selected = true;
159-
$this->offerToApply[0] = array(
159+
$this->offerToApply[0] = [
160160
"id" => $id_offer,
161161
"label" => "Free minutes",
162162
"type" => $packagetype,
163163
"billingblock" => $modelOffer->billingblock,
164164
"initblock" => $modelOffer->initblock,
165165
"minimal_time_charge" => $modelOffer->minimal_time_charge,
166-
);
166+
];
167167
$agi->verbose(print_r($this->offerToApply[0], true), 6);
168168
}
169169
}
@@ -174,34 +174,30 @@ public function calculateTimeout(&$MAGNUS, $agi)
174174

175175
$credit -= $connectcharge;
176176
$this->tariffObj[0]['timeout'] = 0;
177-
$this->tariffObj[0]['timeout_without_rules'] = 0;
178177
$this->tariffObj[0]['freetime_include_in_timeout'] = $this->freetimetocall_left[0];
179178
$agi->verbose("Credit $credit", 20);
180-
if ($credit < 0 && !$this->freecall[0] && $this->freetimetocall_left[0] <= 0) {
179+
if ($credit < 0 && ! $this->freecall[0] && $this->freetimetocall_left[0] <= 0) {
181180
return "ERROR CT1";
182181
/*NO CREDIT TO CALL */
183182
}
184183

185184
$TIMEOUT = 0;
186185
$answeredtime_1st_leg = 0;
187-
if ($rateinitial <= 0) /*Se o preço for 0, entao retornar o timeout em 3600 s*/ {
188-
$this->tariffObj[0]['timeout'] = 3600;
189-
$this->tariffObj[0]['timeout_without_rules'] = 3600;
190-
$TIMEOUT = 3600;
186+
if ($rateinitial <= 0) /*Se o preço for 0, entao retornar o timeout em 3600 s*/{
187+
$this->tariffObj[0]['timeout'] = $MAGNUS->config['global']['max_call_duration'];
188+
$TIMEOUT = $MAGNUS->config['global']['max_call_duration'];
191189
return $TIMEOUT;
192190
}
193191

194-
if ($this->freecall[0]) /*usado para planos gratis*/ {
195-
$this->tariffObj[0]['timeout'] = 3600;
196-
$TIMEOUT = 3600;
197-
$this->tariffObj[0]['timeout_without_rules'] = 3600;
198-
$this->tariffObj[0]['freetime_include_in_timeout'] = 3600;
192+
if ($this->freecall[0]) /*usado para planos gratis*/{
193+
$this->tariffObj[0]['timeout'] = $MAGNUS->config['global']['max_call_duration'];
194+
$TIMEOUT = $MAGNUS->config['global']['max_call_duration'];
195+
$this->tariffObj[0]['freetime_include_in_timeout'] = $MAGNUS->config['global']['max_call_duration'];
199196
return $TIMEOUT;
200197
}
201198
if ($credit < 0 && $this->freetimetocall_left[0] > 0) {
202-
$this->tariffObj[0]['timeout'] = $this->freetimetocall_left[0];
203-
$TIMEOUT = $this->freetimetocall_left[0];
204-
$this->tariffObj[0]['timeout_without_rules'] = $this->freetimetocall_left[0];
199+
$this->tariffObj[0]['timeout'] = $this->freetimetocall_left[0];
200+
$TIMEOUT = $this->freetimetocall_left[0];
205201
return $TIMEOUT;
206202
}
207203

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

217213
$num_sec = intval($num_min * 60) - $answeredtime_1st_leg; /*numero de segundos - o tempo que gastou para completar*/
214+
218215
if ($billingblock > 0) {
219216
$mod_sec = $num_sec % $billingblock;
220217
$num_sec = $num_sec - $mod_sec;
221218
}
222219
$TIMEOUT = $num_sec;
223220

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

230-
return $TIMEOUT + $this->freetimetocall_left[0];
223+
if ($TIMEOUT > $MAGNUS->config['global']['max_call_duration']) {
224+
$agi->verbose('TIMEOUT1 use max_call_duration ' . $MAGNUS->config['global']['max_call_duration'], 5);
225+
$TIMEOUT = $MAGNUS->config['global']['max_call_duration'];
226+
}
227+
$this->tariffObj[0]['timeout'] = $TIMEOUT + $this->freetimetocall_left[0];
228+
return $TIMEOUT;
231229
}
232230

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

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

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

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

566564
public function sendCall($agi, $destination, &$MAGNUS, $typecall = 0)
567565
{
568-
if (substr("$destination", 0, 4) == 1111) /*Retira o techprefix de numeros portados*/ {
566+
if (substr("$destination", 0, 4) == 1111) /*Retira o techprefix de numeros portados*/{
569567
$destination = str_replace(substr($destination, 0, 7), "", $destination);
570568
}
571569
$old_destination = $destination;
@@ -580,7 +578,7 @@ public function sendCall($agi, $destination, &$MAGNUS, $typecall = 0)
580578
}
581579
$modelTrunks = $agi->query($sql)->fetchAll(PDO::FETCH_OBJ);
582580

583-
if (!isset($modelTrunks[0]->id)) {
581+
if ( ! isset($modelTrunks[0]->id)) {
584582
$MAGNUS->hangup($agi, 34);
585583
return;
586584
}
@@ -634,7 +632,7 @@ public function sendCall($agi, $destination, &$MAGNUS, $typecall = 0)
634632
}
635633
}
636634
if ($typecall == 1) {
637-
$timeout = 3600;
635+
$timeout = $MAGNUS->config['global']['max_call_duration'];
638636
}
639637

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

754-
if (!isset($modelReteCallshop->id)) {
752+
if ( ! isset($modelReteCallshop->id)) {
755753
$agi->verbose('Not found CallShop rate => ' . $MAGNUS->destination . ' ' . $MAGNUS->id_user);
756754
return;
757755
}
@@ -799,11 +797,11 @@ public function saveCDR($agi, $MAGNUS, $returnID = false)
799797
$CalcAgi->saveCDR($agi, $MAGNUS);
800798
*/
801799

802-
if ($this->sipiax == 3 && !preg_match('/\_WT/', $MAGNUS->sip_account)) {
800+
if ($this->sipiax == 3 && ! preg_match('/\_WT/', $MAGNUS->sip_account)) {
803801
//if call is a DID, check is sipaccount is valid, else, set the callerid
804802
$sql = "SELECT name FROM pkg_sip WHERE name = '" . $MAGNUS->sip_account . "' LIMIT 1";
805803
$modelSipaccount = $agi->query($sql)->fetch(PDO::FETCH_OBJ);
806-
if (!isset($modelSipaccount->name)) {
804+
if ( ! isset($modelSipaccount->name)) {
807805
$MAGNUS->sip_account = $MAGNUS->CallerID;
808806
}
809807
}

resources/asterisk/Magnus.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ class Magnus
6767
public $language;
6868
public $sip_account;
6969
public $user_calllimit = 0;
70-
public $modelUser = array();
71-
public $modelSip = array();
72-
public $modelUserAgent = array();
70+
public $modelUser = [];
71+
public $modelSip = [];
72+
public $modelUserAgent = [];
7373
public $demo = false;
7474
public $voicemail;
7575
public $magnusFilesDirectory = '/usr/local/src/magnus/';
@@ -90,7 +90,7 @@ public function init()
9090
}
9191

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

189189
public static function getDialStatus_Revert_List()
190190
{
191-
$dialstatus_rev_list = array();
191+
$dialstatus_rev_list = [];
192192
$dialstatus_rev_list["ANSWER"] = 1;
193193
$dialstatus_rev_list["BUSY"] = 2;
194194
$dialstatus_rev_list["NOANSWER"] = 3;
@@ -303,7 +303,7 @@ public function checkNumber($agi, &$CalcAgi, $try_num, $call2did = false)
303303
}
304304
}
305305

306-
if (!$res_all_calcultimeout) {
306+
if ( ! $res_all_calcultimeout) {
307307
$this->executePlayAudio("prepaid-no-enough-credit", $agi);
308308
return false;
309309
}
@@ -477,7 +477,7 @@ public function sayRate($agi, $rate)
477477
/* say 'the cost of the call is '*/
478478
$agi->stream_file('prepaid-cost-call', '#');
479479
$this->agiconfig['play_rate_cents_if_lower_one'] = 1;
480-
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)) {
480+
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)) {
481481
$agi->say_number(0);
482482
$agi->stream_file($unit_audio, '#');
483483
} else {
@@ -738,7 +738,7 @@ public function checkRestrictPhoneNumber($agi, $type = 'outbound')
738738
}
739739
} else if ($this->restriction == 2) {
740740
/* ALLOW TO CALL ONLY RESTRICTED NUMBERS */
741-
if (!isset($modelRestrictedPhonenumber->id)) {
741+
if ( ! isset($modelRestrictedPhonenumber->id)) {
742742
/*NUMBER NOT AUHTORIZED*/
743743
$agi->verbose("NUMBER NOT AUHTORIZED - ALLOW TO CALL ONLY RESTRICTED NUMBERS", 1);
744744
if ($this->play_audio == 1) {
@@ -911,4 +911,4 @@ public function generatePassword($tamanho, $maiuscula, $minuscula, $numeros, $co
911911
return $password;
912912
}
913913

914-
};
914+
}

0 commit comments

Comments
 (0)