예제 #1
0
    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)
예제 #2
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()
#!/usr/bin/env python

import logging

from sensor import log
from sensor import functions
from sensor import config

c = config.Config()
mainInf = c.getMainIf()
if not mainInf == "":
    # only update if we have tunnels
    if functions.networkStatus(mainInf):
        functions.aptUpdate()
        functions.aptInstall()
    else:
        logging.debug("Sensor not active, not checking APT")
else:
    logging.error(
        "Could not determine mainInf while running sensor-apt-update.py")
#!/usr/bin/env python

import logging

from sensor import log
from sensor import functions
from sensor import config

c = config.Config()
mainInf = c.getMainIf()
if not mainInf == "":
    # only update if we have tunnels
    if functions.networkStatus(mainInf):
        functions.aptUpdate()
        functions.aptInstall()
    else:
        logging.debug("Sensor not active, not checking APT")
else:
    logging.error("Could not determine mainInf while running sensor-apt-update.py")
예제 #5
0
    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)