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 | |
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.
-rw-r--r-- | Makefile | 6 | ||||
-rw-r--r-- | cobbler.spec | 1 | ||||
-rw-r--r-- | cobbler/remote.py | 56 | ||||
-rw-r--r-- | cobbler/webui/CobblerWeb.py | 34 | ||||
-rw-r--r-- | docs/cobbler.pod | 5 | ||||
-rw-r--r-- | webui_templates/ksfile_list.tmpl | 18 |
6 files changed, 90 insertions, 30 deletions
@@ -16,13 +16,17 @@ manpage: test: install python tests/tests.py -rm -rf /tmp/_cobbler-* - build: clean updatewui messages python setup.py build -f install: clean manpage python setup.py install -f +devinstall: + cp /var/lib/cobbler/settings /tmp/cobbler_settings + make install + cp /tmp/cobbler_settings /var/lib/cobbler/settings + sdist: clean messages updatewui python setup.py sdist diff --git a/cobbler.spec b/cobbler.spec index d3dde58..2f8fca8 100644 --- a/cobbler.spec +++ b/cobbler.spec @@ -138,6 +138,7 @@ test "x$RPM_BUILD_ROOT" != "x" && rm -rf $RPM_BUILD_ROOT %defattr(755,root,root) %dir /var/lib/cobbler +%dir /var/lib/cobbler/kickstarts/ %dir /var/lib/cobbler/triggers/add/distro/pre %dir /var/lib/cobbler/triggers/add/distro/post %dir /var/lib/cobbler/triggers/add/profile/pre 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): diff --git a/docs/cobbler.pod b/docs/cobbler.pod index 2b3e00f..44ac200 100644 --- a/docs/cobbler.pod +++ b/docs/cobbler.pod @@ -116,10 +116,13 @@ the name of a previously defined cobbler distribution =item kickstart -Local filesystem path to a kickstart file. +Local filesystem path to a kickstart file. http:// URLs (even CGI's) are also accepted, but a local file path is recommended, so that the kickstart templating engine can be taken advantage of. If this parameter is not provided, the kickstart file will default to /etc/cobbler/default.ks. This file is initially blank, meaning default kickstarts are not automated "out of the box". Admins can change the default.ks if they desire.. +When using kickstart files, they can be placed anywhere on the filesystem, but the recommended path is /var/lib/cobbler/kickstarts. + + =item virt-file-size (optional) (Virt-only) how large the disk image should be in gigabytes. The default is "5". diff --git a/webui_templates/ksfile_list.tmpl b/webui_templates/ksfile_list.tmpl index af196ec..2675d71 100644 --- a/webui_templates/ksfile_list.tmpl +++ b/webui_templates/ksfile_list.tmpl @@ -5,8 +5,8 @@ <thead> <caption>Cobbler Kickstart Files</caption> <tr> - <th class="text">Name</th> - <th> </th> + <th class="text">File</th> + <th class="text">Edit/View</th> </tr> </thead> <tbody> @@ -21,11 +21,15 @@ <tr class="$tr_class"> <td>$ksfile</td> - <td><!-- - <a href="/ksfile_edit?ksfile=$ksfile">edit</a> - <a href="/ksfile_view?ksfile=$ksfile">view</a> - --> - </td> + #if $ksfile.startswith("/var/lib/cobbler/kickstarts") + <td><a href="/ksfile_edit?name=$ksfile">edit</a></td> + #else if $ksfile.startswith("/etc/cobbler") + <td><a href="/ksfile_edit?name=$ksfile">edit</a></td> + #else if $ksfile.startswith("http://") + <td><a href="$ksfile">view</A></td> + #else + <td>N/A</td> + #end if </tr> #end for </tbody> |