import strutils, json proc CtrlCHook* () {.noconv.} = echo "Ctrl+C fired! \nStopping Server now!" quit() proc isInt* (s: string): bool = try: discard s.parseInt() result = true except: discard proc isFloat* (s: string): bool = try: discard s.parseFloat() result = true except: discard proc parseCtlMgr* (n: string): JsonNode = var input = n.split("\n") input.del(0) var last_group = "" var data = newJObject() for i in items(input): let line = strip(i) if line == "": continue if endsWith(line, "/"): last_group = replace(line, "/", "") continue let entry = line.split("=") var value = "" if entry.len > 1: value = entry[1] if last_group == "": if isInt(value): data.add(entry[0], newJInt(parseInt(value))) elif isFloat(value): data.add(entry[0], newJFloat(parseFloat(value))) else: data.add(entry[0], %(value)) else: if not data.hasKey(last_group): data.add(last_group, newJObject()) if isInt(value): data[last_group].add(entry[0], newJInt(parseInt(value))) elif isFloat(value): data[last_group].add(entry[0], newJFloat(parseFloat(value))) else: data[last_group].add(entry[0], %(value)) return data proc getTxTraffic* (data: JsonNode, mode: string): int = if data[mode].hasKey("BytesSentHigh") and data[mode].hasKey("BytesSentLow"): return data[mode]["BytesSentHigh"].getInt shl 32 + data[mode]["BytesSentLow"].getInt proc getRxTraffic* (data: JsonNode, mode: string): int = if data[mode].hasKey("BytesReceivedHigh") and data[mode].hasKey("BytesReceivedLow"): return data[mode]["BytesReceivedHigh"].getInt shl 32 + data[mode]["BytesReceivedLow"].getInt