config= $config;
$this->ui= $ui;
/* Creat dialog object */
$this->DivListSystem = new divListSystem($this->config,$this);
}
function execute()
{
/* Call parent execute */
plugin::execute();
$_SESSION['LOCK_VARS_TO_USE'] = array("/^system_edit_/i","/^system_del_/","/^act/","/^id/");
/********************
Check for functional posts, edit|delete|add|... system devices
********************/
$s_action = ""; // Contains the action to proceed
$s_entry = ""; // The value for s_action
$base_back = ""; // The Link for Backbutton
$smarty = get_smarty();
/* Test Posts */
foreach($_POST as $key => $val){
// Post for delete
if(preg_match("/system_del.*/",$key)){
$s_action = "del";
$s_entry = preg_replace("/system_del_/i","",$key);
// Post for edit
}elseif(preg_match("/system_edit_.*/",$key)){
$s_action="edit";
$s_entry = preg_replace("/system_edit_/i","",$key);
// Post for new
}elseif(preg_match("/system_new.*/",$key)){
$s_action="new";
}elseif(preg_match("/system_tplnew.*/i",$key)){
$s_action="new_tpl";
}elseif(preg_match("/system_setpwd_.*/i",$key)){
$s_action="change_pw";
$s_entry = preg_replace("/system_setpwd_/i","",$key);
}elseif(preg_match("/gen_cd_.*/i",$key)){
$s_action="gen_cd";
$s_entry = preg_replace("/gen_cd_/i","",$key);
}elseif(preg_match("/newsystem_.*/i",$key)){
$s_action="newsystem";
$s_entry = preg_replace("/newsystem_/i","",$key);
}
}
/* Incoming handling
* If someone made a systemtype and ogroup selection
* Display the new requested entry type ... servtab in case of server and so on.
*/
if(isset($_POST['SystemTypeChoosen'])){
$s_action = "SelectedSystemType";
$s_entry = $_POST['SystemType'];
$_SESSION['SelectedSystemType']['ogroup'] = $_POST['ObjectGroup'];
$this->systab = NULL;
}
/* remove image tags from posted entry (posts looks like this 'name_x')*/
$s_entry = preg_replace("/_.$/","",$s_entry);
/* Edit was requested by pressing the name(link) of an item */
if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){
$s_action ="edit";
$s_entry = $_GET['id'];
}
/* Check for exeeded sizelimit */
if (($message= check_sizelimit()) != ""){
return($message);
}
/* Try to get informations about what kind of system to create */
if ($s_action=="new") {
return ($smarty->fetch(get_template_path('chooser.tpl', TRUE)));
}
/********************
Create FAI CD ...
********************/
if ($s_action=="gen_cd"){
$this->dn= $this->terminals[$s_entry]['dn'];
$_SESSION['objectinfo']= $this->dn;
return ($smarty->fetch(get_template_path('gencd.tpl', TRUE)));
}
/* Start CD-Creation */
if ((isset($_POST["cd_create"])) && !empty($this->dn)){
$smarty->assign("src", "?plug=".$_GET['plug']."&PerformIsoCreation");
return ($smarty->fetch(get_template_path('gencd_frame.tpl', TRUE)));
}
if ($this->dn != "" && isset($_GET['PerformIsoCreation'])){
$return_button = "
";
$dsc = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"));
/* Get and check command */
$command= search_config($this->config->data['TABS'], "workgeneric", "ISOCMD");
if (check_command($command)){
@DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__, $command, "Execute");
/* Print out html introduction */
echo '
';
/* Open process handle and check if it is a valid process */
$process= proc_open($command." '".$this->dn."'", $dsc, $pipes);
if (is_resource($process)) {
fclose($pipes[0]);
/* Print out returned lines && write JS to scroll down each line */
while (!feof($pipes[1])){
$cur_dat = fgets($pipes[1], 1024);
echo $cur_dat;
echo '' ;
flush();
}
}
/* Get error string && close streams */
$buffer= stream_get_contents($pipes[2]);
fclose($pipes[1]);
fclose($pipes[2]);
echo "
"._("Creating the image failed. Please see the report below.")."
";
echo "
$buffer
";
}
echo $return_button." ";
} else {
$tmp= "
".sprintf(_("Command '%s', specified for ISO creation doesn't seem to exist."), $command)."
";
echo $tmp;
}
/* Scroll down completly */
echo '' ;
echo '';
flush();
exit;
}
/********************
Create new system ...
********************/
/* Create new default terminal
* Or create specified object of selected system type, from given incoming object
*/
$save_object_directly = false;
if(($s_action == "SelectedSystemType") && (isset($_POST['ObjectGroup']) && ($_POST['ObjectGroup'] != "none"))){
$save_object_directly = true;
}
if (isset($_POST['create_system'])||$s_action=="newsystem"||$s_action == "SelectedSystemType") {
/* If the current entry is an incoming object
* $sw = System type as posted in new incoming handling dialog
*/
if($s_action == "SelectedSystemType") {
$sw = $s_entry;
}else{
if(isset($_POST['system'])){
$sw = $_POST['system'];
}else{
$sw = $s_entry;
}
$this->dn= "new";
}
$tabs = array(
"terminal" => array("CLASS"=>"TERMTABS", "TABNAME"=>"termgeneric", "TABCLASS" =>"termtabs", "ACL"=> "terminal"),
"workstation" => array("CLASS"=>"WORKTABS", "TABNAME"=>"workgeneric", "TABCLASS" =>"worktabs", "ACL"=> "workstation"),
"server" => array("CLASS"=>"SERVTABS", "TABNAME"=>"servgeneric", "TABCLASS" =>"servtabs", "ACL"=> "server"),
"printer" => array("CLASS"=>"PRINTTABS", "TABNAME"=>"printgeneric", "TABCLASS" =>"printtabs", "ACL"=> "printer"),
"phone" => array("CLASS"=>"PHONETABS", "TABNAME"=>"phonegeneric", "TABCLASS" =>"phonetabs", "ACL"=> "phone"),
"component" => array("CLASS"=>"COMPONENTTABS","TABNAME"=>"componentgeneric","TABCLASS" =>"componenttabs", "ACL"=> "component"));
if(isset($tabs[$sw])){
$class = $tabs[$sw]["CLASS"];
$tabname = $tabs[$sw]["TABNAME"];
$tabclass = $tabs[$sw]["TABCLASS"];
$acl_cat = $tabs[$sw]["ACL"];
/* Load permissions for selected 'dn' and check if
we're allowed to remove this 'dn' */
$ui = get_userinfo();
$tabacl = $ui->get_permissions($this->DivListSystem->selectedBase,$acl_cat."/".$tabname);
if(preg_match("/c/",$tabacl)){
$this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$sw);
$this->systab->set_acl_base($this->DivListSystem->selectedBase);
$this->systab->by_object[$tabname]->base = $this->DivListSystem->selectedBase;
$this->systab->base = $this->DivListSystem->selectedBase;
}else{
print_red(_("You are not allowed to create a new object of this type."));
}
}
}
/********************
Edit system ...
********************/
/* User wants to edit data? */
if (($s_action == "edit") && (!isset($this->systab->config))){
$this->dn= $this->terminals[$s_entry]['dn'];
/* Check locking, save current plugin in 'back_plugin', so
the dialog knows where to return. */
if (($user= get_lock($this->dn)) != ""){
return(gen_locked_message ($user, $this->dn));
}
/* Find out more about the object type */
$ldap= $this->config->get_ldap_link();
$ldap->cat($this->dn, array('objectClass'));
$attrs= $ldap->fetch();
$type= $this->get_system_type($attrs['objectClass']);
/* Lock the current entry, so everyone will get the
above dialog */
$tabs = array(
"terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal"),
"workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs", "ACL"=> "workstation"),
"server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs", "ACL"=> "server"),
"printer" => array("CLASS"=>"PRINTTABS", "TABCLASS" =>"printtabs", "ACL"=> "printer"),
"phone" => array("CLASS"=>"PHONETABS", "TABCLASS" =>"phonetabs", "ACL"=> "phone"),
"winstation" => array("CLASS"=>"WINTABS", "TABCLASS" =>"wintabs", "ACL"=> "winworkstation"),
"component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component"));
if($type == "NewDevice"){
$this->systab = new SelectDeviceType($this->config,$this->dn) ;
}elseif(isset($tabs[$type])){
$class = $tabs[$type]["CLASS"];
$acl_cat = $tabs[$type]["ACL"];
$tabclass = $tabs[$type]["TABCLASS"];
$this->systab= new $tabclass($this->config, $this->config->data['TABS'][$class], $this->dn,$acl_cat);
$this->systab->set_acl_base($this->dn);
$_SESSION['objectinfo']= $this->dn;
add_lock ($this->dn, $this->ui->dn);
}else{
print_red (_("You can't edit this object type yet!"));
del_lock($this->dn);
}
}
/********************
Change password ...
********************/
/* Set terminals root password */
if ($s_action=="change_pw"){
$tabs = array(
"terminal" => array("CLASS"=>"TERMTABS", "TABNAME"=>"termgeneric", "TABCLASS" =>"termtabs", "ACL"=> "terminal"),
"workstation" => array("CLASS"=>"WORKTABS", "TABNAME"=>"workgeneric", "TABCLASS" =>"worktabs", "ACL"=> "workstation"));
$type = $this->get_system_type($this->terminals[$s_entry]['objectClass']);
$class = $tabs[$type]["CLASS"];
$tabname = $tabs[$type]["TABNAME"];
$acl_cat = $tabs[$type]["ACL"];
$tabclass = $tabs[$type]["TABCLASS"];
$ui = get_userinfo();
$tabacl = $ui->get_permissions($this->DivListSystem->selectedBase,$acl_cat."/".$tabname,"gotoRootPasswd");
if(preg_match("/w/",$tabacl)){
$this->dn= $this->terminals[$s_entry]['dn'];
$_SESSION['objectinfo']= $this->dn;
return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
}else{
print_red(_("You are not allowed to change the password for this object."));
}
}
/********************
Password change finish, but check if entered data is ok
********************/
/* Correctly specified? */
if (isset($_POST['password_finish'])){
if ($_POST['new_password'] != $_POST['repeated_password']){
print_red (_("Passwords entered as new and repeated do not match!"));
return($smarty->fetch(get_template_path('password.tpl', TRUE)));
}
}
/********************
Password change finish
********************/
/* Change terminal password */
if (isset($_POST['password_finish']) &&
$_POST['new_password'] == $_POST['repeated_password']){
/* Check if user is allowed to set password */
$tabs = array(
"terminal" => array("CLASS"=>"TERMTABS", "TABNAME"=>"termgeneric", "TABCLASS" =>"termtabs", "ACL"=> "terminal"),
"workstation" => array("CLASS"=>"WORKTABS", "TABNAME"=>"workgeneric", "TABCLASS" =>"worktabs", "ACL"=> "workstation"));
/* Detect object type */
$type = "";
foreach($this->terminals as $terminal){
if($terminal['dn'] == $this->dn){
$type = $this->get_system_type($terminal['objectClass']);
break;
}
}
/* Type detected */
if(!empty($type)){
/* Get infos */
$class = $tabs[$type]["CLASS"];
$tabname = $tabs[$type]["TABNAME"];
$acl_cat = $tabs[$type]["ACL"];
$tabclass = $tabs[$type]["TABCLASS"];
/* Get acls */
$ui = get_userinfo();
$tabacl = $ui->get_permissions($this->DivListSystem->selectedBase,$acl_cat."/".$tabname,"gotoRootPasswd");
/* Check acls */
if(preg_match("/w/",$tabacl)){
$ldap = $this->config->get_ldap_link();
$ldap->cd($this->dn);
$attrs= array();
if ($_POST['new_password'] == ""){
$attrs['gotoRootPasswd']= array();
} else {
$attrs['gotoRootPasswd']= crypt($_POST['new_password'],substr(session_id(),0,2));
}
$ldap->modify($attrs);
gosa_log ("Password for '".$this->dn."' has been changed");
}else{
print_red(_("You are not allowed to change the password for this object."));
}
}else{
print_red(_("Can't detect object to change password."));
}
unset($_SESSION['objectinfo']);
}
/********************
Delete system cancel
********************/
/* Delete terminal canceled? */
if (isset($_POST['delete_cancel']) || isset($_POST['password_cancel'])){
del_lock ($this->dn);
unset($_SESSION['objectinfo']);
}
/********************
Delete system, confirm dialog
********************/
/* Remove terminal was requested */
if ($s_action=="del"){
/* Get 'dn' from posted termlinst */
$this->dn = $this->terminals[$s_entry]['dn'];
$attrs = $this->terminals[$s_entry];
$type= $this->get_system_type($attrs['objectClass']);
$ui = get_userinfo();
$tabs = array(
"terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal/termgeneric"),
"workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs", "ACL"=> "workstation/workgeneric"),
"server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs", "ACL"=> "server/servgeneric"),
"printer" => array("CLASS"=>"PRINTTABS", "TABCLASS" =>"printtabs", "ACL"=> "printer/printgeneric"),
"phone" => array("CLASS"=>"PHONETABS", "TABCLASS" =>"phonetabs", "ACL"=> "phone/phoneGeneric"),
"winstation" => array("CLASS"=>"WINTABS", "TABCLASS" =>"wintabs", "ACL"=> "winworkstation/wingeneric"),
"component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
/* get object type */
$tabtype = "termtabs";
$tabobj = "TERMTABS";
$tabacl = "";
if(isset($tabs[$type])){
$tabtype = $tabs[$type]['TABCLASS'];
$tabobj = $tabs[$type]['CLASS'];
$tabacl = $ui->get_permissions($this->dn,$tabs[$type]['ACL']);
}
/* Load permissions for selected 'dn' and check if
we're allowed to remove this 'dn' */
if(preg_match("/d/",$tabacl)){
/* Check locking, save current plugin in 'back_plugin', so
the dialog knows where to return. */
if (($user= get_lock($this->dn)) != ""){
return(gen_locked_message ($user, $this->dn));
}
/* Lock the current entry, so nobody will edit it during deletion */
add_lock ($this->dn, $this->ui->dn);
$smarty->assign("warning", sprintf(_("You're about to delete all information about the component at '%s'."), @LDAP::fix($this->dn)));
return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
} else {
/* Obviously the user isn't allowed to delete. Show message and
clean session. */
print_red (_("You are not allowed to delete this component!"));
}
}
/********************
Delete system, confirmed
********************/
/* Confirmation for deletion has been passed. Terminal should be deleted. */
if (isset($_POST['delete_terminal_confirm'])){
/* Find out more about the object type */
$ldap= $this->config->get_ldap_link();
$ldap->cat($this->dn, array('objectClass'));
$attrs= $ldap->fetch();
$type= $this->get_system_type($attrs['objectClass']);
$ui = get_userinfo();
$tabs = array(
"terminal" => array("CLASS"=>"TERMTABS", "TABCLASS" =>"termtabs", "ACL"=> "terminal/termgeneric"),
"workstation" => array("CLASS"=>"WORKTABS", "TABCLASS" =>"worktabs", "ACL"=> "workstation/workgeneric"),
"server" => array("CLASS"=>"SERVTABS", "TABCLASS" =>"servtabs", "ACL"=> "server/servgeneric"),
"printer" => array("CLASS"=>"PRINTTABS", "TABCLASS" =>"printtabs", "ACL"=> "printer/printgeneric"),
"phone" => array("CLASS"=>"PHONETABS", "TABCLASS" =>"phonetabs", "ACL"=> "phone/phoneGeneric"),
"winstation" => array("CLASS"=>"WINTABS", "TABCLASS" =>"wintabs", "ACL"=> "winworkstation/wingeneric"),
"component" => array("CLASS"=>"COMPONENTTABS","TABCLASS" =>"componenttabs", "ACL"=> "component/componentGeneric"));
/* get object type */
$tabtype = "termtabs";
$tabobj = "TERMTABS";
$tabacl = "";
if(isset($tabs[$type])){
$tabtype = $tabs[$type]['TABCLASS'];
$tabobj = $tabs[$type]['CLASS'];
$tabacl = $ui->get_permissions($this->dn,$tabs[$type]['ACL']);
}
/* Check if we are allowed to remove this object */
if(preg_match("/d/",$tabacl)){
/* Delete request is permitted, perform LDAP action */
if($tabtype=="phonetabs"){
$this->systab= new $tabtype($this->config, $this->config->data['TABS'][$tabobj], $this->dn,$type);
$this->systab->set_acl_base($this->dn);
$this->systab->by_object['phonegeneric']->remove_from_parent ();
}else{
$this->systab= new $tabtype($this->config,$this->config->data['TABS'][$tabobj], $this->dn,$type);
$this->systab->set_acl_base($this->dn);
$this->systab->delete();
}
unset ($this->systab);
gosa_log ("System object'".$this->dn."' has been removed");
$this->systab= NULL;
/* Terminal list has changed, reload it. */
} else {
/* Normally this shouldn't be reached, send some extra
logs to notify the administrator */
print_red (_("You are not allowed to delete this component!"));
gosa_log ("Warning: '".$this->ui->uid."' tried to trick system ".
"deletion.");
}
/* Remove lock file after successfull deletion */
del_lock ($this->dn);
}
/********************
Edit system type finished, check if everything went ok
********************/
/* Finish user edit is triggered by the tabulator dialog, so
the user wants to save edited data. Check and save at this
point. */
if ((isset($_POST['edit_finish'])) && (isset($this->systab->config)) || $save_object_directly){
/* Check tabs, will feed message array */
$message = array();
if(!$save_object_directly){
$message = $this->systab->check();
}else{
$found = false;
/* Set gotoMode to active if we there was an ogroup selected . (save_object_directly) */
foreach(array("workgeneric"=>"active","servgeneric"=>"active","termgeneric"=>"graphic") as $tab => $value){
if(isset($this->systab->by_object[$tab]->gotoMode)) {
$found = true;
$this->systab->by_object[$tab]->gotoMode = $value;
}
}
if(!$found){
print_red(sprintf(_("Can't set gotoMode to status 'avtice', the current object couldn't be identified.")));
}
}
/* Save, or display error message? */
if (count($message) == 0){
/* Save terminal data to ldap */
if(isset($_SESSION['SelectedSystemType']['ogroup']) && $_SESSION['SelectedSystemType']['ogroup'] != 'none'){
foreach (array("workservice", "termservice") as $cls){
if (isset($this->systab->by_object[$cls])){
$this->systab->by_object[$cls]->gotoXMouseport= "";
$this->systab->by_object[$cls]->gotoXMouseType= "";
$this->systab->by_object[$cls]->gotoXResolution= "";
$this->systab->by_object[$cls]->gotoXColordepth= "";
}
}
}
$this->systab->save();
gosa_log ("System object'".$this->dn."' has been saved");
/* Incoming behavior; you can select a system type and an ogroup membership.
* If this object is an Incoming object, $_SESSION['SelectedSystemType'] isset.
* Check if we must add the new object to an object group.
*
* If this is done, delete the old incoming entry... it is still there, because this is a new
* entry and not an edited one, so we will delete it.
*
*/
if(isset($_SESSION['SelectedSystemType'])){
$SelectedSystemType= $_SESSION['SelectedSystemType'];
unset($_SESSION['SelectedSystemType']);
if($SelectedSystemType['ogroup'] != "none"){
$og = new ogroup($this->config,$SelectedSystemType['ogroup']);
if($og){
$og->AddDelMembership($this->systab->dn);
$og->save();
}
}
if(!isset($ldap)){
$ldap = $this->config->get_ldap_link();
}
$ldap->cd ($this->dn);
$ldap->cat($this->dn, array('dn'));
if(count($ldap->fetch())){
$ldap->cd($this->dn);
$ldap->rmDir($this->dn);
}
$ldap->cd($this->config->current['BASE']);
}
/* Terminal has been saved successfully, remove lock from
LDAP. */
if ($this->dn != "new"){
del_lock ($this->dn);
}
unset ($this->systab);
$this->systab= NULL;
unset($_SESSION['objectinfo']);
} else {
/* Ok. There seem to be errors regarding to the tab data,
show message and continue as usual. */
show_errors($message);
}
}
/********************
Edit system was canceled
********************/
/* Cancel dialogs */
if (isset($_POST['edit_cancel']) || isset($_POST['password_cancel']) || isset($_POST['SystemTypeAborted'])){
if (isset($this->systab)){
del_lock ($this->systab->dn);
unset ($this->systab);
}
$this->systab= NULL;
unset($_SESSION['objectinfo']);
/* Remove ogroup selection, which was set while editing a new incoming entry */
if(isset($_SESSION['SelectedSystemType'])){
unset($_SESSION['SelectedSystemType']);
}
}
/********************
Display edit dialog, or some other
********************/
/* Show tab dialog if object is present */
if (isset($this->systab->config)){
$display= $this->systab->execute();
/* Don't show buttons if tab dialog requests this */
if ((isset($this->systab->by_object))&&(!$this->systab->by_object[$this->systab->current]->dialog)){
$display.= "