Example #1
0
    def run(self):

        # lock a tmp file to avoid starting multiple daemons
        self.lockf = open("/tmp/clipon-lock", "w")
        try:
            fcntl.flock(self.lockf, fcntl.LOCK_EX | fcntl.LOCK_NB)
        except BlockingIOError:
            logger.error("Unable to lock file")
            return

        self.setup()

        self.cfg = CliponConfig(self.cfg_file)
        self.cfg.load()
        self.cfg.save()

        self.history = ClipHistory(self.cfg)

        self.monitor = ClipboardMonitor(self.history)
        self.monitor.start()

        dbus_loop = DBusGMainLoop()
        bus_name = dbus.service.BusName(CLIPON_BUS_NAME, bus=dbus.SessionBus(mainloop=dbus_loop))
        dbus.service.Object.__init__(self, bus_name, CLIPON_OBJ_PATH)

        GObject.threads_init()  # should be called before mainloop
        self.main_loop = GObject.MainLoop()

        self.status = "active"
        try:
            logger.info("DBus service started")
            self.main_loop.run()
        except (KeyboardInterrupt, SystemExit):
            self.stop()
Example #2
0
def push_email(to_address, email_subject, email_message, reply_to_address, cc_addresses=[]):
    if config.getboolean("MAIL_CONF", "mail_active"):
        logger.debug("Sending mail to %s with subject %s" % (to_address, email_subject))
        rtn = mail.send(
            to=to_address, subject=email_subject, message=email_message, reply_to=reply_to_address, cc=cc_addresses
        )
        logger.error("ERROR:: " + str(mail.error))
        logger.info("EMAIL STATUS:: " + str(rtn))
Example #3
0
    def config(self, key, value):
        method = self.cfg.get_method(key)
        if method is None:
            logger.error("No method for key %s" % key)
            return False

        logger.info("Setting option %s to value %s" % (key, value))
        return method(value)
Example #4
0
def login_ldap_callback(form):
    if current.auth.is_logged_in():
        user_name = current.auth.user.username
        if current.db.user(username=user_name)["last_name"] == "":
            user_info = fetch_ldap_user(user_name)
            if user_info:
                create_or_update_user(user_info, True)
            else:
                logger.error("Unable To Update User Info!!!")
Example #5
0
def fetch_ldap_user(username):
    ldap_url = config.get("LDAP_CONF", "ldap_url")
    base_dn = config.get("LDAP_CONF", "ldap_dn")

    import ldap

    try:
        l = ldap.open(ldap_url)
        l.protocol_version = ldap.VERSION3
    except ldap.LDAPError, e:
        logger.error(e)
        return None
Example #6
0
    def __init__(self, file_name):
        try:
            self.tree = self.parse(file_name)
        except ET.ParseError:
            logger.error(str(ET.ParseError))
            if os.path.getsize(file_name) > 0:
                raise Exception("Error parsing file %s" % file_name)
            # create a new tree if the file is empty
            self.create_tree()

        if self.tree is None:
            return

        self.root = self.tree.getroot()
        if self.root is None:
            self.create_tree()

        if self.root.tag != self.ROOT_TAG:
            raise Exception("Invalid root element")

        self.file_name = file_name

        self.save()
Example #7
0
                                    user_info["last_name"] = vals[0][vals[0].index(" ") :].lstrip()
        #                             if k == 'altEmail':
        #                                 if vals[0] != 'none':
        #                                     user_info['email'] = vals[0]

        # TODO: find role and organisation from ldap and set in db accordingly (current iitd ldap does not support this feature entirely)
        user_info["email"] = username + config.get("MAIL_CONF", "email_domain")
        user_info["roles"] = fetch_user_role(username)
        # If user has super admin rights; it is added to separate organization
        if current.ADMIN in user_info["roles"]:
            user_info["organisation"] = "ADMIN"
        else:
            user_info["organisation"] = "IITD"

    except ldap.LDAPError, e:
        logger.error(e)

    logger.info(user_info)
    if "first_name" in user_info:
        return user_info
    else:
        return None


