Beispiel #1
0
    def toggle_webapp(self, action=None):
        # Set up a generic error catching variable for this page.
        error = ''

        if action == 'activate':
            status = 'active'
            action = 'activated'
        else:
            status = 'disabled'
            action = 'deactivated'

        query = "UPDATE webapps SET status=? WHERE name=?;"
        template = template = (status, self.app, )
        database, cursor = _utils.execute_query(self.servicedb, query, template=template)
        database.commit()
        cursor.close()

        # Render the HTML page and send it to the browser.
        try:
            page = self.templatelookup.get_template("/services/toggled.html")
            return page.render(title = "Byzantium Node Services",
                               purpose_of_page = "Service toggled.",
                               error = error, app = self.app,
                               action = action)
        except:
            return exceptions.html_error_template().render()
Beispiel #2
0
    def toggle_webapp(self, action=None):
        # Set up a generic error catching variable for this page.
        error = ''

        if action == 'activate':
            status = 'active'
            action = 'activated'
        else:
            status = 'disabled'
            action = 'deactivated'

        query = "UPDATE webapps SET status=? WHERE name=?;"
        template = template = (
            status,
            self.app,
        )
        database, cursor = _utils.execute_query(self.servicedb,
                                                query,
                                                template=template)
        database.commit()
        cursor.close()

        # Render the HTML page and send it to the browser.
        try:
            page = self.templatelookup.get_template("/services/toggled.html")
            return page.render(title="Byzantium Node Services",
                               purpose_of_page="Service toggled.",
                               error=error,
                               app=self.app,
                               action=action)
        except:
            return exceptions.html_error_template().render()
Beispiel #3
0
    def webapps(self, app=None):
        # Save the name of the app in a class attribute to save effort later.
        self.app = app

        query = "SELECT name, status FROM webapps WHERE name=?;"
        template = (self.app, )
        _, cursor = _utils.execute_query(self.servicedb, query, template=template)
        result = cursor.fetchall()
        status = result[0][1]

        # Save the status of the app in another class attribute for later.
        self.status = status

        # Determine what to do.
        if status == 'active':
            action = 'deactivate'
            warning = 'This will deactivate the application!'
        else:
            action = 'activate'
            warning = 'This will activate the application!'

        # Close the connection to the database.
        cursor.close()

        # Display to the user the page that asks them if they really want to
        # shut down that app.
        try:
            page = self.templatelookup.get_template("/services/webapp.html")
            return page.render(title = "Byzantium Node Services",
                               purpose_of_page = (action + " service"),
                               app = app, action = action, warning = warning)
        except:
            return exceptions.html_error_template().render()
Beispiel #4
0
    def enable(self):
        # Set up the error and successful output messages.
        error = ''
        output = ''

        # Set up a default set of command line options for babeld.  Some of
        # these are redundant but are present in case an older version of
        # babeld is used on the node.  See the following file to see why:
        # http://www.pps.jussieu.fr/~jch/software/babel/CHANGES.text
        common_babeld_opts = [
            '-m', 'ff02:0:0:0:0:0:1:6', '-p', '6696', '-D', '-g', '33123',
            '-c', '/etc/babeld.conf'
        ]

        # Create a set of unique command line options for babeld.  Right now,
        # this variable is empty but it might be used in the future.  Maybe
        # it'll be populated from a config file or something.
        unique_babeld_opts = []

        # Set up a list of mesh interfaces for which babeld is already running.
        interfaces = []
        query = "SELECT interface, enabled, protocol FROM meshes WHERE enabled='yes' AND protocol='babel';"
        connection, cursor = _utils.execute_query(self.meshconfdb, query)
        results = cursor.fetchall()
        for i in results:
            logging.debug("Adding interface: %s", i[0])
            interfaces.append(i[0])

        # By definition, if we're in this method the new interface hasn't been
        # added yet.
        interfaces.append(self.interface)

        self.update_babeld(common_babeld_opts, unique_babeld_opts, interfaces)

        # Get the PID of babeld, then test to see if that pid exists and
        # corresponds to a running babeld process.  If there is no match,
        # babeld isn't running.
        pid = self.pid_check()
        if pid:
            error, output = self._pid_helper(pid,
                                             error,
                                             output,
                                             cursor,
                                             connection,
                                             commit=True)
        cursor.close()

        # Render the HTML page.
        try:
            page = self.templatelookup.get_template("/mesh/enabled.html")
            return page.render(title="Byzantium Node Mesh Configuration",
                               purpose_of_page="Mesh Interface Enabled",
                               protocol=self.protocol,
                               interface=self.interface,
                               error=error,
                               output=output)
        except:
            _utils.output_error_data()
