def printUsers(site): global br r = br.get(site + actions['users'] + '?json=yes', headers=mkHeader(site)) findError(r.json(), site) h = "{:<12} | {:<15} | {:<15} \t".format("user", "Bandwidth", "Disk Usage") print(h) print('=' * 60) for mess in range(int(r.json()["info"]["rows"])): if r.json()[str(mess)]["username"]["is_user"] == "yes": quota = float(r.json()[str( mess)]["quota"]["usage"]) if "unlimited" in r.json()[str( mess)]["quota"]["limit"] else 100 * float( r.json()[str(mess)]["quota"]["usage"]) / float( r.json()[str(mess)]["quota"]["limit"]) banwidth = float(r.json()[str(mess)]["bandwidth"]["usage"]) if "unlimited" in \ r.json()[str(mess)]["bandwidth"][ "limit"] else 100 * float( r.json()[str(mess)]["bandwidth"]["usage"]) / float(r.json()[str(mess)]["bandwidth"]["limit"]) row = "{:<12} | {:<22} | {:<22} \t".format( r.json()[str(mess)]["username"]["value"], paint("{:.4f}/Unli".format(banwidth), 'f_green') if banwidth > 100 else warn(banwidth, "{:.4f}%".format(banwidth)), paint("{:.4f}/Unli".format(quota), 'f_green') if quota > 100 else warn(quota, "{:.4f}%".format(quota))) print(row) print('-' * 60)
def printTickets(site): removeNonsenseTickets(site) global br r = br.get(site + actions['tickets'] + '?json=yes', headers=mkHeader(site)) findError(r.json(), site) h = "{:<5} | {:<19} | {} \t".format("isNew", "Time", "Subject") if int(r.json()["messages"]["info"]['rows']) == 0: print('--There is no message to view---') return 0 print(h) print('=' * 60) for mess in range(int(r.json()["messages"]["info"]["rows"]) - 1, -1, -1): row = "{:<5} | {} | {} \t".format( r.json()["messages"][str(mess)]["new"], datetime.fromtimestamp( int(r.json()["messages"][str(mess)]["last_message"])), # r.json()["messages"][str(mess)]["message"], # message id r.json()["messages"][str(mess)]["subject"]) if 'are now ready' in row or 'has been updated' in row: print(paint(row, 'f_green')) elif 'getting old' in row: print(paint(row, 'f_yellow')) elif 'error' in row: print(paint(row, 'f_red')) elif 'Warning' in row: print(paint(row, 'b_red')) print('-' * 60)
def flightsJS(): flightsJS = open("htmlJS/flights.js", "w") flightsJS.write("document.write(\' \\" + "\n") __main__.USAGE = {} __main__.column = 0 for __main__.k in sorted(__main__.AIRLINE_FLEET.keys()): __main__.column += 1 __main__.length = 0 flightsJS.write("<div class=\"toleft\"> \\" + "\n") for i in sorted(__main__.AIRLINE_FLEET[__main__.k].keys()): __main__.X = __main__.AIRLINE_FLEET[__main__.k][i] C.paint(__main__.X) F.graph_data() title = __main__.X['Departure Airport Code'] + " - " + __main__.X['Arrive Airport Code'] tooltip_tekst = "<p>Reg " + __main__.k + "</p><p style=\"line-height: 1.7\">Take-off " + __main__.X['Departure Time'] + " " + __main__.X['Departure Airport Full'] \ + "<br>Landing " + __main__.X['Arrive Time'] + " " + __main__.X['Arrive Airport Full'] + "<br>"\ + "Duration " + __main__.X['Duration'] + "</p><p>" + __main__.X['Status'] + "</p>" flightsJS.write(" <div class=\"empty\" style=\"height:" + str(__main__.X['boxGround']) + "px\"></div> \\" + "\n") flightsJS.write(" <div class=\"tooltip container\" style=\"height:" + str(__main__.X['boxAirborne']-2) + "px; color:" + __main__.colF + "; " + __main__.fill + "\"> \\" + "\n" \ + " <span>" + title + "<span class=\"tooltiptext" + F.typetool() + "\">" + F.raw(tooltip_tekst) + "</span></span></div> \\" + "\n") flightsJS.write("</div> \\" + "\n") flightsJS.write("\');") flightsJS.close()
def login(site): global br r = br.post(site + actions['login'], headers=mkHeader(site), data=cre2) try: if r.json()["success"] == "yes": print(paint("--login success--", 'f_green')) logged[site] = True else: print(paint("--loginfailed--", 'b_red')) logged[site] = False except Exception: print(paint("--loginfailed--", 'b_red')) logged[site] = False
def updateLicense(site): r = br.get(site + actions['license'] + '?json=yes&update=license', headers=mkHeader(site)) findError(r.json(), site) if r.json()["success"] == "Update queued": print("License update success.") else: print(paint("License update Failed.", 'f_red', True)) log(r.json()["result"], site) r = br.get(site + actions['license'] + '?json=yes&update=program', headers=mkHeader(site)) if not "You already have the most recent version of the program" in r.json( )["result"]: print("DA update success.") else: print(paint("DA update Failed.", 'f_red', True)) log(r.json()["result"], func, site)
def findError(json, site): try: if json["success"] == "no": log(json["error"], site) print(paint("=Logged out due to unexpected error", "f_red")) logged[site] = False return 0 except Exception as ex: pass
def option(): global cre2 OptionSwitcher = {"1": signin} choice = menuInput("=== OPTION ===\n" + "1.Re-enter credential\n" + "2.Mark as read all tickets\n" + "3.Mark as read all tickets\n" + "Choice : ") if choice == "1": cre2 = signin() for site in sites: print("- - - {:<50} : ".format(paint(site, 'f_purple', True)), end='') login(site) if choice == "2": for site in sites: print("- - - - - - - " + paint(site, 'f_purple', True) + " - - - - - - - - -") seenTickets(site) if choice == "3": print(PatchNote)
def signin(): global usr, pas try: print( paint( '--- Please enter Credential to login program prevent leaking cre ---', 'b_green')) usr = input("username : ") pas = getpass.getpass() return 'referer=%2F&username={}&password={}&json=yes'.format(usr, pas) except Exception as e: log(e, 'singin')
def main(): global cre2 cre2 = signin() func = login for site in sites: print("- - - {:<50} : ".format(paint(site, 'f_purple', True)), end='') login(site) switcher = { "1": printTickets, "2": printUsers, "3": printStats, "4": mailQueue, "5": printService, "6": printLicense, "7": updateLicense, "8": checkSpam, "9": checkBackups, "10": login } while True: choice = menuInput( paint("-----------menu----------\n", 'f_cyan') + "1.Print Ticket/ Message\n" + "2.Print Users usage \n" + "3.Print System Stats\n" + "4.Print Mail Queue\n" + "5.Print Services usage\n" + "6.Print DA License\n" + "7.Update DA License\n" + "8.Check Spam Level\n" + "9.Check Backups via ssh \n" + "10.Re-login\n" "11.Option\n" "Choice : ") if choice == -1: print(paint("Invalid Choice", "f_red")) elif choice == "11": option() elif choice == "8": checkSpam() elif choice == "10": for site in sites: print("- - - {:<50} : ".format(paint(site, 'f_purple', True)), end='') login(site) else: func = switcher.get(choice, "Invalid Choice") for site in sites: print("- - - - - - - " + paint(site, 'f_purple', True) + " - - - - - - - - -") if logged[site] == True or choice == "10": try: func(site) except Exception as exception: log(exception, func, site) else: print(paint("Not Logged in", "f_yellow"))
def printService(site): global br r = br.get(site + actions['services'] + '?json=yes', headers=mkHeader(site)) head = "{:15} | {:7} | {:6} | {} \t".format("Name", "Memory", "Status", "Pids") print(head) findError(r.json(), site) for service in list(r.json()["memory"].keys()): pids = '' percentage = "{:17}".format(paint('0.00', 'f_blue')) if not r.json()["memory"][service] == "": percentage = warn( float(r.json()["memory"][service]) / 15.01, r.json()["memory"][service]) if service in r.json()["pids"].keys(): pids = ", ".join(r.json()["pids"][service]) row = "{:15} | {:8} | {:6} | {} \t".format( service, percentage, r.json()["status"][service], pids) print(row)
def printStats(site): r = br.get(site + actions['stats'] + '?json=yes', headers=mkHeader(site)) head = "{:25} | {:14} | {:12} | {:5} | {} \t".format( "Filesystem", "Used", "Available", "Capacity", "Mounted on") print(head) findError(r.json(), site) for mess in range(int(r.json()["disk"]["info"]["rows"])): if "root" in r.json()["disk"][str( mess)]["Filesystem"] or "/dev" in r.json()["disk"][str( mess)]["Filesystem"]: a = paint("Unlimited", 'f_green') if r.json()["disk"][str( mess)]["Available"] == "unlimited" else float( r.json()["disk"][str(mess)]["Available"]) / 1048576 row = "{:25} | {:10.4f} GB | {:10.4f} GB | {:18} | {} \t".format( r.json()["disk"][str(mess)]["Filesystem"], float(r.json()["disk"][str(mess)]["Used"]) / 1048576, a, warn(r.json()["disk"][str(mess)]["Capacity"]), r.json()["disk"][str(mess)]["Mounted on"]) if int(r.json()["disk"][str(mess)]["Capacity"].replace('%', '')) > 80: row += "\t Limit Warning" print(row)
def mailQueue(site): # #No - not updated error code loopError = { "#01": "OverQuotaTemp", "#02": "overquota", "#03": "temporarily blocked due to spam", "(-44)": "451 Internal resource temporarily unavailable", "(-46)": "454 Transient reject by behaviour spam", "(110)": "Connection timed out", "(-51)": "retry time not yet reached for any host", "(-52)": "retry time not reached", "(-53)": "retry time not reached for any host", "(-1)": "host lookup did not complete", "(32)": "Broken pipe", "(-18)": "closed connection in response", "(111)": "Connection refused", "(113)": "No route to host" } r = br.get(site + actions['mail'] + '?json=yes', headers=mkHeader(site)) findError(r.json(), site) for mess in range(int(r.json()["table"]["info"]["rows"])): if not "<>" in r.json()["table"][str(mess)]["sender"]: print("-ID= " + r.json()["table"][str(mess)]["id"] + " --- " + str(int(r.json()["table"][str(mess)]["time"]) / 3600) + "h") temp = br.get(site + actions['mail'] + '?json=yes&id=' + r.json()["table"][str(mess)]["id"], headers=mkHeader(site)) tempLogList = list( set( map(lambda x: " ".join(list(x.split(" "))[2:]), list(temp.json()['logs'].split("\n"))))) loop = dict() unknow = [] logList = [] errorList = list(loopError.keys()) for i in tempLogList: success = False if 'Received' in i or 'succeeded' in i or i == "": success = True if not success: logList.append(i) for er in errorList: mailList = "" for i in logList: if er not in loop.keys(): if er in i or loopError[er] in i: loop[er] = str(i.split(" ")[0]) elif er not in i and loopError[ er] not in i and i not in unknow: confirm = True for error in list(loopError.keys()): if error in i or loopError[error] in i: confirm = False if confirm: unknow.append(i) line = paint('#Unknow log line : ', 'f_red') + paint(i, 'f_yellow') print(line) log('Unknow log : ' + i, func, site, 'checking log line') else: mail = str(i.split(" ")[0]) if '@' in mail and mail not in mailList: mailList += mail + ', ' if er in loop.keys(): if mailList != "" and '@' not in loop[er]: loop[er] = mailList[:-2] print( paint("{} {} ({})".format(er, loopError[er], loop[er]), 'f_yellow'))
# made by ThanhNguyen import os, subprocess from colors import paint, warn print(paint("Start initialize sequence", 'f_green'), end='') import requests, base64 import time, concurrent.futures, getpass import re from datetime import datetime from checker import Checker from ssh import sshSession from logger import log usr = '' pas = '' PatchNote = ( "-" + paint("---------UPDATE NOTE Ver4.0\n", "f_green") + paint("Ver 4.0\n", "f_cyan") + paint(" + Using input credential\n", "f_red", True) + paint(" + Add Option - Reinput credential\n", "f_green", True) + paint(" + Add Check spam level UCE protect\n", "f_red", True) + paint(" + Add ssh backup checker \n", "f_red", True) + paint("Ver 4.1\n", "f_cyan") + paint(" + Add colors and functions\n", "f_green", True) + paint(" + Add mail error detect\n", "f_green", True) + paint("Ver 4.2\n", "f_cyan") + paint(" + Update Mail error detect, now show destination address\n", "f_green", True) + paint(" + Add log unknow mail error\n", "f_green", True) + paint("Ver 4.3\n", "f_cyan") +