コード例 #1
0
ファイル: userby1.py プロジェクト: AdUser/karesansui
    def _PUT(self, *param, **params):
        user_id = param[0]
        if not validates_param_id(self, user_id):
            self.logger.debug("Failed to update account. the value of parameter is invalid.")
            return web.notfound(self.view.alert)

        if not validates_user(self):
            self.logger.debug("Failed to update account. the value of input is invalid.")
            return web.badrequest(self.view.alert)

        user = findby1(self.orm, user_id)
        if not user:
            self.logger.debug("Failed to update account. No such account - id=%s" % user_id)
            return web.notfound()

        cmp_user = findby1email(self.orm, self.input.email)
        if not cmp_user is None:
            if int(user_id) != cmp_user.id:
                self.logger.debug("Failed to update account. The same mail address '%s' already exist - user='******'" % (self.input.email, cmp_user.nickname))
                return web.conflict(web.ctx.path)

        user.nickname = self.input.nickname
        user.email = self.input.email
        user.languages = self.input.languages

        if not is_empty(self.input.new_password):
            if compare_password(self, user) == False:
                return web.badrequest(self.view.alert)

            (password, salt) = sha1encrypt(self.input.new_password)
            user.password = password
            user.salt = salt

        update(self.orm, user)
        return web.seeother(web.ctx.path)
コード例 #2
0
ファイル: http.py プロジェクト: goura/karesansui
def proxies(proxy_host, proxy_port, user=None, password=None, method="http"):

    if is_empty(user) is False and is_empty(password) is False \
           and is_empty(proxy_host) is False and is_empty(proxy_port) is False:

        return {method: "%s://%s:%s@%s:%s" \
                % (method,user,password,proxy_host,proxy_port)}

    elif is_empty(user) is False and is_empty(proxy_host) is False \
             and is_empty(proxy_port) is False:

        return {method: "%s://%s:@%s:%s" % (method,user,proxy_host,proxy_port)}

    elif is_empty(proxy_host) is False and is_empty(proxy_port) is False:
        return {method: "%s://%s:%s" % (method,proxy_host,proxy_port)}

    elif is_empty(proxy_host) is False:
        return {method: "%s://%s" % (method,proxy_host)}

    else:
        return None
コード例 #3
0
ファイル: http.py プロジェクト: goura/karesansui
def get_proxy(config):
    if is_proxy(config) is False:
        return None

    host = None
    port = None
    if config.has_key("application.proxy.server") is True:
        host = config["application.proxy.server"]

    if config.has_key("application.proxy.port") is True:
        port = config["application.proxy.port"]

    if is_empty(host) is True:
        return None, None

    return host, port
コード例 #4
0
ファイル: http.py プロジェクト: goura/karesansui
def get_proxy_user(config):
    if is_proxy(config) is False:
        return None

    user = ""
    password = ""

    if config.has_key("application.proxy.user") is True:
        user = config["application.proxy.user"]

    if config.has_key("application.proxy.password") is True:
        password = config["application.proxy.password"]

    if is_empty(user) is True:
        return None, None

    return user, password
コード例 #5
0
    def _PUT(self, *param, **params):
        user_id = param[0]
        if not validates_param_id(self, user_id):
            self.logger.debug(
                "Failed to update account. the value of parameter is invalid.")
            return web.notfound(self.view.alert)

        if not validates_user(self):
            self.logger.debug(
                "Failed to update account. the value of input is invalid.")
            return web.badrequest(self.view.alert)

        user = findby1(self.orm, user_id)
        if not user:
            self.logger.debug(
                "Failed to update account. No such account - id=%s" % user_id)
            return web.notfound()

        cmp_user = findby1email(self.orm, self.input.email)
        if not cmp_user is None:
            if int(user_id) != cmp_user.id:
                self.logger.debug(
                    "Failed to update account. The same mail address '%s' already exist - user='******'"
                    % (self.input.email, cmp_user.nickname))
                return web.conflict(web.ctx.path)

        user.nickname = self.input.nickname
        user.email = self.input.email
        user.languages = self.input.languages

        if not is_empty(self.input.new_password):
            if compare_password(self, user) == False:
                return web.badrequest(self.view.alert)

            (password, salt) = sha1encrypt(self.input.new_password)
            user.password = password
            user.salt = salt

        update(self.orm, user)
        return web.seeother(web.ctx.path)
