Skip to content

Commit f1d7545

Browse files
ensure the ID is int vall
1 parent 83e2f61 commit f1d7545

File tree

2,040 files changed

+712
-821423
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,040 files changed

+712
-821423
lines changed

protected/commands/BDServiceCommand.php

Lines changed: 38 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* =======================================
45
* ###################################
@@ -26,7 +27,7 @@ public function run($args)
2627
define('LOGFILE', 'protected/runtime/BDServicePid.log');
2728
define('DEBUG', 0);
2829

29-
if ( ! defined('PID')) {
30+
if (! defined('PID')) {
3031
define("PID", "/var/run/magnus/BDServicePid.php");
3132
}
3233

@@ -41,7 +42,6 @@ public function run($args)
4142
$this->tanaSend();
4243

4344
$this->ezzeapi();
44-
4545
}
4646

4747
public function tanaSend()
@@ -60,15 +60,17 @@ public function tanaSend()
6060

6161
foreach ($modelSendCreditSummary as $key => $sendCredit) {
6262
$url = "http://takasend.org/ezzeapi/status?id=" . $sendCredit->id . "&user=" . $userBD . "&key=" . $keyBD . "";
63-
if ( ! $result = @file_get_contents($url, false)) {
63+
if (! $result = @file_get_contents($url, false)) {
6464
$result = '';
6565
}
6666
echo $result . " $sendCredit->id \n";
67-
$modelRefill = Refill::model()->find('invoice_number = :key AND id_user = :key1',
67+
$modelRefill = Refill::model()->find(
68+
'invoice_number = :key AND id_user = :key1',
6869
[
6970
':key' => $sendCredit->id,
7071
':key1' => $sendCredit->id_user,
71-
]);
72+
]
73+
);
7274

7375
if (preg_match("/ERROR|CANCELLED/", strtoupper($result))) {
7476

@@ -84,49 +86,43 @@ public function tanaSend()
8486
try {
8587
$modelRefill->save();
8688
} catch (Exception $e) {
87-
8889
}
8990

90-
$modelUser = User::model()->findByPk($sendCredit->id_user);
91+
$modelUser = User::model()->findByPk((int) $sendCredit->id_user);
9192
$modelUser->credit = $modelUser->credit + ($modelRefill->credit * -1);
9293
try {
9394
$modelUser->save();
9495
} catch (Exception $e) {
95-
9696
}
9797

9898
if ($modelUser->id_user > 1) {
9999
echo "is agent \n";
100100
$id_agent = $modelUser->id_user;
101-
$modelRefillAgent = Refill::model()->find('invoice_number = :key AND id_user = :key1',
101+
$modelRefillAgent = Refill::model()->find(
102+
'invoice_number = :key AND id_user = :key1',
102103
[
103104
':key' => $sendCredit->id,
104105
':key1' => $id_agent,
105-
]);
106+
]
107+
);
106108

107109
if (isset($modelRefillAgent->id)) {
108110
$modelRefillAgent->description = $modelRefillAgent->description . '. Status: ' . $result[0] . '. Ref:' . $result[1];
109111
$modelRefillAgent->payment = 0;
110112
try {
111113
$modelRefillAgent->save();
112114
} catch (Exception $e) {
113-
114115
}
115116

116-
$modelUser = User::model()->findByPk($id_agent);
117+
$modelUser = User::model()->findByPk((int) $id_agent);
117118
$modelUser->credit = $modelUser->credit + ($modelRefillAgent->credit * -1);
118119
try {
119120
$modelUser->save();
120121
} catch (Exception $e) {
121-
122122
}
123-
124123
}
125-
126124
}
127-
128125
}
129-
130126
} else if (preg_match("/SUCCESS|COMPLETED|ERROR/", $result)) {
131127

132128
$result = explode(':', $result);
@@ -141,33 +137,29 @@ public function tanaSend()
141137
try {
142138
$modelRefill->save();
143139
} catch (Exception $e) {
144-
145140
}
146-
$modelUser = User::model()->findByPk($sendCredit->id_user);
141+
$modelUser = User::model()->findByPk((int) $sendCredit->id_user);
147142
if ($modelUser->id_user > 1) {
148143
echo "is agent \n";
149144
$id_agent = $modelUser->id_user;
150-
$modelRefillAgent = Refill::model()->find('invoice_number = :key AND id_user = :key1',
145+
$modelRefillAgent = Refill::model()->find(
146+
'invoice_number = :key AND id_user = :key1',
151147
[
152148
':key' => $sendCredit->id,
153149
':key1' => $id_agent,
154-
]);
150+
]
151+
);
155152

156153
$modelRefillAgent->description = @$modelRefillAgent->description . '. Status: ' . $result[0] . '. Ref:' . $result[1];
157154
$modelRefillAgent->payment = 1;
158155
try {
159156
$modelRefillAgent->save();
160157
} catch (Exception $e) {
161-
162158
}
163-
164159
}
165160
}
166-
167161
}
168-
169162
}
170-
171163
}
172164
public function ezzeapi()
173165
{
@@ -184,12 +176,15 @@ public function ezzeapi()
184176
$BDService_url = $config['global']['BDService_url'];
185177

186178
$url = $BDService_url . "/ezzeapi/balance?user=$userBD&key=$keyBD";
187-
if ( ! $result = @file_get_contents($url, false)) {
179+
if (! $result = @file_get_contents($url, false)) {
188180
$result = '';
189181
}
190182

191-
Configuration::model()->updateAll(['config_value' => $result], 'config_key = :key',
192-
[':key' => 'BDService_credit_provider']);
183+
Configuration::model()->updateAll(
184+
['config_value' => $result],
185+
'config_key = :key',
186+
[':key' => 'BDService_credit_provider']
187+
);
193188

194189
$modelSendCreditSummary = SendCreditSummary::model()->findAll('confirmed = 0 AND service != :key AND date > :key1 ', [
195190
':key' => 'international',
@@ -202,25 +197,28 @@ public function ezzeapi()
202197

203198
$url = $BDService_url . "/ezzeapi/status?id=" . $idApi . "&user=" . $userBD . "&key=" . $keyBD;
204199

205-
if ( ! $result = @file_get_contents($url, false)) {
200+
if (! $result = @file_get_contents($url, false)) {
206201
$result = '';
207202
}
208203

209204
print_r($result);
210205

211206
if (preg_match("/SUCCESS/", $result)) {
212207

213-
$modelRefill = Refill::model()->find('invoice_number = :key AND id_user = :key1',
208+
$modelRefill = Refill::model()->find(
209+
'invoice_number = :key AND id_user = :key1',
214210
[
215211
':key' => $sendCredit->id,
216212
':key1' => $sendCredit->id_user,
217-
]);
213+
]
214+
);
218215

219-
if ( ! isset($modelRefill->id)) {
216+
if (! isset($modelRefill->id)) {
220217
continue;
221218
}
222219
$message = explode("SUCCESS: ", $result);
223-
User::model()->updateByPk($sendCredit->id_user,
220+
User::model()->updateByPk(
221+
$sendCredit->id_user,
224222
[
225223
'credit' => new CDbExpression('credit + ' . $modelRefill->credit),
226224
]
@@ -237,13 +235,16 @@ public function ezzeapi()
237235

238236
echo "\n\nIS A USER AGENT" . $sendCredit->idUser->id_user;
239237

240-
$modelRefill = Refill::model()->find('invoice_number = :key AND id_user = :key1',
238+
$modelRefill = Refill::model()->find(
239+
'invoice_number = :key AND id_user = :key1',
241240
[
242241
':key' => $sendCredit->id,
243242
':key1' => $sendCredit->idUser->id_user,
244-
]);
243+
]
244+
);
245245

246-
User::model()->updateByPk($sendCredit->idUser->id_user,
246+
User::model()->updateByPk(
247+
$sendCredit->idUser->id_user,
247248
[
248249
'credit' => new CDbExpression('credit + ' . $modelRefill->credit),
249250
]
@@ -252,7 +253,6 @@ public function ezzeapi()
252253
$modelRefill->payment = 1;
253254
$modelRefill->description = $modelRefill->description . '. Ref: ' . $message[1];
254255
$modelRefill->save();
255-
256256
}
257257
} else if (preg_match("/ERROR|CANCELLED/", $result)) {
258258

@@ -266,6 +266,5 @@ public function ezzeapi()
266266
}
267267
}
268268
}
269-
270269
}
271270
}

protected/commands/DidwwwCommand.php

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* =======================================
45
* ###################################
@@ -31,7 +32,7 @@ public function run($args)
3132
foreach ($modelDid as $key => $did) {
3233

3334
$order_id = explode('=', $did->description);
34-
if ( ! isset($order_id[1])) {
35+
if (! isset($order_id[1])) {
3536
continue;
3637
}
3738

@@ -92,18 +93,26 @@ public function run($args)
9293
if ($priceDid > 0) // se tiver custo
9394
{
9495

95-
$modelUser = User::model()->findByPk($did->id_user);
96+
$modelUser = User::model()->findByPk((int) $did->id_user);
9697

9798
if ($modelUser->id_user == 1) //se for cliente do master
9899
{
99100
//adiciona a recarga e pagamento do custo de ativaçao
100101
if ($did->connection_charge > 0) {
101-
UserCreditManager::releaseUserCredit($model->id_user, $did->connection_charge,
102-
Yii::t('zii', 'Activation DID') . ' ' . $did->did, 0);
102+
UserCreditManager::releaseUserCredit(
103+
$model->id_user,
104+
$did->connection_charge,
105+
Yii::t('zii', 'Activation DID') . ' ' . $did->did,
106+
0
107+
);
103108
}
104109

105-
UserCreditManager::releaseUserCredit($did->id_user, $did->fixrate,
106-
Yii::t('zii', 'Monthly payment DID') . ' ' . $did->did, 0);
110+
UserCreditManager::releaseUserCredit(
111+
$did->id_user,
112+
$did->fixrate,
113+
Yii::t('zii', 'Monthly payment DID') . ' ' . $did->did,
114+
0
115+
);
107116

108117
$mail = new Mail(Mail::$TYPE_DID_CONFIRMATION, $did->id_user);
109118
$mail->replaceInEmail(Mail::$BALANCE_REMAINING_KEY, $modelUser->credit);
@@ -112,7 +121,7 @@ public function run($args)
112121
$mail->send();
113122
} else {
114123
//charge the agent
115-
$modelUser = User::model()->findByPk($modelUser->id_user);
124+
$modelUser = User::model()->findByPk((int) $modelUser->id_user);
116125
$modelUser->credit = $modelUser->credit - $priceDid;
117126
$modelUser->save();
118127
}
@@ -125,8 +134,6 @@ public function run($args)
125134
} else {
126135
echo "order to DID $did->did is not completd yet \n";
127136
}
128-
129137
}
130-
131138
}
132139
}

protected/commands/ImportCdrCSV_CCommand.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* =======================================
45
* ###################################
@@ -30,11 +31,7 @@ public function run($args)
3031
} else {
3132
$server_set = '';
3233
}
33-
if (isset($args[1]) && $args[1] == 'LOCAL') {
34-
$local_command = $args[1];
35-
} else {
36-
$local_command = '';
37-
}
34+
3835

3936
exec('mkdir -p /var/log/asterisk/cdr-csv/');
4037
$archive = false;
@@ -56,6 +53,15 @@ public function run($args)
5653
$con->active = true;
5754
$time = time();
5855

56+
$sql = "SHOW VARIABLES LIKE 'secure_file_priv'";
57+
$result2 = Yii::app()->db->createCommand($sql)->queryAll();
58+
59+
if (isset($result2[0]['Value']) && $result2[0]['Value'] != '' || (isset($args[1]) && $args[1] == 'LOCAL')) {
60+
$local_command = 'LOCAL';
61+
} else {
62+
$local_command = '';
63+
}
64+
5965
if (file_exists('/var/log/asterisk/cdr-csv/MBilling_Offer.csv')) {
6066
exec('mv /var/log/asterisk/cdr-csv/MBilling_Offer.csv /var/log/asterisk/cdr-csv/MBilling_Offer_' . $time . '.csv');
6167
$sql = "LOAD DATA " . $local_command . " INFILE '/var/log/asterisk/cdr-csv/MBilling_Offer_" . $time . ".csv' INTO TABLE pkg_offer_cdr FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' (id_user, id_offer, used_secondes)";
@@ -78,7 +84,6 @@ public function run($args)
7884
}
7985

8086
exec("rm -rf /var/log/asterisk/cdr-csv/MBilling_Success_CallShop_" . $time . ".csv");
81-
8287
}
8388

