commit | author | age
|
8bd4d9
|
1 |
<?php |
JK |
2 |
// Skrypt aktualizujący dane pobierane okresowo. |
|
3 |
|
|
4 |
define('MAINSTAR', ' '."\033".'[1;37m*'.' '); |
|
5 |
define('NORMAL', "\033".'[0m'); |
|
6 |
define('STAR', ' '."\033".'[1;34m*'."\033".'[0m '); |
|
7 |
define('OK', "\033[55G\033[32m".'[ OK ]'."\033[0m\n"); |
|
8 |
define('NOT', "\033[55G\033[33m".'[ OK ]'."\033[0m\n"); |
|
9 |
define('FAIL', "\033[55G\033[31m".'[ FAIL ]'."\033[0m\n"); |
|
10 |
|
|
11 |
echo "\033".'[1;37;44m Bot GG - Skrypt aktualizujący ('.date('d.m.Y H:i:s').')'."\033".'[K'."\033".'[0m'."\n\n"; |
|
12 |
|
|
13 |
function crontab_field($field, $number) { |
|
14 |
$field = explode(',', $field); |
|
15 |
foreach($field as $one) { |
|
16 |
$mod = FALSE; |
|
17 |
$range_start = 0; |
|
18 |
$range_stop = 0; |
|
19 |
|
|
20 |
if(($pos=strpos($one, '/'))!==FALSE) { |
|
21 |
$mod = (int)substr($one, $pos+1); |
|
22 |
if($mod==0) { |
|
23 |
continue; |
|
24 |
} |
|
25 |
$one = substr($one, 0, $pos); |
|
26 |
} |
|
27 |
|
|
28 |
if($one != '*') { |
|
29 |
if(($pos=strpos($one, '-'))!==FALSE) { |
|
30 |
$range_start = (int)substr($one, 0, $pos); |
|
31 |
$range_stop = (int)substr($one, $pos+1); |
|
32 |
} |
|
33 |
else |
|
34 |
{ |
|
35 |
$range_start = $one; |
|
36 |
$range_stop = $one; |
|
37 |
} |
|
38 |
|
|
39 |
if($range_start > $number OR $range_stop < $number) { |
|
40 |
continue; |
|
41 |
} |
|
42 |
} |
|
43 |
|
|
44 |
if($mod && ($number-$range_start)%$mod != 0) { |
|
45 |
continue; |
|
46 |
} |
|
47 |
|
|
48 |
return TRUE; |
|
49 |
} |
|
50 |
|
|
51 |
return FALSE; |
|
52 |
} |
|
53 |
|
|
54 |
function crontab_match($line) { |
|
55 |
$parts = preg_split('/[\40\t]+/', $line, 6); |
|
56 |
|
|
57 |
return $parts[5]; |
|
58 |
} |
|
59 |
|
|
60 |
$included = array(); |
|
61 |
|
|
62 |
function launch($file) { |
|
63 |
global $included; |
|
64 |
if(!in_array($file, $included)) { |
|
65 |
$included[] = $file; |
|
66 |
return include($file); |
|
67 |
} |
|
68 |
} |
|
69 |
|
|
70 |
function crontab_parse($dir) { |
|
71 |
chdir($dir); |
|
72 |
|
|
73 |
$done = FALSE; |
|
74 |
|
|
75 |
$file = file('crontab'); |
|
76 |
foreach($file as $line) { |
|
77 |
$line = trim($line); |
|
78 |
if(empty($line) || substr($line, 0, 1)=='#') continue; |
|
79 |
|
|
80 |
$ret = crontab_match($line); |
|
81 |
if($ret) { |
|
82 |
if(!$done) |
|
83 |
echo "\n"; |
|
84 |
launch($ret); |
|
85 |
$done = TRUE; |
|
86 |
} |
|
87 |
} |
|
88 |
|
|
89 |
if(!$done) { |
|
90 |
echo NOT; |
|
91 |
} |
|
92 |
|
|
93 |
chdir('..'); |
|
94 |
} |
|
95 |
|
|
96 |
chdir(dirname(__FILE__)); |
|
97 |
|
|
98 |
$dir = './'.$_SERVER['argv'][1]; |
|
99 |
|
|
100 |
if(file_exists($dir.'/crontab')) { |
|
101 |
echo MAINSTAR.'Moduł '.basename($dir).NORMAL; |
|
102 |
crontab_parse($dir); |
|
103 |
} |
|
104 |
|
|
105 |
echo "\n"; |
|
106 |
?> |