216e9966531a9612f7fb37643c8959b116ec2bf3
1 <?php
3 class gotomasses extends plugin
4 {
5 /* Definitions */
6 var $plHeadline = "System mass deployment";
7 var $plDescription = "This does something";
9 /* attribute list for save action */
10 var $attributes= array();
11 var $objectclasses= array();
13 /* Source file that contains the csv data */
14 var $file_to_read = "Undefined"; #Set in constructor
16 /* Queue tasks */
17 var $tasks = array();
18 var $current =false;
19 var $dialog = NULL;
21 function gotomasses($config, $dn= NULL)
22 {
23 /* Define source file */
24 $this->file_to_read = CONFIG_DIR."/gotomasses_machines";
26 /* Include config object */
27 $this->config= $config;
29 $this->load_csv_data();
30 }
34 function execute()
35 {
36 /************
37 * Handle posts
38 ************/
40 $s_entry = $s_action = "";
41 $arr = array("/^edit_/"=>"edit","/^remove_/"=>"remove");
42 foreach($arr as $regex => $action){
43 foreach($_POST as $name => $value){
44 if(preg_match($regex,$name)){
45 $s_action = $action;
46 $s_entry = preg_replace($regex,"",$name);
47 $s_entry = preg_replace("/_(x|y)$/","",$s_entry);
48 }
49 }
50 }
52 /************
53 * List posts
54 ************/
56 /* Remove entry from list */
57 if($s_action == "remove" && isset($this->tasks[$s_entry])){
58 unset($this->tasks[$s_entry]);
59 }
61 /* Edit selected entry */
62 if($s_action == "edit" && isset($this->tasks[$s_entry])){
63 $entry = $this->tasks[$s_entry];
64 $this->dialog = new goto_task($this->config,$this,$entry);
65 $this->current = $s_entry;
66 }
68 /* Close dialog */
69 if(isset($_POST['close_goto_task'])){
70 $this->dialog = NULL;
71 }
73 /* Close dialog */
74 if(isset($_POST['save_goto_task'])){
75 $this->dialog->save_object();
76 $msgs = $this->dialog->check();
77 if(count($msgs)){
78 foreach($msgs as $msg){
79 print_red($msg);
80 }
81 }else{
82 $this->tasks[$this->current] = $this->dialog->save();
83 $this->dialog = NULL;
84 }
85 }
87 /* Display dialogs if currently opened */
88 if(is_object($this->dialog)){
89 $this->dialog->save_object();
90 return($this->dialog->execute());
91 }
94 /************
95 * Handle Divlist
96 ************/
98 $smarty = get_smarty();
99 $plug = $_GET['plug'];
100 $divlist = new divlist("gotomasses");
101 $divlist->SetWidth("100%");
102 $divlist->SetHeader(array( array("string"=>"<a href='?plug=".$plug."&sort=object'>"._("Target")."</a>"),
103 array("string"=>"<a href='?plug=".$plug."&sort=schedule'>"._("Schedule")."</a>",
104 "attach"=>"style='width:150px;'"),
105 array("string"=>"<a href='?plug=".$plug."&sort=action'>"._("Type")."</a>",
106 "attach"=>"style='width:50px;'"),
107 array("string"=>_("Action"),
108 "attach"=>"style='border-right:0px;width:50px;'")));
111 foreach($this->tasks as $key => $task){
113 $action = "<input type='image' src='images/edit.png' name='edit_".$key."' class='center' alt='"._("Edit")."'>";
114 $action.= "<input type='image' src='images/edittrash.png' name='remove_".$key."' class='center' alt='"._("Reomve")."'>";
116 $field1 = array("string" => $this->target_to_string($task));
117 $field2 = array("string" => $this->time_to_string($task));
118 $field3 = array("string" => $this->action_to_string($task));
119 $field4 = array("string" => $action,"attach" => "style='border-right:0px;'");
122 $divlist->AddEntry(array($field1,$field2,$field3,$field4));
123 }
125 $smarty->assign("divlist" , $divlist->DrawList());
126 $smarty->assign("contents_modified" , TRUE );
127 return ($smarty->fetch (get_template_path('contents.tpl', TRUE)));
128 }
131 function target_to_string($data)
132 {
133 $ret = "";
134 foreach($data['Target'] as $target){
135 $ret .= preg_replace("/^[^:]+:/i","",$target).", ";
136 }
137 return(preg_replace("/, $/","",$ret));
138 }
141 function time_to_string($data)
142 {
143 return($data['Minute']." ".$data['Hour']." ".$data['Day']." ".$data['Month']." ".$data['Weekday']);
144 }
147 function action_to_string($data)
148 {
149 switch($data['Action']){
151 case 'reinstall' : return("Reinstall");break;
152 case 'install' : return("Install");break;
153 case 'reboot' : return("Restart");break;
154 case 'update' : return("Update");break;
155 default : return("Unknown");
156 }
157 }
160 function load_csv_data()
161 {
162 $ui = get_userinfo();
165 if(!file_exists($this->file_to_read) || !is_readable($this->file_to_read)){
166 print_red(sprintf(_("Can't locate or read csv storage file '%s'."),$this->file_to_read));
167 return(FALSE);
168 }
170 $fp = @fopen($this->file_to_read,"r");
171 if(!$fp){
172 print_red(sprintf(_("Can't read csv storage file '%s'."),$this->file_to_read));
173 return(FALSE);
174 }
176 /* Get file contents */
177 $data ="";
178 while(!feof($fp)){
179 $data.= fread($fp,512);
180 }
182 /* Get lines from file */
183 $this->tasks = array();
184 $comment = "";
185 $rows = split("\n",$data);
187 /* Walk trough rows and parse data */
188 foreach($rows as $row){
190 /* Skip empty lines */
191 $row = trim($row);
192 if(empty($row)){
193 continue;
194 }
196 /* Get comment, if available */
197 if(preg_match("/^#/",$row)){
198 $comment = preg_replace("/^#/","",$row);
199 continue;
200 }
202 /* Split row into minutes/ hours ...*/
203 $row = preg_replace('/[\t ]/umi'," ",$row);
204 $row = preg_replace('/ */umi'," ",$row);
205 $parts = split(" ",$row);
207 if(count($parts) != 8){
208 print_red(_("Entry broken, skipped."));
209 }else{
211 $entry = array();
212 $entry['Minute'] = $parts[0];
213 $entry['Hour'] = $parts[1];
214 $entry['Day'] = $parts[2];
215 $entry['Month'] = $parts[3];
216 $entry['Weekday'] = $parts[4];
217 $entry['Action'] = $parts[5];
218 $entry['OGroup'] = $parts[6];
219 $entry['Target'] = split(",",$parts[7]);
220 $entry['Comment'] = $comment;
221 $this->tasks [] = $entry;
222 }
223 }
224 }
227 function save_csv_data()
228 {
229 }
232 function save_object()
233 {
234 if(isset($_POST['gotomasses'])){
235 }
236 }
239 /* Return list of object groups */
240 function get_object_groups()
241 {
242 $ret = array();
243 $ldap = $this->config->get_ldap_link();
244 $ldap->cd($this->config->current['BASE']);
245 $ldap->search("(&(objectClass=gosaGroupOfNames)(cn=*))",array("cn"));
246 while($attrs = $ldap->fetch()){
247 $ret[$attrs['cn'][0]] = $attrs['cn'][0];
248 }
249 return($ret);
250 }
253 function get_actions()
254 {
255 /* Prepare list of available actions */
256 $actions = array( "reboot" => _("Reboot"),
257 "localboot" => _("Localboot"),
258 "halt" => _("Halt system"),
259 "update" => _("Update"),
260 "reinstall" => _("(Re)Install"),
261 "rescan" => _("Rescan"),
262 "memcheck" => _("Memory check"));
263 return($actions);
264 }
267 function plInfo()
268 {
269 return (array(
270 "plShortName" => _("System mass deployment"),
271 "plDescription" => _("Provide a mechanism to automatically activate a set of systems"),
272 "plSelfModify" => FALSE,
273 "plDepends" => array(),
274 "plPriority" => 0,
275 "plSection" => array("addon"),
276 "plCategory" => array("gotomasses" => array("objectClass" => "none", "description" => _("System mass deployment"))),
277 "plProvidedAcls" => array("Comment" => _("Description"),
278 "Action" => _("Action"),
279 "Day" => _("Day"),
280 "Minute" => _("Minute"),
281 "Hour" => _("Hour"),
282 "Month" => _("Month"),
283 "Weekday" => _("Week day"),
284 "Target" => _("Target"))
285 ));
286 }
287 }
288 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
289 ?>