forked from GAMEBotLand/scumlogs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scumlogs.py
118 lines (106 loc) · 4.83 KB
/
scumlogs.py
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
# -*- coding: utf-8 -*-
# g-portal logs downloader for scum servers
# by GAMEBotLand.com
import json
import asyncio
from bs4 import BeautifulSoup
import cfscrape
from configparser import RawConfigParser
from datetime import datetime
def log(text):
print('[%s] %s' % (datetime.strftime(datetime.now(), '%H:%M:%S'), text))
def help():
print('\nPlease edit scumlogs.ini and include your g-portal credentials, use:')
print(' user = gportal email or username')
print(' password = gportal password')
print(' serverid = gportal server id')
print(' loc = com (for gportal international) or us (for gportal us)')
print(' folder = blank for local or path folder to store your log files')
print(' leave the rest of the parameters as is\n')
def load_configini():
config = RawConfigParser()
with open('scumlogs.ini', 'r', encoding="utf-8") as f:
config.read_file(f)
global configini
configini = dict(config['GPORTAL'])
def save_configini():
parser = RawConfigParser()
parser.add_section('GPORTAL')
for key in configini.keys():
parser.set('GPORTAL', key, configini[key])
with open('scumlogs.ini', 'w', encoding="utf-8") as f:
parser.write(f)
async def read_logs():
values = ('user','password','serverid','loc','folder','admin_file','admin_line','chat_file','chat_line','kill_file','kill_line','login_file','login_line','violations_file','violations_line')
print('scumlogs v1.0, scum server logs downloader from gportal\nby htttps://GAMEBotLand.com')
try:
load_configini()
except:
global configini
configini = {}
for value in values:
if value not in configini:
configini[value] = ''
if configini['folder'] != '':
if configini['folder'][-1:] != '/' and configini['folder'][-1:] != '\\':
configini['folder'] = configini['folder'] + '/'
save_configini()
if configini['loc'] == 'com':
loc = 'com'
else:
loc = 'us'
URL_LOGIN = 'https://id2.g-portal.com/login?redirect=https://www.g-portal.{0}/auth/login?redirectAfterLogin=https://www.g-portal.{0}/es/'.format(configini['loc'])
URL_LOGS = 'https://www.g-portal.{0}/server/scum/{1}/logs'.format(configini['loc'], configini['serverid'])
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)'}
with cfscrape.create_scraper() as session:
try:
log('connecting g-portal...')
payload = {'_method': 'POST', 'login': configini['user'], 'password': configini['password'],
'rememberme': '1'}
raw_response = session.post(URL_LOGIN, headers=headers, data=payload)
raw_response = session.get(URL_LOGS, headers=headers)
response = raw_response.text
html = BeautifulSoup(response, 'html.parser')
select = html.find('div', {'class': 'wrapper logs'})
loglist = select['data-logs']
logs = json.loads(loglist)
for i in range(len(logs)):
getid = logs["file_" + str(i + 1)]
id = (getid[int(getid.find('Logs')) + 5:])
type = id.split('_')[0]
if configini[type + '_file'] != '':
if id < configini[type + '_file']:
continue
payload = {'_method': 'POST', 'load': 'true', 'ExtConfig[config]': getid}
raw_response = session.post(URL_LOGS, headers=headers, data=payload)
response = raw_response.text
content = json.loads(response)
lines = content["ExtConfig"]["content"].splitlines()
filename = configini['folder'] + id
file = open(filename, "a+", encoding='utf-8')
found = False
writing = False
for line in lines:
if id == configini[type + '_file'] and not found:
if line == configini[type + '_line']:
found = True
continue
else:
file.write(line + '\n')
writing = True
if writing:
if found:
log('updating {}'.format(id))
else:
log('creating {}'.format(id))
file.close()
configini[type + '_file'] = id
configini[type + '_line'] = lines[-1]
save_configini()
except:
log('error connecting, check connectivity and scumlogs.ini')
help()
if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(read_logs())
loop.close()