Beispiel #1
0
def use_test_config(request):
    Environment.reset()
    Environment.config = os.path.join(
        os.path.dirname(os.path.realpath(__file__)), "..", "test_conf")
    Environment.noargs = True
    env = Environment.getInstance()

    if has_dbus:
        # Enable DBus runner
        dr = DBusRunner()
        dr.start()

    PluginRegistry(component='gosa.client.module')  # @UnusedVariable
    env.active = True

    def shutdown():
        env.active = False

        # Wait for threads to shut down
        for t in env.threads:
            if hasattr(t, 'stop'):
                t.stop()
            if hasattr(t, 'cancel'):
                t.cancel()
            t.join(2)

        PluginRegistry.shutdown()
        if has_dbus:
            dr.stop()

    request.addfinalizer(shutdown)
Beispiel #2
0
def use_test_config(request):
    env = Environment.getInstance()

    if has_dbus:
        # Enable DBus runner
        dr = DBusRunner()
        dr.start()

    PluginRegistry(component='gosa.client.module')  # @UnusedVariable
    env.active = True

    def shutdown():
        env.active = False

        # Wait for threads to shut down
        for t in env.threads:
            if hasattr(t, 'stop'):
                t.stop()
            if hasattr(t, 'cancel'):
                t.cancel()
            t.join(2)

        PluginRegistry.shutdown()
        if has_dbus:
            dr.stop()

    request.addfinalizer(shutdown)
Beispiel #3
0
def main():
    """
    Main programm which is called when the GOsa backend process gets started.
    It does the main forking os related tasks.
    """

    # Enable DBus runner
    dr = DBusRunner()
    dr.start()

    # Set process list title
    os.putenv('SPT_NOENV', 'non_empty_value')
    setproctitle("gosa-session")

    description = 'Helper commands to notify the GOsa backend about active user sessions on the client.'
    parser = argparse.ArgumentParser(description=description)
    parser.add_argument(
        '-m',
        '--mode',
        dest="mode",
        type=str,
        help='"start" or "end" to specify the user session state')
    parser.add_argument('-u',
                        '--user',
                        dest="user",
                        type=str,
                        help='user name')

    options, unknown = parser.parse_known_args()

    # Initialize core environment
    env = Environment.getInstance()
    notify_backend(env, options.mode, options.user)
Beispiel #4
0
    def __init__(self):
        env = Environment.getInstance()
        self.env = env
        self.__dr = DBusRunner.get_instance()
        self.__bus = None

        # Register for resume events
        zope.event.subscribers.append(self.__handle_events)
Beispiel #5
0
    def __init__(self):
        self.log = logging.getLogger(__name__)

        # Get a dbus proxy and check if theres a service registered called 'org.gosa'
        # if not, then we can skip all further processing. (The gosa-dbus seems not to be running)
        self.__dr = DBusRunner.get_instance()
        self.bus = self.__dr.get_system_bus()
        self.methods = {}
Beispiel #6
0
    def __init__(self):
        env = Environment.getInstance()
        self.env = env
        self.__dr = DBusRunner.get_instance()
        self.__bus = None

        # Register for resume events
        zope.event.subscribers.append(self.__handle_events)
Beispiel #7
0
    def __init__(self):
        env = Environment.getInstance()
        self.env = env
        self.__dr = DBusRunner.get_instance()
        self.__bus = None
        self.__notify_backend = env.config.getboolean("client.dbus-login", default=True)

        # Register for resume events
        zope.event.subscribers.append(self.__handle_events)
Beispiel #8
0
    def __init__(self):
        env = Environment.getInstance()
        self.env = env
        self.__dr = DBusRunner.get_instance()
        self.__bus = None
        self.__notify_backend = env.config.getboolean("client.dbus-login", default=True)

        # Register for resume events
        zope.event.subscribers.append(self.__handle_events)
Beispiel #9
0
    def __init__(self):
        env = Environment.getInstance()
        self.env = env
        self.log = logging.getLogger(__name__)

        # Register ourselfs for bus changes on org.freedesktop.login1
        dr = DBusRunner.get_instance()
        self.bus = dr.get_system_bus()
        self.bus.watch_name_owner("org.freedesktop.login1", self.__dbus_proxy_monitor)
