From 6eb3ec3e75572fa166648f73dd5810157b86500e Mon Sep 17 00:00:00 2001 From: hickert Date: Mon, 29 Jun 2009 07:56:37 +0000 Subject: [PATCH] Updated FAI package plugin -Allow to add free-text fai packages. git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@13812 594d385d-05f5-0310-b6e9-bd551577e9d8 --- .../fai/admin/fai/class_faiPackage.inc | 80 ++++++++++++++++++- gosa-plugins/fai/admin/fai/faiPackage.tpl | 17 +++- 2 files changed, 91 insertions(+), 6 deletions(-) diff --git a/gosa-plugins/fai/admin/fai/class_faiPackage.inc b/gosa-plugins/fai/admin/fai/class_faiPackage.inc index 4380ba3c7..a18c3c8ea 100644 --- a/gosa-plugins/fai/admin/fai/class_faiPackage.inc +++ b/gosa-plugins/fai/admin/fai/class_faiPackage.inc @@ -40,7 +40,7 @@ class faiPackage extends plugin var $usedPackages = array(); var $buffer = NULL; - var $newDialogShown =false; + var $newDialogShown = false; var $FAIstate = ""; var $view_logged = FALSE; @@ -198,12 +198,88 @@ class faiPackage extends plugin * Add ******/ + if(isset($_POST['AddManualpkg']) && + isset($_POST['addPpkgsText']) && + strlen($_POST['addPpkgsText']) && + $this->acl_is_writeable("FAIpackage") && + !preg_match("/freeze/",$this->FAIstate)){ + + // Check all splitted packages for valid package names + $add_packages = preg_split( "/[\s,]+/", get_post('addPpkgsText'), -1, PREG_SPLIT_NO_EMPTY ); + if( is_array($add_packages) ) { + $invalid_packages = array(); + foreach ($add_packages as $value) { + if(!preg_match( "/^[a-z0-9][-0-9a-z+\.]+$/",$value)){ + $invalid_packages[] = trim($value); + }else{ + $valid_packages[] = trim($value); + } + } + if(count($invalid_packages)){ + $str = implode(", ",$invalid_packages); + msg_dialog::display(_("Invalid package names"), + sprintf(_("The following package names don't match the Debian policy: %s"),$str), + ERROR_DIALOG); + } + + + // If we have a complete list of valid packages, add them + if(count($valid_packages)){ + + foreach($valid_packages as $key => $value){ + if(array_key_exists($value,$this->usedPackages)) { + unset($valid_packages[$key]); + } + } + + // Query SI-Deamon for additional package information + $daemon = new gosaSupportDaemon(); + $query_attrs = array("distribution", "package","version", "section", "description", "timestamp"); + $do_si_query = true; + + + foreach ($valid_packages as $value) { + + if( $do_si_query == true ) { + $res = $daemon->FAI_get_packages($this->FAIdebianRelease,$query_attrs,array($value),0,1); + if( ! $daemon->is_error()){ + + if(count($res)){ + + // We just use the last answer - there shouldn't be multiple + $res_attrs = array_pop( $res ); + $this->list[$value] = $res_attrs; + $this->usedPackages[$value] = $res_attrs['PACKAGE']; + + }else{ + $this->usedPackages[$value] = $value; + } + }else{ + msg_dialog::display(_("Service infrastructure"), + msgPool::siError($daemon->get_error()), + ERROR_DIALOG); + $do_si_query = false; + } + } + } + + ksort($this->usedPackages); + + /* Generate package list */ + $this->list= $this->genPkgs(TRUE); + } + } + } + /* + was pressed to open the package dialog */ - if(isset($_POST['Addpkg']) && $this->acl_is_writeable("FAIpackage") && !preg_match("/freeze/",$this->FAIstate)){ + if(isset($_POST['Addpkg']) && + $this->acl_is_writeable("FAIpackage") && + !preg_match("/freeze/",$this->FAIstate)){ $this->dialog = new faiPackageEntry($this->config, $this->FAIdebianRelease,$this->usedPackages); $this->is_dialog =true; } + /* Check image Posts */ foreach($_POST as $name => $value){ diff --git a/gosa-plugins/fai/admin/fai/faiPackage.tpl b/gosa-plugins/fai/admin/fai/faiPackage.tpl index 3ab7fdebb..cfe8ca80c 100644 --- a/gosa-plugins/fai/admin/fai/faiPackage.tpl +++ b/gosa-plugins/fai/admin/fai/faiPackage.tpl @@ -67,15 +67,24 @@

 

- + {render acl=$FAIpackageACL} - -{/render} + + + +{/render}
+

 {t}Used packages{/t}

{$divlist} -
+
+ {t}Manually add packages{/t}: + + + + {t}Add from list{/t}: +
-- 2.30.2