Beispiel #5
0
 def _get_mesh_interfaces(self, interface):
     interfaces = []
     query = "SELECT interface FROM meshes WHERE enabled='yes' AND protocol='babel';"
     _, cursor = _utils.execute_query(self.meshconfdb, query)
     results = cursor.fetchall()
     for i in results:
         interfaces.append(i[0])
     interfaces.append(interface)
     cursor.close()
     return interfaces
Beispiel #6
0
 def _get_mesh_interfaces(self, interface):
     interfaces = []
     query = "SELECT interface FROM meshes WHERE enabled='yes' AND protocol='babel';"
     _, cursor = _utils.execute_query(self.meshconfdb, query)
     results = cursor.fetchall()
     for i in results:
         interfaces.append(i[0])
     interfaces.append(interface)
     cursor.close()
     return interfaces
Beispiel #7
0
    def enable(self):
        # Set up the error and successful output messages.
        error = ""
        output = ""

        # Set up a default set of command line options for babeld.  Some of
        # these are redundant but are present in case an older version of
        # babeld is used on the node.  See the following file to see why:
        # http://www.pps.jussieu.fr/~jch/software/babel/CHANGES.text
        common_babeld_opts = ["-m", "ff02:0:0:0:0:0:1:6", "-p", "6696", "-D", "-g", "33123", "-c", "/etc/babeld.conf"]

        # Create a set of unique command line options for babeld.  Right now,
        # this variable is empty but it might be used in the future.  Maybe
        # it'll be populated from a config file or something.
        unique_babeld_opts = []

        # Set up a list of mesh interfaces for which babeld is already running.
        interfaces = []
        query = "SELECT interface, enabled, protocol FROM meshes WHERE enabled='yes' AND protocol='babel';"
        connection, cursor = _utils.execute_query(self.meshconfdb, query)
        results = cursor.fetchall()
        for i in results:
            logging.debug("Adding interface: %s", i[0])
            interfaces.append(i[0])

        # By definition, if we're in this method the new interface hasn't been
        # added yet.
        interfaces.append(self.interface)

        self.update_babeld(common_babeld_opts, unique_babeld_opts, interfaces)

        # Get the PID of babeld, then test to see if that pid exists and
        # corresponds to a running babeld process.  If there is no match,
        # babeld isn't running.
        pid = self.pid_check()
        if pid:
            error, output = self._pid_helper(pid, error, output, cursor, connection, commit=True)
        cursor.close()

        # Render the HTML page.
        try:
            page = self.templatelookup.get_template("/mesh/enabled.html")
            return page.render(
                title="Byzantium Node Mesh Configuration",
                purpose_of_page="Mesh Interface Enabled",
                protocol=self.protocol,
                interface=self.interface,
                error=error,
                output=output,
            )
        except:
            _utils.output_error_data()
Beispiel #8
0
    def toggle_service(self, action=None):
        # Set up an error handling variable just in case.
        error = ''
        query = "SELECT name, initscript FROM daemons WHERE name=?;"
        template = template = (self.app, )
        database, cursor = _utils.execute_query(self.servicedb,
                                                query,
                                                template=template)
        results = cursor.fetchall()
        self.initscript = results[0][1]

        if action == 'activate':
            status = 'active'
        else:
            status = 'disabled'

        # Construct the command line ahead of time to make the code a bit
        # simpler in the long run.
        initscript = '/etc/rc.d/' + self.initscript
        if self.status == 'active':
            if self.test:
                logging.debug('Would run "%s stop" here.' % initscript)
            else:
                subprocess.Popen([initscript, 'stop'])
        else:
            if self.test:
                logging.debug('Would run "%s start" here.' % initscript)
            else:
                subprocess.Popen([initscript, 'start'])

        # Update the status of the service in the database.
        template = (
            status,
            self.app,
        )
        cursor.execute("UPDATE daemons SET status=? WHERE name=?;", template)
        database.commit()
        cursor.close()

        # Render the HTML page and send it to the browser.
        try:
            page = self.templatelookup.get_template("/services/toggled.html")
            return page.render(title="Byzantium Node Services",
                               purpose_of_page="Service toggled.",
                               app=self.app,
                               action=action,
                               error=error)
        except:
            return exceptions.html_error_template().render()