8489
if ($result = $this->scan_dir('/var/log/asterisk/cdr-csv/', 1)) {
@@ -88,7 +93,6 @@ public function run($args)
8893

8994
if (preg_match('/^MBilling_Success/', $file)) {
9095
$sql = "LOAD DATA " . $local_command . " INFILE '/var/log/asterisk/cdr-csv/" . $file . "' IGNORE INTO TABLE pkg_cdr FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' (uniqueid,callerid,starttime,id_user,id_plan,src,id_prefix,id_trunk,calledstation,buycost,sessionbill,sessiontime,real_sessiontime,agent_bill,sipiax,id_campaign,terminatecauseid) $server_set ";
91-
9296
} else if (preg_match('/^MBilling_Failed/', $file)) {
9397
$sql = "LOAD DATA " . $local_command . " INFILE '/var/log/asterisk/cdr-csv/" . $file . "' IGNORE INTO TABLE pkg_cdr_failed FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' (uniqueid,callerid,starttime,id_user,id_plan,src,id_prefix,id_trunk,calledstation,terminatecauseid,hangupcause) $server_set ";
9498
}
@@ -115,7 +119,6 @@ public function run($args)
115119
} else {
116120
exec("rm -rf /var/log/asterisk/cdr-csv/MBilling_Success_" . $time . ".csv");
117121
}
118-
119122
} catch (Exception $e) {
120123
print_r($e);
121124
}
@@ -134,9 +137,7 @@ public function run($args)
134137
}
135138
} catch (Exception $e) {
136139
print_r($e);
137-
138140
}
139-
140141
}
141142

