Esempio n. 1
0
 def get_kws_mgt_kws_query_range(self):
     offset = get_var("kws_start")
     limit = get_var("kws_per_page")
     if not offset or not offset.isdigit() or int(offset) < 1: offset = 1
     if not limit or not limit.isdigit() or int(limit) <= 0: limit = 30
     web_session["kws_mgt_query_offset"] = int(offset) - 1;
     web_session["kws_mgt_query_limit"] = int(limit);
     web_session.save()
Esempio n. 2
0
 def kws_mgt_specific(self):
     
     # Get the Teambox ID.
     kws_id = get_var("kws_mgt_specific_kws")
     if not kws_id or not kws_id.isdigit(): raise Exception("no Teambox specified")
     kws_id = int(kws_id)
    
     # Get the Teambox information.
     kws_info = self.get_kws_mgt_kws_info(kws_id)
     
     if get_var('kws_mgt_set_kws_quota'): return self.kws_mgt_set_quota(kws_info)
     else: return self.show_kws_mgt_specific_page(kws_info)
Esempio n. 3
0
    def process_config_page_posted_form(self, forms, form_name):
       
        # Return if system is in production mode.
        if c.mc.production_mode:
            return
 
        # Check if something was posted.
        if get_var('action') != "update": 
            # Nothing posted.
            return
        
        # Get custom form if needed.
        show_errors_in_form = self.process_form_dict[form_name][2]
        
        # Validate the posted form, if required.
        fill_form = None
        if not (self.process_form_dict[form_name][1] & NO_FILL):
            
            # No such form, bail out.
            if not forms.forms.has_key(form_name): return
            
            # Fill the form with the posted variables.
            fill_form = forms.forms[form_name]
            fill_form.fill(request.params)
            
            # Convert exceptions (if any) to strings using the map.
            fill_form.localize_validation_exceptions(self.validation_exceptions_messages)
            
            # The form is not valid, bail out.
            if not fill_form.valid(): return
        
        try:
            # Dispatch form update.
            method = getattr(self, self.process_form_dict[form_name][0])
            method(fill_form)
            
            # Update the configuration.
            save_master_config(c.mc)

            # Re-load services status after the change.
            tmp_mc = load_master_config()
            for name, service in c.services.items():
                service.update_from_conf(tmp_mc)

            if fill_form:
                fill_form.confirmations = ['Changes have been saved.']
            
            # Hide form if flag set.
            if self.process_form_dict[form_name][1] & HIDE_FORM and fill_form:
                fill_form.show = 0
            
        except ErrorMsg, e:
            msg = str(e)
            
            if show_errors_in_form:
                s = c.template_store[show_errors_in_form]
                s.error = msg

            elif fill_form:
                fill_form.notices += [msg]
Esempio n. 4
0
 def kws_mgt_set_quota(self, kws_info):
     
     # Validate the quota.
     valid_quota = 0
     try:
         current_size = kws_info.file_size
         user_quota = get_var("kws_quota")
         if user_quota == None or not user_quota.isdigit(): raise ValueError
         new_quota = int(user_quota) * 1024*1024
         if new_quota < current_size: raise ValueError
         valid_quota = 1
     except ValueError: pass
         
     # Update the quota.
     if valid_quota:
         self.update_kws_quota(kws_info.kws_id, new_quota)
         kws_info.file_quota = new_quota
     
     # Show the management page.
     return self.show_kws_mgt_specific_page(kws_info)
Esempio n. 5
0
    def show(self):
        # Push variables to templates.
        c.GT = GT
        c.dyn_ress_id = dyn_ress_id
 
        try:
            # Make sure KCD database is reachable.
            db_session.execute('SELECT 1')
        except OperationalError:
            ui_error(message="Database connection to MAS could not be established. You might want to check the configuration.")
            return render('/common/message.mako')

        # Dispatch.
        if get_var("kws_mgt_specific_kws"): return self.kws_mgt_specific()
        elif get_var("kws_mgt_query_action"): return self.kws_mgt_query_action()
        elif get_var("kws_mgt_show_kws"): return self.kws_mgt_show()
        elif get_var("kws_mgt_reshow_kws"): return self.show_kws_mgt_query_page()
        elif get_var("kws_mgt_next_kws"): return self.kws_mgt_next()
        elif get_var("kws_mgt_last_kws"): return self.kws_mgt_last()
        elif get_var("kwmo_redir"): return self.kws_mgt_kwmo_management()
        else: return self.kws_mgt_new_query()
