-
Notifications
You must be signed in to change notification settings - Fork 7
/
cron.php
49 lines (44 loc) · 2.01 KB
/
cron.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
/*
Запускаем по крону каждое воскресенье для рассылки статистики по трафику на зашитые в коде адреса
*/
if (php_sapi_name() != "cli") {
echo 'not run from web!';
exit;
}
require("init.php");
require("PHPMailer/PHPMailerAutoload.php");
//Эта неделя
$week_result = $db->arrayQuery("SELECT sum(tx) as sumtx, sum(rx) as sumrx FROM traffic WHERE device_id='1' AND datetime>='".strtotime(date('Y').'W'.date('W').'1')."' AND datetime<'".strtotime(date('Y').'W'.date('W').'7')."'", SQLITE_ASSOC);
$msg = 'Эта неделя: ';
$msg .= 'TX '.round(($week_result[0][sumtx]/1024/1024),2).' ';
$msg .= 'RX '.round(($week_result[0][sumrx]/1024/1024),2).' ';
$msg .= 'Total '.round((($week_result[0][sumtx]+$week_result[0][sumrx])/1024/1024),2).'Mb<br>';
//Этот месяц
$month_result = $db->arrayQuery("SELECT sum(tx) as sumtx, sum(rx) as sumrx FROM traffic WHERE device_id='1' AND datetime>='".strtotime(date('Y-m-1'))."' AND datetime<'".strtotime(date('Y-m-t'))."'", SQLITE_ASSOC);
$msg .= 'Этот месяц: ';
$msg .= 'TX '.round(($month_result[0][sumtx]/1024/1024),2).' ';
$msg .= 'RX '.round(($month_result[0][sumrx]/1024/1024),2).' ';
$msg .= 'Total '.round((($month_result[0][sumtx]+$month_result[0][sumrx])/1024/1024),2).'Mb<br>';
$msg .= '<a href="http://example.com/tikstat/?id=1">Детальная статистика</a>';
//Create a new PHPMailer instance
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPSecure = "tls";
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->Username = '';
$mail->Password = '';
$mail->CharSet = "UTF-8";
$mail->setFrom('', 'статистика');
$mail->addAddress('', '');
$mail->Subject = 'Статистика ('.date("d-m-Y").')';
$mail->isHTML(true);
$mail->Body = $msg;
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error:<br>" . $mail->ErrorInfo ."";
} else {
echo "Message sent!";
}