diff options
author | Michael DeHaan <mdehaan@mdehaan.rdu.redhat.com> | 2007-09-18 13:11:07 -0400 |
---|---|---|
committer | Michael DeHaan <mdehaan@mdehaan.rdu.redhat.com> | 2007-09-18 13:11:07 -0400 |
commit | 063f3d86ce09cc6662b06fbb1f01625a2c85e837 (patch) | |
tree | 8e7f50567d8e6cff803e4fe17c634ca1d46acbd3 /cobbler | |
parent | d2e53a84199b1594cb491c85a24822a113ac07d9 (diff) | |
download | third_party-cobbler-063f3d86ce09cc6662b06fbb1f01625a2c85e837.tar.gz third_party-cobbler-063f3d86ce09cc6662b06fbb1f01625a2c85e837.tar.xz third_party-cobbler-063f3d86ce09cc6662b06fbb1f01625a2c85e837.zip |
Make cookies be session cookies + some backend cleanup.
Diffstat (limited to 'cobbler')
-rw-r--r-- | cobbler/remote.py | 32 | ||||
-rw-r--r-- | cobbler/webui/CobblerWeb.py | 50 |
2 files changed, 42 insertions, 40 deletions
diff --git a/cobbler/remote.py b/cobbler/remote.py index 12f13f8..e559ab5 100644 --- a/cobbler/remote.py +++ b/cobbler/remote.py @@ -109,12 +109,12 @@ class CobblerXMLRPCInterface: self.api.clear() self.api.deserialize() - def __get_all(self,collection): + def __get_all(self,collection_fn): """ Internal function to return an array of hashes from a particular collection object. """ self._refresh() - data = collection.to_datastruct() + data = collection_fn().to_datastruct() data.sort(self.__sorter) return self._fix_none(data) @@ -129,33 +129,33 @@ class CobblerXMLRPCInterface: """ Returns all cobbler distros as an array of hashes. """ - return self.__get_all(self.api.distros()) + return self.__get_all(self.api.distros) def get_profiles(self,token=None): """ Returns all cobbler profiles as an array of hashes. """ - return self.__get_all(self.api.profiles()) + return self.__get_all(self.api.profiles) def get_systems(self,token=None): """ Returns all cobbler systems as an array of hashes. """ - return self.__get_all(self.api.systems()) + return self.__get_all(self.api.systems) def get_repos(self,token=None): """ Returns all cobbler repos as an array of hashes. """ - return self.__get_all(self.api.repos()) + return self.__get_all(self.api.repos) - def __get_specific(self,collection,name,flatten=False): + def __get_specific(self,collection_fn,name,flatten=False): """ Internal function to return a hash representation of a given object if it exists, otherwise an empty hash will be returned. """ self._refresh() - item = collection.find(name=name) + item = collection_fn().find(name=name) if item is None: return self._fix_none({}) result = item.to_datastruct() @@ -167,25 +167,25 @@ class CobblerXMLRPCInterface: """ Returns the distro named "name" as a hash. """ - return self.__get_specific(self.api.distros(),name,flatten=flatten) + return self.__get_specific(self.api.distros,name,flatten=flatten) def get_profile(self,name,flatten=False,token=None): """ Returns the profile named "name" as a hash. """ - return self.__get_specific(self.api.profiles(),name,flatten=flatten) + return self.__get_specific(self.api.profiles,name,flatten=flatten) def get_system(self,name,flatten=False,token=None): """ Returns the system named "name" as a hash. """ - return self.__get_specific(self.api.systems(),name,flatten=flatten) + return self.__get_specific(self.api.systems,name,flatten=flatten) def get_repo(self,name,flatten=False,token=None): """ Returns the repo named "name" as a hash. """ - return self.__get_specific(self.api.repos(),name,flatten=flatten) + return self.__get_specific(self.api.repos,name,flatten=flatten) def get_distro_as_rendered(self,name,token=None): """ @@ -605,7 +605,7 @@ class CobblerReadWriteXMLRPCInterface(CobblerXMLRPCInterface): obj = self.__get_object(object_id) return self.__call_method(obj, attribute, arg) - def distro_remove(self,name): + def distro_remove(self,name,token): """ Deletes a distro from a collection. Note that this just requires the name of the distro, not a handle. @@ -613,7 +613,7 @@ class CobblerReadWriteXMLRPCInterface(CobblerXMLRPCInterface): self.__validate_token(token) return self.api._config.distros().remove(name) - def profile_remove(self,name): + def profile_remove(self,name,token): """ Deletes a profile from a collection. Note that this just requires the name of the profile, not a handle. @@ -621,7 +621,7 @@ class CobblerReadWriteXMLRPCInterface(CobblerXMLRPCInterface): self.__validate_token(token) return self.api._config.profiles().remove(name) - def system_remove(self,name): + def system_remove(self,name,token): """ Deletes a system from a collection. Note that this just requires the name of the system, not a handle. @@ -629,7 +629,7 @@ class CobblerReadWriteXMLRPCInterface(CobblerXMLRPCInterface): self.__validate_token(token) return self.api._config.systems().remove(name) - def repo_remove(self,name): + def repo_remove(self,name,token): """ Deletes a repo from a collection. Note that this just requires the name of the repo, not a handle. diff --git a/cobbler/webui/CobblerWeb.py b/cobbler/webui/CobblerWeb.py index 395c9bc..ed6df8b 100644 --- a/cobbler/webui/CobblerWeb.py +++ b/cobbler/webui/CobblerWeb.py @@ -71,23 +71,12 @@ class CobblerWeb(object): if self.token is None: self.token = self.__get_cookie_token() - # if we have don't have a token, login for the first time - if self.token is None: - try: - self.token = self.remote.login( self.username, self.password ) - except Exception, e: - logger.info("login failed for: %s" % self.username) - log_exc() - return False - self.__cookie_login(self.token) # save what we've got - self.password = None # don't need it anymore, get rid of it - return True - # else if we do have a token, try to use it... - else: + if self.token is not None: # validate that our token is still good try: self.remote.token_check(self.token) + return True except Exception, e: # FIXME: check exception type to see that it is login related logger.info("token timeout for: %s" % self.username) @@ -95,8 +84,21 @@ class CobblerWeb(object): self.token = None # this should put us back to the login screen self.__cookie_logout() - return False + + # if we (still) don't have a token, login for the first time + if self.token is None and is_login: + try: + self.token = self.remote.login( self.username, self.password ) + except Exception, e: + logger.info("login failed for: %s" % self.username) + log_exc() + return False + self.__cookie_login(self.token) # save what we've got + self.password = None # don't need it anymore, get rid of it return True + + # login failed + return False def __render(self, template, data): @@ -128,12 +130,12 @@ class CobblerWeb(object): def __cookie_logout(self,): self.__cookies["cobbler_xmlrpc_token"] = "null" - self.__cookies["cobbler_xmlrpc_token"]['expires'] = 0 + # self.__cookies["cobbler_xmlrpc_token"]['expires'] = time.time() - 9999 return self.cookies def __cookie_login(self,token): self.__cookies["cobbler_xmlrpc_token"] = token - self.__cookies["cobbler_xmlrpc_token"]['expires'] = time.time() + 29*60 + # self.__cookies["cobbler_xmlrpc_token"]['expires'] = time.time() + 29*60 return self.cookies def __get_cookie_token(self): @@ -179,7 +181,7 @@ class CobblerWeb(object): self.username = username self.password = password - if not self.__xmlrpc_setup(): + if not self.__xmlrpc_setup(is_login=True): return self.login(message="") return self.index() @@ -236,17 +238,17 @@ class CobblerWeb(object): } ) # FIXME: deletes and renames - def distro_save(self,name=None,new_or_edit=None,kernel=None,initrd=None,kopts=None,ksmeta=None,arch=None,breed=None,**args): + def distro_save(self,name=None,new_or_edit=None,kernel=None,initrd=None,kopts=None,ksmeta=None,arch=None,breed=None,delete1=None,delete2=None,**args): if not self.__xmlrpc_setup(): return self.login(message="") - #if delete1 and delete2: - # try: - # self.remote.distro_remove(name) - # except Exception, e: - # self.error_page("could not delete %s, %s" % str(e)) - # return self.distro_edit(name=name) + if new_or_edit == 'edit' and delete1 and delete2: + try: + self.remote.distro_remove(name,self.token) + except Exception, e: + return self.error_page("could not delete %s, %s" % (name,str(e))) + return self.distro_list() # pre-command paramter checking if name is None: |