Skip to content

Commit f63e554

Browse files
committed
Ref no. PR-2021270901 hotfix
1 parent b19c08e commit f63e554

File tree

3 files changed

+33
-13
lines changed

3 files changed

+33
-13
lines changed

app/Http/Controllers/CronMail/MainController.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ public function getMailTags()
3737

3838
public function addCronMail()
3939
{
40+
if (!filter_var( request()->to, FILTER_VALIDATE_EMAIL )) {
41+
return respond("Geçerli bir mail adresi giriniz.", 201);
42+
}
4043
$obj = new CronMail(request()->all());
4144
$obj->last = Carbon::now()->subDecade();
4245
if ($obj->save()) {

app/Http/Controllers/HomeController.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,18 @@ public function setLocale()
119119
private function calculateNetworkBytes($download = true)
120120
{
121121
$text = $download ? 'rx_bytes' : 'tx_bytes';
122-
$count = 0;
123-
$raw = trim(shell_exec("cat /sys/class/net/*/statistics/$text"));
124-
125-
foreach (explode("\n", trim($raw)) as $data) {
126-
$count += intval($data);
122+
if ($text == "rx_bytes" || $text == "tx_bytes")
123+
{
124+
$count = 0;
125+
$raw = trim(shell_exec("cat /sys/class/net/*/statistics/$text"));
126+
127+
foreach (explode("\n", trim($raw)) as $data) {
128+
$count += intval($data);
129+
}
130+
return $count;
131+
} else {
132+
return "Invalid data";
127133
}
128-
return $count;
129134
}
130135

131136

app/Jobs/CronEmailJob.php

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ public function __construct(CronMail $mailObj)
4545
*/
4646
public function handle()
4747
{
48+
// If not a valid e-mail address, do not run handler
49+
if (!filter_var( $this->obj->to, FILTER_VALIDATE_EMAIL )) {
50+
return;
51+
}
4852
if (!$this->doubleCheckTime()) {
4953
return;
5054
}
@@ -74,8 +78,11 @@ public function handle()
7478

7579
$encoded = base64_encode($this->obj->extension_id . "-" . $this->obj->server_id . "-" . $this->obj->target);
7680
$time = "awk -F'[]]|[[]' '$0 ~ /^\[/ && $2 >= \"$before\" { p=1 } $0 ~ /^\[/ && $2 >= \"$now\" { p=0 } p { print $0 }' /liman/logs/extension.log";
77-
$command = "$time | grep '" . $encoded . "' | grep '" . $this->obj->user_id . "' | wc -l";
78-
$count = trim(shell_exec($command));
81+
$command = Command::runLiman("{:time} | grep @{:encoded} | grep @{:user_id} | wc -l", [
82+
"time" => $time,
83+
"encoded" => $encoded,
84+
"user_id" => $this->user->id
85+
]);
7986
$subject = $this->user->name . " kullanıcısının " . __($this->obj->cron_type) . " Liman MYS Raporu";
8087
$view = view('email.cron_mail', [
8188
"user" => $this->user,
@@ -87,14 +94,19 @@ public function handle()
8794
"extension" => $this->extension,
8895
"target" => $this->getTagText($this->obj->target, $this->extension->name),
8996
"from" => trim(env("APP_NOTIFICATION_EMAIL")),
90-
"to" => $this->obj->to
97+
"to" => trim($this->obj->to)
9198
])->render();
9299
$file = "/tmp/" . str_random(16);
93100
file_put_contents($file, $view);
94-
$command = "curl -s -v --connect-timeout 15 \"smtp://" . trim(env("MAIL_HOST")) . ":" . trim(env("MAIL_PORT")) . "\" -u \"" .
95-
trim(env("MAIL_USERNAME")) . ":" . trim(env("MAIL_PASSWORD")) . "\" --mail-from \"" . trim(env("APP_NOTIFICATION_EMAIL")) . "\" --mail-rcpt \"" .
96-
$this->obj->to . "\" -T " . $file . " 2>&1";
97-
$output = shell_exec($command);
101+
$output = Command::runLiman("curl -s -v --connect-timeout 15 \"smtp://{:mail_host}:{:mail_port}\" -u \"{:mail_username}:{:mail_password}\" --mail-from \"{:mail_from}\" --mail-rcpt \"{:mail_receipt}\" -T {:file} 2>&1", [
102+
"mail_host" => trim(env("MAIL_HOST")),
103+
"mail_port" => trim(env("MAIL_PORT")),
104+
"mail_username" => trim(env("MAIL_USERNAME")),
105+
"mail_password" => trim(env("MAIL_PASSWORD")),
106+
"mail_from" => trim(env("APP_NOTIFICATION_EMAIL")),
107+
"mail_receipt" => trim($this->obj->to),
108+
"file" => $file
109+
]);
98110
if (env("MAIL_DEBUG")) {
99111
echo "---BEGIN---\n$command\n$output\n---END---\n";
100112
}

0 commit comments

Comments
 (0)