diff --git a/code/controllers/configuration.dm b/code/controllers/configuration.dm index 8f1bc9652c8..f72fd30742a 100644 --- a/code/controllers/configuration.dm +++ b/code/controllers/configuration.dm @@ -64,6 +64,7 @@ var/ToRban = 0 var/automute_on = 0 //enables automuting/spam prevention var/jobs_have_minimal_access = 0 //determines whether jobs use minimal access or expanded access. + var/copy_logs = 0 var/cult_ghostwriter = 1 //Allows ghosts to write in blood in cult rounds... var/cult_ghostwriter_req_cultists = 10 //...so long as this many cultists are active. @@ -478,6 +479,8 @@ config.assistantlimit = 1 if("assistant_ratio") config.assistantratio = text2num(value) + if("copy_logs") + config.copy_logs = value else diary << "Unknown setting in configuration: '[name]'" diff --git a/code/modules/ext_scripts/copylogs.dm b/code/modules/ext_scripts/copylogs.dm new file mode 100644 index 00000000000..d5f91535843 --- /dev/null +++ b/code/modules/ext_scripts/copylogs.dm @@ -0,0 +1,3 @@ +/proc/copy_logs() + if(config.copy_logs) + ext_python("copy_logs.py", "data/logs \"[config.copy_logs]\"") \ No newline at end of file diff --git a/code/world.dm b/code/world.dm index 819208ac555..165d34a0c80 100644 --- a/code/world.dm +++ b/code/world.dm @@ -16,6 +16,10 @@ starticon = rotate_icon('icons/obj/lightning.dmi', "lightningstart") midicon = rotate_icon('icons/obj/lightning.dmi', "lightning") endicon = rotate_icon('icons/obj/lightning.dmi', "lightningend") + + // Copy logs before opening streams. + copy_logs() + //logs var/date_string = time2text(world.realtime, "YYYY/MM-Month/DD-Day") href_logfile = file("data/logs/[date_string] hrefs.htm") diff --git a/config-example/config.txt b/config-example/config.txt index e8aaa40bcbf..441b4e7d9ad 100644 --- a/config-example/config.txt +++ b/config-example/config.txt @@ -241,4 +241,9 @@ RESPAWN_AS_MOMMI #IRC_BOT_PORT 45678 ## ID tag used to identify the server in the channel -#IRC_BOT_SERVER_ID Server 1 \ No newline at end of file +#IRC_BOT_SERVER_ID Server 1 + +## Copy logs to a location on server startup? +## IPs are automatically removed. +## Default: Don't copy logs. +#COPY_LOGS data/cleaned_logs \ No newline at end of file diff --git a/scripts/copy_logs.py b/scripts/copy_logs.py new file mode 100644 index 00000000000..7afcd60c52a --- /dev/null +++ b/scripts/copy_logs.py @@ -0,0 +1,37 @@ +""" +copy_logs.py unclean_logs/ cleaned_logs/ +* Strips IPs and CIDs. + +""" +import re,os,sys,fnmatch + +REG_IP4=re.compile(r'\d+\.\d+\.\d+\.\d+') # Matches IPv4 addresses. + +# [04:07:35]ACCESS: Login: N3X15/(N3X15) from 127.0.0.1-1234567890 || BYOND v499 +REG_CONNECT=re.compile(r'from [^\|]+\|\| BYOND v([0-9]+)$') # Matches IPv4 addresses. + +def fix(in_file, out_file): + print(' {0} -> {1}'.format(in_file,out_file)) + if os.path.isfile(out_file): + os.remove(out_file) + if not os.path.isdir(os.path.dirname(out_file)): + os.makedirs(os.path.dirname(out_file)) + with open(out_file,'w') as w: + with open(in_file,'r') as r: + for line in r: + line=line.strip('\r\n') + line=REG_CONNECT.sub('from [NOPE] || BYOND v\g<1>', line) + line=REG_IP4.sub('[IP CENSORED]', line) + w.write('{0}\n'.format(line)) +def replace_walk(in_dir,out_dir): + print(' {0} -> {1}'.format(in_dir,out_dir)) + for root, dirnames, filenames in os.walk(in_dir): + for filename in fnmatch.filter(filenames, '*.log'): + path = os.path.join(root, filename) + to = os.path.join(out_dir, path.replace(in_dir, '').replace(os.path.basename(path), '')) + to = os.path.join(to, filename) + path = os.path.abspath(path) + to = os.path.abspath(to) + fix(path, to) + +replace_walk(sys.argv[1],sys.argv[2]) \ No newline at end of file