Beispiel #10
0
    def __init__(self):
        env = Environment.getInstance()
        self.env = env
        self.log = logging.getLogger(__name__)

        # Register ourselfs for bus changes on org.gosa
        dr = DBusRunner.get_instance()
        self.bus = dr.get_system_bus()
        self.bus.watch_name_owner("org.gosa", self.__dbus_proxy_monitor)
Beispiel #11
0
    def __init__(self):
        env = Environment.getInstance()
        self.env = env
        self.log = logging.getLogger(__name__)

        # Register ourselfs for bus changes on org.gosa
        dr = DBusRunner.get_instance()
        self.bus = dr.get_system_bus()
        self.bus.watch_name_owner("org.gosa", self.__dbus_proxy_monitor)

        # Create icon cache directory
        self.spool = env.config.get("client.spool", default="/var/spool/gosa")
Beispiel #12
0
    def __init__(self):
        env = Environment.getInstance()
        self.env = env
        self.log = logging.getLogger(__name__)

        # Register ourselfs for bus changes on org.gosa
        dr = DBusRunner.get_instance()
        self.bus = dr.get_system_bus()
        self.bus.watch_name_owner("org.gosa", self.__dbus_proxy_monitor)

        # Create icon cache directory
        self.spool = env.config.get("client.spool", default="/var/spool/gosa")
Beispiel #13
0
    def startAvahi(self):
        self.__runner = DBusRunner.get_instance()
        bus = self.__runner.get_system_bus()
        self.__server = dbus.Interface(
                            bus.get_object(avahi.DBUS_NAME, '/'),
                            'org.freedesktop.Avahi.Server')

        # Register for all types we're interested in
        for reg_type in self.__regtypes:
            self.__registerServiceTypeAvahi(reg_type)

        self.__runner.start()
Beispiel #14
0
    def __init__(self, callback=None):
        self.__callback = callback
        self.log = getLogger(__name__)
        self.__running = False
        self.__thread = None

        self.log.info("Initializing network state monitor")

        # Initialize DBUS
        dr = DBusRunner.get_instance()
        self.__bus = dr.get_system_bus()

        # Register actions to detect the network state
        self.__upower_actions()
        self.__network_actions()

        # Get current state
        try:
            proxy = self.__bus.get_object('org.freedesktop.NetworkManager',
                                          '/org/freedesktop/NetworkManager')
            iface = dbus.Interface(proxy, 'org.freedesktop.DBus.Properties')

            version = str(
                iface.Get("org.freedesktop.NetworkManager", "Version"))
            if tuple(version.split(".")) < ("0", "9"):
                self.log.warning(
                    "network-manager is too old: defaulting to state 'online'")
                self.__state = True

            else:
                # Register actions to detect the network state
                self.__upower_actions()
                self.__network_actions()

                self.__state = iface.Get("org.freedesktop.NetworkManager",
                                         "State") in [
                                             NM_STATE_CONNECTED_SITE,
                                             NM_STATE_CONNECTED_GLOBAL
                                         ]

        except:
            self.log.warning(
                "no network-manager detected: defaulting to state 'online'")
            self.__state = True
Beispiel #15
0
    def __init__(self, callback=None):
        self.__callback = callback
        self.log = getLogger(__name__)
        self.__running = False
        self.__thread = None

        self.log.info("Initializing network state monitor")

        # Initialize DBUS
        dr = DBusRunner.get_instance()
        self.__bus = dr.get_system_bus()

        # Register actions to detect the network state
        self.__upower_actions()
        self.__network_actions()

        # Get current state
        try:
            proxy = self.__bus.get_object('org.freedesktop.NetworkManager', '/org/freedesktop/NetworkManager')
            iface = dbus.Interface(proxy, 'org.freedesktop.DBus.Properties')

            version = str(iface.Get("org.freedesktop.NetworkManager", "Version"))
            if tuple(version.split(".")) < ("0", "9"):
                self.log.warning("network-manager is too old: defaulting to state 'online'")
                self.__state = True

            else:
                # Register actions to detect the network state
                self.__upower_actions()
                self.__network_actions()

                self.__state = iface.Get("org.freedesktop.NetworkManager", "State") in [NM_STATE_CONNECTED_SITE, NM_STATE_CONNECTED_GLOBAL]

        except:
            self.log.warning("no network-manager detected: defaulting to state 'online'")
            self.__state = True
Beispiel #16
0
 def serve(self):
     # Register ourselfs for bus changes on org.gosa
     dr = DBusRunner.get_instance()
     self.bus = dr.get_system_bus()
     self.bus.watch_name_owner("org.gosa", self.__dbus_proxy_monitor)
