X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=gosa-plugins%2Ffai%2Fadmin%2Ffai%2Fclass_faiPackage.inc;h=d32f26a64d41e27de24dc2c150bd47363a5deaee;hb=ac00a6eccb7dd4f40043288482e701a3f17fcc6e;hp=b4dcfa82b3b7494e0f4e806e1749f7ac2d280539;hpb=cd908b227bcbdd35837e1105f6bbfde220b4f9e3;p=gosa.git diff --git a/gosa-plugins/fai/admin/fai/class_faiPackage.inc b/gosa-plugins/fai/admin/fai/class_faiPackage.inc index b4dcfa82b..d32f26a64 100644 --- a/gosa-plugins/fai/admin/fai/class_faiPackage.inc +++ b/gosa-plugins/fai/admin/fai/class_faiPackage.inc @@ -40,13 +40,15 @@ class faiPackage extends plugin var $usedPackages = array(); var $buffer = NULL; - var $newDialogShown =false; + var $newDialogShown = false; var $FAIstate = ""; var $view_logged = FALSE; var $base; var $FAIpackage ; + var $packageSelect ; + var $FAIinstallMethods = array( "install", "ninstall", "remove", "dselect-upgrade", "taskinst", "taskrm", "hold", "clean", "aptitude", "aptitude-r", @@ -65,18 +67,13 @@ class faiPackage extends plugin if($dn != "new"){ $this->dn =$dn; - /* Get FAIstate */ - if(isset($this->attrs['FAIstate'][0])){ - $this->FAIstate = $this->attrs['FAIstate'][0]; - } - /* Check if there are already some packages in this list */ $this->usedPackages = array(); if(isset($this->attrs['FAIpackage'])){ unset($this->attrs['FAIpackage']['count']); foreach($this->attrs['FAIpackage'] as $pkg){ - $name = preg_replace("/^\-/","",$pkg); + $name = preg_replace("/\-$/","",$pkg); $this->usedPackages[$name] = $pkg; } ksort($this->usedPackages); @@ -178,9 +175,9 @@ class faiPackage extends plugin /* Assemble release name */ $release = $this->parent->parent->fai_release; - $tmp= preg_replace('/[,]*'.normalizePreg(get_ou('faiou')).'.*$/', '', $release); + $tmp= preg_replace('/[,]*'.preg_quote(get_ou('faiBaseRDN'), '/').'.*$/i', '', $release); $tmp= preg_replace('/ou=/', '', $tmp); - $rev= array_reverse(split(',', $tmp)); + $rev= array_reverse(explode(',', $tmp)); $this->FAIdebianRelease= "/"; foreach ($rev as $part){ $this->FAIdebianRelease.= "/$part"; @@ -203,12 +200,122 @@ class faiPackage extends plugin * Add ******/ - /* + was pressed to open the package dialog */ - if(isset($_POST['Addpkg']) && $this->acl_is_writeable("FAIpackage")){ - $this->dialog = new faiPackageEntry($this->config, $this->FAIdebianRelease,$this->usedPackages); - $this->is_dialog =true; + 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); + } + } + } + + // Open the packageSelect dialog to allow adding packages out of a list. + if(isset($_POST['Addpkg']) && $this->acl_is_writeable("FAIpackage") && !preg_match("/freeze/",$this->FAIstate)){ + $this->packageSelect = new packageSelect($this->config, get_userinfo()); + session::set('packageSelect_Release',$this->FAIdebianRelease); + $this->dialog =true; } + // Close packageSelect dialog. + if(isset($_POST['packageSelect_cancel'])){ + $this->packageSelect = FALSE; + $this->dialog =FALSE; + } + + // Close packageSelect dialog and add the selected packages. + if(isset($_POST['packageSelect_save']) && $this->packageSelect instanceOf packageSelect){ + if(!preg_match("/freeze/i", $this->FAIstate)){ + $use = $this->packageSelect->save(); + + foreach($use as $pkg){ + $item = array(); + for($i =0; $i < $pkg['count']; $i++){ + $item[$pkg[$i]] = $pkg[$pkg[$i]][0]; + } + $this->usedPackages[$item['PACKAGE']] = $item['PACKAGE']; + } + + ksort($this->usedPackages); + + /* Generate package list */ + $this->list= $this->genPkgs(TRUE); + } + $this->packageSelect = FALSE; + $this->dialog =FALSE; + } + + // Display package add dialog + if($this->packageSelect instanceOf packageSelect){ + + session::set('filterBlacklist', array('PACKAGE' => $this->usedPackages)); + return $this->packageSelect->execute(); + } + + /* Check image Posts */ foreach($_POST as $name => $value){ @@ -217,14 +324,14 @@ class faiPackage extends plugin * Mark as removed ******/ - if(!preg_match('/^freeze/', $this->FAIstate) && preg_match("/^removal_package_/",$name)){ + if(!preg_match('/freeze/i', $this->FAIstate) && preg_match("/^removal_package_/",$name)){ $id = @base64_decode(preg_replace("/^removal_package_(.*)_[xy]*$/","\\1",$name)); if(isset($this->usedPackages[$id])){ $pkg = $this->usedPackages[$id]; - if (preg_match('/^-/', $pkg)){ - $pkg= preg_replace('/^-/', '', $pkg); + if (preg_match('/\-$/', $pkg)){ + $pkg= preg_replace('/\-$/', '', $pkg); } else { - $pkg= preg_replace('/^/', '-', $pkg); + $pkg= preg_replace('/$/', '-', $pkg); } $this->usedPackages[$id] = $pkg; } @@ -234,7 +341,7 @@ class faiPackage extends plugin /****** * Delete Pkgs ******/ - if(!preg_match('/^freeze/', $this->FAIstate) && preg_match("/^remove_package_/",$name)){ + if(!preg_match('/freeze/i', $this->FAIstate) && preg_match("/^remove_package_/",$name)){ $id = @base64_decode(preg_replace("/^remove_package_(.*)_[xy]*$/","\\1",$name)); if(isset($this->usedPackages[$id])){ unset($this->usedPackages[$id]); @@ -245,7 +352,7 @@ class faiPackage extends plugin /****** * Configure Pkgs ******/ - if(!preg_match('/^freeze/', $this->FAIstate) && preg_match("/^configure_package_/",$name)){ + if(!preg_match('/freeze/i', $this->FAIstate) && preg_match("/^configure_package_/",$name)){ $pkg = @base64_decode(preg_replace("/^configure_package_(.*)_[xy]*$/","\\1",$name)); if(isset($this->usedPackages[$pkg])){ @@ -268,30 +375,6 @@ class faiPackage extends plugin $this->is_dialog=false; } - /* attach new packages */ - if(isset($_POST['SaveSubObject'])) { - if(!preg_match("/^freeze/", $this->FAIstate)){ - $this->dialog->save_object(); - if(count($this->dialog->check())){ - foreach($this->dialog->check() as $msgs){ - msg_dialog::display(_("Error"), $msgs, ERROR_DIALOG); - } - }else{ - $use = $this->dialog->save(); - $this->usedPackages = $use; - $this->dialog = false; - $this->is_dialog=false; - ksort($this->usedPackages); - - /* Generate package list */ - $this->list= $this->genPkgs(TRUE); - } - }else{ - $this->dialog = false; - $this->is_dialog=false; - } - } - /* Save Configuration */ if(isset($_POST['SaveObjectConfig'])){ if(!preg_match("/^freeze/", $this->FAIstate)){ @@ -325,40 +408,44 @@ class faiPackage extends plugin ksort($this->usedPackages); if(is_array($this->usedPackages)){ foreach($this->usedPackages as $usedName => $name){ + + $actions = ""; /* Append message if package is configured */ $configured = " "; if(isset($this->ConfiguredPackages[$usedName])){ - $configured = ""._("Configured").""; } /* Adapt used name if we're marked for removal */ $removal = " "; - if (preg_match('/^-/', $name)){ - $removal = ""._("Package marked for removal").""; } /* Get Version */ - $version = ""; + $version = " "; if(isset($this->list[$usedName]['VERSION'])){ $version = $this->list[$usedName]['VERSION']; } /* Get description */ - $description = ""; + $description = " "; if(isset($this->list[$usedName]['DESCRIPTION'])){ - $description = $this->list[$usedName]['DESCRIPTION']; + $description = base64_decode($this->list[$usedName]['DESCRIPTION']); } if(!preg_match('/^freeze/', $this->FAIstate) && $this->acl_is_writeable("FAIpackage")){ $actions = ""; + src='plugins/fai/images/removal_mark.png' name='removal_package_".base64_encode($usedName)."' >"; } - if(!preg_match('/^freeze/', $this->FAIstate) && $this->acl_is_writeable("FAIdebconfInfo")){ + + if(isset($this->list[$usedName]['TEMPLATE']) && + !preg_match('/^freeze/', $this->FAIstate) && $this->acl_is_writeable("FAIdebconfInfo")){ $actions.= " "; + src='plugins/fai/images/package_configure.png' name='configure_package_".base64_encode($usedName)."' >"; } if(!preg_match('/^freeze/', $this->FAIstate) && $this->acl_is_writeable("FAIpackage")){ $actions.= "  $translated){ $smarty->assign($name."ACL",$this->getacl($name,preg_match("/freeze/",$this->FAIstate))); } - + + $smarty->assign("freeze", preg_match("/freeze/",$this->FAIstate)); $smarty->assign("divlist",$divlist->DrawList()); $smarty->assign("release" ,$this->FAIdebianRelease); $smarty->assign("sections",$this->sections); @@ -407,13 +495,13 @@ class faiPackage extends plugin $ldap = $this->config->get_ldap_link(); $ldap->cd ($this->dn); $release = $this->parent->parent->fai_release; - $use_dn = preg_replace("/".normalizePreg(FAI::get_release_dn($this->dn))."/i", $release, $this->dn); + $use_dn = preg_replace("/".preg_quote(FAI::get_release_dn($this->dn), '/')."/i", $release, $this->dn); FAI::prepare_to_save_FAI_object($use_dn,array(),true); new log("remove","fai/".get_class($this),$use_dn,$this->attributes); foreach($this->ConfiguredPackages as $pkgname => $attrs){ foreach($attrs as $name => $attr){ $pkgdn = "FAIvariable=".$name.",".$this->dn; - $use_dn = preg_replace("/".normalizePreg(FAI::get_release_dn($this->dn))."/i", $release, $pkgdn); + $use_dn = preg_replace("/".preg_quote(FAI::get_release_dn($this->dn), '/')."/i", $release, $pkgdn); FAI::prepare_to_save_FAI_object($use_dn,array(),true); } } @@ -450,7 +538,7 @@ class faiPackage extends plugin */ if($this->is_new){ $release = $this->parent->parent->fai_release; - $new_dn= 'cn='.$this->cn.",".get_ou('faipackageou').get_ou('faiou').$release; + $new_dn= 'cn='.$this->cn.",".get_ou('faiPackageRDN').get_ou('faiBaseRDN').$release; $res = faiManagement::check_class_name("FAIpackageList",$this->cn,$new_dn); if(isset($res[$this->cn])){ $message[] = msgPool::duplicated(_("Name")); @@ -465,9 +553,11 @@ class faiPackage extends plugin */ function genPkgs($force = false) { + if(empty($this->FAIdebianRelease)) return; + if(!count($this->buffer) || $force){ $q = new gosaSupportDaemon(); - $attrs = array("distribution", "package","version", "section", "description", "timestamp"); + $attrs = array("distribution", "package","version", "section", "description", "timestamp","template"); $packages = array_keys($this->usedPackages); @@ -493,9 +583,9 @@ class faiPackage extends plugin if($this->FAIdebianRelease == "ClearFromCopyPaste"){ $current_release = $this->parent->parent->fai_release; - $tmp= preg_replace('/,'.normalizePreg(get_ou('faiou')).'.*$/', '', $current_release); + $tmp= preg_replace('/,'.preg_quote(get_ou('faiBaseRDN'), '/').'.*$/i', '', $current_release); $tmp= preg_replace('/ou=/', '', $tmp); - $rev= array_reverse(split(',', $tmp)); + $rev= array_reverse(explode(',', $tmp)); $this->FAIdebianRelease= ""; foreach ($rev as $part){ $this->FAIdebianRelease.= "/$part"; @@ -674,9 +764,9 @@ class faiPackage extends plugin if(isset($attrs['FAIrepository'])){ for($i =0 ; $i < $attrs['FAIrepository']['count']; $i++){ $obj = $attrs['FAIrepository'][$i]; - $tmp = split("\|",$obj); + $tmp = explode("|",$obj); if(count($tmp)==4){ - foreach(split(",",$tmp[3]) as $sec){ + foreach(explode(",",$tmp[3]) as $sec){ if(!empty($sec)){ $ret[$tmp[2]][] = $sec; }