Exemplo n.º 1
0
import select
import requests
import logging
from zipfile import ZipFile
from zipfile import BadZipfile
from zipfile import zlib
from threading import Thread
from threading import Lock
from threading import Timer
import Queue  # for windows
from uuid import getnode as get_mac_address
from requests.exceptions import ConnectionError
from application.config_base import Config
from application.utils import http_request

MAC_ADDRESS = get_mac_address()  # the MAC address of the worker
PLATFORM = platform.system()
SYSTEM = PLATFORM + ' ' + platform.release()
PROCESS = None
LOCK = Lock()
ACTIVITY = None
LOG = None
TIME_INIT = None
CONNECTIVITY = False
FLAMENCO_MANAGER = Config.FLAMENCO_MANAGER
HOSTNAME = Config.HOSTNAME

if platform.system() is not 'Windows':
    from fcntl import fcntl, F_GETFL, F_SETFL
    from signal import SIGKILL
else:
Exemplo n.º 2
0
from threading import Lock
from threading import Timer
import Queue # for windows

from flask import redirect
from flask import url_for
from flask import request
from flask import jsonify

from uuid import getnode as get_mac_address

from application import app
from application import clean_dir
from requests.exceptions import ConnectionError

MAC_ADDRESS = get_mac_address()  # the MAC address of the worker
PLATFORM = platform.system()
SYSTEM = PLATFORM + ' ' + platform.release()
PROCESS = None
LOCK = Lock()
ACTIVITY = None
LOG = None
TIME_INIT = None
CONNECTIVITY = False
FLAMENCO_MANAGER = app.config['FLAMENCO_MANAGER']
HOSTNAME = app.config['HOSTNAME']
#HOSTNAME = app.config['']

if platform.system() is not 'Windows':
    from fcntl import fcntl, F_GETFL, F_SETFL
    from signal import SIGKILL
Exemplo n.º 3
0
#!python3

# from the standard library
import configparser
import os
import sys
from uuid import getnode as get_mac_address

# our code
from Database import Database

config_file_path = "config.ini"

# Look at Command Line for Overrides
if 1 < len(sys.argv):
    if os.path.isfile(sys.argv[1]):
        # override default config file
        config_file_path = sys.argv[1]
    # else print help message?

# Read our Configuration
settings = configparser.ConfigParser()
settings.read(config_file_path)

mac_address = format(get_mac_address(), 'x')

db = Database(settings['db'])
is_registered = db.is_registered(mac_address)
if not is_registered:
    db.register(mac_address)