Beispiel #17
0
 def serve(self):
     # Register ourselfs for bus changes on org.freedesktop.login1
     dr = DBusRunner.get_instance()
     self.bus = dr.get_system_bus()
     self.bus.watch_name_owner("org.freedesktop.login1",
                               self.__dbus_proxy_monitor)
Beispiel #18
0
def mainLoop(env):
    global netstate, dr

    # Enable DBus runner
    dr = DBusRunner()
    dr.start()

    # Do network monitoring
    nm = Monitor(netactivity)
    netactivity(nm.is_online())

    """ Main event loop which will process all registered threads in a loop.
        It will run as long env.active is set to True."""
    try:
        log = logging.getLogger(__name__)

        while True:

            # Check netstate and wait until we're back online
            if not netstate:
                log.info("waiting for network connectivity")
            while not netstate:
                time.sleep(1)

            # Load plugins
            PluginRegistry(component='gosa.client.module')

            # Sleep and slice
            wait = 2
            while True:
                # Threading doesn't seem to work well with python...
                for p in env.threads:

                    # Bail out if we're active in the meanwhile
                    if not env.active:
                        break

                    p.join(wait)

                # No break, go to main loop
                else:
                    continue

                # Break, leave main loop
                break

            # Break, leave main loop
            if not env.reset_requested:
                break

            # Wait for threads to shut down
            for t in env.threads:
                if hasattr(t, 'stop'):
                    t.stop()
                if hasattr(t, 'cancel'):
                    t.cancel()
                t.join(wait)

                #TODO: remove me
                if t.is_alive():
                    try:
                        t._stop()
                    except:
                        print(str(t.getName()) + ' could not be terminated')

            # Lets do an environment reset now
            PluginRegistry.shutdown()

            # Make us active and loop from the beginning
            env.reset_requested = False
            env.active = True

            if not netstate:
                log.info("waiting for network connectivity")
            while not netstate:
                time.sleep(1)

            sleep = randint(30, 60)
            env.log.info("waiting %s seconds to try an MQTT connection recovery" % sleep)
            time.sleep(sleep)

    except Exception as detail:
        log.critical("unexpected error in mainLoop")
        log.exception(detail)
        log.debug(traceback.format_exc())

    except KeyboardInterrupt:
        log.info("console requested shutdown")

    finally:
        shutdown()
Beispiel #19
0
def mainLoop(env):
    global netstate, dr

    # Enable DBus runner
    dr = DBusRunner()
    dr.start()

    # Do network monitoring
    nm = Monitor(netactivity)
    netactivity(nm.is_online())
    """ Main event loop which will process all registered threads in a loop.
        It will run as long env.active is set to True."""
    try:
        log = logging.getLogger(__name__)

        while True:

            # Check netstate and wait until we're back online
            if not netstate:
                log.info("waiting for network connectivity")
            while not netstate:
                time.sleep(1)

            # Load plugins
            PluginRegistry(component='gosa.client.module')

            # Sleep and slice
            wait = 2
            while True:
                # Threading doesn't seem to work well with python...
                for p in env.threads:

                    # Bail out if we're active in the meanwhile
                    if not env.active:
                        break

                    p.join(wait)

                # No break, go to main loop
                else:
                    continue

                # Break, leave main loop
                break

            # Break, leave main loop
            if not env.reset_requested:
                break

            # Wait for threads to shut down
            for t in env.threads:
                if hasattr(t, 'stop'):
                    t.stop()
                if hasattr(t, 'cancel'):
                    t.cancel()
                t.join(wait)

                #TODO: remove me
                if t.is_alive():
                    try:
                        t._stop()
                    except:
                        print(str(t.getName()) + ' could not be terminated')

            # Lets do an environment reset now
            PluginRegistry.shutdown()

            # Make us active and loop from the beginning
            env.reset_requested = False
            env.active = True

            if not netstate:
                log.info("waiting for network connectivity")
            while not netstate:
                time.sleep(1)

            sleep = randint(30, 60)
            env.log.info(
                "waiting %s seconds to try an MQTT connection recovery" %
                sleep)
            time.sleep(sleep)

    except Exception as detail:
        log.critical("unexpected error in mainLoop")
        log.exception(detail)
        log.debug(traceback.format_exc())

    except KeyboardInterrupt:
        log.info("console requested shutdown")

    finally:
        shutdown()