# This method is called only when user logs in for the first time or when faculty name is verified on 'request VM' screen
def create_or_update_user(user_info, update_session):

    user_name = user_info["user_name"]
    user = current.db(current.db.user.username == user_name).select().first()

    if not user:
Example #8
0
def get_vm_operations(vm_id):

    vm_operations = {
        "start_vm": ("user", "on-off.png", "Turn on this virtual machine"),
        "suspend_vm": ("user", "pause2.png", "Suspend this Virtual Machine"),
        "resume_vm": ("user", "play2.png", "Unpause this virtual machine"),
        "stop_vm": ("user", "shutdown2.png", "Gracefully shut down this virtual machine"),
        "destroy_vm": ("user", "on-off.png", "Forcefully power off this virtual machine"),
        "clone_vm": ("user", "clonevm.png", "Request VM Clone"),
        "attach_extra_disk": ("user", "disk.jpg", "Attach Extra Disk"),
        "snapshot": ("user", "snapshot.png", "Take VM snapshot"),
        "edit_vm_config": ("user", "editme.png", "Edit VM Config"),
        "show_vm_performance": ("user", "performance.jpg", "Check VM Performance"),
        "vm_history": ("user", "history.png", "Show VM History"),
        "grant_vnc": ("user", "vnc.jpg", "Grant VNC Access"),
        "confirm_vm_deletion()": (None, "delete.png", "Delete this virtual machine"),
        "migrate_vm": ("admin", "migrate.png", "Migrate this virtual machine"),
        "user_details": ("admin", "user_add.png", "Add User to VM"),
        "save_as_template": ("user", "save.png", "Save as Template"),
        "mail_user": ("admin", "email_icon.png", "Send Mail to users of the VM"),
        "affinity_host": ("admin", "affinity.png", "Set Affinity"),
    }

    valid_operations_list = []

    vm_status = db.vm_data[vm_id].status

    if vm_status not in (VM_STATUS_UNKNOWN, VM_STATUS_IN_QUEUE):
        valid_operations = ["snapshot", "show_vm_performance", "affinity_host"]

        if vm_status == VM_STATUS_RUNNING:
            valid_operations.extend(["suspend_vm", "stop_vm", "destroy_vm"])
        elif vm_status == VM_STATUS_SUSPENDED:
            valid_operations.extend(["resume_vm"])
        elif vm_status == VM_STATUS_SHUTDOWN:
            # Start VM option is not valid if edit VM or attach disk option is in queue
            if not (is_request_in_queue(vm_id, VM_TASK_EDIT_CONFIG) | is_request_in_queue(vm_id, VM_TASK_ATTACH_DISK)):
                valid_operations.extend(["start_vm"])

            valid_operations.extend(["clone_vm", "edit_vm_config", "attach_extra_disk", "save_as_template"])

        if not is_vm_user():
            valid_operations.extend(["confirm_vm_deletion()"])
            if is_moderator():
                valid_operations.extend(["migrate_vm"])
                valid_operations.extend(["user_details"])
                valid_operations.extend(["mail_user"])

        valid_operations.extend(["grant_vnc", "vm_history"])

        # Disable all links if Delete VM option is in queue
        link_disabled = True if is_request_in_queue(vm_id, VM_TASK_DELETE) else False
        for valid_operation in valid_operations:

            op_data = vm_operations[valid_operation]
            op_image = IMG(_src=URL("static", "images/" + op_data[1]), _style="height:20px;weight:20px")

            if link_disabled:
                valid_operations_list.append(op_image)
            else:
                if op_data[0] != None:
                    valid_operations_list.append(
                        A(
                            op_image,
                            _title=op_data[2],
                            _alt=op_data[2],
                            _href=URL(r=request, c=op_data[0], f=valid_operation, args=[vm_id]),
                        )
                    )
                else:
                    valid_operations_list.append(
                        A(op_image, _title=op_data[2], _alt=op_data[2], _onclick=valid_operation)
                    )

    else:
        logger.error("INVALID VM STATUS!!!")
        raise
    return valid_operations_list