83 lines
2.6 KiB
PHP
83 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace app\process;
|
|
|
|
use app\common\model\User;
|
|
use app\common\model\UserRoles;
|
|
use app\common\utils\WsEvents;
|
|
use support\Redis;
|
|
use Workerman\Crontab\Crontab;
|
|
|
|
class CheckWeb
|
|
{
|
|
|
|
public function onWorkerStart()
|
|
{
|
|
if (getenv('ENVIRONMENT') === 'master') {
|
|
new Crontab('0 */10 * * * *', function(){
|
|
$result = $this->tocurl('https://magicbridgeauto.com');
|
|
if (!preg_match('/magicbridgeauto/', $result['body'])) {
|
|
flg("【magicbridgeauto】疑似被篡改");
|
|
}
|
|
return true;
|
|
});
|
|
}
|
|
|
|
new Crontab('*/3 * * * * *', function(){
|
|
$userIds = UserRoles::where('role_id', 1)->pluck('user_id')->toArray();
|
|
foreach ($userIds as $userId) {
|
|
$status = Redis::hGet('user:init:check:'.$userId, 'status');
|
|
if ($status) {
|
|
continue;
|
|
}
|
|
$ws = new WsEvents();
|
|
$ws->pushWebsocket('system.init.check', $userId, $ws->initCheck($userId));
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
public function check()
|
|
{
|
|
$result = $this->tocurl('https://magicbridgeauto.com');
|
|
if (!preg_match('/magicbridgeauto/', $result['body'])) {
|
|
// flg("【magicbridgeauto】未检查到异常");
|
|
// } else {
|
|
flg("【magicbridgeauto】疑似被篡改");
|
|
}
|
|
return true;
|
|
}
|
|
|
|
|
|
public function tocurl($url, $header = null, $content = null)
|
|
{
|
|
$ch = curl_init();
|
|
if(substr($url,0,5)=='https'){
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 跳过证书检查
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // 从证书中检查SSL加密算法是否存在
|
|
curl_setopt($ch, CURLOPT_SSLVERSION, 1);
|
|
}
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
curl_setopt($ch, CURLOPT_URL, $url);
|
|
if (is_array($header)) {
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
|
|
}
|
|
curl_setopt($ch, CURLOPT_POST, true);
|
|
if (!empty($content)) {
|
|
if (is_array($content)) {
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($content));
|
|
} else if (is_string($content)) {
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $content);
|
|
}
|
|
}
|
|
$response = curl_exec($ch);
|
|
$error=curl_error($ch);
|
|
if($error){
|
|
die($error);
|
|
}
|
|
$header = curl_getinfo($ch);
|
|
curl_close($ch);
|
|
$data = array('header' => $header,'body' => $response);
|
|
return $data;
|
|
}
|
|
} |