142143
$con = null;
@@ -152,7 +153,7 @@ public function scan_dir($dir)
152153
if (in_array($file, $ignored)) {
153154
continue;
154155
}
155-
if ( ! preg_match('/^MBilling_/', $file)) {
156+
if (! preg_match('/^MBilling_/', $file)) {
156157
if ($file != 'Master.csv' && $file != 'error.csv') {
157158
exec('rm -rf /var/log/asterisk/cdr-csv/' . $file);
158159
}
@@ -166,5 +167,4 @@ public function scan_dir($dir)
166167

167168
return ($files) ? $files : false;
168169
}
169-
170170
}

protected/commands/UpdateMysqlCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2095,7 +2095,7 @@ public function run($args)
20952095
$sql = "ALTER TABLE pkg_firewall ADD UNIQUE KEY ipperserver (ip, id_server);";
20962096
$this->executeDB($sql);
20972097

2098-
exec("echo '\n*/2 * * * * root php /var/www/html/mbilling/cron.php failtwobanip' >> /etc/crontab");
2098+
exec("echo '\n*/2 * * * * root flock -n /tmp/importcdr.lock php /var/www/html/mbilling/cron.php failtwobanip' >> /etc/crontab");
20992099
exec("sed -i 's/ssh-iptables/sshd/g' /etc/fail2ban/jail.local");
21002100
exec("systemctl restart fail2ban");
21012101

0 commit comments

Comments
 (0)