b712323cc0a584fb65ed23a45b41e3ce332996d4
1 <?php
3 class workgeneric extends plugin
4 {
5 /* CLI vars */
6 var $cli_summary= "Manage workstation base objects";
7 var $cli_description= "Some longer text\nfor help";
8 var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
10 /* Generic terminal attributes */
11 var $gotoMode= "disabled";
12 var $gotoTerminalPath= "";
13 var $gotoSwapServer= "";
14 var $gotoSyslogServer= "";
15 var $gotoNtpServer= "";
16 var $gotoSndModule= "";
17 var $gotoFloppyEnable= "";
18 var $gotoCdromEnable= "";
19 var $ghCpuType= "-";
20 var $ghMemSize= "-";
21 var $macAddress= "";
22 var $ipHostNumber= "";
23 var $ghUsbSupport= "-";
24 var $ghNetNic= array();
25 var $ghIdeDev= array();
26 var $ghScsiDev= array();
27 var $ghGfxAdapter= "-";
28 var $ghSoundAdapter= "-";
29 var $gotoLastUser= "-";
32 /* Needed values and lists */
33 var $base= "";
34 var $cn= "";
35 var $orig_dn= "";
37 /* Plugin side filled */
38 var $modes= array();
40 /* attribute list for save action */
41 var $attributes= array("gotoMode", "gotoTerminalPath", "macAddress",
42 "gotoSwapServer", "gotoSyslogServer", "gotoNtpServer",
43 "gotoFloppyEnable", "gotoCdromEnable", "cn", "gotoSndModule",
44 "ghCpuType", "ghMemSize", "ghUsbSupport", "ipHostNumber",
45 "ghGfxAdapter", "ghSoundAdapter", "gotoLastUser");
46 var $objectclasses= array("top", "gotoWorkstation", "GOhard");
48 function workgeneric ($config, $dn= NULL)
49 {
50 plugin::plugin ($config, $dn);
52 /* Load available modes */
53 $ldap= $this->config->get_ldap_link();
54 $ldap->cd ($this->config->current['BASE']);
55 $ldap->search ("(objectClass=gotoInstallProfile)");
56 while ($attrs= $ldap->fetch()){
57 $this->modes[]= $attrs["cn"][0];
58 }
60 /* Read arrays */
61 foreach (array("ghNetNic", "ghIdeDev", "ghScsiDev") as $val){
62 if (!isset($this->attrs[$val])){
63 continue;
64 }
65 for ($i= 0; $i<$this->attrs[$val]['count']; $i++){
66 array_push($this->$val, $this->attrs[$val][$i]);
67 }
68 }
70 $this->modes["disabled"]= _("disabled");
71 $this->modes["text"]= _("text");
72 $this->modes["graphic"]= _("graphic");
74 /* Set base */
75 if ($this->dn == "new"){
76 $ui= get_userinfo();
77 $this->base= dn2base($ui->dn);
78 } else {
79 $this->base= preg_replace ("/^[^,]+,[^,]+,[^,]+,/", "", $this->dn);
80 }
82 /* Save 'dn' for later referal */
83 $this->orig_dn= $this->dn;
84 }
86 function execute()
87 {
88 /* Do we need to flip is_account state? */
89 if (isset($_POST['modify_state'])){
90 $this->is_account= !$this->is_account;
91 }
93 if (isset($_POST['action'])){
94 switch($_POST['saction']){
95 case 'wake':
96 $cmd= $this->search($this->config->data['TABS'], "terminfo", "WAKECMD");
97 if ($cmd == ""){
98 print_red(_("No WAKECMD definition found in your gosa.conf"));
99 } else {
100 exec ($cmd." ".$this->macAddress, $dummy, $retval);
101 if ($retval != 0){
102 print_red(sprintf(_("Execution of '%s' failed!"), $cmd));
103 }
104 }
105 break;
107 case 'reboot':
108 $cmd= $this->search($this->config->data['TABS'], "terminfo", "REBOOTCMD");
109 if ($cmd == ""){
110 print_red(_("No REBOOTCMD definition found in your gosa.conf"));
111 } else {
112 exec ($cmd." ".$this->cn, $dummy, $retval);
113 if ($retval != 0){
114 print_red(sprintf(_("Execution of '%s' failed!"), $cmd));
115 }
116 }
117 break;
119 case 'halt':
120 $cmd= $this->search($this->config->data['TABS'], "terminfo", "HALTCMD");
121 if ($cmd == ""){
122 print_red(_("No HALTCMD definition found in your gosa.conf"));
123 } else {
124 exec ($cmd." ".$this->cn, $dummy, $retval);
125 if ($retval != 0){
126 print_red(sprintf(_("Execution of '%s' failed!"), $cmd));
127 }
128 }
129 break;
130 }
131 }
133 /* Do we represent a valid terminal? */
134 if (!$this->is_account && $this->parent == NULL){
135 $display= "<img src=\"images/stop.png\" align=center> <b>".
136 _("This 'dn' has no workstation features.")."</b>";
137 return($display);
138 }
140 /* Fill templating stuff */
141 $smarty= get_smarty();
142 $smarty->assign("cn", $this->cn);
143 $smarty->assign("bases", $this->config->idepartments);
145 /* Check if workstation is online */
146 $query= "fping -q -r 1 -t 500 ".$this->cn;
147 exec ($query, $dummy, $retval);
149 /* Offline */
150 if ($retval == 0){
151 $smarty->assign("actions", array("halt" => _("Switch off"), "reboot" => _("Reboot")));
152 } else {
153 $smarty->assign("actions", array("wake" => _("Wake up")));
154 }
155 /* Arrays */
156 $smarty->assign("modes", $this->modes);
157 $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
158 $smarty->assign("syslogservers", $this->config->data['SERVERS']['SYSLOG']);
159 $smarty->assign("ntpservers", $this->config->data['SERVERS']['NTP']);
161 /* Variables */
162 foreach(array("base", "gotoMode", "gotoTerminalPath", "gotoSwapServer",
163 "gotoSyslogServer", "gotoNtpServer") as $val){
165 $smarty->assign($val."_select", $this->$val);
166 $smarty->assign($val."ACL", chkacl($this->acl, $val));
167 }
168 $smarty->assign("ipHostNumber", $this->ipHostNumber);
169 $smarty->assign("macAddress", $this->macAddress);
171 /* Show main page */
172 $smarty->assign("netconfig", dirname(__FILE__)."/network.tpl");
173 return($smarty->fetch (get_template_path('workstation.tpl', TRUE)));
174 }
176 function remove_from_parent()
177 {
178 $ldap= $this->config->get_ldap_link();
179 $ldap->rmdir($this->dn);
180 show_ldap_error($ldap->get_error());
182 /* Optionally execute a command after we're done */
183 $this->handle_post_events("remove");
185 /* Delete references to object groups */
186 $ldap->cd ($this->config->current['BASE']);
187 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
188 while ($ldap->fetch()){
189 $og= new ogroup($this->config, $ldap->getDN());
190 unset($og->member[$this->dn]);
191 $og->save ();
192 }
194 }
197 /* Save data to object */
198 function save_object()
199 {
200 plugin::save_object();
202 /* Save base, since this is no LDAP attribute */
203 if (isset($_POST['base']) && chkacl($this->acl, "create") == ""){
204 $this->base= $_POST['base'];
205 }
207 /* Save terminal path to parent since it is used by termstartup, too */
208 $this->parent->by_object['termstartup']->gotoTerminalPath=
209 $this->gotoTerminalPath;
210 }
213 /* Check supplied data */
214 function check()
215 {
216 $message= array();
218 $ui= get_userinfo();
219 $this->dn= "cn=".$this->cn.",ou=workstations,ou=systems,".$this->base;
220 $acl= get_permissions ($this->dn, $ui->subtreeACL);
221 $acl= get_module_permission($acl, "group", $this->dn);
222 if (chkacl($acl, "create") != ""){
223 $message[]= _("You have no permissions to create a workstation on this 'Base'.");
224 }
226 if ($this->cn == "" && chkacl ($this->acl, "cn") == ""){
227 $message[]= _("The required field 'Workstation name' is not set.");
228 }
230 if ($this->orig_dn != $this->dn){
231 $ldap= $this->config->get_ldap_link();
232 $ldap->cd ($this->base);
233 $ldap->search ("(cn=".$this->cn.")", array("cn"));
234 if ($ldap->count() != 0){
235 while ($attrs= $ldap->fetch()){
236 if (preg_match ("/,ou=incoming,/", $ldap->getDN())){
237 continue;
238 } else {
239 if ($attrs['dn'] != $this->orig_dn){
240 $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
241 break;
242 }
243 }
244 }
245 }
246 }
248 return ($message);
249 }
252 /* Save to LDAP */
253 function save()
254 {
255 plugin::save();
257 /* Strip out 'default' values */
258 foreach (array("gotoTerminalPath", "gotoSwapServer", "gotoSyslogServer") as $val){
260 if ($this->attrs[$val] == "default"){
261 $this->attrs[$val]= array();
262 }
263 }
265 /* Add missing arrays */
266 foreach (array("ghScsiDev", "ghIdeDev", "ghNetNic") as $val){
267 if (isset ($this->$val) && count ($this->$val) != 0){
268 $this->attrs["$val"]= $this->$val;
269 }
270 }
272 /* Remove all empty values */
273 if ($this->orig_dn == 'new'){
274 $attrs= array();
275 foreach ($this->attrs as $key => $val){
276 if (is_array($val) && count($val) == 0){
277 continue;
278 }
279 $attrs[$key]= $val;
280 }
281 $this->attrs= $attrs;
282 }
284 /* Write back to ldap */
285 $ldap= $this->config->get_ldap_link();
286 if ($this->orig_dn == 'new'){
287 $ldap->cd($this->config->current['BASE']);
288 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
289 $ldap->cd($this->dn);
290 $ldap->add($this->attrs);
291 $this->handle_post_events("add");
292 } else {
293 if ($this->orig_dn != $this->dn){
294 $this->move($this->orig_dn, $this->dn);
295 }
296 $ldap->cd($this->dn);
297 $ldap->modify($this->attrs);
298 $this->handle_post_events("modify");
299 }
300 show_ldap_error($ldap->get_error());
302 /* Optionally execute a command after we're done */
303 $this->postcreate();
304 }
306 }
308 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
309 ?>