2b304d31ff4f7c89ce6f5b34664a51969f190fc2
1 <?php
3 class gotomasses extends plugin
4 {
5 /* Definitions */
6 var $plHeadline = "System deployment";
7 var $plDescription = "This does something";
9 /* attribute list for save action */
10 var $attributes= array();
11 var $objectclasses= array();
13 /* Queue tasks */
14 var $current =false;
15 var $dialog = FALSE;
16 var $ids_to_remove = array();
17 var $divlist = NULL;
19 function gotomasses(&$config, $dn= NULL)
20 {
21 /* Include config object */
22 $this->config= &$config;
23 $this->divlist = new divListMasses($this->config,$this);
24 $this->o_queue = new hostActionQueue(&$config);
25 }
28 function execute()
29 {
30 $smarty = get_smarty();
31 /************
32 * Handle posts
33 ************/
35 $s_entry = $s_action = "";
36 $arr = array( "/^edit_task_/"=>"edit","/^remove_task_/"=>"remove",
37 "/^new_task_/"=>"new_task","/^remove_multiple_task_/" => "remove_multiple");
38 foreach($arr as $regex => $action){
39 foreach($_POST as $name => $value){
40 if(preg_match($regex,$name)){
41 $s_action = $action;
42 $s_entry = preg_replace($regex,"",$name);
43 $s_entry = preg_replace("/_(x|y)$/","",$s_entry);
44 }
45 }
46 }
48 /* Edit posted from list link */
49 if(isset($_GET['act']) && $_GET['act'] == "edit" && isset($_GET['id']) && isset($this->tasks[$_GET['id']])){
50 $s_action = "edit";
51 $s_entry = $_GET['id'];
52 }
54 /************
55 * REMOVE
56 ************/
58 /* Remove multiple */
59 if($s_action == "remove_multiple"){
60 if(!$this->acl_is_removeable()){
61 print_red(_("You are not allowed to remove a task."));
62 }else{
63 $this->ids_to_remove = $this->list_get_selected_items();
64 $tmp = "";
65 foreach($this->ids_to_remove as $key => $id){
66 if(isset($this->tasks[$id])){
67 $task = $this->tasks[$id];
68 $tmp.= "\n".$this->target_to_string($task);
69 }else{
70 unset($this->ids_to_remove[$key]);
71 }
72 }
73 $smarty->assign("multiple", TRUE);
74 $smarty->assign("info",sprintf(_("Your are about to delete the following tasks: %s"),"<pre>".$tmp."</pre>"));
75 $this->current = $s_entry;
76 return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
77 }
78 }
80 /* Remove specified tasks */
81 if(count($this->ids_to_remove) && isset($_POST['delete_multiple_confirm'])){
82 foreach($this->ids_to_remove as $id){
83 $this->o_queue->remove($id);
84 }
85 $this->save();
86 }
88 /* Remove aborted */
89 if(isset($_POST['delete_cancel'])){
90 $this->ids_to_remove = array();;
91 }
94 /************
95 * EDIT
96 ************/
98 /* Edit selected entry */
99 if($s_action == "edit"){
100 $entry = $this->o_queue->get_entry($s_entry);
101 if($entry){
102 $this->dialog = new goto_task($this->config,$this,$entry);
103 $this->current = $s_entry;
104 }
105 }
107 /* New entry */
108 if($s_action== "new_task" && $this->acl_is_createable()){
109 $this->dialog = new goto_task($this->config,$this);
110 $this->current = -1;
111 }
113 /* Close dialog */
114 if(isset($_POST['close_goto_task'])){
115 $this->dialog = FALSE;
116 $this->current = -1;
117 }
119 /* Close dialog */
120 if((isset($_POST['save_goto_task']) || isset($_POST['apply_goto_task'])) && is_object($this->dialog) ){
121 $this->dialog->save_object();
122 $msgs = $this->dialog->check();
123 if(count($msgs)){
124 foreach($msgs as $msg){
125 print_red($msg);
126 }
127 }else{
129 if($this->o_queue->id_exists($this->current)){
130 $this->o_queue->update_entry($this->current,$this->dialog->save());
131 }else{
132 $tmp = $this->dialog->save();
133 $tmp2= array();
134 $targets =$tmp['Target'];
135 foreach($targets as $target){
136 $tmp['Target'] = array($target);
137 $tmp2[] = $tmp;
138 }
139 if(!$this->o_queue->add_multiple($tmp2)){
140 print_red($this->o_queue->get_error());
141 }
142 }
143 if(!isset($_POST['apply_goto_task'])){
144 $this->dialog = FALSE;
145 $this->current = -1;
146 }
147 $this->save();
148 }
149 }
151 /* Display dialogs if currently opened */
152 if(is_object($this->dialog)){
153 $this->dialog->save_object();
154 return($this->dialog->execute());
155 }
157 /************
158 * Handle Divlist
159 ************/
161 $this->divlist->execute();
162 $this->divlist->SetEntries($this->get_queue_entries());
163 return($this->divlist->Draw());
164 }
167 function get_queue_entries()
168 {
169 if(!$this->o_queue->load()){
170 print_red("ERROR:".$this->o_queue->get_error());
171 return(FALSE);
172 }
174 $tasks = array();
175 $ret = array();
176 while($entry = $this->o_queue->fetch()){
177 $task = $entry['TASK_ID'];
178 if(!isset($tasks[$task])){
179 $tasks[$task] = dechex(rand(100,240)).dechex(rand(100,240)).dechex(rand(100,240));
180 }
182 $entry['color'] = $tasks[$task];
183 $ret[]= $entry;
184 }
185 return($ret);
186 }
189 function target_to_string($data)
190 {
191 $ret = "";
192 if($data['Action'] == "initial_install"){
193 foreach($data['Initial_Target'] as $target){
194 $ret .= $target['MAC'].", ";
195 }
196 }else{
197 foreach($data['Target'] as $target){
198 $ret .= $target.", ";
199 }
200 }
201 return(preg_replace("/, $/","",$ret));
202 }
205 function time_to_string($data)
206 {
207 return($data['Minute']." ".$data['Hour']." ".$data['Day']." ".$data['Month']." ".$data['Weekday']);
208 }
211 function action_to_string($data)
212 {
213 $tmp = $this->get_actions();
214 if(isset($tmp[$data['Action']])){
215 return($tmp[$data['Action']]);
216 }else{
217 return(_("Unknown"));
218 }
219 }
222 function save_object()
223 {
224 $this->divlist->save_object();
225 }
228 /* Return list of object groups */
229 function get_object_groups()
230 {
231 $ret = array();
232 $ldap = $this->config->get_ldap_link();
233 $ldap->cd($this->config->current['BASE']);
234 $ldap->search("(&(objectClass=gosaGroupOfNames)(cn=*))",array("cn"));
235 while($attrs = $ldap->fetch()){
236 $ret[$attrs['cn'][0]] = $attrs['cn'][0];
237 }
238 return($ret);
239 }
242 function save()
243 {
244 }
247 function list_get_selected_items()
248 {
249 $ids = array();
250 foreach($_POST as $name => $value){
251 if(preg_match("/^item_selected_[0-9]*$/",$name)){
252 $id = preg_replace("/^item_selected_/","",$name);
253 $ids[$id] = $id;
254 }
255 }
256 return($ids);
257 }
260 function get_actions()
261 {
262 /* Prepare list of available actions */
263 $actions = array( "reboot" => _("Reboot"),
264 "localboot" => _("Localboot"),
265 "halt" => _("Halt system"),
266 "initial_install" => _("Initial installation"),
267 "update" => _("Update"),
268 "reinstall" => _("(Re)Install"),
269 "rescan" => _("Rescan"),
270 "wake" => _("Wake"),
271 "memcheck" => _("Memory check"));
272 return($actions);
273 }
276 function plInfo()
277 {
278 return (array(
279 "plShortName" => _("System mass deployment"),
280 "plDescription" => _("Provide a mechanism to automatically activate a set of systems"),
281 "plSelfModify" => FALSE,
282 "plDepends" => array(),
283 "plPriority" => 0,
284 "plSection" => array("addon"),
285 "plCategory" => array("gotomasses" => array("objectClass" => "none", "description" => _("System mass deployment"))),
286 "plProvidedAcls" => array("Comment" => _("Description"),
287 "Action" => _("Action"),
288 "Day" => _("Day"),
289 "Minute" => _("Minute"),
290 "Hour" => _("Hour"),
291 "Month" => _("Month"),
292 "Weekday" => _("Week day"),
293 "Target" => _("Target"))
294 ));
295 }
296 }
297 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
298 ?>