示例#1
0
    def post(self):
        next = self.get_argument("next")

        if  len(self.get_arguments("password")) != 0:
                
            #print self.application.password, self.get_argument("password") , next
            if (utils.getDigest(self.get_argument("password"))  ==  self.application.config['security']['password_digest'] and
                self.get_argument("username")  ==  self.application.config['security']['username']):
                #self.set_secure_cookie("auth", self.application.config['security']['password_digest'])
                self.set_secure_cookie("user", fix_username(self.application.config['security']['username']))
                
        self.redirect(next)
示例#2
0
    def post(self):
        next = self.get_argument("next")

        if  len(self.get_arguments("password")) != 0:
                
            #print self.application.password, self.get_argument("password") , next
            if (utils.getDigest(self.get_argument("password"))  ==  self.application.config['security']['password_digest'] and
                self.get_argument("username")  ==  self.application.config['security']['username']):
                #self.set_secure_cookie("auth", self.application.config['security']['password_digest'])
                self.set_secure_cookie("user", fix_username(self.application.config['security']['username']))
                
        self.redirect(next)
示例#3
0
 def get(self):
     if  len(self.get_arguments("next")) != 0:
         next=self.get_argument("next")
     else:
         next=self.webroot + "/"
         
     #if password and user are blank, just skip to the "next"
     if (  self.application.config['security']['password_digest'] == utils.getDigest("")  and
           self.application.config['security']['username'] == ""
         ):
         self.set_secure_cookie("user", fix_username(self.application.config['security']['username']))
         self.redirect(next)
     else:    
         self.render('login.html', next=next)
示例#4
0
 def get(self):
     if  len(self.get_arguments("next")) != 0:
         next=self.get_argument("next")
     else:
         next=self.webroot + "/"
         
     #if password and user are blank, just skip to the "next"
     if (  self.application.config['security']['password_digest'] == utils.getDigest("")  and
           self.application.config['security']['username'] == ""
         ):
         self.set_secure_cookie("user", fix_username(self.application.config['security']['username']))
         self.redirect(next)
     else:    
         self.render('login.html', next=next)