コード例 #6
0
    def _GET(self, *param, **params):
        host_id = self.chk_hostby1(param)
        if host_id is None: return web.notfound()

        target = param[1]
        if target is None: return web.notfound()

        dev = param[2]
        if dev is None: return web.notfound()

        if not validates_report(self):
            self.logger.debug("Get report failed. Did not validate.")
            return web.badrequest(self.view.alert)

        today = datetime.datetime.today()

        if is_param(self.input, 'report_start_day') and not is_empty(self.input.report_start_day):
            start_day = str2datetime(self.input.report_start_day,
                                     DEFAULT_LANGS[self.me.languages]['DATE_FORMAT'][0])
        else:
            start_day = today - datetime.timedelta(1)

        if is_param(self.input, 'report_start_time') and not is_empty(self.input.report_start_time):
            (start_hour, start_minute) = self.input.report_start_time.split(':',2)
            start_hour = int(start_hour)
            start_minute = int(start_minute)
        else:
            start_hour = today.hour
            start_minute = today.minute

        if is_param(self.input, 'report_end_day') and not is_empty(self.input.report_end_day):
            end_day = str2datetime(self.input.report_end_day,
                                     DEFAULT_LANGS[self.me.languages]['DATE_FORMAT'][0])
        else:
            end_day = today

        if is_param(self.input, 'report_end_time') and not is_empty(self.input.report_end_time):
            (end_hour, end_minute) = self.input.report_end_time.split(':', 2)
            end_hour = int(end_hour)
            end_minute = int(end_minute)

        else:
            end_hour = today.hour
            end_minute = today.minute

        start_time = create_epochsec(start_day.year,
                                     start_day.month,
                                     start_day.day,
                                     start_hour,
                                     start_minute,
                                     )

        end_time = create_epochsec(end_day.year,
                                   end_day.month,
                                   end_day.day,
                                   end_hour,
                                   end_minute,
                                   )
        if int(start_time) > int(end_time):
            self.logger.error("Getting reports failed. Start time > end time.")
            return web.badrequest(_('Getting reports failed. Start time > end time.'))

        if is_param(self.input, 'type') and not is_empty(self.input.type):
            type = self.input.type
        else:
            type = "default"

        if is_param(self.input, 'host') and not is_empty(self.input.host):
            host = self.input.host
        else:
            host = None

        if is_param(self.input, 'libvirt_target') and not is_empty(self.input.libvirt_target):
            libvirt_target = self.input.libvirt_target
        else:
            libvirt_target = None

        rrd = RRD(self._, self.me.languages)
        if host is not None:
            if rrd.set_rrd_dir_host(host) is False:
                self.logger.debug("Get report failed. Target host not found.")
                return web.notfound()

        filepath = rrd.create_graph(target, dev, type, start_time, end_time, libvirt_target)

        if filepath != "":
            self.download.type = OUTPUT_TYPE_FILE
            self.download.file = filepath
            self.download.once = True

        return True
