1d55d22d88a4f2ab55190f65e9054dbac2be4d42
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= "locked";
12 var $gotoSyslogServer= "";
13 var $gotoNtpServer= "";
14 var $gotoSndModule= "";
15 var $gotoFloppyEnable= "";
16 var $gotoCdromEnable= "";
17 var $ghCpuType= "-";
18 var $ghMemSize= "-";
19 var $macAddress= "";
20 var $ipHostNumber= "";
21 var $ghUsbSupport= "-";
22 var $ghNetNic= array();
23 var $ghIdeDev= array();
24 var $ghScsiDev= array();
25 var $ghGfxAdapter= "-";
26 var $ghSoundAdapter= "-";
27 var $gotoLastUser= "-";
29 /* Needed values and lists */
30 var $base= "";
31 var $cn= "";
32 var $l= "";
33 var $orig_dn= "";
35 /* Plugin side filled */
36 var $modes= array();
38 /* attribute list for save action */
39 var $ignore_account= TRUE;
40 var $attributes= array("gotoMode", "macAddress", "gotoSyslogServer", "gotoNtpServer",
41 "gotoFloppyEnable", "gotoCdromEnable", "cn", "gotoSndModule",
42 "ghCpuType", "ghMemSize", "ghUsbSupport", "ipHostNumber",
43 "ghGfxAdapter", "ghSoundAdapter", "gotoLastUser", "l");
44 var $objectclasses= array("top", "gotoWorkstation", "GOhard");
46 function workgeneric ($config, $dn= NULL)
47 {
48 plugin::plugin ($config, $dn);
50 /* Load available modes */
51 $ldap= $this->config->get_ldap_link();
52 $ldap->cd ($this->config->current['BASE']);
53 $ldap->search ("(objectClass=gotoInstallProfile)");
54 while ($attrs= $ldap->fetch()){
55 $this->modes[]= $attrs["cn"][0];
56 }
58 /* Read arrays */
59 foreach (array("ghNetNic", "ghIdeDev", "ghScsiDev") as $val){
60 if (!isset($this->attrs[$val])){
61 continue;
62 }
63 for ($i= 0; $i<$this->attrs[$val]['count']; $i++){
64 array_push($this->$val, $this->attrs[$val][$i]);
65 }
66 }
68 $this->modes["active"]= _("Activated");
69 $this->modes["locked"]= _("Locked");
70 $this->modes["memcheck"]= _("Memory test");
72 /* Set base */
73 if ($this->dn == "new"){
74 $ui= get_userinfo();
75 $this->base= dn2base($ui->dn);
76 } else {
77 $this->base= preg_replace ("/^[^,]+,[^,]+,[^,]+,/", "", $this->dn);
78 }
80 /* Save 'dn' for later referal */
81 $this->orig_dn= $this->dn;
82 }
84 function execute()
85 {
86 /* Call parent execute */
87 plugin::execute();
89 /* Do we need to flip is_account state? */
90 if (isset($_POST['modify_state'])){
91 $this->is_account= !$this->is_account;
92 }
94 if (isset($_POST['action'])){
95 $cmd= search_config($this->config->data['TABS'], "terminfo", "ACTIONCMD");
96 if ($cmd == ""){
97 print_red(_("No ACTIONCMD definition found in your gosa.conf"));
98 } else {
99 exec ($cmd." ".$this->macAddress." ".escapeshellarg($_POST['action']), $dummy, $retval);
100 if ($retval != 0){
101 print_red(sprintf(_("Execution of '%s' failed!"), $cmd));
102 }
103 }
104 }
106 /* Do we represent a valid terminal? */
107 if (!$this->is_account && $this->parent == NULL){
108 $display= "<img alt=\"\" src=\"images/stop.png\" align=middle> <b>".
109 _("This 'dn' has no workstation features.")."</b>";
110 return($display);
111 }
113 /* Fill templating stuff */
114 $smarty= get_smarty();
115 $smarty->assign("cn", $this->cn);
116 $smarty->assign("l", $this->l);
117 $smarty->assign("bases", $this->config->idepartments);
118 $smarty->assign("staticAddress", "");
120 /* Check if workstation is online */
121 $query= "fping -q -r 1 -t 500 ".$this->cn;
122 exec ($query, $dummy, $retval);
124 /* Offline */
125 if ($retval == 0){
126 $smarty->assign("actions", array("halt" => _("Switch off"), "reboot" => _("Reboot"),
127 "instant_update" => _("Instant update"),
128 "update" => _("Scheduled update"),
129 "update" => _("Reinstall"),
130 "rescan" => _("Rescan hardware")));
131 } else {
132 $smarty->assign("actions", array("wake" => _("Wake up"),
133 "update" => _("Scheduled update")));
134 }
135 /* Arrays */
136 $smarty->assign("modes", $this->modes);
137 $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
138 $smarty->assign("syslogservers", $this->config->data['SERVERS']['SYSLOG']);
139 $smarty->assign("ntpservers", $this->config->data['SERVERS']['NTP']);
141 /* Variables */
142 foreach(array("base", "gotoMode", "gotoSyslogServer", "gotoNtpServer") as $val){
143 $smarty->assign($val."_select", $this->$val);
144 $smarty->assign($val."ACL", chkacl($this->acl, $val));
145 }
146 $smarty->assign("ipHostNumber", $this->ipHostNumber);
147 $smarty->assign("macAddress", $this->macAddress);
148 $smarty->assign("actionACL", chkacl($this->acl, 'action'));
150 /* Show main page */
151 $smarty->assign("netconfig", dirname(__FILE__)."/network.tpl");
152 return($smarty->fetch (get_template_path('workstation.tpl', TRUE)));
153 }
155 function remove_from_parent()
156 {
157 $ldap= $this->config->get_ldap_link();
158 $ldap->rmdir($this->dn);
159 show_ldap_error($ldap->get_error());
161 /* Optionally execute a command after we're done */
162 $this->handle_post_events("remove");
164 /* Delete references to object groups */
165 $ldap->cd ($this->config->current['BASE']);
166 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
167 while ($ldap->fetch()){
168 $og= new ogroup($this->config, $ldap->getDN());
169 unset($og->member[$this->dn]);
170 $og->save ();
171 }
173 }
176 /* Save data to object */
177 function save_object()
178 {
179 plugin::save_object();
181 /* Save base, since this is no LDAP attribute */
182 if (isset($_POST['base']) && chkacl($this->acl, "create") == ""){
183 $this->base= $_POST['base'];
184 }
185 }
188 /* Check supplied data */
189 function check()
190 {
191 $message= array();
193 $ui= get_userinfo();
194 $this->dn= "cn=".$this->cn.",ou=workstations,ou=systems,".$this->base;
195 $acl= get_permissions ($this->dn, $ui->subtreeACL);
196 $acl= get_module_permission($acl, "group", $this->dn);
197 if (chkacl($acl, "create") != ""){
198 $message[]= _("You have no permissions to create a workstation on this 'Base'.");
199 }
201 if ($this->cn == "" && chkacl ($this->acl, "cn") == ""){
202 $message[]= _("The required field 'Workstation name' is not set.");
203 }
205 if ($this->orig_dn != $this->dn){
206 $ldap= $this->config->get_ldap_link();
207 $ldap->cd ($this->base);
208 $ldap->search ("(cn=".$this->cn.")", array("cn"));
209 if ($ldap->count() != 0){
210 while ($attrs= $ldap->fetch()){
211 if (preg_match ("/,ou=incoming,/", $ldap->getDN())){
212 continue;
213 } else {
214 if ($attrs['dn'] != $this->orig_dn){
215 $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
216 break;
217 }
218 }
219 }
220 }
221 }
223 return ($message);
224 }
227 /* Save to LDAP */
228 function save()
229 {
230 plugin::save();
232 /* Strip out 'default' values */
233 foreach (array("gotoSyslogServer") as $val){
235 if ($this->attrs[$val] == "default"){
236 $this->attrs[$val]= array();
237 }
238 }
240 /* Add missing arrays */
241 foreach (array("ghScsiDev", "ghIdeDev", "ghNetNic") as $val){
242 if (isset ($this->$val) && count ($this->$val) != 0){
243 $this->attrs["$val"]= $this->$val;
244 }
245 }
247 /* Remove all empty values */
248 if ($this->orig_dn == 'new'){
249 $attrs= array();
250 foreach ($this->attrs as $key => $val){
251 if (is_array($val) && count($val) == 0){
252 continue;
253 }
254 $attrs[$key]= $val;
255 }
256 $this->attrs= $attrs;
257 }
259 /* Write back to ldap */
260 $ldap= $this->config->get_ldap_link();
261 if ($this->orig_dn == 'new'){
262 $ldap->cd($this->config->current['BASE']);
263 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
264 $ldap->cd($this->dn);
265 $ldap->add($this->attrs);
266 $this->handle_post_events("add");
267 } else {
268 if ($this->orig_dn != $this->dn){
269 $this->move($this->orig_dn, $this->dn);
270 }
271 $ldap->cd($this->dn);
272 $ldap->modify($this->attrs);
273 $this->handle_post_events("modify");
274 }
275 show_ldap_error($ldap->get_error());
277 /* Optionally execute a command after we're done */
278 $this->postcreate();
279 }
281 }
283 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
284 ?>