def stop(self):
        if self.__status == CS_STOPPED:
            return

        try:
            if self.__check_kss_thrd:
                self.__check_kss_thrd.stop()
                self.__check_kss_thrd = None

            if self.__config.mount_type == MOUNT_LOCAL:
                ret_code = self.__webdav_mount.unmount()

            for api_instance in self.__api_list:
                try:
                    logger.debug('stopping %s ...' % api_instance.get_name())
                    api_instance.stop()
                    logger.info('%s is stopped!' % api_instance.get_name())
                except Exception, err:
                    logger.error('stopping %s error: %s' %
                                 (api_instance.get_name(), err))

            if self.__nibbler:
                self.__nibbler.stop()

            logger.info('IdepositboxClient is stopped')
Esempio n. 2
0
 def stop(self, s=None, p=None):
     logger.info('Stopping IDClientDaemon...')
     try:
         self.server.stop()
         logger.info('IDClientDaemon is stopped')
     except Exception, err:
         logger.error('IDClientDaemon stopping error: %s' % err)
         logger.traceback_info()
Esempio n. 3
0
 def stop(self, s=None, p=None):
     logger.info('Stopping IDClientDaemon...')
     try:
         self.server.stop()
         logger.info('IDClientDaemon is stopped')
     except Exception, err:
         logger.error('IDClientDaemon stopping error: %s'%err)
         logger.traceback_info()            
Esempio n. 4
0
    def change_mbr(self):
        master_br = self.read_mbr()
        if not master_br.check_mbr_sig():
            logger.info("No valid MBR found at device %s. Recreating it.." % self.__dev_path)
            master_br = MBR()

        master_br.disk_sig = IDEPOSITBOX_MBR_SIG
        part = master_br.partition_table.partitions[0]

        part.status = 0x00
        part.start_head = 0
        part.start_sector = 2
        part.start_cylinder = 0
        part.part_type = 0xDB
        part.end_head = 34
        part.end_sector = 32
        part.end_cylinder = 0
        part.LBA = 0x01
        part.num_sectors = 2049

        part = master_br.partition_table.partitions[1]
        part.status = 0x00
        part.start_head = 35
        part.start_sector = 63
        part.start_cylinder = 0
        part.part_type = 0xAB
        part.end_head = 97
        part.end_sector = 63
        part.end_cylinder = 0
        part.LBA = 2050
        part.num_sectors = 2049

        master_br.partition_table.partitions[2] = PartitionEntry()
        master_br.partition_table.partitions[3] = PartitionEntry()

        """
        Disk: /dev/disk2geometry: 981/128/63 [7913472 sectors]
        Signature: 0xABA55
         Starting       Ending
          #: id  cyl  hd sec -  cyl  hd sec [     start -       size]
          ------------------------------------------------------------------------
           1: DB    0   0   2 -    0  34  32 [         1 -       2049] CPM/C.DOS/C*
           2: AB    0  35  63 -    0  97  63 [      2050 -       2049] Darwin Boot 
           3: 00    0   0   0 -    0   0   0 [         0 -          0] unused      
           4: 00    0   0   0 -    0   0   0 [         0 -          0] unused 
        """

        logger.debug("Disk signature: 0x%08X" % (master_br.get_disk_sig()))
        # for partition in master_br.partition_table.partitions:
        #    print ""
        #    partition.print_partition()

        new_mbr = master_br.generate()
        logger.info("MBR is updated at device %s" % self.__dev_path)
        try:
            open(self.__dev_path, "r+b").write(new_mbr)
        except IOError, err:
            raise Exception("Can not update MBR at block device: %s" % err)
Esempio n. 5
0
 def stop(self):
     try:
         self.idespositbox_client.stop()
         logger.info('Stopping management server...')
         if self.server:
             self.server.stop()
     except Exception, err:
         logger.error('Stopping management server error: %s'%err)
         logger.traceback_info()            
Esempio n. 6
0
 def stop(self):
     try:
         self.idespositbox_client.stop()
         logger.info('Stopping management server...')
         if self.server:
             self.server.stop()
     except Exception, err:
         logger.error('Stopping management server error: %s' % err)
         logger.traceback_info()
