-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemon.php
80 lines (76 loc) · 1.91 KB
/
demon.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
<?php
/**
* Created by PhpStorm.
* User: BravovRM
* Date: 19.03.2018
* Time: 10:09
*/
$stop = false;
define('E_MAIL_ERROR','[email protected]');
define('LOG_F', dirname(__FILE__).'/log.txt');
$url = 'https://syn.su/testwork.php';
$messege = array();
function xor_bytes($data , $key){
$l = strlen($data);
$k = strlen($key);
$r = '';
for($i = 0; $i < $l; $i++){
$r .= $data[$i] ^ $key[$i % $k];
}
return $r;
}
function getMessage($url, $props){
$sendmessege = '';
if($curl = curl_init()){
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $props);
$out = curl_exec($curl);
curl_close($curl);
$out = json_decode($out, true);
}else{
$out = array(
'response' => NULL,
'errorCode' => 'arr',
'errorMessage' => 'Fail curl_init'
);
}
if ($out['response'] == NULL) {
switch ($out['errorCode']) {
case '15':
$sendmessege = 'Код 15 – Нет такого метода';
break;
case '20':
$sendmessege = 'Код 20 – Пустое значение параметра message';
break;
case '10':
$sendmessege = 'Код 10 – Не получилось расшифровать строку';
break;
case 'arr':
$sendmessege = 'Код err – curl_init';
break;
}
mail(E_MAIL_ERROR, "Ошибка с кодом ".$out['errorCode'], $sendmessege);
$stop = true;
exit(1);
}
return $out;
}
$pid = pcntl_fork();
if ($pid == -1) {
die('Error fork process' . PHP_EOL);
} elseif ($pid) {
die('Die parent process' . PHP_EOL);
} else {
while(!$stop) {
$messege = getMessage($url, 'method=get');
$key = base64_encode(xor_bytes($messege['response']['message'], $messege['response']['key']));
$messege = getMessage($url, 'method=update&message='.$key);
if($messege['response'] == "Success"){
$stop = false;
sleep(3600);
}
}
}
posix_setsid();