-
Notifications
You must be signed in to change notification settings - Fork 71
/
engine.php
executable file
·231 lines (216 loc) · 6.85 KB
/
engine.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
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
<?php
////////////////////////////////////
///////////TorrentMonitor///////////
////////////////////////////////////
$dir = dirname(__FILE__).'/';
include_once $dir.'config.php';
include_once $dir.'class/System.class.php';
include_once $dir.'class/Database.class.php';
include_once $dir.'class/Errors.class.php';
include_once $dir.'class/Notification.class.php';
header('Content-Type: text/html; charset=utf-8');
function getTimestamp()
{
return '['.date_format(date_create(), 'Y-m-d H:i:s').'] ';
}
$debug = Database::getSetting('debug');
$autoUpdate = Database::getSetting('autoUpdate');
$is_console = PHP_SAPI == 'cli';
if ($is_console)
$NL = "\r\n";
else
$NL = "<br />";
$time_start_full = microtime(true);
if (Sys::checkCurl())
{
$torrentsList = Database::getTorrentsList('name');
if ($torrentsList != NULL)
$count = count($torrentsList);
else
$count = 0;
echo getTimestamp();
echo 'Опрос новых раздач на трекерах:'.$NL;
$time_start_overall = microtime(true);
for ($i=0; $i<$count; $i++)
{
$tracker = $torrentsList[$i]['tracker'];
if (Database::checkTrackersCredentialsExist($tracker))
{
$engineFile = $dir.'trackers/'.$tracker.'.engine.php';
if (file_exists($engineFile))
{
Database::clearWarnings('system');
$functionEngine = include_once $engineFile;
$class = explode('.', $tracker);
$class = $class[0];
$functionClass = str_replace('-', '', $class);
if ($tracker == 'tracker.0day.kiev.ua')
$functionClass = 'kiev';
if ($tracker == 'tv.mekc.info')
$functionClass = 'mekc';
if ($tracker == 'baibako.tv_forum')
$functionClass = 'baibako_f';
echo getTimestamp();
echo $torrentsList[$i]['name'].' на трекере '.$tracker.$NL;
if ($torrentsList[$i]['pause'])
{
echo getTimestamp();
echo 'Наблюдение за данной темой приостановлено.'.$NL;
continue;
}
if ($torrentsList[$i]['type'] == 'RSS')
{
$time_start = microtime(true);
call_user_func($functionClass.'::main', $torrentsList[$i]);
$time_end = microtime(true);
$time = $time_end - $time_start;
if ($debug)
{
echo getTimestamp();
echo 'Время выполнения: '.$time.$NL;
}
}
if ($torrentsList[$i]['type'] == 'forum')
{
$time_start = microtime(true);
call_user_func($functionClass.'::main', $torrentsList[$i]);
$time_end = microtime(true);
$time = $time_end - $time_start;
if ($debug)
{
echo getTimestamp();
echo 'Время выполнения: '.$time.$NL;
}
}
$functionClass = NULL;
$functionEngine = NULL;
}
else
Errors::setWarnings('system', 'missing_files');
}
else
Errors::setWarnings('system', 'credential_miss');
}
$time_end_overall = microtime(true);
$time = $time_end_overall - $time_start_overall;
if ($debug)
{
echo getTimestamp();
echo 'Общее время опроса трекеров: '.$time.$NL;
}
echo getTimestamp();
echo 'Опрос новых раздач пользователей на трекерах:'.$NL;
$time_start_overall = microtime(true);
$usersList = Database::getUserToWatch();
if ( ! empty($usersList))
{
$count = count($usersList);
for ($i=0; $i<$count; $i++)
{
$tracker = $usersList[$i]['tracker'];
if (Database::checkTrackersCredentialsExist($tracker))
{
$serchFile = $dir.'trackers/'.$tracker.'.search.php';
if (file_exists($serchFile))
{
Database::clearWarnings('system');
$functionEngine = include_once $serchFile;
$class = explode('.', $tracker);
$class = $class[0];
$class = str_replace('-', '', $class);
$functionClass = $class.'Search';
echo getTimestamp();
echo 'Пользователь '.$usersList[$i]['name'].' на трекере '.$tracker.$NL;
$time_start = microtime(true);
call_user_func($functionClass .'::mainSearch', $usersList[$i]);
$time_end = microtime(true);
$time = $time_end - $time_start;
if ($debug)
{
echo getTimestamp();
echo 'Время выполнения: '.$time.$NL;
}
$functionClass = NULL;
$functionEngine = NULL;
}
else
Errors::setWarnings('system', 'missing_files');
}
else
Errors::setWarnings('system', 'credential_miss');
}
}
$time_end_overall = microtime(true);
$time = $time_end_overall - $time_start_overall;
if ($debug)
{
echo getTimestamp();
echo 'Общее время опроса пользователей на трекерах: '.$time.$NL;
}
echo getTimestamp();
echo '=================='.$NL;
echo getTimestamp();
echo 'Выполение служебных функций:'.$NL;
echo getTimestamp();
echo 'Добавляем темы из Temp.'.$NL;
$time_start = microtime(true);
$tempList = Database::getAllFromTemp();
if ( ! empty($tempList))
{
if (count($tempList) > 0)
Sys::AddFromTemp($tempList);
}
$time_end = microtime(true);
$time = $time_end - $time_start;
if ($debug)
{
echo getTimestamp();
echo 'Время выполнения: '.$time.$NL;
}
echo getTimestamp();
echo 'Обновление новостей.'.$NL;
$time_start = microtime(true);
Sys::getNews();
$time_end = microtime(true);
$time = $time_end - $time_start;
if ($debug)
{
echo getTimestamp();
echo 'Время выполнения: '.$time.$NL;
}
echo getTimestamp();
echo 'Удаление старых torrent-файлов.'.$NL;
Sys::deleteOldTorrents();
if ($autoUpdate)
{
echo getTimestamp();
echo 'Установка обновлений.'.$NL;
include_once $dir.'class/Update.class.php';
Update::main();
}
else
{
if (Sys::checkUpdate())
{
if ( ! Database::getUpdateNotification())
{
$msg = 'Выпущена новая версия ТМ, автоматическое обновление отключено, обновите систему самостоятельно.';
Notification::sendNotification('news', date('r'), 0, $msg, 0);
Database::setUpdateNotification(1);
}
}
}
echo getTimestamp();
echo 'Запись времени последнего запуска ТМ.'.$NL;
Sys::lastStart();
}
else
Errors::setWarnings('system', 'curl');
$time_end_full = microtime(true);
$time = $time_end_full - $time_start_full;
if ($debug)
{
echo getTimestamp();
echo 'Общее время работы скрипта: '.$time.$NL;
}
?>