Esempio n. 6
0
    def kws_mgt_kwmo_management(self):
        # Get workspace ID.
        kws_id = get_var("kws_id") or abort(404)

        # Get kcd password.
        if c.mc.kcd_pwd and len(c.mc.kcd_pwd):
            passwd = c.mc.kcd_pwd
        else:
            passwd = c.mc.admin_pwd

        # Get current timestamp.
        stamp = int(time.time())

        # Generate a time-based hash of the password.
        md5 = hashlib.md5()
        md5.update(str(stamp))
        md5.update(passwd)
        hex_hash = md5.digest().encode('hex')

        # Generate the url to redirect to.
        url = "https://%s/teambox_admin/login/%s?stamp=%i&hash=%s" % \
            ( c.mc.kwmo_host, str(kws_id), stamp, str(hex_hash) )

        return redirect(url)
Esempio n. 7
0
    def show(self):

        ## Check that server is in maintenance mode.
        #if c.mc.production_mode:
        #    # Redirect to the status page.
        #    return redirect_to(url_for('status'))

        # Push variables to template.
        c.GT = GT
        c.dyn_ress_id = dyn_ress_id
        c.template_store = {}
 
        # Determine which form has been requested or posted, if any.
        requested_form = get_var('form') or ""
        
        # Setup the configuration page forms.
        forms = Forms()
        self.get_config_page_forms(forms, requested_form)
        
        # Process the configuration page posted form, if any.
        self.process_config_page_posted_form(forms, requested_form)
       
        # Render the result.
        return render(self.config_template)
Esempio n. 8
0
    def show(self):

        ## Check that server is in maintenance mode.
        #if c.mc.production_mode:
        #    # Redirect to the status page.
        #    return redirect_to(url_for('status'))

        # Push variables to template.
        c.GT = GT
        c.dyn_ress_id = dyn_ress_id
        c.template_store = {}

        # Determine which form has been requested or posted, if any.
        requested_form = get_var('form') or ""

        # Setup the configuration page forms.
        forms = Forms()
        self.get_config_page_forms(forms, requested_form)

        # Process the configuration page posted form, if any.
        self.process_config_page_posted_form(forms, requested_form)

        # Render the result.
        return render(self.config_template)
Esempio n. 9
0
 def kws_mgt_query_action(self):
     choice = get_var("kws_mgt_query_action_select")
     if choice == "delete": return self.kws_mgt_delete()
     else: return self.show_kws_mgt_query_page()
Esempio n. 10
0
    def process_config_page_posted_form(self, forms, form_name):

        # Return if system is in production mode.
        if c.mc.production_mode:
            return

        # Check if something was posted.
        if get_var('action') != "update":
            # Nothing posted.
            return

        # Get custom form if needed.
        show_errors_in_form = self.process_form_dict[form_name][2]

        # Validate the posted form, if required.
        fill_form = None
        if not (self.process_form_dict[form_name][1] & NO_FILL):

            # No such form, bail out.
            if not forms.forms.has_key(form_name): return

            # Fill the form with the posted variables.
            fill_form = forms.forms[form_name]
            fill_form.fill(request.params)

            # Convert exceptions (if any) to strings using the map.
            fill_form.localize_validation_exceptions(
                self.validation_exceptions_messages)

            # The form is not valid, bail out.
            if not fill_form.valid(): return

        try:
            # Dispatch form update.
            method = getattr(self, self.process_form_dict[form_name][0])
            method(fill_form)

            # Update the configuration.
            save_master_config(c.mc)

            # Re-load services status after the change.
            tmp_mc = load_master_config()
            for name, service in c.services.items():
                service.update_from_conf(tmp_mc)

            if fill_form:
                fill_form.confirmations = ['Changes have been saved.']

            # Hide form if flag set.
            if self.process_form_dict[form_name][1] & HIDE_FORM and fill_form:
                fill_form.show = 0

        except ErrorMsg, e:
            msg = str(e)

            if show_errors_in_form:
                s = c.template_store[show_errors_in_form]
                s.error = msg

            elif fill_form:
                fill_form.notices += [msg]