コード例 #7
0
ファイル: job.py プロジェクト: nabeken/karesansui
    def _GET(self, *param, **params):
        (check, edit) = validates_jobsearch(self)
        if check is False:
            return web.badrequest(self.view.alert)

        if edit is True:
            # user search
            users = findbyname_BM(self.orm, self.input.user)
            users_id = []
            for user in users:
                users_id.append(user.id)

            machine_name = self.input.name.strip()
            if is_empty(machine_name):
                machine_name = None

            if is_empty(self.input.start):
                start = None
            else:
                start = str2datetime(self.input.start, DEFAULT_LANGS[self.me.languages]["DATE_FORMAT"][0])
            if is_empty(self.input.end):
                end = None
            else:
                end = str2datetime(self.input.end, DEFAULT_LANGS[self.me.languages]["DATE_FORMAT"][0], True)

            # machine search
            m_m2js = m2mj_findbyall(self.orm, machine_name, start, end, users_id, True)
            if not m_m2js:
                self.logger.debug(
                    "Search m_m2js failed. "
                    "Did not exist m_m2js that in accord with these query. "
                    "name %s, user_id %s, start %s, end %s" % (machine_name, users_id, start, end)
                )
                return web.nocontent()

            self.view.m_m2js = m_m2js
            self.view.name = self.input.name
            self.view.user = self.input.user
            self.view.status = self.input.status
            self.view.start = self.input.start
            self.view.end = self.input.end

            jobgroup_ids = []
            for m_m2j in m_m2js:
                jobgroup_ids.append(m_m2j[1].jobgroup_id)
            jobgroup_status = self.input.status
            if is_empty(jobgroup_status):
                jobgroup_status = None

            jobgroups = jg_findbyalltype(
                self.pysilhouette.orm, JOBGROUP_TYPE["SERIAL"], jobgroup_ids, jobgroup_status, desc=True
            )
            if not jobgroups:
                self.logger.debug(
                    "Search jobgroups failed. "
                    "Did not exist jobgroups that in accord with these query. "
                    "jobgroup_ids %s, jobgroup_status %s" % (jobgroup_ids, jobgroup_status)
                )
                return web.nocontent()

        else:
            m_m2js = m2mj_findbyall(self.orm)
            self.view.m_m2js = m_m2js
            self.view.name = ""
            self.view.user = ""
            self.view.status = ""
            self.view.start = ""
            self.view.end = ""

            self.view.m_m2js = m_m2js

            jobgroup_ids = []
            for m_m2j in m_m2js:
                jobgroup_ids.append(m_m2j[1].jobgroup_id)

            jobgroups = jg_findbyalltype(self.pysilhouette.orm, JOBGROUP_TYPE["SERIAL"], jobgroup_ids, desc=True)

        self.view.JOBGROUP_STATUS = JOBGROUP_STATUS
        self.view.HYPERVISOR = MACHINE_HYPERVISOR

        if self.input.has_key("p") is True:
            start = int(self.input.p)
        else:
            start = 0
        self.view.date_format = DEFAULT_LANGS[self.me.languages]["DATE_FORMAT"][1]
        self.view.pager = Pager(jobgroups, start, JOB_LIST_RANGE)

        return True
コード例 #8
0
def validates_user(obj):
    checker = Checker()
    check = True

    _ = obj._
    checker.errors = []

    if not is_param(obj.input, 'nickname'):
        check = False
        checker.add_error(_('"%s" is required.') % _('User Name'))
    else:
        check = checker.check_username(
                _('User Name'),
                obj.input.nickname,
                CHECK_EMPTY | CHECK_LENGTH | CHECK_ONLYSPACE,
                min = USER_MIN_LENGTH,
                max = USER_MAX_LENGTH,
                ) and check

    if not is_param(obj.input, 'email'):
        check = False
        checker.add_error(_('"%s" is required.') % _('Mail Address'))
    else:
        check = checker.check_mailaddress(
                _('Mail Address'),
                obj.input.email,
                CHECK_EMPTY | CHECK_LENGTH | CHECK_VALID,
                min = EMAIL_MIN_LENGTH,
                max = EMAIL_MAX_LENGTH,
                ) and check

    _password_flag = True
    if not is_param(obj.input, 'password'):
        check = False
        _password_flag = False
        checker.add_error(_('"%s" is required.') % _('Password'))
    if not is_param(obj.input, 'retype'):
        check = False
        _password_flag = False
        checker.add_error(_('"%s" is required.') % _('Retype'))

    if _password_flag == True:
        if not is_empty(obj.input.password) or \
           not is_empty(obj.input.retype):
            check = checker.check_password(
                    _('Password'),
                    obj.input.password,
                    obj.input.password,
                    CHECK_EMPTY | CHECK_LENGTH,
                    min = PASSWORD_MIN_LENGTH,
                    max = PASSWORD_MAX_LENGTH,
                    ) and check

    check = checker.check_languages(
            _('Language'),
            obj.input.languages,
            CHECK_EMPTY | CHECK_VALID | CHECK_LENGTH,
            min = LANGUAGES_MIN_LENGTH,
            max = LANGUAGES_MAX_LENGTH,
            ) and check

    obj.view.alert = checker.errors
    return check