示例#5
0
    def post(self):
        formdata = dict()
        formdata['port'] = self.get_argument(u"port", default="")
        formdata['webroot'] = self.get_argument(u"webroot", default="")
        formdata['folders'] = self.get_argument(u"folders", default="")
        formdata['use_authentication'] = (len(self.get_arguments("use_authentication"))!=0)
        formdata['username'] = self.get_argument(u"username", default="")
        formdata['password'] = self.get_argument(u"password", default="")
        formdata['password_confirm'] = self.get_argument(u"password_confirm", default="")
        formdata['use_api_key'] = (len(self.get_arguments("use_api_key"))!=0)
        formdata['api_key'] = self.get_argument(u"api_key", default="")
        formdata['launch_browser'] = (len(self.get_arguments("launch_browser"))!=0)
        
        failure_str = ""
        success_str = ""
        failure_strs = list()
        validated = False
        
        old_folder_list = self.application.config['general']['folder_list']
        new_folder_list = [os.path.normcase(os.path.abspath(os.path.normpath(unicode(a)))) for a in formdata['folders'].splitlines()]

        try:
            for i, f in enumerate(new_folder_list):
                #validate folders exist
                if not (os.path.exists(f) and  os.path.isdir(f)):
                    failure_strs.append(u"Folder {0} doesn't exist.".format(f))
                    break
                # check for repeat or contained 
                for j, f1 in enumerate(new_folder_list):
                    if i != j:
                        if  f1 == f:
                            failure_strs.append(u"Can't have repeat folders.")
                            raise Exception
                        if  f1.startswith(f + os.path.sep):
                            failure_strs.append(u"One folder can't contain another.")
                            raise Exception
        except Exception:
            pass
    
            

        port_failed = False
        old_port = self.application.config['general']['port']

        #validate numeric port
        if not formdata['port'].isdigit():
            port_failed = True
            failure_strs.append(u"Non-numeric port value: {0}".format(formdata['port']))
              
        #validate port range
        if not port_failed:  
            new_port = int(formdata['port'])
            if new_port > 49151 or new_port < 1024:
                failure_strs.append(u"Port value out of range (1024-4151): {0}".format(new_port))
                port_failed = True

        #validate port availability
        if not port_failed:  
            if new_port != old_port and not self.is_port_available(new_port):
                failure_strs.append(u"Port not available: {0}".format(new_port))
                port_failed = True
          
        #validate password and username are set
        if formdata['use_authentication'] and (formdata['username']=="" or formdata['password']==""):
            failure_strs.append(u"Username and password must be filled in if the 'use authentication' box is checked")
            
        #validate password pair is the same
        if formdata['password'] != formdata['password_confirm']:
            failure_strs.append(u"Password fields don't match.")

        if formdata['use_api_key'] and formdata['api_key']=="":
            failure_strs.append(u"API Key must have a value if the box is checked")

        if len(failure_strs) == 0:
            validated = True
            
        if validated:
            # was the password changed?
            password_changed = True
            if formdata['use_authentication']:
                if formdata['password'] == ConfigPageHandler.fakepass:
                    password_changed = False 
                elif utils.getDigest(formdata['password']) == self.application.config['security']['password_digest']:
                    password_changed = False
            else:
                password_changed = False
                
            # find out if we need to save:
            if (new_port != old_port or
                formdata['webroot'] != self.application.config['general']['webroot'] or
                new_folder_list != old_folder_list or
                formdata['username'] != self.application.config['security']['username'] or
                password_changed or
                formdata['use_api_key'] != self.application.config['security']['use_api_key'] or
                formdata['api_key'] != self.application.config['security']['api_key'] or
                formdata['launch_browser'] != self.application.config['general']['launch_browser'] 
               ): 
                # apply everything from the form
                self.application.config['general']['folder_list'] = new_folder_list
                self.application.config['general']['port'] = new_port
                self.application.config['general']['webroot'] = formdata['webroot']
                self.application.config['security']['use_authentication'] = formdata['use_authentication']
                self.application.config['security']['username'] = formdata['username']
                if formdata['password'] != ConfigPageHandler.fakepass:
                    self.application.config['security']['password_digest'] = utils.getDigest(formdata['password'])
                self.application.config['security']['use_api_key'] = formdata['use_api_key']
                if self.application.config['security']['use_api_key']:
                    self.application.config['security']['api_key'] = formdata['api_key']
                else:
                    self.application.config['security']['api_key'] = ""
                    formdata['api_key'] = ""
                self.application.config['general']['launch_browser'] = formdata['launch_browser']
                    
                success_str = "Saved. Server restart needed"                
                self.application.config.write()
        else:
            failure_str = "<br/>".join(failure_strs)
        formdata['password'] = ""
        formdata['password_confirm'] = ""
        logging.info("Config: " + str(self.application.config))
        self.render_config(formdata, success=success_str, failure=failure_str)
