forked from aaPanel/BaoTa
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
1,489 additions
and
241 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
# +------------------------------------------------------------------- | ||
# | Author: 黄文良 <[email protected]> | ||
# +------------------------------------------------------------------- | ||
import system,psutil,time,public,db,os,sys,json,py_compile | ||
import system,psutil,time,public,db,os,sys,json,py_compile,re | ||
os.chdir('/www/server/panel') | ||
sm = system.system(); | ||
taskConfig = json.loads(public.ReadFile('config/task.json')) | ||
|
@@ -61,9 +61,61 @@ def control_init(): | |
public.ExecShell("chmod -R 600 /www/server/cron/*.log") | ||
public.ExecShell("chown -R root:root /www/server/panel/data") | ||
public.ExecShell("chown -R root:root /www/server/panel/config") | ||
|
||
|
||
disable_putenv('putenv') | ||
clean_session() | ||
set_crond() | ||
|
||
#默认禁用指定PHP函数 | ||
def disable_putenv(fun_name): | ||
try: | ||
is_set_disable = '/www/server/panel/data/disable_%s' % fun_name | ||
if os.path.exists(is_set_disable): return True | ||
php_vs = ('52','53','54','55','56','70','71','72','73','74') | ||
php_ini = "/www/server/php/{0}/etc/php.ini" | ||
rep = "disable_functions\s*=\s*.*" | ||
for pv in php_vs: | ||
php_ini_path = php_ini.format(pv) | ||
if not os.path.exists(php_ini_path): continue | ||
php_ini_body = public.readFile(php_ini_path) | ||
tmp = re.search(rep,php_ini_body) | ||
if not tmp: continue | ||
disable_functions = tmp.group() | ||
if disable_functions.find(fun_name) != -1: continue | ||
print(disable_functions) | ||
php_ini_body = php_ini_body.replace(disable_functions,disable_functions+',%s' % fun_name) | ||
php_ini_body.find(fun_name) | ||
public.writeFile(php_ini_path,php_ini_body) | ||
public.phpReload(pv) | ||
public.writeFile(is_set_disable,'True') | ||
return True | ||
except: return False | ||
|
||
|
||
#创建计划任务 | ||
def set_crond(): | ||
try: | ||
echo = public.md5(public.md5('renew_lets_ssl_bt')) | ||
cron_id = public.M('crontab').where('echo=?',(echo,)).getField('id') | ||
|
||
import crontab | ||
args_obj = public.dict_obj() | ||
if not cron_id: | ||
cronPath = public.GetConfigValue('setup_path') + '/cron/' + echo | ||
shell = 'python /www/server/panel/class/panelLets.py renew_lets_ssl' | ||
public.writeFile(cronPath,shell) | ||
args_obj.id = public.M('crontab').add('name,type,where1,where_hour,where_minute,echo,addtime,status,save,backupTo,sType,sName,sBody,urladdress',("续签Let's Encrypt证书",'day','','0','10',echo,time.strftime('%Y-%m-%d %X',time.localtime()),0,'','localhost','toShell','',shell,'')) | ||
crontab.crontab().set_cron_status(args_obj) | ||
else: | ||
cron_path = public.get_cron_path() | ||
if os.path.exists(cron_path): | ||
cron_s = public.readFile(cron_path) | ||
if cron_s.find(echo) == -1: | ||
public.M('crontab').where('echo=?',(echo,)).setField('status',0) | ||
args_obj.id = cron_id | ||
crontab.crontab().set_cron_status(args_obj) | ||
except: | ||
print(public.get_error_info()) | ||
|
||
|
||
#清理多余的session文件 | ||
def clean_session(): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
#!/usr/bin/python | ||
#coding: utf-8 | ||
# +------------------------------------------------------------------- | ||
# | 宝塔Linux面板 | ||
# +------------------------------------------------------------------- | ||
# | Copyright (c) 2015-2099 宝塔软件(http://bt.cn) All rights reserved. | ||
# +------------------------------------------------------------------- | ||
# | Author: 王张杰 <[email protected]> | ||
# +------------------------------------------------------------------- | ||
|
||
import os | ||
import json | ||
|
@@ -21,6 +27,14 @@ def __get_file_json(self, filename): | |
except: | ||
return {} | ||
|
||
def __get_file_nums(self, filepath): | ||
if not os.path.exists(filepath): return 0 | ||
|
||
count = 0 | ||
for index, line in enumerate(open(filepath, 'r')): | ||
count += 1 | ||
return count | ||
|
||
def _get_site_list(self): | ||
sites = public.M('sites').where('status=?', (1,)).field('name').get() | ||
return sites | ||
|
@@ -120,14 +134,14 @@ def _php_count(self, args): | |
|
||
# 获取攻击数 | ||
def _get_attack_nums(self, args): | ||
file_name = '/www/server/btwaf/total.json' | ||
if not os.path.exists(file_name): return 0 | ||
today = time.strftime('%Y-%m-%d', time.localtime()) | ||
sites = self._get_site_list() | ||
|
||
try: | ||
file_body = json.loads(public.readFile(file_name)) | ||
return int(file_body['total']) | ||
except: | ||
return 0 | ||
count = 0 | ||
for site in sites: | ||
file_path = '/www/wwwlogs/btwaf/{0}_{1}.log'.format(site['name'], today) | ||
count += self.__get_file_nums(file_path) | ||
return count | ||
|
||
def get_exception(self, args): | ||
data = {'mysql_slow': self._get_slow_log_nums(args), 'php_slow': self._php_count(args), 'attack_num': self._get_attack_nums(args)} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.