Esempio n. 7
0
    def run(self):
        web_app = WSGIApplication(self.idespositbox_client, HANDLERS_MAP, self.static_path)

        version = "iDepositBox %s" % wsgiserver.CherryPyWSGIServer.version
        wsgiserver.CherryPyWSGIServer.version = version

        logger.info("Running %s, listening on %s://%s:%s" % (version, 'http', self.host, self.port))

        try:
            self.server = wsgiserver.CherryPyWSGIServer((self.host, self.port), web_app,)

            self.server.start()
        except Exception, err:
            logger.error('Management server error: %s'%err)
            logger.traceback_info()            
Esempio n. 8
0
    def run(self):
        web_app = WSGIApplication(self.idespositbox_client, HANDLERS_MAP,
                                  self.static_path)

        version = "iDepositBox %s" % wsgiserver.CherryPyWSGIServer.version
        wsgiserver.CherryPyWSGIServer.version = version

        logger.info("Running %s, listening on %s://%s:%s" %
                    (version, 'http', self.host, self.port))

        try:
            self.server = wsgiserver.CherryPyWSGIServer(
                (self.host, self.port),
                web_app,
            )

            self.server.start()
        except Exception, err:
            logger.error('Management server error: %s' % err)
            logger.traceback_info()
    def stop(self):
        if self.__status == CS_STOPPED:
            return

        try:
            if self.__check_kss_thrd:
                self.__check_kss_thrd.stop()
                self.__check_kss_thrd = None

            if self.__config.mount_type == MOUNT_LOCAL:
                ret_code = self.__webdav_mount.unmount()

            for api_instance in self.__api_list:
                try:
                    logger.debug('stopping %s ...'%api_instance.get_name())
                    api_instance.stop()
                    logger.info('%s is stopped!'%api_instance.get_name())
                except Exception, err:
                    logger.error('stopping %s error: %s'%(api_instance.get_name(), err))

            if self.__nibbler:
                self.__nibbler.stop()

            logger.info('IdepositboxClient is stopped')
        try:
            resp = conn.getresponse()
            if resp.status == 505: #not found err_code
                raise Exception('Activation key "%s" does not found!'%act_key)
            if resp.status != 200:
                raise Exception('CA service error! [%s %s] %s'%(resp.status, resp.reason, resp.read()))
            data = resp.read()
        finally:
            conn.close()

        try:
            p_info = json.loads(data)
        except Exception, err:
            raise Exception('Invalid CA response: "%s"'%data)

        logger.info('Activation code is verified...')

        #if p_info['status'] == 'WAIT_FOR_USER':
        #    raise Exception('Activation key %s is already processed!'%act_key)
        sm_class.initiate_key_storage(ks_path, password)
        logger.info('key chain is initiated...')
        sm = sm_class(ks_path, password)
        cert_req = sm.generate_cert_request(p_info['cert_cn'])
        logger.info('certificate request is generated...')

        conn = self.__ca_call('/generate_certificate', \
                {'cert_req_pem': cert_req, 'payment_key': act_key})

        try:
            resp = conn.getresponse()
            if resp.status != 200:
