示例#1
0
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")

    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:
            f.sensorDown()
        except:
            logging.error("Could not shutdown the sensor during SIGINT")

        logging.debug("WATCHME inthandler cleanup phase")
        # Cleaning up temporary files
        f.cleanUp()

#    if os.path.exists(locations.OPENVPNPID):
#        os.unlink(locations.OPENVPNPID)
    os.system('clear')
    logging.warning("SURFids menu stopped (received ctrl-c)")
    sys.exit(1)
示例#2
0
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)
示例#3
0
 def shutdown(self):
     """ Shutdown the machine gracefully """
     logging.debugv("menu/manage.py->shutdown(self)", [])
     try:
         self.d.infobox("Bringing sensor down...")
         functions.sensorDown()
     except:
         logging.info("Sensor down failed before shutdown")
     self.d.infobox("Shutting down machine...")
     functions.shutdown()
示例#4
0
 def shutdown(self):
     """ Shutdown the machine gracefully """
     logging.debugv("menu/manage.py->shutdown(self)", [])
     try:
         self.d.infobox("Bringing sensor down...")
         functions.sensorDown()
     except:
         logging.info("Sensor down failed before shutdown")
     self.d.infobox("Shutting down machine...")
     functions.shutdown()
示例#5
0
    def sensorDown(self):
        """ Bring down the sensor """
        logging.debugv("menu/manage.py->sensorDown(self)", [])
        try:
            self.d.infobox("Bringing sensor down...")
            functions.sensorDown()
        except excepts.NetworkException:
            logging.info("No network connection, so can't deregister")
            functions.allInfsDown()

            # Get network working again
            functions.networkUp()

        self.d.msgbox("Sensor succesfully brought offline")
示例#6
0
    def sensorDown(self):
        """ Bring down the sensor """
        logging.debugv("menu/manage.py->sensorDown(self)", [])
        try:
            self.d.infobox("Bringing sensor down...")
            functions.sensorDown()
        except excepts.NetworkException:
            logging.info("No network connection, so can't deregister")
            functions.allInfsDown()

            # Get network working again
            functions.networkUp()

        self.d.msgbox("Sensor succesfully brought offline")
示例#7
0
 def activateChoice(self):
     """ Choose to stop or restart sensor after changing the config """
     logging.debugv("menu/config.py->activateChoice(self)", [])
     choices = [
             ("Stop", "Stop the sensor"),
             ("Restart", "Restart the sensor"),
             ]
     choice = self.d.menu("The configuration of the sensor has changed. What would you like to do?", choices=choices, cancel="back")
     if choice[1] == "Stop":
         manage.Manage(self.d).sensorDown()
         client.saveConf()
     elif choice[1] == "Restart":
         self.d.infobox("Bringing sensor down...")
         f.sensorDown()
         client.saveConf()
         manage.Manage(self.d).sensorUp()
     else:
         self.activateChoice()
示例#8
0
 def activateChoice(self):
     """ Choose to stop or restart sensor after changing the config """
     logging.debugv("menu/config.py->activateChoice(self)", [])
     choices = [
         ("Stop", "Stop the sensor"),
         ("Restart", "Restart the sensor"),
     ]
     choice = self.d.menu(
         "The configuration of the sensor has changed. What would you like to do?",
         choices=choices,
         cancel="back")
     if choice[1] == "Stop":
         manage.Manage(self.d).sensorDown()
         client.saveConf()
     elif choice[1] == "Restart":
         self.d.infobox("Bringing sensor down...")
         f.sensorDown()
         client.saveConf()
         manage.Manage(self.d).sensorUp()
     else:
         self.activateChoice()
示例#9
0
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()
示例#10
0
        except excepts.ConfigException, err:
            self.d.msgbox("The network configuration is invalid: \n%s" %
                          str(err),
                          width=60)
            return

        # Validate DNS config
        try:
            self.c.validDNSConf()
        except excepts.ConfigException, err:
            self.d.msgbox("The DNS configuration is invalid: \n%s" % str(err),
                          width=60)
            return

        self.d.infobox("Bringing sensor up...")
        functions.sensorDown()
        try:
            if functions.sensorUp():
                self.d.msgbox("Sensor succesfully brought online")
            else:
                self.d.msgbox("Unable to start the sensor")
        except excepts.NetworkException, msg:
            self.d.msgbox(str(msg) + "\nplease see logfile for details",
                          width=60)
            self.sensorDown()
        except excepts.ConfigException, msg:
            self.d.msgbox(str(msg) + "\nplease see logfile for details",
                          width=60)
            self.sensorDown()

    def sensorDown(self):
示例#11
0
#!/usr/bin/env python

from sensor import log
from sensor import functions
from sensor import excepts

# make sure we have an empty network config
functions.sensorDown()

# remove old stuff, maybe sensor crashed or something
functions.cleanUp()

functions.networkUp()