コード例 #9
0
ファイル: guestby1job.py プロジェクト: AdUser/karesansui
    def _GET(self, *param, **params):

        (host_id, guest_id) = self.chk_guestby1(param)
        if guest_id is None: return web.notfound()
        
        model = findbyguest1(self.orm, guest_id)
        # virt
        self.kvc = KaresansuiVirtConnection()
        try:
            domname = self.kvc.uuid_to_domname(model.uniq_key)
            if not domname: return web.notfound()
        finally:
            self.kvc.close()


        (check, edit) = validates_jobsearch(self)
        if check is False:
            return web.badrequest(self.view.alert)

        if edit is True:
            # user search
            users = findbyname_BM(self.orm, self.input.user)
            users_id = []

            for user in users:
                users_id.append(user.id)
            if is_empty(self.input.start):
                start = None
            else:
                start = str2datetime(self.input.start,
                                     DEFAULT_LANGS[self.me.languages]['DATE_FORMAT'][0])
            if is_empty(self.input.end):
                end = None
            else:
                end = str2datetime(self.input.end,
                                   DEFAULT_LANGS[self.me.languages]['DATE_FORMAT'][0],True)

            # machine search
            m_m2js = m2mj_findbyguest(self.orm,
                           guest_id,
                           start,
                           end,
                           users_id,
                           )
            if not m_m2js:
                self.logger.debug("Search m_m2js failed. "
                                  "Did not exist m_m2js that in accord with these query. "
                                  "guest_id %s, start %s, end %s, users_id %s" % (guest_id, start, end, users_id))
                return web.nocontent()
            
            self.view.m_m2js = m_m2js
            self.view.user   = self.input.user
            self.view.status = self.input.status
            self.view.start  = self.input.start
            self.view.end    = self.input.end

            jobgroup_ids = []
            for m_m2j in m_m2js:
                jobgroup_ids.append(m_m2j[1].jobgroup_id)

            jobgroup_status = self.input.status
            if is_empty(jobgroup_status):
                jobgroup_status = None
            jobgroups = jg_findbyalltype(self.pysilhouette.orm, JOBGROUP_TYPE["SERIAL"],
                                         jobgroup_ids, jobgroup_status, desc=True)
            if not jobgroups:
                self.logger.debug("Search jobgroups failed. "
                                  "Did not exist jobgroups that in accord with these query."
                                  "jobgroup_ids %s, jobgroup_status %s" % (jobgroup_ids, jobgroup_status))
                return web.nocontent()
        else:
            m_m2js = m2mj_findbyguest(self.orm, guest_id)

            self.view.m_m2js = m_m2js
            self.view.user   = ''
            self.view.status = ''
            self.view.start  = ''
            self.view.end    = ''

            jobgroup_ids = []
            for m_m2j in m_m2js:
                 jobgroup_ids.append(m_m2j[1].jobgroup_id)

            jobgroups = jg_findbyalltype(self.pysilhouette.orm, JOBGROUP_TYPE["SERIAL"],
                         jobgroup_ids, desc=True)

        self.view.JOBGROUP_STATUS = JOBGROUP_STATUS
        self.view.HYPERVISOR = MACHINE_HYPERVISOR

        if self.input.has_key('p') is True:
            if validates_page(self) is True:
                start = int(self.input.p)
            else:
                return web.badrequest(self.view.alert)

        else:
            start = 0
        self.view.date_format = DEFAULT_LANGS[self.me.languages]['DATE_FORMAT'][1]
        self.view.pager = Pager(jobgroups, start, JOB_LIST_RANGE)

        return True