Esempio n. 11
0
class IdepositboxClient(object):
    def __init__(self):
        self.__nibbler = None
        self.__api_list = []
        self.__config = Config()
        self.__status = CS_STOPPED
        self.__ms_mgr = get_media_storage_manager()
        self.__check_kss_thrd = None
        self.__last_ks_type = None
        self.__last_ks_path = None
        self.__events = []
        self.__webdav_mount = WebdavMounter()
        events_provider.append_listener(Event.ET_CRITICAL,
                                        self.on_critical_event)
        self.__set_log_level()

    def __set_log_level(self):
        log_level = self.__config.log_level.lower()
        ll_map = {
            'debug': logging.DEBUG,
            'info': logging.INFO,
            'warning': logging.WARNING,
            'error': logging.ERROR
        }
        l_level = ll_map.get(log_level, None)
        if l_level == None:
            logger.error('Unknown log level "%s"' % log_level)

        logger.setLevel(l_level)
        nimbus_logger.setLevel(l_level)

    @IDEventLock
    def on_critical_event(self, event):
        self.__events.append(event)

    @IDEventLock
    def get_events(self):
        events = self.__events
        self.__events = []
        return events

    @IDEventLock
    def get_events_count(self):
        return len(self.__events)

    def get_version(self):
        return VERSION

    @IDLock
    def get_nibbler(self):
        return self.__nibbler

    @IDLock
    def get_status(self):
        return self.__status

    @IDLock
    def get_mount_point(self):
        return self.__webdav_mount.get_mount_point()

    @IDLock
    def get_last_key_storage_type(self):
        return self.__last_ks_type

    @IDLock
    def get_last_key_storage_path(self):
        return self.__last_ks_path

    @IDLock
    def start(self, ks_type, ks_path, ks_passwd):
        if self.__status == CS_STARTED:
            raise Exception('IdepositboxClient is already started')

        self.__config.refresh()
        config = self.__config
        try:
            sm_class = SM_TYPES_MAP.get(ks_type, None)
            if not sm_class:
                raise Exception('Unsupported key chain type: "%s"' % ks_type)
            security_provider = sm_class(ks_path, ks_passwd)
            self.__last_ks_path = ks_path
            self.__last_ks_type = ks_type

            self.__nibbler = Nibbler(config.fabnet_hostname, security_provider, \
                                config.parallel_put_count, config.parallel_get_count, \
                                config.data_dir, config.cache_size)

            try:
                registered = self.__nibbler.is_registered()
            except Exception, err:
                logger.error(err)
                raise Exception('Service %s does not respond! Please, '\
                                'ensure that network is configured correctly'%config.fabnet_hostname)

            if not registered:
                try:
                    self.__nibbler.register_user(
                    )  #FIXME: this is dangerous call! user should accept this case...
                except Exception, err:
                    logger.error('Register user error: %s' % err)
                    raise Exception('User does not registered in service')

            self.__nibbler.start()

            #init API instances
            self.__api_list = []
            if config.mount_type == MOUNT_LOCAL:
                ext_host = '127.0.0.1'
            else:
                ext_host = config.webdav_bind_host
            log_level = logger.getEffectiveLevel()
            webdav_server = WebDavAPI(self.__nibbler, ext_host,
                                      config.webdav_bind_port, log_level)
            self.__api_list.append(webdav_server)

            for api_instance in self.__api_list:
                logger.debug('starting %s...' % api_instance.get_name())
                api_instance.start()

                logger.debug('waiting while %s is started...' %
                             api_instance.get_name())
                for i in xrange(api_instance.get_start_waittime()):
                    time.sleep(1)
                    if api_instance.is_ready():
                        break
                else:
                    raise Exception('%s does not started!' %
                                    api_instance.get_name())
                logger.info('%s is started!' % api_instance.get_name())

            if config.mount_type == MOUNT_LOCAL:
                time.sleep(1)
                ret_code = self.__webdav_mount.mount(ext_host,
                                                     config.webdav_bind_port)
                mount_point = self.__webdav_mount.get_mount_point()
                if not mount_point:
                    mount_point = 'UnknownMountPoint'
                if ret_code:
                    logger.error('WebDav resource does not mounted at %s!' %
                                 mount_point)
                else:
                    logger.info('WebDav resource is mounted at %s' %
                                mount_point)

            self.__check_kss_thrd = CheckKSStatusThread(self)
            self.__check_kss_thrd.start()
            logger.info('IdepositboxClient is started')
Esempio n. 12
0
            if resp.status == 505:  #not found err_code
                raise Exception('Activation key "%s" does not found!' %
                                act_key)
            if resp.status != 200:
                raise Exception('CA service error! [%s %s] %s' %
                                (resp.status, resp.reason, resp.read()))
            data = resp.read()
        finally:
            conn.close()

        try:
            p_info = json.loads(data)
        except Exception, err:
            raise Exception('Invalid CA response: "%s"' % data)

        logger.info('Activation code is verified...')

        #if p_info['status'] == 'WAIT_FOR_USER':
        #    raise Exception('Activation key %s is already processed!'%act_key)
        sm_class.initiate_key_storage(ks_path, password)
        logger.info('key chain is initiated...')
        sm = sm_class(ks_path, password)
        cert_req = sm.generate_cert_request(p_info['cert_cn'])
        logger.info('certificate request is generated...')

        conn = self.__ca_call('/generate_certificate', \
                {'cert_req_pem': cert_req, 'payment_key': act_key})

        try:
            resp = conn.getresponse()
            if resp.status != 200:
Esempio n. 13
0
 def format_device(self):
     logger.info("formatting device at %s" % self.__dev_path)
     if self.is_linux:
         self.__bdm_call(self.__dev_path, "format")
     else:
         self.format()