Skip to content

Commit

Permalink
优化防盗链和一些小调整
Browse files Browse the repository at this point in the history
  • Loading branch information
showpy committed Jul 20, 2019
1 parent 00acb06 commit b2867aa
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 85 deletions.
5 changes: 0 additions & 5 deletions class/crontab_ssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,10 @@
class dict_obj:
def __contains__(self, key):
return getattr(self, key, None)

def __setitem__(self, key, value): setattr(self, key, value)

def __getitem__(self, key): return getattr(self, key, None)

def __delitem__(self, key): delattr(self, key)

def __delattr__(self, key): delattr(self, key)

def get_items(self): return self


Expand Down
2 changes: 1 addition & 1 deletion class/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ 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')
#disable_putenv('putenv')
clean_session()
set_crond()

Expand Down
34 changes: 31 additions & 3 deletions class/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,35 @@ def _php_count(self, args):

return result

# 获取攻击数
def _get_attack_nums(self, args):
# 获取当天cc攻击数
def _get_cc_attack_num(self, args):
zero_point = int(time.time()) - int(time.time() - time.timezone) % 86400
log_path = '/www/server/btwaf/drop_ip.log'
if not os.path.exists(log_path): return 0

num = 100
log_body = public.GetNumLines(log_path, num).split('\n')
while True:
if len(log_body) < num:
break
if json.loads(log_body[0])[0] < zero_point:
break
else:
num += 100
log_body = public.GetNumLines(log_path, num).split('\n')

num = 0
for line in log_body:
try:
item = json.loads(line)
if item[0] > zero_point and item[-1] == 'cc':
num += 1
except: continue

return num

# 获取当天攻击总数
def _get_attack_num(self, args):
today = time.strftime('%Y-%m-%d', time.localtime())
sites = self._get_site_list()

Expand All @@ -144,7 +171,8 @@ def _get_attack_nums(self, args):
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)}
data = {'mysql_slow': self._get_slow_log_nums(args), 'php_slow': self._php_count(args),
'attack_num': self._get_attack_num(args), 'cc_attack_num': self._get_cc_attack_num(args)}
statuscode_distribute = self._statuscode_distribute(args)
data.update(statuscode_distribute)
return data
Expand Down
1 change: 1 addition & 0 deletions class/panelSite.py
Original file line number Diff line number Diff line change
Expand Up @@ -3349,6 +3349,7 @@ def GetSecurity(self,get):
#设置防盗链
def SetSecurity(self,get):
if len(get.fix) < 2: return public.returnMsg(False,'URL后缀不能为空!');
if len(get.domains) < 3: return public.returnMsg(False,'防盗链域名不能为空!');
file = '/www/server/panel/vhost/nginx/' + get.name + '.conf';
if os.path.exists(file):
conf = public.readFile(file);
Expand Down
Loading

0 comments on commit b2867aa

Please sign in to comment.