Skip to content

Commit

Permalink
Ref no. PR-2021270901 hotfix
Browse files Browse the repository at this point in the history
  • Loading branch information
dogukanoksuz committed Sep 27, 2021
1 parent b19c08e commit f63e554
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 deletions.
3 changes: 3 additions & 0 deletions app/Http/Controllers/CronMail/MainController.php
Expand Up @@ -37,6 +37,9 @@ public function getMailTags()

public function addCronMail()
{
if (!filter_var( request()->to, FILTER_VALIDATE_EMAIL )) {
return respond("Geçerli bir mail adresi giriniz.", 201);
}
$obj = new CronMail(request()->all());
$obj->last = Carbon::now()->subDecade();
if ($obj->save()) {
Expand Down
17 changes: 11 additions & 6 deletions app/Http/Controllers/HomeController.php
Expand Up @@ -119,13 +119,18 @@ public function setLocale()
private function calculateNetworkBytes($download = true)
{
$text = $download ? 'rx_bytes' : 'tx_bytes';
$count = 0;
$raw = trim(shell_exec("cat /sys/class/net/*/statistics/$text"));

foreach (explode("\n", trim($raw)) as $data) {
$count += intval($data);
if ($text == "rx_bytes" || $text == "tx_bytes")
{
$count = 0;
$raw = trim(shell_exec("cat /sys/class/net/*/statistics/$text"));

foreach (explode("\n", trim($raw)) as $data) {
$count += intval($data);
}
return $count;
} else {
return "Invalid data";
}
return $count;
}


Expand Down
26 changes: 19 additions & 7 deletions app/Jobs/CronEmailJob.php
Expand Up @@ -45,6 +45,10 @@ public function __construct(CronMail $mailObj)
*/
public function handle()
{
// If not a valid e-mail address, do not run handler
if (!filter_var( $this->obj->to, FILTER_VALIDATE_EMAIL )) {
return;
}
if (!$this->doubleCheckTime()) {
return;
}
Expand Down Expand Up @@ -74,8 +78,11 @@ public function handle()

$encoded = base64_encode($this->obj->extension_id . "-" . $this->obj->server_id . "-" . $this->obj->target);
$time = "awk -F'[]]|[[]' '$0 ~ /^\[/ && $2 >= \"$before\" { p=1 } $0 ~ /^\[/ && $2 >= \"$now\" { p=0 } p { print $0 }' /liman/logs/extension.log";
$command = "$time | grep '" . $encoded . "' | grep '" . $this->obj->user_id . "' | wc -l";
$count = trim(shell_exec($command));
$command = Command::runLiman("{:time} | grep @{:encoded} | grep @{:user_id} | wc -l", [
"time" => $time,
"encoded" => $encoded,
"user_id" => $this->user->id
]);
$subject = $this->user->name . " kullanıcısının " . __($this->obj->cron_type) . " Liman MYS Raporu";
$view = view('email.cron_mail', [
"user" => $this->user,
Expand All @@ -87,14 +94,19 @@ public function handle()
"extension" => $this->extension,
"target" => $this->getTagText($this->obj->target, $this->extension->name),
"from" => trim(env("APP_NOTIFICATION_EMAIL")),
"to" => $this->obj->to
"to" => trim($this->obj->to)
])->render();
$file = "/tmp/" . str_random(16);
file_put_contents($file, $view);
$command = "curl -s -v --connect-timeout 15 \"smtp://" . trim(env("MAIL_HOST")) . ":" . trim(env("MAIL_PORT")) . "\" -u \"" .
trim(env("MAIL_USERNAME")) . ":" . trim(env("MAIL_PASSWORD")) . "\" --mail-from \"" . trim(env("APP_NOTIFICATION_EMAIL")) . "\" --mail-rcpt \"" .
$this->obj->to . "\" -T " . $file . " 2>&1";
$output = shell_exec($command);
$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", [
"mail_host" => trim(env("MAIL_HOST")),
"mail_port" => trim(env("MAIL_PORT")),
"mail_username" => trim(env("MAIL_USERNAME")),
"mail_password" => trim(env("MAIL_PASSWORD")),
"mail_from" => trim(env("APP_NOTIFICATION_EMAIL")),
"mail_receipt" => trim($this->obj->to),
"file" => $file
]);
if (env("MAIL_DEBUG")) {
echo "---BEGIN---\n$command\n$output\n---END---\n";
}
Expand Down

0 comments on commit f63e554

Please sign in to comment.