コード例 #10
0
    def _GET(self, *param, **params):
        host_id = self.chk_hostby1(param)
        if host_id is None: return web.notfound()

        (check, edit) = validates_jobsearch(self)
        if check is False:
            return web.badrequest(self.view.alert)

        if edit is True:
            users = findbyname_BM(self.orm, self.input.user)
            users_id = []
            for user in users:
                users_id.append(user.id)

            machine_name = self.input.name.strip()

            if is_empty(machine_name):
                machine_name = None

            if is_empty(self.input.start):
                start = None
            else:
                start = str2datetime(
                    self.input.start,
                    DEFAULT_LANGS[self.me.languages]['DATE_FORMAT'][0])

            if is_empty(self.input.end):
                end = None
            else:
                end = str2datetime(
                    self.input.end,
                    DEFAULT_LANGS[self.me.languages]['DATE_FORMAT'][0], True)

            m_m2js = m2mj_findbyall(self.orm, machine_name, start, end,
                                    users_id, True)
            if not m_m2js:
                self.logger.debug(
                    "Search m_m2js failed. "
                    "Did not exist m_m2js that in accord with these query. "
                    "name %s, user_id %s, start %s, end %s" %
                    (machine_name, users_id, start, end))
                return web.nocontent()

            self.view.m_m2js = m_m2js
            self.view.name = self.input.name
            self.view.user = self.input.user
            self.view.status = self.input.status
            self.view.start = self.input.start
            self.view.end = self.input.end

            jobgroup_ids = []
            for m_m2j in m_m2js:
                jobgroup_ids.append(m_m2j[1].jobgroup_id)

            jobgroup_status = self.input.status
            if is_empty(jobgroup_status):
                jobgroup_status = None

            jobgroups = jg_findbyalltype(self.pysilhouette.orm,
                                         JOBGROUP_TYPE["SERIAL"],
                                         jobgroup_ids,
                                         jobgroup_status,
                                         desc=True)
            if not jobgroups:
                self.logger.debug(
                    "Search jobgroups failed. "
                    "Did not exist jobgroups that in accord with these query. "
                    "jobgroup_ids %s, jobgroup_status %s" %
                    (jobgroup_ids, jobgroup_status))
                return web.nocontent()
        else:
            m_m2js = m2mj_findbyhost(self.orm, host_id)

            self.view.m_m2js = m_m2js
            self.view.name = ''
            self.view.user = ''
            self.view.status = ''
            self.view.start = ''
            self.view.end = ''

            jobgroup_ids = []
            for m_m2j in m_m2js:
                jobgroup_ids.append(m_m2j[1].jobgroup_id)

            jobgroups = jg_findbyalltype(self.pysilhouette.orm,
                                         JOBGROUP_TYPE["SERIAL"],
                                         jobgroup_ids,
                                         desc=True)

        self.view.JOBGROUP_STATUS = JOBGROUP_STATUS
        self.view.HYPERVISOR = MACHINE_HYPERVISOR

        if self.input.has_key('p') is True:
            if validates_page(self) is True:
                start = int(self.input.p)
            else:
                return web.badrequest(self.view.alert)
        else:
            start = 0

        self.view.date_format = DEFAULT_LANGS[
            self.me.languages]['DATE_FORMAT'][1]
        self.view.pager = Pager(jobgroups, start, JOB_LIST_RANGE)
        return True
コード例 #11
0
ファイル: userby1.py プロジェクト: goura/karesansui
def validates_user(obj):
    checker = Checker()
    check = True

    _ = obj._
    checker.errors = []

    if not is_param(obj.input, "nickname"):
        check = False
        checker.add_error(_('"%s" is required.') % _("Nickname"))
    else:
        check = (
            checker.check_username(
                _("Nickname"),
                obj.input.nickname,
                CHECK_EMPTY | CHECK_LENGTH | CHECK_ONLYSPACE,
                min=USER_MIN_LENGTH,
                max=USER_MAX_LENGTH,
            )
            and check
        )

    if not is_param(obj.input, "email"):
        check = False
        checker.add_error(_('"%s" is required.') % _("Mail Address"))
    else:
        check = (
            checker.check_mailaddress(
                _("Mail Address"),
                obj.input.email,
                CHECK_EMPTY | CHECK_LENGTH | CHECK_VALID,
                min=EMAIL_MIN_LENGTH,
                max=EMAIL_MAX_LENGTH,
            )
            and check
        )

    _password_flag = True
    if not is_param(obj.input, "password"):
        check = False
        _password_flag = False
        checker.add_error(_('"%s" is required.') % _("Password"))
    if not is_param(obj.input, "new_password"):
        _password_flag = False
        checker.add_error(_('"%s" is required.') % _("New Password"))
    if not is_param(obj.input, "retype"):
        check = False
        _password_flag = False
        checker.add_error(_('"%s" is required.') % _("Retype"))

    if _password_flag == True:
        if not is_empty(obj.input.password) or not is_empty(obj.input.new_password) or not is_empty(obj.input.retype):
            check = (
                checker.check_password(
                    _("Password"),
                    obj.input.password,
                    obj.input.password,
                    CHECK_EMPTY | CHECK_LENGTH,
                    min=PASSWORD_MIN_LENGTH,
                    max=PASSWORD_MAX_LENGTH,
                )
                and check
            )

            check = (
                checker.check_password(
                    _("Password"),
                    obj.input.new_password,
                    obj.input.retype,
                    CHECK_VALID | CHECK_LENGTH,
                    min=PASSWORD_MIN_LENGTH,
                    max=PASSWORD_MAX_LENGTH,
                )
                and check
            )

    check = (
        checker.check_languages(
            _("Language"),
            obj.input.languages,
            CHECK_EMPTY | CHECK_VALID | CHECK_LENGTH,
            min=LANGUAGES_MIN_LENGTH,
            max=LANGUAGES_MAX_LENGTH,
        )
        and check
    )

    obj.view.alert = checker.errors
    return check
