HEX
Server: Apache/2.2.34 (Unix) mod_fastcgi/mod_fastcgi-SNAP-0910052141
System: Linux Kou-Etsu-Dou 4.4.59+ #25556 SMP PREEMPT Thu Mar 4 18:03:46 CST 2021 x86_64
User: hosam (1026)
PHP: 7.2.29
Disabled: NONE
Upload Files
File: //usr/syno/bin/user.data.collector/synouserdata_webapi
#!/usr/bin/python

import os, json, time

COUNT_POOL_PATH = "/var/spool/webapi"
COUNT_POOL_TIMESTAMP = os.path.join(COUNT_POOL_PATH, ".timestamp")

collect_data = { "collector_version": 2, "version": 1, "method": [] };
try:
	st = os.stat(COUNT_POOL_TIMESTAMP)
	collect_data["time_begin"] = st.st_mtime
except: pass

for root, dirs, files in os.walk(COUNT_POOL_PATH):
	for f in files:
		if f.startswith(".") or f.endswith(".lock"):
			continue

		path = os.path.join(root, f)

		data = None
		try:
			with open(path, "r") as h:
				data = json.load(h)
		except:
			if not collect_data.has_key("broken"):
				collect_data["broken"] = []
			collect_data["broken"].append(os.path.basename(f))
		finally:
			os.unlink(path)
			os.unlink(path + ".lock")

		if not data:
			continue

		for key,value in data.items():
			value["method"] = key
			collect_data['method'].append(value)
try:
	with open(COUNT_POOL_TIMESTAMP, 'a'):
		os.utime(COUNT_POOL_TIMESTAMP, None)
except: pass

collect_data["time_end"] = time.time()

print json.dumps(collect_data)