Beispiel #9
0
    def _update_netconfdb(self, interface):
        query = "SELECT interface FROM wired WHERE interface=?;"
        connection, cursor = _utils.execute_query(self.netconfdb, query, template=(interface, ))
        template = ('yes', interface, )
        results = cursor.fetchall()
        if results:
            cursor.execute("UPDATE wired SET gateway=? WHERE interface=?;",
                            template)
        # Otherwise, it's a wireless interface.
        else:
            cursor.execute("UPDATE wireless SET gateway=? WHERE mesh_interface=?;", template)

        # Clean up.
        connection.commit()
        cursor.close()
Beispiel #10
0
    def toggle_service(self, action=None):
        # Set up an error handling variable just in case.
        error = ''
        query = "SELECT name, initscript FROM daemons WHERE name=?;"
        template = template = (self.app, )
        database, cursor = _utils.execute_query(self.servicedb, query, template=template)
        results = cursor.fetchall()
        self.initscript = results[0][1]

        if action == 'activate':
            status = 'active'
        else:
            status = 'disabled'

        # Construct the command line ahead of time to make the code a bit
        # simpler in the long run.
        initscript = '/etc/rc.d/' + self.initscript
        if self.status == 'active':
            if self.test:
                logging.debug('Would run "%s stop" here.' % initscript)
            else:
                subprocess.Popen([initscript, 'stop'])
        else:
            if self.test:
                logging.debug('Would run "%s start" here.' % initscript)
            else:
                subprocess.Popen([initscript, 'start'])

        # Update the status of the service in the database.
        template = (status, self.app, )
        cursor.execute("UPDATE daemons SET status=? WHERE name=?;", template)
        database.commit()
        cursor.close()

        # Render the HTML page and send it to the browser.
        try:
            page = self.templatelookup.get_template("/services/toggled.html")
            return page.render(title = "Byzantium Node Services",
                               purpose_of_page = "Service toggled.",
                               app = self.app, action = action, error = error)
        except:
            return exceptions.html_error_template().render()
Beispiel #11
0
    def services(self, service=None):
        # Save the name of the app in a class attribute to save effort later.
        self.app = service

        query = "SELECT name, status, initscript FROM daemons WHERE name=?;"
        template = (service, )
        _, cursor = _utils.execute_query(self.servicedb,
                                         query,
                                         template=template)
        result = cursor.fetchall()
        status = result[0][1]
        initscript = result[0][2]

        # Save the status of the app and the initscript in class attributes for
        # later use.
        self.status = status
        self.initscript = initscript

        # Figure out what to do.
        if status == 'active':
            action = 'deactivate'
            warning = 'This will deactivate the application!'
        else:
            action = 'activate'
            warning = 'This will activate the application!'

        # Close the connection to the database.
        cursor.close()

        # Display to the user the page that asks them if they really want to
        # shut down that app.
        try:
            page = self.templatelookup.get_template("/services/services.html")
            return page.render(title="Byzantium Node Services",
                               purpose_of_page=(action + " service"),
                               action=action,
                               app=service,
                               warning=warning)
        except:
            return exceptions.html_error_template().render()
Beispiel #12
0
    def _update_netconfdb(self, interface):
        query = "SELECT interface FROM wired WHERE interface=?;"
        connection, cursor = _utils.execute_query(self.netconfdb,
                                                  query,
                                                  template=(interface, ))
        template = (
            'yes',
            interface,
        )
        results = cursor.fetchall()
        if results:
            cursor.execute("UPDATE wired SET gateway=? WHERE interface=?;",
                           template)
        # Otherwise, it's a wireless interface.
        else:
            cursor.execute(
                "UPDATE wireless SET gateway=? WHERE mesh_interface=?;",
                template)

        # Clean up.
        connection.commit()
        cursor.close()
Beispiel #13
0
    def index(self):
        ethernet_buttons = ""
        wireless_buttons = ""

        # To find any new network interfaces, rescan the network interfaces on
        # the node.
        self.update_network_interfaces()

        query = "SELECT interface FROM wired WHERE gateway='no';"
        _, cursor = _utils.execute_query(self.netconfdb, query)
        results = cursor.fetchall()
        if results:
            for interface in results:
                ethernet_buttons = ethernet_buttons + "<td><input type='submit' name='interface' value='" + interface[
                    0] + "' /></td>\n"

        # Generate a list of wireless interfaces on the node that are not
        # enabled but are known.  As before, each button gets is own button
        # in a table.
        cursor.execute(
            "SELECT mesh_interface FROM wireless WHERE gateway='no';")
        results = cursor.fetchall()
        if results:
            for interface in results:
                wireless_buttons = wireless_buttons + "<td><input type='submit' name='interface' value='" + interface[
                    0] + "' /></td>\n"

        # Close the connection to the database.
        cursor.close()

        # Render the HTML page.
        try:
            page = self.templatelookup.get_template("/gateways/index.html")
            return page.render(title="Network Gateway",
                               purpose_of_page="Configure Network Gateway",
                               ethernet_buttons=ethernet_buttons,
                               wireless_buttons=wireless_buttons)
        except:
            _utils.output_error_data()