コード例 #12
0
    def _GET(self, *param, **params):
        host_id = self.chk_hostby1(param)
        if host_id is None: return web.notfound()

        target = param[1]
        if target is None: return web.notfound()

        dev = param[2]
        if dev is None: return web.notfound()

        if not validates_report(self):
            self.logger.debug("Get report failed. Did not validate.")
            return web.badrequest(self.view.alert)

        today = datetime.datetime.today()

        if is_param(self.input, 'report_start_day') and not is_empty(
                self.input.report_start_day):
            start_day = str2datetime(
                self.input.report_start_day,
                DEFAULT_LANGS[self.me.languages]['DATE_FORMAT'][0])
        else:
            start_day = today - datetime.timedelta(1)

        if is_param(self.input, 'report_start_time') and not is_empty(
                self.input.report_start_time):
            (start_hour,
             start_minute) = self.input.report_start_time.split(':', 2)
            start_hour = int(start_hour)
            start_minute = int(start_minute)
        else:
            start_hour = today.hour
            start_minute = today.minute

        if is_param(
                self.input,
                'report_end_day') and not is_empty(self.input.report_end_day):
            end_day = str2datetime(
                self.input.report_end_day,
                DEFAULT_LANGS[self.me.languages]['DATE_FORMAT'][0])
        else:
            end_day = today

        if is_param(self.input, 'report_end_time') and not is_empty(
                self.input.report_end_time):
            (end_hour, end_minute) = self.input.report_end_time.split(':', 2)
            end_hour = int(end_hour)
            end_minute = int(end_minute)

        else:
            end_hour = today.hour
            end_minute = today.minute

        start_time = create_epochsec(
            start_day.year,
            start_day.month,
            start_day.day,
            start_hour,
            start_minute,
        )

        end_time = create_epochsec(
            end_day.year,
            end_day.month,
            end_day.day,
            end_hour,
            end_minute,
        )
        if int(start_time) > int(end_time):
            self.logger.error("Getting reports failed. Start time > end time.")
            return web.badrequest(
                _('Getting reports failed. Start time > end time.'))

        if is_param(self.input, 'type') and not is_empty(self.input.type):
            type = self.input.type
        else:
            type = "default"

        if is_param(self.input, 'host') and not is_empty(self.input.host):
            host = self.input.host
        else:
            host = None

        if is_param(
                self.input,
                'libvirt_target') and not is_empty(self.input.libvirt_target):
            libvirt_target = self.input.libvirt_target
        else:
            libvirt_target = None

        rrd = RRD(self._, self.me.languages)
        if host is not None:
            if rrd.set_rrd_dir_host(host) is False:
                self.logger.debug("Get report failed. Target host not found.")
                return web.notfound()

        filepath = rrd.create_graph(target, dev, type, start_time, end_time,
                                    libvirt_target)

        if filepath != "":
            self.download.type = OUTPUT_TYPE_FILE
            self.download.file = filepath
            self.download.once = True

        return True