示例#6
0
    def post(self):
        formdata = dict()
        formdata['port'] = self.get_argument(u"port", default="")
        formdata['webroot'] = self.get_argument(u"webroot", default="")
        formdata['folders'] = self.get_argument(u"folders", default="")
        formdata['use_authentication'] = (len(
            self.get_arguments("use_authentication")) != 0)
        formdata['username'] = self.get_argument(u"username", default="")
        formdata['password'] = self.get_argument(u"password", default="")
        formdata['password_confirm'] = self.get_argument(u"password_confirm",
                                                         default="")
        formdata['use_api_key'] = (len(self.get_arguments("use_api_key")) != 0)
        formdata['api_key'] = self.get_argument(u"api_key", default="")
        formdata['launch_browser'] = (len(self.get_arguments("launch_browser"))
                                      != 0)

        failure_str = ""
        success_str = ""
        failure_strs = list()
        validated = False

        old_folder_list = self.application.config['general']['folder_list']
        new_folder_list = [
            os.path.normcase(os.path.abspath(os.path.normpath(unicode(a))))
            for a in formdata['folders'].splitlines()
        ]

        try:
            for i, f in enumerate(new_folder_list):
                #validate folders exist
                if not (os.path.exists(f) and os.path.isdir(f)):
                    failure_strs.append(u"Folder {0} doesn't exist.".format(f))
                    break
                # check for repeat or contained
                for j, f1 in enumerate(new_folder_list):
                    if i != j:
                        if f1 == f:
                            failure_strs.append(u"Can't have repeat folders.")
                            raise Exception
                        if f1.startswith(f + os.path.sep):
                            failure_strs.append(
                                u"One folder can't contain another.")
                            raise Exception
        except Exception:
            pass

        port_failed = False
        old_port = self.application.config['general']['port']

        #validate numeric port
        if not formdata['port'].isdigit():
            port_failed = True
            failure_strs.append(u"Non-numeric port value: {0}".format(
                formdata['port']))

        #validate port range
        if not port_failed:
            new_port = int(formdata['port'])
            if new_port > 49151 or new_port < 1024:
                failure_strs.append(
                    u"Port value out of range (1024-4151): {0}".format(
                        new_port))
                port_failed = True

        #validate port availability
        if not port_failed:
            if new_port != old_port and not self.is_port_available(new_port):
                failure_strs.append(
                    u"Port not available: {0}".format(new_port))
                port_failed = True

        #validate password and username are set
        if formdata['use_authentication'] and (formdata['username'] == ""
                                               or formdata['password'] == ""):
            failure_strs.append(
                u"Username and password must be filled in if the 'use authentication' box is checked"
            )

        #validate password pair is the same
        if formdata['password'] != formdata['password_confirm']:
            failure_strs.append(u"Password fields don't match.")

        if formdata['use_api_key'] and formdata['api_key'] == "":
            failure_strs.append(
                u"API Key must have a value if the box is checked")

        if len(failure_strs) == 0:
            validated = True

        if validated:
            # was the password changed?
            password_changed = True
            if formdata['use_authentication']:
                if formdata['password'] == ConfigPageHandler.fakepass:
                    password_changed = False
                elif utils.getDigest(
                        formdata['password']
                ) == self.application.config['security']['password_digest']:
                    password_changed = False
            else:
                password_changed = False

            # find out if we need to save:
            if (new_port != old_port or formdata['webroot'] !=
                    self.application.config['general']['webroot']
                    or new_folder_list != old_folder_list
                    or formdata['username'] !=
                    self.application.config['security']['username']
                    or password_changed or formdata['use_api_key'] !=
                    self.application.config['security']['use_api_key']
                    or formdata['api_key'] !=
                    self.application.config['security']['api_key']
                    or formdata['launch_browser'] !=
                    self.application.config['general']['launch_browser']):
                # apply everything from the form
                self.application.config['general'][
                    'folder_list'] = new_folder_list
                self.application.config['general']['port'] = new_port
                self.application.config['general']['webroot'] = formdata[
                    'webroot']
                self.application.config['security'][
                    'use_authentication'] = formdata['use_authentication']
                self.application.config['security']['username'] = formdata[
                    'username']
                if formdata['password'] != ConfigPageHandler.fakepass:
                    self.application.config['security'][
                        'password_digest'] = utils.getDigest(
                            formdata['password'])
                self.application.config['security']['use_api_key'] = formdata[
                    'use_api_key']
                if self.application.config['security']['use_api_key']:
                    self.application.config['security']['api_key'] = formdata[
                        'api_key']
                else:
                    self.application.config['security']['api_key'] = ""
                    formdata['api_key'] = ""
                self.application.config['general'][
                    'launch_browser'] = formdata['launch_browser']

                success_str = "Saved. Server restart needed"
                self.application.config.write()
        else:
            failure_str = "<br/>".join(failure_strs)
        formdata['password'] = ""
        formdata['password_confirm'] = ""
        logging.info("Config: " + str(self.application.config))
        self.render_config(formdata, success=success_str, failure=failure_str)