From ddf84c3bf1e4e06e0a871586368e8d55f7230c91 Mon Sep 17 00:00:00 2001 From: hickert Date: Wed, 22 Aug 2007 06:35:22 +0000 Subject: [PATCH] Added initial_install action git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@7092 594d385d-05f5-0310-b6e9-bd551577e9d8 --- plugins/addons/gotomasses/class_goto_task.inc | 116 ++++++++++++++---- .../addons/gotomasses/class_gotomasses.inc | 55 ++++++--- plugins/addons/gotomasses/goto_task.tpl | 75 ++++++++++- 3 files changed, 204 insertions(+), 42 deletions(-) diff --git a/plugins/addons/gotomasses/class_goto_task.inc b/plugins/addons/gotomasses/class_goto_task.inc index 6631e0dab..f67fd7f11 100644 --- a/plugins/addons/gotomasses/class_goto_task.inc +++ b/plugins/addons/gotomasses/class_goto_task.inc @@ -18,9 +18,10 @@ class goto_task extends plugin var $OGroup = "keep_current"; var $OGroups = array(); var $Target = array(); + var $Initial_Target = array(); var $Actions = array(); var $new = FALSE; - var $attributes = array("OGroup","Minute","Hour","Day","Month","Weekday","Action","Comment","Target"); + var $attributes = array("OGroup","Minute","Hour","Day","Month","Weekday","Action","Comment","Target","Initial_Target"); function goto_task($config,$parent,$data = array()) @@ -69,14 +70,61 @@ class goto_task extends plugin } } - /* Add target */ - if(isset($_POST['add_target']) && !empty($_POST['target_text'])){ - $target = get_post("target_text"); - if($this->is_valid_target($target) && !in_array($target,$this->Target)){ - $this->Target[] = $target; + if($this->Action != "initial_install"){ + + /* Add target */ + if(isset($_POST['add_target']) && !empty($_POST['target_text'])){ + $target = get_post("target_text"); + if($this->is_valid_target($target) && !in_array($target,$this->Target)){ + $this->Target[] = $target; + } + } + }else{ + + /* Add target */ + if(isset($_POST['add_target']) && !empty($_POST['task_MAC'])){ + $MAC = $_POST['task_MAC']; + $NAME= ""; + $IP = ""; + if(isset($_POST['task_Name'])){ + $NAME = $_POST['task_Name']; + } + if(isset($_POST['task_IP']) && is_ip($_POST['task_IP'])){ + $IP = $_POST['task_IP']; + } + if(is_mac($MAC)){ + $this->Initial_Target[] = array("MAC"=>$MAC,"IP"=>$IP,"NAME"=>$NAME); + } } } - + + /* Add via csv */ + if(isset($_FILES['import_file'])){ + $file = $_FILES['import_file']['tmp_name']; + if(file_exists($file) && is_readable($file)){ + $str =""; + $fp = fopen($file,"r"); + while(!feof($fp)){ + $line = fgets($fp,512); + $tmp = preg_split("/(,|;)/",$line); + + $MAC = $IP = $NAME = ""; + if(isset($tmp[0])){ + $MAC = $tmp[0]; + } + if(isset($tmp[1])){ + $IP = $tmp[1]; + } + if(isset($tmp[2])){ + $NAME = $tmp[2]; + } + if(is_mac($MAC)){ + $this->Initial_Target[] = array("MAC"=>$MAC,"IP"=>$IP,"NAME"=>$NAME); + } + } + } + } + /******** * Add target from list ********/ @@ -112,26 +160,40 @@ class goto_task extends plugin ********/ $divlist = new divlist("goto_task"); - //$divlist->SetWidth("600"); $divlist->SetHeight("160"); $divlist->SetEntriesPerPage(0); - $divlist->SetHeader(array( + $acl_target = $this->parent->getacl("Target"); + if(preg_match("/w/i",$acl_target)){ + $field_del = array("string" => "" , + "attach" => "style='width:44px;border-right:0px;'"); + }else{ + $field_del = array("string" => "", + "attach" => "style='width:44px;border-right:0px;'"); + } + + /* Add entries to divlist */ + if($this->Action == "initial_install"){ + $divlist->SetHeader(array( + array("string" => "Target"), + array("string" => "IP" , "attach" => "style='width:90px;'"), + array("string" => "Name" , "attach" => "style='width:150px;'"), + array("string" => "Actions" , "attach" => "style='width:44px;border-right:0px;text-align:right;'"))); + foreach($this->Initial_Target as $key => $target){ + $field1 = array("string" => $target['MAC'] ); + $field2 = array("string" => $target['IP'] ,"attach" => "style='width:90px;'"); + $field3 = array("string" => $target['NAME'] ,"attach" => "style='width:150px;'"); + $divlist->AddEntry(array($field1,$field2,$field3,preg_replace("/%KEY%/",$key,$field_del))); + } + }else{ + $divlist->SetHeader(array( array("string" => "Target", "attach" => "style=''"), array("string" => "Actions" , "attach" => "style='width:44px;border-right:0px;text-align:right;'"))); - - $acl_target = $this->parent->getacl("Target"); - foreach($this->Target as $key => $target){ - $field1 = array("string" => $target, "attach" => "style:''"); - if(preg_match("/w/i",$acl_target)){ - $field2 = array("string" => "" , - "attach" => "style='width:44px;border-right:0px;'"); - }else{ - $field2 = array("string" => "", - "attach" => "style='width:44px;border-right:0px;'"); - } - $divlist->AddEntry(array($field1,$field2)); - } + foreach($this->Target as $key => $target){ + $field1 = array("string" => $target); + $divlist->AddEntry(array($field1,preg_replace("/%KEY%/",$key,$field_del))); + } + } $smarty = get_smarty(); foreach($this->attributes as $attr){ @@ -140,6 +202,7 @@ class goto_task extends plugin } $tmp = $this->get_array_values(); + $smarty->assign("JS" , $_SESSION['js']); $smarty->assign("Minutes" , $tmp['Minute']); $smarty->assign("Hours" , $tmp['Hour']); $smarty->assign("Days" , $tmp['Day']); @@ -161,14 +224,19 @@ class goto_task extends plugin "OGroup" => _("Object group") ,"Minute" => _("Minute"), "Hour" => _("Hour") ,"Day" => _("Day"), "Month" => _("Month") ,"Weekday"=> _("Week day"), - "Action" => _("Action") ,"Comment"=> _("Description"), - "Target" => _("Target objects")); + "Action" => _("Action") ,"Comment"=> _("Description")); foreach($tmp as $name => $desc){ if(empty($this->$name)){ $message[] = sprintf(_("The given value for attribute '%s' is invalid."),$desc); } } + if(count($this->Target) == 0 && $this->Action != "initial_install"){ + $message[] = sprintf(_("You must specify at least one traget")); + } + if(count($this->Initial_Target) == 0 && $this->Action == "initial_install"){ + $message[] = sprintf(_("You must specify at least one traget")); + } return($message); } diff --git a/plugins/addons/gotomasses/class_gotomasses.inc b/plugins/addons/gotomasses/class_gotomasses.inc index c1850155b..b90853392 100644 --- a/plugins/addons/gotomasses/class_gotomasses.inc +++ b/plugins/addons/gotomasses/class_gotomasses.inc @@ -154,7 +154,7 @@ class gotomasses extends plugin $divlist->AddHeader(array("string"=>""._("Schedule")."", "attach"=>"style='width:100px;'")); $divlist->AddHeader(array("string"=>""._("Type")."", - "attach"=>"style='width:60px;'")); + "attach"=>"style='width:80px;'")); $divlist->AddHeader(array("string"=>_("Action"), "attach"=>"style='border-right:0px;width:40px;'")); @@ -166,7 +166,7 @@ class gotomasses extends plugin } $field1 = array("string" => "
".$this->target_to_string($task)."
"); $field2 = array("string" => $this->time_to_string($task),"attach" => "style='width:100px;'"); - $field3 = array("string" => $this->action_to_string($task),"attach" => "style='width:60px;'"); + $field3 = array("string" => $this->action_to_string($task),"attach" => "style='width:80px;'"); $field4 = array("string" => $action,"attach" => "style='text-align:right;width:40px;border-right:0px;'"); $divlist->AddElement(array($field1,$field2,$field3,$field4)); } @@ -179,9 +179,15 @@ class gotomasses extends plugin function target_to_string($data) { $ret = ""; - foreach($data['Target'] as $target){ - $ret .= $target.", "; - } + if($data['Action'] == "initial_install"){ + foreach($data['Initial_Target'] as $target){ + $ret .= $target['MAC'].", "; + } + }else{ + foreach($data['Target'] as $target){ + $ret .= $target.", "; + } + } return(preg_replace("/, $/","",$ret)); } @@ -194,13 +200,11 @@ class gotomasses extends plugin function action_to_string($data) { - switch($data['Action']){ - - case 'reinstall' : return("Reinstall");break; - case 'install' : return("Install");break; - case 'reboot' : return("Restart");break; - case 'update' : return("Update");break; - default : return("Unknown"); + $tmp = $this->get_actions(); + if(isset($tmp[$data['Action']])){ + return($tmp[$data['Action']]); + }else{ + return(_("Unknown")); } } @@ -265,7 +269,17 @@ class gotomasses extends plugin $entry['Weekday'] = $parts[4]; $entry['Action'] = $parts[5]; $entry['OGroup'] = $parts[6]; - $entry['Target'] = split(",",$parts[7]); + if($entry['Action'] == "initial_install"){ + $tmp2 = split(";",$parts[7]); + foreach($tmp2 as $target){ + $tmp = split(",",$target); + $entry['Initial_Target'][] = array("MAC" => $tmp[0],"IP"=>$tmp[1],"NAME" => $tmp[2]); + } + $entry['Target'] = array(); + }else{ + $entry['Initial_Target'] = array(); + $entry['Target'] = split(";",$parts[7]); + } $entry['Comment'] = $comment; $this->tasks [] = $entry; } @@ -286,10 +300,16 @@ class gotomasses extends plugin $str .= str_pad($task['Weekday'],5," ")." "; $str .= str_pad($task['Action'] ,5," ")." "; $str .= str_pad($task['OGroup'] ,5," ")." "; - foreach($task['Target'] as $target){ - $str .= $target.","; + if($task['Action'] == "initial_install"){ + foreach($task['Initial_Target'] as $target){ + $str .= $target['MAC'].",".$target['IP'].",".$target['NAME'].";"; + } + }else{ + foreach($task['Target'] as $target){ + $str .= $target.";"; + } } - $str = preg_replace("/,$/","",$str); + $str = preg_replace("/;$/","",$str); } /* check file existence*/ @@ -341,9 +361,10 @@ class gotomasses extends plugin function get_actions() { /* Prepare list of available actions */ - $actions = array( "reboot" => _("Reboot"), + $actions = array( "reboot" => _("Reboot"), "localboot" => _("Localboot"), "halt" => _("Halt system"), + "initial_install" => _("Initial installation"), "update" => _("Update"), "reinstall" => _("(Re)Install"), "rescan" => _("Rescan"), diff --git a/plugins/addons/gotomasses/goto_task.tpl b/plugins/addons/gotomasses/goto_task.tpl index 3dd8a97c7..c50798aa1 100644 --- a/plugins/addons/gotomasses/goto_task.tpl +++ b/plugins/addons/gotomasses/goto_task.tpl @@ -39,10 +39,13 @@ {render acl=$ActionACL} - {html_options options=$Actions selected=$Action} {/render} + {if !$JS} + + {/if} @@ -50,6 +53,75 @@ +{if $Action == "initial_install"} +

 

+ + + + + + + + + + + +
+

{t}Target systems{/t}

+
+ + + + +
+ {render acl=$TargetACL} + {$Target_list} + {/render} +
+
+ + + + + + + + + + + + + +
{t}MAC address{/t}* + +
{t}Name{/t} + +
{t}IP address{/t} + + {render acl=$TargetACL} + + {/render} +
+
+ + + + + + + + +
+ + +
 
+ {render acl=$TargetACL} + + {/render} +
+
+ +{else}

 

@@ -123,6 +195,7 @@
+{/if}

-- 2.30.2