Beispiel #14
0
    def webapps(self, app=None):
        # Save the name of the app in a class attribute to save effort later.
        self.app = app

        query = "SELECT name, status FROM webapps WHERE name=?;"
        template = (self.app, )
        _, cursor = _utils.execute_query(self.servicedb,
                                         query,
                                         template=template)
        result = cursor.fetchall()
        status = result[0][1]

        # Save the status of the app in another class attribute for later.
        self.status = status

        # Determine what to do.
        if status == 'active':
            action = 'deactivate'
            warning = 'This will deactivate the application!'
        else:
            action = 'activate'
            warning = 'This will activate the application!'

        # Close the connection to the database.
        cursor.close()

        # Display to the user the page that asks them if they really want to
        # shut down that app.
        try:
            page = self.templatelookup.get_template("/services/webapp.html")
            return page.render(title="Byzantium Node Services",
                               purpose_of_page=(action + " service"),
                               app=app,
                               action=action,
                               warning=warning)
        except:
            return exceptions.html_error_template().render()
Beispiel #15
0
    def services(self, service=None):
        # Save the name of the app in a class attribute to save effort later.
        self.app = service

        query = "SELECT name, status, initscript FROM daemons WHERE name=?;"
        template = (service, )
        _, cursor = _utils.execute_query(self.servicedb, query, template=template)
        result = cursor.fetchall()
        status = result[0][1]
        initscript = result[0][2]

        # Save the status of the app and the initscript in class attributes for
        # later use.
        self.status = status
        self.initscript = initscript

        # Figure out what to do.
        if status == 'active':
            action = 'deactivate'
            warning = 'This will deactivate the application!'
        else:
            action = 'activate'
            warning = 'This will activate the application!'

        # Close the connection to the database.
        cursor.close()

        # Display to the user the page that asks them if they really want to
        # shut down that app.
        try:
            page = self.templatelookup.get_template("/services/services.html")
            return page.render(title = "Byzantium Node Services",
                               purpose_of_page = (action + " service"),
                               action = action, app = service, warning = warning)
        except:
            return exceptions.html_error_template().render()
Beispiel #16
0
    def index(self):
        ethernet_buttons = ""
        wireless_buttons = ""

        # To find any new network interfaces, rescan the network interfaces on
        # the node.
        self.update_network_interfaces()

        query = "SELECT interface FROM wired WHERE gateway='no';"
        _, cursor = _utils.execute_query(self.netconfdb, query)
        results = cursor.fetchall()
        if results:
            for interface in results:
                ethernet_buttons = ethernet_buttons + "<td><input type='submit' name='interface' value='" + interface[0] + "' /></td>\n"

        # Generate a list of wireless interfaces on the node that are not
        # enabled but are known.  As before, each button gets is own button
        # in a table.
        cursor.execute("SELECT mesh_interface FROM wireless WHERE gateway='no';")
        results = cursor.fetchall()
        if results:
            for interface in results:
                wireless_buttons = wireless_buttons + "<td><input type='submit' name='interface' value='" + interface[0] + "' /></td>\n"

        # Close the connection to the database.
        cursor.close()

        # Render the HTML page.
        try:
            page = self.templatelookup.get_template("/gateways/index.html")
            return page.render(title = "Network Gateway",
                               purpose_of_page = "Configure Network Gateway",
                               ethernet_buttons = ethernet_buttons,
                               wireless_buttons = wireless_buttons)
        except:
            _utils.output_error_data()
