def inthandler(signum, frame): """ Signal handler for ctrl-c """ import os from sensor import functions as f from sensor import dialog di = dialog.Dialog() logging.debug("SIGINT received") logging.debug("WATCHMEEE INTHANDLER SIGINT received") if f.managerStatus(str(os.getpid())): di.setBackgroundTitle('SURFids v3.0 sensor running on ' + f.system()) di.infobox("CTRL-C received, shutting down sensor...") # Shutting down the sensor try: logging.debug("WATCHMEEE INTHANDLER f.sensorDown") logging.debug("WATCHMEEE INTHANDLER tunnel status: %s" % str(f.tunnelStatus())) f.sensorDown() logging.debug("WATCHMEEE INTHANDLER tunnel status: %s" % str(f.tunnelStatus())) except: err = str(sys.exc_info()[1]) logging.debug("WATCHMEEE error: %s" % str(err)) logging.error("Could not shutdown the sensor during SIGINT") logging.debug("WATCHMEEE inthandler cleanup phase") # Cleaning up temporary files f.cleanUp() logging.debug("WATCHMEEE INTHANDLER tunnel status: %s" % str(f.tunnelStatus())) # if os.path.exists(locations.OPENVPNPID): # os.unlink(locations.OPENVPNPID) os.system('clear') logging.warning("SURFids menu stopped (received ctrl-c)") sys.exit(1)
def inthandler(signum, frame): """ Signal handler for ctrl-c """ import os from sensor import functions as f from sensor import dialog di = dialog.Dialog() logging.debug("SIGINT received") logging.debug("WATCHMEEE INTHANDLER SIGINT received") if f.managerStatus(str(os.getpid())): di.setBackgroundTitle("SURFids v3.0 sensor running on " + f.system()) di.infobox("CTRL-C received, shutting down sensor...") # Shutting down the sensor try: logging.debug("WATCHMEEE INTHANDLER f.sensorDown") logging.debug("WATCHMEEE INTHANDLER tunnel status: %s" % str(f.tunnelStatus())) f.sensorDown() logging.debug("WATCHMEEE INTHANDLER tunnel status: %s" % str(f.tunnelStatus())) except: err = str(sys.exc_info()[1]) logging.debug("WATCHMEEE error: %s" % str(err)) logging.error("Could not shutdown the sensor during SIGINT") logging.debug("WATCHMEEE inthandler cleanup phase") # Cleaning up temporary files f.cleanUp() logging.debug("WATCHMEEE INTHANDLER tunnel status: %s" % str(f.tunnelStatus())) # if os.path.exists(locations.OPENVPNPID): # os.unlink(locations.OPENVPNPID) os.system("clear") logging.warning("SURFids menu stopped (received ctrl-c)") sys.exit(1)
def sensor(self): """ Prints information about the sensor status """ logging.debugv("menu/status.py->sensor(self)", []) sid = self.c.getSensorID() mainInf = self.c.getMainIf() status = f.tunnelStatus() if status: status = True else: status = False networkStatus = f.networkStatus(mainInf) pversion = f.getPackageVersion() # Subtitle report = t.formatTitle("General sensor info") # Package version report += t.formatLog("Package version", str(pversion)) # Sensor name report += t.formatLog("Sensor", sid) # Sensor status report += t.formatLog("Status", status, 1) # Network status report += t.formatLog("Network", networkStatus, 1) report += "\n" # Subtitle report += t.formatTitle("Sanity checks") if networkStatus: # OpenVPN port check ovnport = f.scanPort(self.c.getServer(), 1194) report += t.formatLog("OpenVPN port", ovnport, 1) # Updates port check upport = f.scanPort(self.c.getServer(), 4443) report += t.formatLog("Updates port", upport, 1) else: report += t.formatLog("OpenVPN port", "Unchecked") report += t.formatLog("Updates port", "Unchecked") # Check crt existance report += t.formatLog("Sensor certificate", f.verifyCrt(), 1) # Check key existance report += t.formatLog("Sensor key", f.verifyKey(), 1) report += "\n" # Subtitle report += t.formatTitle("Program checks") # Check SSH status report += t.formatLog("SSH daemon running", f.sshStatus(), 1) if status: # Checking OpenVPN daemon report += t.formatLog("OpenVPN daemon running", f.openvpnStatus(), 1) return self.d.msgbox(report, width=70, height=25, no_collapse=1, colors=1)
class Manage: def __init__(self, d): # d = dialog object logging.debugv("menu/manage.py->__init__(self, d)", []) self.d = d # c = config object self.c = config.Config() def run(self): """ Submenu of main to for sensor management """ logging.debugv("menu/manage.py->run(self)", []) # Checking for network configuration try: chk = self.c.validNetConf() except excepts.ConfigException, e: self.d.msgbox("The network configuration is invalid: \n%s" % str(e), width=60) return choices = [] if functions.tunnelStatus(): choices.append(("Sensor Down", "Bring sensor down")) choices.append(("Sensor Restart", "Restart the sensor")) else: choices.append(("Sensor Up", "Bring sensor up")) mainInf = self.c.getMainIf() if functions.networkStatus(mainInf): choices.append(("Update", "Sync with server now")) #choices.append( ("Get Config", "Get the latest network config") ) choices.append(("Ping", "Check if connection is okay")) if functions.sshStatus(): choices.append(("SSH server off", "Disable remote shell access")) else: choices.append(("SSH server on", "Enable remote shell access")) if functions.checkKey(): choices.append(("Reinit sensor", "Removes keys and sensor ID")) # TODO #choices.append( ("Startup on", "Enable SURFids at startup") ) title = "\\ZbStart > Manage\\n\\ZB" subtitle = "Select an action" title += subtitle choice = self.d.menu(title, choices=choices, cancel="Back", colors=1) # cancel if choice[0] == 1: return elif choice[1] == "Sensor Up": self.sensorUp() elif choice[1] == "Sensor Down": self.sensorDown() elif choice[1] == "Sensor Restart": self.sensorUp() elif choice[1] == "Update": self.update() #elif choice[1] == "Get Config": self.getConfig() elif choice[1] == "SSH server on": functions.sshUp() self.d.msgbox("SSH server enabled") elif choice[1] == "SSH server off": functions.sshDown() self.d.msgbox("SSH server disabled") elif choice[1] == "Reinit sensor": if not self.d.yesno( "Are you sure you want to reinit this sensor? " + "This will result in a new sensor ID"): functions.sensorDown() functions.delKey() self.c.setSensorID("") self.d.msgbox( "Sensor cleaned (removed key & certificate). Ignore the old sensor in the web interface. Restart the sensor.", width=60) elif choice[1] == "Ping": self.ping() else: self.d.msgbox("not yet implemented") self.run()
sys.exit(1) def run(self): logging.debugv("manager.py->run(self)", []) logging.info("SURFids manager starting") try: f.networkUp() except excepts.ConfigException, msg: logging.warn(msg) except excepts.InterfaceException, msg: logging.warn(msg) except SystemExit: logging.info("Sensor manager exiting") except: self.handleException() if not f.tunnelStatus(): if self.c.getAutoStart() == "Enabled": logging.info("Sensor not active - Auto Starting") self.d.setBackgroundTitle('SURFids v3.0 running on ' + f.system()) self.d.infobox("Auto Starting sensor...") try: self.c.validNetConf() except excepts.ConfigException, err: self.d.infobox("Autostart Failed\n\nCONFIG ERROR: %s" % str(err)) else: try: f.sensorUp() except excepts.NetworkException, msg: msg = str(msg)
sys.exit(1) def run(self): logging.debugv("manager.py->run(self)", []) logging.info("SURFids manager starting") try: f.networkUp() except excepts.ConfigException, msg: logging.warn(msg) except excepts.InterfaceException, msg: logging.warn(msg) except SystemExit: logging.info("Sensor manager exiting") except: self.handleException() if not f.tunnelStatus(): if self.c.getAutoStart() == "Enabled": logging.info("Sensor not active - Auto Starting") self.d.setBackgroundTitle('SURFids v3.0 running on ' + f.system()) self.d.infobox("Auto Starting sensor...") try: self.c.validNetConf() except excepts.ConfigException, err: self.d.infobox("Autostart Failed\n\nCONFIG ERROR: %s" % str(err)) else: try: f.sensorUp() except excepts.NetworkException, msg: msg = str(msg) self.d.msgbox("Autostart Failed\n\nNETWORK ERROR: " + msg) except excepts.ConfigException, msg: