diff --git a/gosa-plugins/goto/admin/applications/class_applicationGeneric.inc b/gosa-plugins/goto/admin/applications/class_applicationGeneric.inc
index 7e854daaf0762e09edf065393ad64e38c209588b..bf11b1f7aba247fc43dd11fe70a9124912a42532 100644 (file)
<?php
class application extends plugin
{
- /* CLI vars */
- var $cli_summary= "Handling of GOsa's application object";
- var $cli_description= "Some longer text\nfor help";
- var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
-
/* application attributes */
var $cn= "";
var $description= "";
var $last_sorting= "invalid";
var $applications= array();
+ var $orig_base = "";
+ var $orig_cn = "";
+ var $orig_dn = "";
+
/* attribute list for save action */
var $attributes= array("cn", "description", "gosaApplicationExecute", "gosaApplicationName","gosaApplicationIcon",
"gosaApplicationFlags","gotoLogonScript");
+
var $objectclasses= array("top", "gosaApplication");
+ var $FAIstate ="";
- var $isReleaseApplikation = false;
+ var $baseSelector;
function application (&$config, $dn= NULL, $parent= NULL)
{
plugin::plugin ($config, $dn, $parent);
- $appfilter = session::get('appfilter') ;
-
- $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
- if(!empty($tmp)) {
- if(!preg_match("/^".get_ou('applicationou')."/",$appfilter['release'])){
- $this->isReleaseApplikation = true;
- }
- }
-
/* Load icon */
$ldap= $config->get_ldap_link();
+ $this->orig_dn = $dn;
if ($dn != 'new'){
$this->iconData= $ldap->get_attribute($dn, "gosaApplicationIcon");
$this->saved_attributes['gosaApplicationIcon'] = $this->iconData;
$this->base= dn2base($ui->dn);
}
} else {
-
- if($this->isReleaseApplikation){
- $this->base = preg_replace("/^.*,".get_ou('applicationou')."/","",$this->dn);
- }else{
- $this->base= preg_replace ("/^[^,]+,[^,]+,/", "", $this->dn);
- }
+ $this->base= preg_replace ("/^[^,]+,".preg_quote(get_ou('applicationRDN'), '/')."/i", "", $this->dn);
}
+
+ $this->orig_cn = $this->cn;
+ $this->orig_base = $this->base;
+ $this->gosaApplicationFlags = preg_replace("/[^GDLMO]/","",$this->gosaApplicationFlags);
+
+ /* Instanciate base selector */
+ $this->baseSelector= new baseSelector($this->get_allowed_bases(), $this->base);
+ $this->baseSelector->setSubmitButton(false);
+ $this->baseSelector->setHeight(300);
+ $this->baseSelector->update(true);
}
$smarty= get_smarty();
+ /* Assign base ACL */
+ $smarty->assign("base", $this->baseSelector->render());
+
$tmp = $this->plInfo();
foreach($tmp['plProvidedAcls'] as $name => $translation){
- $smarty->assign($name."ACL",$this->getacl($name));
+ $smarty->assign($name."ACL",$this->getacl($name, preg_match("/freeze/i",$this->FAIstate)));
}
+ $smarty->assign("IconReadable", $this->acl_is_readable("gosaApplicationIcon"));
/* Do we represent a valid group? */
if (!$this->is_account && $this->parent === NULL){
- $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\"> <b>".
- _("This 'dn' is no application.")."</b>";
+ $display= "<img alt=\"\" src=\"images/small-error.png\" align=\"middle\"> <b>".
+ msgPool::noValidExtension(_("application"))."</b>";
return ($display);
}
$head = $this->generateTemplate();
$this->gotoLogonScript= $this->generateTemplate().preg_replace('/.*### END HEADER ###/s', '', $this->gotoLogonScript);
- if((isset($_POST['upLoad']))&&(isset($_FILES['ScriptFile']))){
+ if((isset($_POST['upLoad']))&&(isset($_FILES['ScriptFile'])) && !preg_match("/freeze/i",$this->FAIstate)){
$str = file_get_contents($_FILES['ScriptFile']['tmp_name']);
$this->gotoLogonScript = $str;
}
/* Fill templating stuff */
$smarty->assign("cn", $this->cn);
- $smarty->assign("bases", $this->get_allowed_bases());
+ if(!$this->is_release()){
+ $smarty->assign("bases", $this->get_allowed_bases());
+ }else{
+ $smarty->assign("bases", array());
+ }
if ($this->dn == "new"){
$smarty->assign("selectmode", "");
$smarty->assign("namemode", "");
$smarty->assign("selectmode", "disabled");
}
- /* Base select dialog */
- $once = true;
- foreach($_POST as $name => $value){
- if(preg_match("/^chooseBase/",$name) && $once){
- $once = false;
- $this->dialog = new baseSelectDialog($this->config,$this,$this->get_allowed_bases());
- $this->dialog->setCurrentBase($this->base);
- }
- }
-
- /* Dialog handling */
- if(is_object($this->dialog)){
- /* Must be called before save_object */
- $this->dialog->save_object();
-
- if($this->dialog->isClosed()){
- $this->dialog = false;
- }elseif($this->dialog->isSelected()){
-
- /* Just allow selection valid bases */
- $tmp = $this->get_allowed_bases();
- if(isset($tmp[$this->dialog->isSelected()])){
- $this->base = $this->dialog->isSelected();
- }
- $this->dialog= false;
- }else{
- return($this->dialog->execute());
- }
- }
-
/* Get random number for pictures */
srand((double)microtime()*1000000);
$smarty->assign("rand", rand(0, 10000));
}
/* Checkboxes */
- foreach (array("G" => "exec_for_groupmembers", "O" => "overwrite_config",
- "L" => "place_on_kicker",
- "D" => "place_on_desktop", "M" => "place_in_startmenu") as $key => $val){
- if (preg_match("/$key/", $this->gosaApplicationFlags)){
+ foreach (array("G" => "execForGroupmembers", "O" => "overwriteConfig",
+ "L" => "placeOnKicker",
+ "D" => "placeOnDesktop", "M" => "placeInStartmenu") as $key => $val){
+ if (preg_match("/$key/", $this->gosaApplicationFlags) && $this->acl_is_readable("$val")){
$smarty->assign("$val", "checked");
} else {
$smarty->assign("$val", "");
}
}
- $smarty->assign("isReleaseApplikation" , $this->isReleaseApplikation);
+ $smarty->assign("isReleaseApplikation" ,$this->is_release());
$smarty->assign("gotoLogonScript",htmlentities($this->gotoLogonScript, ENT_COMPAT, 'UTF-8'));
$smarty->assign("base_select", $this->base);
/* Show main page */
function remove_from_parent()
{
- restore_error_handler();
-
/* Parse release out of object dn */
- $release = preg_replace("/".get_ou("applicationou").normalizePreg($this->base)."$/","",$this->dn);
+ $release = preg_replace("/".preg_quote(get_ou("applicationRDN").$this->base, '/')."$/i","",$this->dn);
$release = preg_replace("/^cn=[^,]+,/","",$release);
/* Get a list of all groups
$ldap->cd($release.$group);
$ldap->search("(objectClass=gotoMenuEntry)",array("dn"));
while($attrs = $ldap->fetch()){
- $info = preg_replace("/".normalizePreg($release.$group)."$/","",$attrs['dn']);
+ $info = preg_replace("/".preg_quote($release.$group, '/')."$/","",$attrs['dn']);
if(preg_match("/^cn=".$this->cn."/",$info) && !preg_match("/ou=[^,]+,/",$info)){
$found[] = $attrs['dn'];
}
this application is still in use.
*/
if(count($found)){
- $objs = "";
- $cnt = 3;
- for($i = 0 ; $i < $cnt ; $i++ ){
- if(isset($found[$i])){
- $objs .= " ".$found[$i].",";
- }
- }
- if(count($found) > $cnt){
- $objs .= "... ";
- }
- $objs = trim($objs,", ");
- print_red(sprintf(_("Can not remove application, it is still in use by these objects: %s."),$objs));
+ msg_dialog::display(_("Error"), sprintf(_("Cannot remove application - it is still in use by these objects: %s"), "<br>".msgPool::buildList($found)), ERROR_DIALOG);
return(FALSE);
}
$ldap->rmDir($this->dn);
new log("remove","application/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
- show_ldap_error($ldap->get_error(), sprintf(_("Removing of application with dn '%s' failed."),$this->dn));
+ if (!$ldap->success()){
+ msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class()), ERROR_DIALOG);
+ }
/* Optionally execute a command after we're done */
$this->handle_post_events("remove");
$og= new ogroup($this->config, $ldap->getDN());
unset($og->member[$this->dn]);
$og->save ();
- show_ldap_error($ldap->get_error(), sprintf(_("Removing application from objectgroup '%s' failed"), $og->dn));
+ if (!$ldap->success()){
+ msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()), ERROR_DIALOG);
+ }
}
}
/* Save data to object */
function save_object()
{
+ if(preg_match("/freeze/i",$this->FAIstate)){
+ return;
+ }
+
if (isset($_POST['cn'])){
/* Create a base backup and reset the
plugin::save_object();
$this->base = $base_tmp;
+ /* Refresh base */
+ if(!$this->is_release()){
+ if ($this->acl_is_moveable($this->base)){
+ if (!$this->baseSelector->update()) {
+ msg_dialog::display(_("Error"), msgPool::permMove(), ERROR_DIALOG);
+ }
+ if ($this->base != $this->baseSelector->getBase()) {
+ $this->base= $this->baseSelector->getBase();
+ $this->is_modified= TRUE;
+ }
+ }
+ }
+
+
/* Save attributes */
parent::save_object();
+ $checks = array("execForGroupmembers" => "G",
+ "placeOnDesktop" => "D",
+ "placeOnKicker" => "L",
+ "placeInStartmenu" => "M",
+ "overwriteConfig" => "O");
+
+
/* Save application flags */
- $flag= "";
- if (isset($_POST['exec_for_groupmembers']) && $_POST['exec_for_groupmembers'] == 1){
- $flag.= "G";
- }
- if (isset($_POST['place_on_desktop']) && $_POST['place_on_desktop'] == 1){
- $flag.= "D";
- }
- if (isset($_POST['place_on_kicker']) && $_POST['place_on_kicker'] == 1){
- $flag.= "L";
- }
- if (isset($_POST['place_in_startmenu']) && $_POST['place_in_startmenu'] == 1){
- $flag.= "M";
- }
- if (isset($_POST['overwrite_config']) && $_POST['overwrite_config'] == 1){
- $flag.= "O";
- }
- if ($this->acl_is_writeable("gosaApplicationFlags")){
- $this->gosaApplicationFlags= "[$flag]";
+ foreach($checks as $name => $flag){
+ if($this->acl_is_writeable($name)){
+ $set = isset($_POST[$name]) && $_POST[$name] == 1;
+ if(!$set && strstr($this->gosaApplicationFlags,$flag)){
+ $this->gosaApplicationFlags = str_replace($flag,"",$this->gosaApplicationFlags);
+ }elseif($set && !preg_match("/".$flag."/",$this->gosaApplicationFlags)){
+ $this->gosaApplicationFlags .= $flag;
+ }
+ }
}
/* Remove current picture */
if (isset($_FILES['picture_file']['name']) && $_FILES['picture_file']['name'] != ""){
if (!is_uploaded_file($_FILES['picture_file']['tmp_name'])) {
- print_red (_("The specified picture has not been uploaded correctly."));
+ msg_dialog::display(_("Error"), msgPool::incorrectUpload(), ERROR_DIALOG);
}
if (!function_exists("imagick_blob2image")){
/* Get temporary file name for conversation */
- $fname = tempnam ("/tmp", "GOsa");
+ $fname = tempnam (TEMP_DIR, "GOsa");
/* Open file and write out photoData */
$fp = fopen ($fname, "w");
/* Load the new uploaded Photo */
if(!$handle = imagick_ReadImage($_FILES['picture_file']['tmp_name'])){
- print_red(_("Can't access uploaded image."));
+ msg_dialog::display(_("Error"), msgPool::incorrectUpload(_("no read permission")), ERROR_DIALOG);
}
/* Resizing image to 147x200 and blur */
if(!imagick_resize($handle,48,48,IMAGICK_FILTER_GAUSSIAN,0)){
- print_red(_("Uploaded image could not be resized, possilby the image magick extension is missing."));
+ msg_dialog::display(_("Error"), msgPool::incorrectUpload(_("cannot resize image")), ERROR_DIALOG);
}
/* Converting image to JPEG */
if(!imagick_convert($handle,"PNG")) {
- print_red(_("Could not convert image to png, possilby the image magick extension is missing."));
+ msg_dialog::display(_("Error"), msgPool::incorrectUpload(_("cannot convert image")), ERROR_DIALOG);
}
if(!imagick_writeimage($handle,$_FILES['picture_file']['tmp_name'])){
- print_red(sprintf(_("Could not save uploaded image to %s."),$_FILES['picture_file']['tmp_name']));
+ msg_dialog::display(_("Error"), msgPool::incorrectUpload(sprintf(_("cannot save image to '%s'"), $_FILES['picture_file']['tmp_name'])), ERROR_DIALOG);
}
imagick_free($handle);
/* Activate new picture */
$this->set_picture($_FILES['picture_file']['tmp_name']);
}
-
- if(!$this->isReleaseApplikation){
- $tmp = $this->get_allowed_bases();
- if(isset($_POST['base'])){
- if(isset($tmp[$_POST['base']])){
- $this->base= $_POST['base'];
- }
- }
- }
}
}
$message= plugin::check();
if(!preg_match("#^/#",$this->gosaApplicationExecute)){
- $message[]=(_("Specified execute path must start with '/'."));
+ $message[]=msgPool::invalid(_("Execute path"),"","","/some/path");
+ }
+
+ // Check if a wrong base was supplied
+ if(!$this->baseSelector->checkLastBaseUpdate()){
+ $message[]= msgPool::check_base();;
}
/* Permissions for that base? */
if ($this->base != ""){
- $new_dn= "cn=".$this->cn.",".get_ou('applicationou').$this->base;
+ $new_dn= "cn=".$this->cn.",".get_ou('applicationRDN').$this->base;
} else {
$new_dn= $this->dn;
}
/* All required fields are set? */
if ($this->cn == ""){
- $message[]= _("Required field 'Name' is not filled.");
+ $message[]= msgPool::required(_("Name"));
}
- if(preg_match("/[^a-z0-9]/",$this->cn)) {
- $message[]=_("Invalid character in application name. Only a-z 0-9 are allowed.");
+ if(preg_match("/[^a-z0-9_-]/",$this->cn)) {
+ $message[]=msgPool::invalid(_("Name"),$this->cn,"/^[a-z0-9_-]*$/");
}
if ($this->gosaApplicationExecute == ""){
- $message[]= _("Required field 'Execute' is not filled.");
+ $message[]= msgPool::required(_("Execute"));
}
/* Check for existing application */
$ldap= $this->config->get_ldap_link();
$ldap->cd($this->config->current["BASE"]);
-
- $tmp = $this->config->search("faiManagement", "CLASS",array('menu','tabs'));
- $appfilter = session::get('appfilter');
- if((!empty($tmp)) && (isset($appfilter['release']))){
- $baseDn = str_replace($this->config->current['BASE'],$this->base,$appfilter['release']);
- $baseDn = preg_replace("/".get_ou('applicationou').".*/",get_ou('applicationou').$this->base,$appfilter['release']);
- $ldap->ls("(&(objectClass=gosaApplication)(cn=".$this->cn."))",$baseDn,array("cn"));
- if($ldap->count()){
- $attrs = $ldap->fetch();
- if($this->dn != $attrs['dn']) {
- $message[]= _("There's already an application with this 'Name'.");
- }
- }
+ if($this->is_release()){
+ $base = $this->parent->parent->app_release;
}else{
- $ldap->ls("(&(objectClass=gosaApplication)(cn=".$this->cn."))",get_ou('applicationou').$this->base,array("cn"));
- if ($ldap->count()){
- $attrs = $ldap->fetch();
- if($this->dn != $attrs['dn']) {
- $message[]= _("There's already an application with this 'Name'.");
- }
+ $base = get_ou('applicationRDN').$this->base;
+ }
+
+ $ldap->ls("(&(objectClass=gosaApplication)(cn=".$this->cn."))",$base,array("cn"));
+ if($ldap->count()){
+ $attrs = $ldap->fetch();
+ if($this->dn != $attrs['dn']) {
+ $message[]= msgPool::duplicated("cn");
}
}
+
+ /* Check if we are allowed to create or move this object
+ */
+ if($this->orig_dn == "new" && !$this->acl_is_createable($this->base)){
+ $message[] = msgPool::permCreate();
+ }elseif($this->orig_dn != "new" && $this->base != $this->orig_base && !$this->acl_is_moveable($this->base)){
+ $message[] = msgPool::permMove();
+ }
+
return $message;
}
/* Get application script without header part, to check if we must save the script itself */
$script = preg_replace('/.*### END HEADER ###/s', '', $this->gotoLogonScript);
+ $this->gosaApplicationFlags ="[{$this->gosaApplicationFlags}]";
plugin::save();
$this->attrs["gosaApplicationIcon"]= $this->gosaApplicationIcon;
new log("create","application/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
$this->handle_post_events("add");
}
- show_ldap_error($ldap->get_error(), sprintf(_("Saving of application with dn '%s' failed."),$this->dn));
+ if (!$ldap->success()){
+ msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()), ERROR_DIALOG);
+ }
}
+
+ function is_release()
+ {
+ if(isset($this->parent->parent)){
+ return($this->parent->parent->IsReleaseManagementActivated());
+ }else{
+
+ /* Check if we should enable the release selection */
+ return($this->config->pluginEnabled("faiManagement"));
+ }
+ return(FALSE);
+ }
+
+
function set_picture($filename)
{
if (!is_file($filename)){
- $filename= "./images/default_icon.png";
+ $filename= "./plugins/goto/images/default_icon.png";
$this->gosaApplicationIcon= "*removed*";
}
{
$vars = array("cn");
- $str ="<h2>"._("Application settings")."</h2>
- <table>
+ $str ="<h3>"._("Application settings")."</h3>
+ <table summary=\""._("Application settings")."\">
<tr>
<td>".
_("Application name").
#FIXME FAIscript seams to ununsed within this class... */
static function plInfo()
{
- return (array(
- "plShortName" => _("Generic"),
- "plDescription" => _("Application generic"),
- "plSelfModify" => FALSE,
- "plDepends" => array(),
- "plPriority" => 0,
- "plSection" => array("administration"),
- "plCategory" => array("application" => array("description" => _("Application"),
- "objectClass" => "gosaApplication")),
+ return (array(
+ "plShortName" => _("Generic"),
+ "plDescription" => _("Application generic"),
+ "plSelfModify" => FALSE,
+ "plDepends" => array(),
+ "plPriority" => 0,
+ "plSection" => array("administration"),
+ "plCategory" => array("application" => array("description" => _("Application"),
+ "objectClass" => "gosaApplication")),
+ "plProperties" =>
+ array(
+ array(
+ "name" => "applicationRDN",
+ "type" => "rdn",
+ "default" => "ou=apps,",
+ "description" => "The 'applicationRDN' statement defines the location where new applications will be created. The default is 'ou=apps,'.",
+ "check" => "gosaProperty::isRdn",
+ "migrate" => "",
+ "group" => "plugin",
+ "mandatory" => FALSE)),
+
"plProvidedAcls"=> array(
- "cn" => _("Name"),
- "base" => _("Base"),
- "description" => _("Description"),
- "gosaApplicationExecute" => _("Execute"),
- "gosaApplicationName" => _("Name"),
- "gosaApplicationIcon" => _("Icon"),
- "gosaApplicationFlags" => _("Flag"),
- "gotoLogonScript" => _("Script content"),
-
- "exec_for_groupmembers" => _("Only executable for members"), // G
- "place_on_desktop" => _("Place icon on members desktop"), // D
- "place_on_kicker" => _("Place entry in members launch bar"), // L
- "place_in_startmenu" => _("Place entry in members startmenu"), // M
- "overwrite_config" => _("Replace user configuration on startup")) // O
- ));
+ "cn" => _("Name"),
+ "base" => _("Base"),
+ "description" => _("Description"),
+ "gosaApplicationExecute" => _("Execute"),
+ "gosaApplicationName" => _("Name"),
+ "gosaApplicationIcon" => _("Icon"),
+ "gotoLogonScript" => _("Script content"),
+
+ "execForGroupmembers" => _("Only executable for members"), // G
+ "placeOnDesktop" => _("Place icon on members desktop"), // D
+ "placeOnKicker" => _("Place entry in members launch bar"), // L
+ "placeInStartmenu" => _("Place entry in members startmenu"), // M
+ "overwriteConfig" => _("Replace user configuration on startup")) // O
+ ));
}
}
// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: