diff --git a/plugins/admin/applications/class_applicationGeneric.inc b/plugins/admin/applications/class_applicationGeneric.inc
index e1e3582b3bbbe99cdec53df83f269fe126086041..967eaaf634992091264694944290d529e0881e14 100644 (file)
/* attribute list for save action */
var $attributes= array("cn", "description", "gosaApplicationExecute", "gosaApplicationName","gosaApplicationIcon",
- "gosaApplicationFlags","gotoLogonScript");
+ "gosaApplicationFlags","gotoLogonScript");
var $objectclasses= array("top", "gosaApplication");
+ var $isReleaseApplikation = false;
+
function application ($config, $dn= NULL)
{
- plugin::plugin ($config, $dn);
-
- /* Load icon */
- $ldap= $config->get_ldap_link();
- if ($dn != 'new'){
- $this->iconData= $ldap->get_attribute($dn, "gosaApplicationIcon");
- $this->saved_attributes['gosaApplicationIcon'] = $this->iconData;
- }
- if ($this->iconData == ""){
- $this->set_picture("");
- }
- $_SESSION['binary']= $this->iconData;
- $_SESSION['binarytype']= "image/jpeg";
- $this->gosaApplicationIcon= $this->iconData;
-
- /* This is always an account */
- $this->is_account= TRUE;
-
- if ($this->dn == "new"){
- if(isset($_SESSION['appfilter']['depselect'])){
- $this->base=$_SESSION['appfilter']['depselect'];
- }else{
- $ui= get_userinfo();
- $this->base= dn2base($ui->dn);
- }
- } else {
- $this->base= preg_replace ("/^[^,]+,[^,]+,/", "", $this->dn);
- }
+ plugin::plugin ($config, $dn);
+
+ $tmp = search_config($this->config->data,"faiManagement","CLASS");
+ if(!empty($tmp)) {
+ if(!preg_match("/^ou=apps,/",$_SESSION['appfilter']['release'])){
+ $this->isReleaseApplikation = true;
+ }
+ }
+
+ /* Load icon */
+ $ldap= $config->get_ldap_link();
+ if ($dn != 'new'){
+ $this->iconData= $ldap->get_attribute($dn, "gosaApplicationIcon");
+ $this->saved_attributes['gosaApplicationIcon'] = $this->iconData;
+ }
+ if ($this->iconData == ""){
+ $this->set_picture("");
+ }
+ $_SESSION['binary']= $this->iconData;
+ $_SESSION['binarytype']= "image/jpeg";
+ $this->gosaApplicationIcon= $this->iconData;
+
+ /* This is always an account */
+ $this->is_account= TRUE;
+
+ if ($this->dn == "new"){
+ if(isset($_SESSION['CurrentMainBase'])){
+ $this->base= $_SESSION['CurrentMainBase'];
+ }else{
+ $ui= get_userinfo();
+ $this->base= dn2base($ui->dn);
+ }
+ } else {
+ $this->base= preg_replace ("/^[^,]+,[^,]+,/", "", $this->dn);
+ }
}
function generateTemplate(){
- $str= "# This code is part of GOsa (https://gosa.gonicus.de)\n#\n";
-
- $values = array();
- $names = array();
- if($this->parent->by_object['applicationParameters']->is_account){
- $names = $this->parent->by_object['applicationParameters']->option_name;
- $values = $this->parent->by_object['applicationParameters']->option_value;
- }
-
- if (count($names)){
- $str .="# This plugin handles these environment variables:\n";
- } else {
- $str .="# This plugin handles no environment variables.\n";
- }
-
- foreach($names as $index => $name){
-
- // Fix length
- for($i = strlen($name) ; $i < 30 ; $i++){
- $name= $name." ";
- }
- if((isset($values[$index]))&&(!empty($values[$index]))){
- $str.= "# ".$name."\t(e.g. '".$values[$index]."')\n";
- }else{
- $str.= "# ".$name."\t("._("no example").")\n";
- }
- }
- $str .= "#\n".
- "# Don't remove the following tag, it is used for header update.\n".
- "### END HEADER ###";
-
- return($str);
+ $str= "# This code is part of GOsa (https://gosa.gonicus.de)\n#\n";
+
+ $values = array();
+ $names = array();
+ if($this->parent->by_object['applicationParameters']->is_account){
+ $names = $this->parent->by_object['applicationParameters']->option_name;
+ $values = $this->parent->by_object['applicationParameters']->option_value;
+ }
+
+ if (count($names)){
+ $str .="# This plugin handles these environment variables:\n";
+ } else {
+ $str .="# This plugin handles no environment variables.\n";
+ }
+
+ foreach($names as $index => $name){
+
+ // Fix length
+ for($i = strlen($name) ; $i < 30 ; $i++){
+ $name= $name." ";
+ }
+ if((isset($values[$index]))&&(!empty($values[$index]))){
+ $str.= "# ".$name."\t(e.g. '".$values[$index]."')\n";
+ }else{
+ $str.= "# ".$name."\t("._("no example").")\n";
+ }
+ }
+ $str .= "#\n".
+ "# Don't remove the following tag, it is used for header update.\n".
+ "### END HEADER ###";
+
+ return($str);
}
function execute()
{
- /* Call parent execute */
- plugin::execute();
-
- $smarty= get_smarty();
-
- /* 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>";
- return ($display);
- }
-
- $head = $this->generateTemplate();
- $this->gotoLogonScript= $this->generateTemplate().preg_replace('/.*### END HEADER ###/s', '', $this->gotoLogonScript);
-
- if((isset($_POST['upLoad']))&&(isset($_FILES['ScriptFile']))){
- $str = file_get_contents($_FILES['ScriptFile']['tmp_name']);
- $this->gotoLogonScript = $str;
- }
-
- /* Fill templating stuff */
- $smarty->assign("cn", $this->cn);
- $smarty->assign("bases", $this->config->idepartments);
- if ($this->dn == "new"){
- $smarty->assign("selectmode", "");
- $smarty->assign("namemode", "");
- } else {
- $smarty->assign("namemode", "readonly");
- $smarty->assign("selectmode", "disabled");
- }
-
- /* Get random number for pictures */
- srand((double)microtime()*1000000);
- $smarty->assign("rand", rand(0, 10000));
-
- /* Variables */
- foreach(array("description", "gosaApplicationExecute", "gosaApplicationName","cn") as $val){
- $smarty->assign($val, $this->$val);
- $smarty->assign($val."ACL", chkacl($this->acl, $val));
- }
-
- /* 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)){
- $smarty->assign("$val", "checked");
- } else {
- $smarty->assign("$val", "");
- }
- }
- $smarty->assign("gotoLogonScript",htmlentities($this->gotoLogonScript, ENT_COMPAT, 'UTF-8'));
- $smarty->assign("base_select", $this->base);
- $smarty->assign("gosaApplicationFlagsACL", chkacl($this->acl, "gosaApplicationFlags"));
- /* Show main page */
- return($smarty->fetch (get_template_path('generic.tpl', TRUE)));
+ /* Call parent execute */
+ plugin::execute();
+
+ $smarty= get_smarty();
+
+ /* 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>";
+ return ($display);
+ }
+
+ $_SESSION['binary'] = $this->gotoLogonScript;
+ $_SESSION['binarytype'] = "octet-stream";
+ $_SESSION['binaryfile'] = $this->cn.".gosaApplication";
+ $smarty->assign("rand", rand(0, 10000));
+ $head = $this->generateTemplate();
+ $this->gotoLogonScript= $this->generateTemplate().preg_replace('/.*### END HEADER ###/s', '', $this->gotoLogonScript);
+
+ if((isset($_POST['upLoad']))&&(isset($_FILES['ScriptFile']))){
+ $str = file_get_contents($_FILES['ScriptFile']['tmp_name']);
+ $this->gotoLogonScript = $str;
+ }
+
+ /* Fill templating stuff */
+ $smarty->assign("cn", $this->cn);
+ $smarty->assign("bases", $this->config->idepartments);
+ if ($this->dn == "new"){
+ $smarty->assign("selectmode", "");
+ $smarty->assign("namemode", "");
+ } else {
+ $smarty->assign("namemode", "readonly");
+ $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->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()){
+ $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));
+
+ /* Variables */
+ foreach(array("description", "gosaApplicationExecute", "gosaApplicationName","cn") as $val){
+ $smarty->assign($val, $this->$val);
+ $smarty->assign($val."ACL", chkacl($this->acl, $val));
+ }
+ $smarty->assign("baseACL", chkacl($this->acl,"base"));
+
+ /* 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)){
+ $smarty->assign("$val", "checked");
+ } else {
+ $smarty->assign("$val", "");
+ }
+ }
+
+ $smarty->assign("isReleaseApplikation" , $this->isReleaseApplikation);
+ $smarty->assign("gotoLogonScript",htmlentities($this->gotoLogonScript, ENT_COMPAT, 'UTF-8'));
+ $smarty->assign("base_select", $this->base);
+ $smarty->assign("gosaApplicationFlagsACL", chkacl($this->acl, "gosaApplicationFlags"));
+ /* Show main page */
+ return($smarty->fetch (get_template_path('generic.tpl', TRUE)));
}
function remove_from_parent()
{
- $ldap= $this->config->get_ldap_link();
- $ldap->rmDir($this->dn);
-
- /* Optionally execute a command after we're done */
- $this->handle_post_events("remove");
-
- /* Delete references to object groups */
- $ldap->cd ($this->config->current['BASE']);
- $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
- while ($ldap->fetch()){
- $og= new ogroup($this->config, $ldap->getDN());
- unset($og->member[$this->dn]);
- $og->save ();
- }
- $ldap->search ("(&(objectClass=posixGroup)(gosaMemberApplication=".$this->cn."))", array("cn"));
- while ($attrs= $ldap->fetch()){
- $ag= new appgroup($this->config, $ldap->getDN());
- $ag->removeApp($this->cn);
- $ag->save ();
- }
+ $ldap= $this->config->get_ldap_link();
+ $ldap->rmDir($this->dn);
+ show_ldap_error($ldap->get_error(), sprintf(_("Removing of application with dn '%s' failed."),$this->dn));
+
+ /* Optionally execute a command after we're done */
+ $this->handle_post_events("remove");
+
+ /* Delete references to object groups */
+ $ldap->cd ($this->config->current['BASE']);
+ $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
+ while ($ldap->fetch()){
+ $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));
+ }
+ $ldap->search ("(&(objectClass=posixGroup)(gosaMemberApplication=".$this->cn."))", array("cn"));
+ while ($attrs= $ldap->fetch()){
+ $ag= new appgroup($this->config, $ldap->getDN());
+ $ag->removeApp($this->cn);
+ $ag->save ();
+ show_ldap_error($ldap->get_error(), sprintf(_("Removing application from group '%s' failed"), $ag->dn));
+ }
}
/* Save data to object */
function save_object()
{
+ if($this->isReleaseApplikation){
+ $tmpBase = $this->base;
+ }
+
if (isset($_POST['cn'])){
/* Save attributes */
if (!is_uploaded_file($_FILES['picture_file']['tmp_name'])) {
print_red (_("The specified picture has not been uploaded correctly."));
}
-
+
if (!function_exists("imagick_blob2image")){
/* Get temporary file name for conversation */
$fname = tempnam ("/tmp", "GOsa");
if(imagick_writeimage($handle,$_FILES['picture_file']['tmp_name'])){
gosa_log("can't write to specified folder");
}
-
+
imagick_free($handle);
}
/* Activate new picture */
$this->set_picture($_FILES['picture_file']['tmp_name']);
- }
+ }
/* Save base, since this is no LDAP attribute */
}
}
+ if($this->isReleaseApplikation){
+ $this->base = $tmpBase;
+ }
}
/* Check values */
function check()
{
- $message= array();
+ /* Call common method to give check the hook */
+ $message= plugin::check();
if(!preg_match("#^/#",$this->gosaApplicationExecute)){
- print_red(_("Specified execute path must start with '/'."));
+ $message[]=(_("Specified execute path must start with '/'."));
}
/* Permissions for that base? */
/* Check for existing application */
$ldap= $this->config->get_ldap_link();
$ldap->cd($this->config->current["BASE"]);
- $ldap->search("(&(objectClass=gosaApplication)(cn=$this->cn))",array("cn"));
- $ldap->fetch();
- if ($ldap->count() != 0 && $this->dn == "new"){
- $message[]= _("There's already an application with this 'Name'.");
- }
+ $tmp = search_config($this->config->data,"faiManagement","CLASS");
+ if((!empty($tmp)) && (isset($_SESSION['appfilter']['release']))){
+ $baseDn = str_replace($this->config->current['BASE'],$this->base,$_SESSION['appfilter']['release']);
+ $baseDn = preg_replace("/ou=apps,.*/","ou=apps,".$this->base,$_SESSION['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'.");
+ }
+ }
+ }else{
+ $ldap->ls("(&(objectClass=gosaApplication)(cn=".$this->cn."))","ou=apps,".$this->base,array("cn"));
+ if ($ldap->count()){
+ $attrs = $ldap->fetch();
+ if($this->dn != $attrs['dn']) {
+ $message[]= _("There's already an application with this 'Name'.");
+ }
+ }
+ }
return $message;
}
/* Save to LDAP */
function save()
{
- plugin::save();
- $this->attrs["gosaApplicationIcon"]= $this->gosaApplicationIcon;
-
- /* Write back to ldap */
- $ldap= $this->config->get_ldap_link();
- $ldap->cat($this->dn);
- $a= $ldap->fetch();
- if (count($a)){
- $ldap->cd($this->dn);
- $this->cleanup();
-$ldap->modify ($this->attrs);
-
- $this->handle_post_events("modify");
- } else {
- $ldap->cd($this->config->current['BASE']);
- $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
- $ldap->cd($this->dn);
- $ldap->add($this->attrs);
- $this->handle_post_events("add");
- }
- show_ldap_error($ldap->get_error());
+ plugin::save();
+ $this->attrs["gosaApplicationIcon"]= $this->gosaApplicationIcon;
+
+ /* Write back to ldap */
+ $ldap= $this->config->get_ldap_link();
+ $ldap->cat($this->dn, array('dn'));
+
+ $a= $ldap->fetch();
+ if (count($a)){
+ $ldap->cd($this->dn);
+ $this->cleanup();
+ $ldap->modify ($this->attrs);
+ $this->handle_post_events("modify");
+ } else {
+ $ldap->cd($this->config->current['BASE']);
+ $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
+ $ldap->cd($this->dn);
+ $ldap->add($this->attrs);
+ $this->handle_post_events("add");
+ }
+ show_ldap_error($ldap->get_error(), sprintf(_("Saving of application with dn '%s' failed."),$this->dn));
}
function set_picture($filename)
{
- if (!is_file($filename)){
- $filename= "./images/default_icon.png";
- $this->gosaApplicationIcon= "*removed*";
- }
-
- if (file_exists($filename)){
- $fd = fopen ($filename, "rb");
- $this->iconData= fread ($fd, filesize ($filename));
- $_SESSION['binary']= $this->iconData;
- $_SESSION['binarytype']= "image/jpeg";
- $this->gosaApplicationIcon= $this->iconData;
-
- fclose ($fd);
- }
+ if (!is_file($filename)){
+ $filename= "./images/default_icon.png";
+ $this->gosaApplicationIcon= "*removed*";
+ }
+
+ if (file_exists($filename)){
+ $fd = fopen ($filename, "rb");
+ $this->iconData= fread ($fd, filesize ($filename));
+ $_SESSION['binary']= $this->iconData;
+ $_SESSION['binarytype']= "image/jpeg";
+ $this->gosaApplicationIcon= $this->iconData;
+
+ fclose ($fd);
+ }
}
function getCopyDialog()
{
$vars = array("cn");
-
- $str ="<h2>"._("Application settings")."</h2>
- <table>
- <tr>
- <td>".
- _("Application name").
- "</td>
- <td>
- <input id='gosaApplicationName' name='cn' size='35' maxlength='60'
- value='".$this->cn."'
- title='"._("Application name to be displayed (i.e. below icons)")."'>
- </td>
- </tr>
- </table>";
- return($str);
+ $str ="<h2>"._("Application settings")."</h2>
+ <table>
+ <tr>
+ <td>".
+ _("Application name").
+ "</td>
+ <td>
+ <input id='gosaApplicationName' name='cn' size='35' maxlength='60'
+ value='".$this->cn."'
+ title='"._("Application name to be displayed (i.e. below icons)")."'>
+ </td>
+ </tr>
+ </table>";
+ $ret = array();
+ $ret['status'] = "";
+ $ret['string'] = $str;
+ return($ret);
}
function saveCopyDialog()
$this->cn = $_POST['cn'];
}
}
+
+
+ /* Return plugin informations for acl handling
+ #FIXME FAIscript seams to ununsed within this class... */
+ 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")),
+ "plProvidedAcls"=> array(
+ "cn" => _("Name"),
+ "description" => _("Description"),
+ "gosaApplicationExecute" => _("Execute"),
+ "gosaApplicationName" => _("Name"),
+ "gosaApplicationIcon" => _("Icon"),
+ "gosaApplicationFlags" => _("Flag"),
+ "gotoLogonScript" => _("Script content"),
+ "gosaApplicationParameter"=> _("Application parameter"),
+
+ "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
+ ));
+ }
}
// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
?>