-
Notifications
You must be signed in to change notification settings - Fork 1
/
functions.php
433 lines (400 loc) · 10.3 KB
/
functions.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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
<?php
function func_rar($path1, $file2, $unrar='')
{
if (!function_exists("rar_open"))
{
if ($unrar['key']==false)
{
echo 'You have not selected the variable $unrar=$arc[type_archive] in setup.php';
echo "\n";
$error6=1;
}
if ($unrar['path']==false)
{
echo 'You have not selected the variable $unrar[path] in setup.php';
echo "\n";
$error6=1;
}
//echo $unrar['path'].' '.$unrar['key'].' '.$path1.'/'.$file2.' '.$unrar['out_dir'].$path1.'/'; echo "\n\n";
exec($unrar['path'].' '.$unrar['key'].' '.$path1.'/'.$file2.' '.$unrar['out_dir'].$path1.'/', $out, $val);
//print_r($out);
if (!isset($out[1]))
{
echo "There no installed php functions php-rar or bash function unrar. Install one of this functions\n";
}
if ($out[$unrar['id_ok']]==$unrar['value_ok'] && $error6==false) return 0;
else return 1;
}
else
{
//echo "rar_php\n";
$rar_file = @rar_open($path1.'/'.$file2);
if ($rar_file==false)
{
return false;
}
else
{
$entries = rar_list($rar_file);
foreach ($entries as $entry) $entry->extract($path1);
rar_close($rar_file);
return 0;
}
}
}
if(!function_exists("file_put_contents"))
{
/**
* file_put_contents PHP4 replace
*
* @param string $file
* @param string $data
* @return boolean
*/
function file_put_contents($file,$data)
{
$fp = fopen($file,"w");
if(!$fp)
{
return false;
}
fwrite($fp,$data);
fclose($fp);
return true;
}
}
if(!function_exists("file_get_contents"))
{
/**
* file_put_contents PHP4 replace
*
* @param string $file
* @return mixed
*/
function file_get_contents($file)
{
$fp = fopen($file,"r");
if(!$fp) return false;
$result = "";
while (!feof($fp)) $result .= fread($fp,1024);
fclose($fp);
return $result;
}
}
/**
* parses update.ver
*
* @param string $db
* @return array
*/
function parseDB($db)
{
$result = array();
$last_section = "";
$lines = explode("\n",$db);
foreach ($lines as $line)
{
$line = trim($line);
if(!empty($line))
{
if(@$line[0] == "[" and $line[strlen($line)-1]=="]")
{
$last_section = strtoupper(trim($line,"[]"));
$result[$last_section] = array();
}
else
{
$a10=@strpos($line, "=");
$var=@substr($line, 0, $a10 );
//@list($var,$val) = explode("=",$line);
$val1=@substr($line, $a10+1);
preg_match('/^(["\']?)(.*[^"\'])(["\']?)/', $val1, $val);
$result[$last_section][$var] = $val[2];
}
}
}
return $result;
}
/**
* Creates update.ver from array
*
* @param unknown_type $arr
* @return unknown
*/
function createDB($arr)
{
$return = "";
foreach ($arr as $section=>$params)
{
$return .= "[{$section}]\n";
foreach ($params as $key=>$value) $return .= "{$key}={$value}\n";
$return .="\n";
}
return $return;
}
/**
* Small function to help parse HTTP Headers
*
* @param unknown_type $array
* @return unknown
*/
function parseHeader($array){
$result = array();
foreach ($array as $value)
{
if(substr_count($value,":"))
{
$data = explode(":",$value);
$result[trim($data[0])] = trim($data[1]);
}
}
return $result;
}
/**
* Downloads file from given host
*
* @param string $host HTTP Host
* @param string $file File on host to download
* @param string $save If not empty - save to file
* @param string $user HTTP Auth User
* @param string $password HTTP Auth Password
* @return mixed
*/
function getHTTPFilec($host,$file,$save="",$user="",$password="", $proxy="", $quiet)
{
//echo "host=$host\n";
$host = trim(str_replace("http://","",$host),"/");
//echo "host2=$host\n";
$file_name=basename($file);
$user_password = ($user)?"$user".(($password)?":{$password}":"")."@":"";
$open_url = "http://{$user_password}{$host}/{$file}";
//echo "$open_url\n";
$ch = curl_init($open_url); // create cURL handle (ch)
if (!$ch) die("Couldn't initialize a cURL handle");
$fp = fopen ($save, "w");
$ret = curl_setopt ($ch, CURLOPT_FILE, $fp);
// Пример взят с http://ca.php.net/manual/en/function.curl-setopt.php#91952
// This is required to curl give us some progress
// if this is not set to false the progress function never
// gets called
$ret = curl_setopt($ch, CURLOPT_NOPROGRESS, $quiet);
// Set up the callback Работает только с версии php 5.3
//$ret = curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, 'callback');
// Big buffer less progress info/callbacks
// Small buffer more progress info/callbacks
$ret = curl_setopt($ch, CURLOPT_BUFFERSIZE, 512);
$ret = curl_setopt($ch, CURLOPT_HEADER, 0);
$ret = curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$ret = curl_setopt($ch, CURLOPT_VERBOSE, 0);
//$ret = curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$ret = curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 0);
$ret = curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
if ($proxy==true)
{
$ret = curl_setopt($ch, CURLOPT_PROXY, $proxy['host']);
$ret = curl_setopt($ch, CURLOPT_PROXYPORT, $proxy['port']);
$ret = curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxy['user'].':'.$proxy['passwd']);
}
//$ret = curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_exec ($ch);
// Chek proxy BEGIN
fclose($fp);
if ($quiet==false) echo "Download $file_name ....";
if (empty($ret))
{
// some kind of an error happened
echo curl_error($ch)."\n";
curl_close($ch); // close cURL handler
}
else
{
$info = curl_getinfo($ch);
//print_r($info);
curl_close($ch); // close cURL handler
if ($info['http_code'] == 200)
{
if ($quiet==false){ echo "OK.\n";}
return true;
}
elseif ($info['http_code'] == 407)
{
if ($quiet==false) echo "Error Proxy Authentication!\n";
return false;
}
elseif ($info['http_code'] == 0)
{
if ($quiet==false) echo "Bad Proxy name or port!\n";
return false;
}
else
{
if ($quiet==false) echo "Can't connect to NOD32 server!\n";
return false;
}
}
}
//function callback ($a=0,$b=0,$c=0, $d=0)
//($download_size, $downloaded, $upload_size, $uploaded)
//{
// echo "$a\n $b\n $c\n $d\n";
// do your progress stuff here
//echo "download_size=$download_size\n";
//echo "downloaded=$downloaded\n";
// return (0);
//}
function version1($db)
{
if (isset($db['ENGINE2'])) $ver=$db['ENGINE2']['version'];
elseif (isset($db['ENGINE1'])) $ver=$db['ENGINE1']['version'];
else $ver=$db['ENGINE0']['version'];
return $ver;
}
function new_section1($db, $file, $path3)
{
if (isset($db['display_name'])) $db['display_name']=trim($db['display_name'], '"');
$db['size']=filesize($path3.$file);
$db['file']=$file;
unset($db['filesize'], $db['crc'], $db['name'], $db['setup'] );
//print_r($db);
return $db;
}
//Функция замены scandir для php4 (спасибо Yuryus)
if (!function_exists('scandir'))
{
function scandir($path)
{
$files11 = opendir($path);
while (false !== ($filename = readdir($files11))) $files1[] = $filename;
return $files1;
}
}
// Удаление nup файлов из дирестории $path
function rmfiles($path)
{
// Список файлов
$files1 = scandir($path);
// Проверяем каждый файл
foreach ($files1 as $file)
{
$file_nup=explode('.', $file);
if (isset($file_nup[1])==true)
{
if ($file_nup[1]=="nup")
{
unlink($path.$file);
}
}
}
}
function copyfiles($paths, $pathd, $dop_path="")
{
// Список файлов
$files1 = scandir($paths);
// Проверяем каждый файл
foreach ($files1 as $file)
{
$file2=explode('.', $file);
if (isset($file2[1])==true)
{
if ($file2[1]=="nup" || $file2[1]=="ver")
{
copy($paths.$file, $pathd.$file);
}
}
}
if($dop_path==true) copy($paths.$dop_path.'/update.ver', $pathd.$dop_path.'/update.ver');
}
// Функция по разделению параметров прокси сервера
function proxy_par($proxy)
{
preg_match('/http:\/\/(.[^\s:@]+):(.[^:@]+)@([a-z.0-9\-_]+):([0-9]+)/is', $proxy, $p);
if ($p[0])
{
$proxy1['user']=$p[1];
$proxy1['passwd']=$p[2];
$proxy1['host']=$p[3];
$proxy1['port']=$p[4];
}else
{
preg_match('/http:\/\/(.[^\s:@]+)@([a-z.0-9\-_]+):([0-9]+)/is', $proxy, $p);
if ($p[0])
{
$proxy1['user']=$p[1];
$proxy1['host']=$p[2];
$proxy1['port']=$p[3];
}else
{
preg_match('/http:\/\/([a-z.0-9\-_]+):([0-9]+)/is', $proxy, $p);
if ($p[0])
{
$proxy1['host']=$p[1];
$proxy1['port']=$p[2];
}
}
}
return $proxy1;
}
function url_servers($URL)
{
$result = array();
$last_section = "";
$lines = explode(",",$URL);
$n=0;
foreach ($lines as $line)
{
preg_match('/([^\s:@]*)http:\/\/([a-z.0-9\-_\/]+)/is', $line, $p);
$result[$n]='http://'.$p[2];
$n++;
}
//print_r($result);
//unset($result[0], $result[1]);
return $result;
}
function url_ser($url, $path2='')
{
$url = trim($url);
if(!empty($url))
{
$num_str=strpos($url, $path2);
if ($num_str==true) $url1=substr($url, 0, $num_str);
else$url1=$url;
$result="http://".$url1;
}
return $result;
}
// Функция по закачке файла через wget + прокси
function func_wget($url, $file, $proxy_wget="", $quiet="")
{
global $wget;
If ($quiet==true)$quiet_wget='-q';
else echo "\n";
if ($proxy_wget ==true)
{
$proxy_parametr=' --proxy=on --proxy-user='.$proxy_wget['user'].' --proxy-password='.
$proxy_wget['passwd'];
$export_proxy='export http_proxy=http://'.$proxy_wget['host'].':'.$proxy_wget['port']."\n";
}
//echo $export_proxy.' '.$wget.' '.$quiet_wget.' '.$url.' -O '.$file.' '.$proxy_parametr."\n";
@exec($export_proxy.' '.$wget.' '.$quiet_wget.' '.$url.' -O '.$file.' '.$proxy_parametr, $out, $val);
if ($val==1) return false;
else return true;
}
function getHTTPFile1($host,$file,$save="",$user="",$password="",$proxy_wget="", $quiet="")
{
$host = trim(str_replace("http://","",$host),"/");
if($user==true) $user_password = $user.':'.$password.'@';
$open_url = "http://{$user_password}{$host}/{$file}";
$fp = func_wget($open_url, $save, $proxy_wget, $quiet);
return $fp;
}
function mkdir_new($savepath,$path)
{
$qq=explode ('/', $path);
foreach ($qq as $a)
{
$savepath .='/'.$a;
mkdir($savepath);
}
return;
}
?>