Beispiel #17
0
    def disable(self):
        logging.debug("Entered MeshConfiguration.disable().")

        # Set up the error and successful output messages.
        error = ""
        output = ""

        # Set up a default set of command line options for babeld.  Some of
        # these are redundant but are present in case an older version of
        # babeld is used on the node.  See the following file to see why:
        # http://www.pps.jussieu.fr/~jch/software/babel/CHANGES.text
        common_babeld_opts = ["-m", "ff02:0:0:0:0:0:1:6", "-p", "6696", "-D"]

        # Create a set of unique command line options for babeld.  Right now,
        # this variable is empty but it might be used in the future.  Maybe
        # it'll be populated from a config file or something.
        unique_babeld_opts = []

        # Set up a list of mesh interfaces for which babeld is already running
        # but omit self.interface.
        interfaces = []
        query = "SELECT interface FROM meshes WHERE enabled='yes' AND protocol='babel';"
        connection, cursor = _utils.execute_query(self.meshconfdb, query)
        results = cursor.fetchall()
        for i in results:
            if i[0] != self.interface:
                interfaces.append(i[0])

        # If there are no mesh interfaces configured anymore, then the node
        # is offline.
        if not interfaces:
            output = "Byzantium node offline."

        babeld_command = self.update_babeld(common_babeld_opts, unique_babeld_opts, interfaces)

        # If there is at least one wireless network interface still configured,
        # then re-run babeld.
        if interfaces:
            logging.debug("value of babeld_command is %s", babeld_command)
            if self.test:
                logging.debug("Pretending to restart babeld.")
            else:
                subprocess.Popen(babeld_command)
            time.sleep(self.babeld_timeout)

        # Get the PID of babeld, then test to see if that pid exists and
        # corresponds to a running babeld process.  If there is no match,
        # babeld isn't running, in which case something went wrong.
        pid = self.pid_check()
        if pid:
            error, output = self._pid_helper(pid, error, output, cursor, connection)
        else:
            # There are no mesh interfaces left, so update the database to
            # deconfigure self.interface.
            template = ("no", self.interface)
            cursor.execute("UPDATE meshes SET enabled=? WHERE interface=?;", template)
        connection.commit()
        cursor.close()

        # Render the HTML page.
        try:
            page = self.templatelookup.get_template("/mesh/disabled.html")
            return page.render(
                title="Byzantium Node Mesh Configuration",
                purpose_of_page="Disable Mesh Interface",
                error=error,
                output=output,
            )
        except:
            _utils.output_error_data()
Beispiel #18
0
    def disable(self):
        logging.debug("Entered MeshConfiguration.disable().")

        # Set up the error and successful output messages.
        error = ''
        output = ''

        # Set up a default set of command line options for babeld.  Some of
        # these are redundant but are present in case an older version of
        # babeld is used on the node.  See the following file to see why:
        # http://www.pps.jussieu.fr/~jch/software/babel/CHANGES.text
        common_babeld_opts = ['-m', 'ff02:0:0:0:0:0:1:6', '-p', '6696', '-D']

        # Create a set of unique command line options for babeld.  Right now,
        # this variable is empty but it might be used in the future.  Maybe
        # it'll be populated from a config file or something.
        unique_babeld_opts = []

        # Set up a list of mesh interfaces for which babeld is already running
        # but omit self.interface.
        interfaces = []
        query = "SELECT interface FROM meshes WHERE enabled='yes' AND protocol='babel';"
        connection, cursor = _utils.execute_query(self.meshconfdb, query)
        results = cursor.fetchall()
        for i in results:
            if i[0] != self.interface:
                interfaces.append(i[0])

        # If there are no mesh interfaces configured anymore, then the node
        # is offline.
        if not interfaces:
            output = 'Byzantium node offline.'

        babeld_command = self.update_babeld(common_babeld_opts,
                                            unique_babeld_opts, interfaces)

        # If there is at least one wireless network interface still configured,
        # then re-run babeld.
        if interfaces:
            logging.debug("value of babeld_command is %s", babeld_command)
            if self.test:
                logging.debug("Pretending to restart babeld.")
            else:
                subprocess.Popen(babeld_command)
            time.sleep(self.babeld_timeout)

        # Get the PID of babeld, then test to see if that pid exists and
        # corresponds to a running babeld process.  If there is no match,
        # babeld isn't running, in which case something went wrong.
        pid = self.pid_check()
        if pid:
            error, output = self._pid_helper(pid, error, output, cursor,
                                             connection)
        else:
            # There are no mesh interfaces left, so update the database to
            # deconfigure self.interface.
            template = (
                'no',
                self.interface,
            )
            cursor.execute("UPDATE meshes SET enabled=? WHERE interface=?;",
                           template)
        connection.commit()
        cursor.close()

        # Render the HTML page.
        try:
            page = self.templatelookup.get_template("/mesh/disabled.html")
            return page.render(title="Byzantium Node Mesh Configuration",
                               purpose_of_page="Disable Mesh Interface",
                               error=error,
                               output=output)
        except:
            _utils.output_error_data()