Exemplo n.º 4
0
    def run(self):
        '''
        Actually get ready to run... we defered initialization in order to
        configure signal handlers in __main__ but they should now be in place

        This corresponds to the transition from Start in FSM.odg see docs
        '''

        # Step 1 Do a bit of a dance to show we are running
        logging.info("Setting display color to wipe red")
        self.box.set_display_color_wipe(RED, 10)
        logging.info("Started PortalBoxApplication.run()")

        # Set 2 Figure out our identity
        mac_address = format(get_mac_address(), 'x')
        logging.info("Discovered Mac Address: %s", mac_address)

        # connect to backend database
        logging.info("Connecting to database on host %s", self.settings['db']['host'])
        try:
            logging.debug("Creating database instance")
            self.db = Database(self.settings['db'])
            logging.info("Connected to Database")
        except Exception as e:
            logging.error("{}".format(e))
            sys.exit(1)

        # be prepared to send emails
        try:
            logging.info("Creating emailer instance")
            self.emailer = Emailer(self.settings['email'])
            logging.info("Cached email settings")
        except Exception as e:
            # should be unreachable
            logging.error("{}".format(e))
            sys.exit(1)

        # give user hint we are makeing progress 
        logging.debug("Setting display color to wipe orange")
        self.box.set_display_color_wipe(ORANGE, 10)

        # determine what we are
        profile = (-1,)
        self.running = True
        while self.running and 0 > profile[0]:
            feed_watchdog("equipment_profile")
            logging.info("Trying to get equipment profile")
            profile = self.db.get_equipment_profile(mac_address)
            if 0 > profile[0]:
                sleep(5)

        # only run if we have role, which we might not if systemd asked us to
        # shutdown before we discovered a role
        if 0 < profile[0]:
            # profile:
            #   (int) equipment id
            #   (int) equipment type id
            #   (str) equipment type
            #   (int) location id
            #   (str) location
            #   (int) time limit in minutes
            self.equipment_id = profile[0]
            self.equipment_type_id = profile[1]
            self.equipment_type = profile[2]
            self.location = profile[4]
            self.timeout_period = profile[5]

            logging.info("Discovered identity. Type: %s(%s) Timeout: %s m",
                    self.equipment_type,
                    self.equipment_type_id,
                    self.timeout_period)
            self.db.log_started_status(self.equipment_id)

            logging.info("Setting display to wipe green")
            self.box.set_display_color_wipe(GREEN, 10)
            self.timeout_period *= 60 # python threading wants seconds, DB has minutes
            self.proxy_uid = -1
            self.training_mode = False
            logging.info("Starting to wait for access card")
            self.wait_for_access_card()
        else:
            logging.info("Running ending; did not discover identity.")
            sys.exit(1)
    def captureEnvData(self):
        if os.name == 'nt':
            # OS specific
            self.envData.append(EnvironmentalDependency("os_name", Format.STRING, 'Windows'))
            self.envData.append(EnvironmentalDependency("os_family", Format.STRING, os.name))  # TODO cmd /c Ver
            self.envData.append(EnvironmentalDependency("os_version", Format.STRING, ''))  # TODO cmd /c Ver
            self.envData.append(EnvironmentalDependency("os_arch", Format.STRING, os.environ['PROCESSOR_ARCHITECTURE']))
            # User specific
            self.envData.append(EnvironmentalDependency("user_home_dir", Format.STRING, os.environ['USERPROFILE']))
            self.envData.append(EnvironmentalDependency("user_lang", Format.STRING, ''))  # TODO
        else:
            # OS specific
            self.envData.append(EnvironmentalDependency("os_name", Format.STRING, os.uname()[0]))  # for example 'Linux'
            self.envData.append(EnvironmentalDependency("os_family", Format.STRING, os.name))  # for example 'posix', 'nt', 'os2', 'ce', 'java', 'riscos'
            self.envData.append(EnvironmentalDependency("os_version", Format.STRING, os.uname()[2]))  # result of 'uname -r' under linux
            self.envData.append(EnvironmentalDependency("os_arch", Format.STRING, os.uname()[4]))  # result of 'uname -m' under linux
            # User specific
            if 'HOME' in os.environ:
                self.envData.append(EnvironmentalDependency("user_home_dir", Format.STRING, os.environ['HOME']))
            if 'LANG' in os.environ:
                self.envData.append(EnvironmentalDependency("user_lang", Format.STRING, os.environ['LANG']))

        # User specific
        if 'USERNAME' in os.environ:
            self.envData.append(EnvironmentalDependency("user_name", Format.STRING, os.environ['USERNAME']))

        # System specific
        self.envData.append(EnvironmentalDependency("hostname", Format.STRING, socket.gethostname()))
        self.envData.append(EnvironmentalDependency("domainname", Format.STRING, "".join(socket.getfqdn().split(".", 1)[1:])))

        # Trick to retrieve the usual IP address
        try:
            s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
            s.connect(("gmail.com", 80))
            ip_address = s.getsockname()[0]
            s.close()
        except:
            ip_address = "127.0.0.1"

        self.envData.append(EnvironmentalDependency("ip_address", Format.STRING, ip_address))
        self.envData.append(EnvironmentalDependency("mac_address", Format.STRING, hex(int(get_mac_address()))[2:-1]))

        # Misc
        self.envData.append(EnvironmentalDependency("date", Format.STRING, str(time.time())))  # elapsed second since epoch in UTC
    def captureEnvData(self):
        if os.name == 'nt':
            # OS specific
            self.envData.append(
                EnvironmentalDependency("os_name", Format.STRING, 'Windows'))
            self.envData.append(
                EnvironmentalDependency("os_family", Format.STRING,
                                        os.name))  # TODO cmd /c Ver
            self.envData.append(
                EnvironmentalDependency("os_version", Format.STRING,
                                        ''))  # TODO cmd /c Ver
            self.envData.append(
                EnvironmentalDependency("os_arch", Format.STRING,
                                        os.environ['PROCESSOR_ARCHITECTURE']))
            # User specific
            self.envData.append(
                EnvironmentalDependency("user_home_dir", Format.STRING,
                                        os.environ['USERPROFILE']))
            self.envData.append(
                EnvironmentalDependency("user_lang", Format.STRING,
                                        ''))  # TODO
        else:
            # OS specific
            self.envData.append(
                EnvironmentalDependency("os_name", Format.STRING,
                                        os.uname()[0]))  # for example 'Linux'
            self.envData.append(
                EnvironmentalDependency("os_family", Format.STRING, os.name)
            )  # for example 'posix', 'nt', 'os2', 'ce', 'java', 'riscos'
            self.envData.append(
                EnvironmentalDependency(
                    "os_version", Format.STRING,
                    os.uname()[2]))  # result of 'uname -r' under linux
            self.envData.append(
                EnvironmentalDependency(
                    "os_arch", Format.STRING,
                    os.uname()[4]))  # result of 'uname -m' under linux
            # User specific
            if 'HOME' in os.environ:
                self.envData.append(
                    EnvironmentalDependency("user_home_dir", Format.STRING,
                                            os.environ['HOME']))
            if 'LANG' in os.environ:
                self.envData.append(
                    EnvironmentalDependency("user_lang", Format.STRING,
                                            os.environ['LANG']))

        # User specific
        if 'USERNAME' in os.environ:
            self.envData.append(
                EnvironmentalDependency("user_name", Format.STRING,
                                        os.environ['USERNAME']))

        # System specific
        self.envData.append(
            EnvironmentalDependency("hostname", Format.STRING,
                                    socket.gethostname()))
        self.envData.append(
            EnvironmentalDependency(
                "domainname", Format.STRING,
                "".join(socket.getfqdn().split(".", 1)[1:])))

        # Trick to retrieve the usual IP address
        try:
            s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
            s.connect(("gmail.com", 80))
            ip_address = s.getsockname()[0]
            s.close()
        except:
            ip_address = "127.0.0.1"

        self.envData.append(
            EnvironmentalDependency("ip_address", Format.STRING, ip_address))
        self.envData.append(
            EnvironmentalDependency("mac_address", Format.STRING,
                                    hex(int(get_mac_address()))[2:-1]))

        # Misc
        self.envData.append(
            EnvironmentalDependency("date", Format.STRING, str(
                time.time())))  # elapsed second since epoch in UTC