usr bin php php set_time_limit class spaces public sid public count pu

 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/php
<?php
set_time_limit(0);
class spaces {
public $sid;
public $count;
public function __construct($sid) {
$this->sid = $sid;
$this->count = array(
"mail" => 0,
"journal" => 0,
"feed" => 0
);
}
public function alert($text) {
exec("notify-send -i /home/efog/Dev/info3.png Spaces '$text'");
}
public function check() {
$ch = curl_init("http://spaces.ru/mysite/?sid=" . $this->sid);
curl_setopt_array($ch, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_USERAGENT => "Mozilla 5.49 (Vodila 228 Edition)",
CURLOPT_REFERER => "http://spaces.ru",
CURLOPT_TIMEOUT => 3,
CURLOPT_COOKIE => "sid=" . $this->sid
));
$e = curl_exec($ch);
if (preg_match("@<p>The document has moved@si", $e)) exit("Не удалось войти на аккаунт. Проверьте SID.\r\n");
file_put_contents("page.html", $e);
preg_match("@mailn.png\" alt=\"Почта\" \/>(.+?)<\/a@sui", $e, $mail_new);
preg_match("@journaln.png\" alt=\"Жур\" \/>(.+?)<\/a@sui", $e, $journal_new);
preg_match("@lenta2n.png\" alt=\"Лента\" \/>(.+?)<\/a@sui", $e, $feed_new);
$mail_new = trim(end($mail_new));
$journal_new = trim(end($journal_new));
$feed_new = trim(end($feed_new));
$new = array(
"mail" => 0,
"journal" => 0,
"feed" => 0
);
if (preg_match("@([0-9]+)@si", $mail_new)) {
preg_match("@([0-9]+)@si", $mail_new, $a);
$count = end($a);
if ($this->count["mail"] != $count) {
$new["mail"] = $count;
$this->count["mail"] = $count;
}
}
if (preg_match("@([0-9]+)@si", $journal_new)) {
preg_match("@([0-9]+)@si", $journal_new, $a);
$count = end($a);
if ($this->count["journal"] != $count) {
$new["journal"] = $count;
$this->count["journal"] = $count;
}
}
if (preg_match("@([0-9]+)@si", $feed_new)) {
preg_match("@([0-9]+)@si", $feed_new, $a);
$count = end($a);
if ($this->count["feed"] != $count) {
$new["feed"] = $count;
$this->count["feed"] = $count;
}
}
$text = "У вас есть новые события на Spaces в ";
$textto = "";
if ($new["mail"] > 0) $textto .= "почте";
if ($new["journal"] > 0) {
if ($new["mail"] > 0) $textto .= ", журнале";
else $textto .= "журнале";
}
if ($new["feed"] > 0) {
if ($new["mail"] > 0 || $new["journal"] > 0) $textto .= ", ленте";
else $textto .= "ленте";
}
$text .= $textto . ".";
if (!empty($textto)) $this->alert($text);
}
}
if (empty($argv[1])) exit("Укажите SID первым параметром.\r\n");
$spaces = new spaces($argv[1]);
while (true) {
$spaces->check();
sleep(5);
}
?>