diff options
author | Michael DeHaan <mdehaan@mdehaan.rdu.redhat.com> | 2007-09-14 18:40:21 -0400 |
---|---|---|
committer | Michael DeHaan <mdehaan@mdehaan.rdu.redhat.com> | 2007-09-14 18:40:21 -0400 |
commit | d5295e872079daa619ffeb24c881be6655716ef1 (patch) | |
tree | ce227491bd7537b6d197afd1520a873c15aa3918 /cobbler | |
parent | 0904cdd86e4eae3d96db0fdec8133d4bd99dc7d6 (diff) | |
download | third_party-cobbler-d5295e872079daa619ffeb24c881be6655716ef1.tar.gz third_party-cobbler-d5295e872079daa619ffeb24c881be6655716ef1.tar.xz third_party-cobbler-d5295e872079daa619ffeb24c881be6655716ef1.zip |
Kickstart listing is back in the WUI, with a backend method to get the exhaustive list.
Edits to come. Also added a "make devinstall" which is like "make install" but doesn't
overwrite your settings file with the default values.
Diffstat (limited to 'cobbler')
-rw-r--r-- | cobbler/remote.py | 56 | ||||
-rw-r--r-- | cobbler/webui/CobblerWeb.py | 34 |
2 files changed, 69 insertions, 21 deletions
diff --git a/cobbler/remote.py b/cobbler/remote.py index 2673cb9..85b7b8b 100644 --- a/cobbler/remote.py +++ b/cobbler/remote.py @@ -650,7 +650,7 @@ class CobblerReadWriteXMLRPCInterface(CobblerXMLRPCInterface): self.__validate_token(token) return self.api.sync() - def reposync(self,token,repos=[]): + def reposync(self,repos=[],token=None): """ Updates one or more mirrored yum repositories. reposync is very slow and probably should not be used @@ -659,7 +659,7 @@ class CobblerReadWriteXMLRPCInterface(CobblerXMLRPCInterface): self.__validate_token(token) return self.api.reposync(repos) - def import_tree(self,mirror_url,mirror_name,network_root=None): + def import_tree(self,mirror_url,mirror_name,network_root=None,token=None): """ I'm exposing this in the XMLRPC API for consistancy but as this can be a very long running operation usage is /not/ recommended. @@ -669,6 +669,58 @@ class CobblerReadWriteXMLRPCInterface(CobblerXMLRPCInterface): self.__validate_token(token) return self.api.import_tree(mirror_url,mirror_name,network_root) + def get_kickstart_templates(self,token): + """ + Returns all of the kickstarts that are in use by the system. + """ + self.__validate_token(token) + files = {} + for x in self.api.profiles(): + if x.kickstart is not None and x.kickstart != "" and x.kickstart != "<<inherit>>": + files[x.kickstart] = 1 + for x in self.api.systems(): + if x.kickstart is not None and x.kickstart != "" and x.kickstart != "<<inherit>>": + files[x.kickstart] = 1 + return files.keys() + + + def read_or_write_kickstart_template(self,kickstart_file,is_read,new_data,token): + """ + Allows the WebUI to be used as a kickstart file editor. For security + reasons we will only allow kickstart files to be edited if they reside in + /var/lib/cobbler/kickstarts/ or /etc/cobbler. This limits the damage + doable by Evil who has a cobbler password but not a system password. + Also if living in /etc/cobbler the file must be a kickstart file. + """ + + self.__validate_token(token) + + if kickstart_file.find("..") != -1 or not kickstart_file.startswith("/"): + raise CX(_("tainted file location")) + + if not kickstart_file.startswith("/etc/cobbler/") and not kickstart_file.startswith("/var/lib/cobbler/kickstarts"): + raise CX(_("unable to view or edit kickstart in this location")) + + if kickstart_file.startswith("/etc/cobbler/"): + if not kickstart_file.endswith(".ks"): + # take care to not allow config files to be altered. + raise CX(_("this does not seem to be a kickstart file")) + if not is_read and not os.path.exists(kickstart_file): + raise CX(_("new files must go in /var/lib/cobbler/kickstarts")) + + if is_read: + fileh = open(kickstart_file,"r") + data = fileh.read() + fileh.close() + return data + else: + fileh = open(kickstart_file,"w+") + fileh.write(new_data) + fileh.close() + return True + + + # ********************************************************************************* # ********************************************************************************* diff --git a/cobbler/webui/CobblerWeb.py b/cobbler/webui/CobblerWeb.py index ab7afec..6abedf2 100644 --- a/cobbler/webui/CobblerWeb.py +++ b/cobbler/webui/CobblerWeb.py @@ -410,31 +410,26 @@ class CobblerWeb(object): # ------------------------------------------------------------------------ # def ksfile_list(self): + self.__xmlrpc_setup() return self.__render( 'ksfile_list.tmpl', { - 'ksfiles': self.__ksfiles() + 'ksfiles': self.remote.get_kickstart_templates(self.token) } ) - def ksfile_view(self, ksfile): + def ksfile_edit(self, name=None): + self.__xmlrpc_setup() return self.__render( 'ksfile_view.tmpl', { - 'ksdata': self.__ksfile_data( ksfile ), - 'ksfile': ksfile - } ) + 'ksfile': name, + 'ksdata': self.remote.read_or_write_kickstart_template(self,name,True,"",self.token) - # FIXME: modify to detect per-system kickstart files (seldom used feature) also + } ) - def __ksfiles(self): + def ksfile_save(self, name=None, data=None): self.__xmlrpc_setup() - ksfiles = [] - for profile in self.remote.get_profiles(): - ksfile = profile['kickstart'] - if not ksfile in ksfiles: - ksfiles.append( ksfile ) - return ksfiles - - # FIXME: implement backend feature for modifying kickstart files in text box - - def __ksfile_data(self, ksfile): - pass + try: + self.remote.read_or_write_kickstart_template(self,name,False,data,self.token) + except Exception, e: + return self.error_page("error with kickstart: %s" % str(e)) + return self.ksfile_edit(name=ksfile) # ------------------------------------------------------------------------ # # Miscellaneous @@ -470,7 +465,8 @@ class CobblerWeb(object): repo_save.exposed = True settings_view.exposed = True - ksfile_view.exposed = True + ksfile_edit.exposed = True + ksfile_save.exposed = True ksfile_list.exposed = True class CobblerWebAuthException(exceptions.Exception): |