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();
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 $cmd= search_config($this->config->data['TABS'], "terminfo", "ACTIONCMD");
95 if ($cmd == ""){
96 print_red(_("No ACTIONCMD definition found in your gosa.conf"));
97 } else {
98 exec ($cmd." ".$this->macAddress." ".escapeshellarg($_POST['action']), $dummy, $retval);
99 if ($retval != 0){
100 print_red(sprintf(_("Execution of '%s' failed!"), $cmd));
101 }
102 }
103 }
105 /* Do we represent a valid terminal? */
106 if (!$this->is_account && $this->parent == NULL){
107 $display= "<img alt=\"\" src=\"images/stop.png\" align=middle> <b>".
108 _("This 'dn' has no workstation features.")."</b>";
109 return($display);
110 }
112 /* Fill templating stuff */
113 $smarty= get_smarty();
114 $smarty->assign("cn", $this->cn);
115 $smarty->assign("l", $this->l);
116 $smarty->assign("bases", $this->config->idepartments);
117 $smarty->assign("staticAddress", "");
119 /* Check if workstation is online */
120 $query= "fping -q -r 1 -t 500 ".$this->cn;
121 exec ($query, $dummy, $retval);
123 /* Offline */
124 if ($retval == 0){
125 $smarty->assign("actions", array("halt" => _("Switch off"), "reboot" => _("Reboot"),
126 "instant_update" => _("Instant update"),
127 "update" => _("Scheduled update"),
128 "rescan" => _("Rescan hardware")));
129 } else {
130 $smarty->assign("actions", array("wake" => _("Wake up"),
131 "update" => _("Scheduled update")));
132 }
133 /* Arrays */
134 $smarty->assign("modes", $this->modes);
135 $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
136 $smarty->assign("syslogservers", $this->config->data['SERVERS']['SYSLOG']);
137 $smarty->assign("ntpservers", $this->config->data['SERVERS']['NTP']);
139 /* Variables */
140 foreach(array("base", "gotoMode", "gotoSyslogServer", "gotoNtpServer") as $val){
141 $smarty->assign($val."_select", $this->$val);
142 $smarty->assign($val."ACL", chkacl($this->acl, $val));
143 }
144 $smarty->assign("ipHostNumber", $this->ipHostNumber);
145 $smarty->assign("macAddress", $this->macAddress);
146 $smarty->assign("actionACL", chkacl($this->acl, 'action'));
148 /* Show main page */
149 $smarty->assign("netconfig", dirname(__FILE__)."/network.tpl");
150 return($smarty->fetch (get_template_path('workstation.tpl', TRUE)));
151 }
153 function remove_from_parent()
154 {
155 $ldap= $this->config->get_ldap_link();
156 $ldap->rmdir($this->dn);
157 show_ldap_error($ldap->get_error());
159 /* Optionally execute a command after we're done */
160 $this->handle_post_events("remove");
162 /* Delete references to object groups */
163 $ldap->cd ($this->config->current['BASE']);
164 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
165 while ($ldap->fetch()){
166 $og= new ogroup($this->config, $ldap->getDN());
167 unset($og->member[$this->dn]);
168 $og->save ();
169 }
171 }
174 /* Save data to object */
175 function save_object()
176 {
177 plugin::save_object();
179 /* Save base, since this is no LDAP attribute */
180 if (isset($_POST['base']) && chkacl($this->acl, "create") == ""){
181 $this->base= $_POST['base'];
182 }
183 }
186 /* Check supplied data */
187 function check()
188 {
189 $message= array();
191 $ui= get_userinfo();
192 $this->dn= "cn=".$this->cn.",ou=workstations,ou=systems,".$this->base;
193 $acl= get_permissions ($this->dn, $ui->subtreeACL);
194 $acl= get_module_permission($acl, "group", $this->dn);
195 if (chkacl($acl, "create") != ""){
196 $message[]= _("You have no permissions to create a workstation on this 'Base'.");
197 }
199 if ($this->cn == "" && chkacl ($this->acl, "cn") == ""){
200 $message[]= _("The required field 'Workstation name' is not set.");
201 }
203 if ($this->orig_dn != $this->dn){
204 $ldap= $this->config->get_ldap_link();
205 $ldap->cd ($this->base);
206 $ldap->search ("(cn=".$this->cn.")", array("cn"));
207 if ($ldap->count() != 0){
208 while ($attrs= $ldap->fetch()){
209 if (preg_match ("/,ou=incoming,/", $ldap->getDN())){
210 continue;
211 } else {
212 if ($attrs['dn'] != $this->orig_dn){
213 $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
214 break;
215 }
216 }
217 }
218 }
219 }
221 return ($message);
222 }
225 /* Save to LDAP */
226 function save()
227 {
228 plugin::save();
230 /* Strip out 'default' values */
231 foreach (array("gotoSyslogServer") as $val){
233 if ($this->attrs[$val] == "default"){
234 $this->attrs[$val]= array();
235 }
236 }
238 /* Add missing arrays */
239 foreach (array("ghScsiDev", "ghIdeDev", "ghNetNic") as $val){
240 if (isset ($this->$val) && count ($this->$val) != 0){
241 $this->attrs["$val"]= $this->$val;
242 }
243 }
245 /* Remove all empty values */
246 if ($this->orig_dn == 'new'){
247 $attrs= array();
248 foreach ($this->attrs as $key => $val){
249 if (is_array($val) && count($val) == 0){
250 continue;
251 }
252 $attrs[$key]= $val;
253 }
254 $this->attrs= $attrs;
255 }
257 /* Write back to ldap */
258 $ldap= $this->config->get_ldap_link();
259 if ($this->orig_dn == 'new'){
260 $ldap->cd($this->config->current['BASE']);
261 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
262 $ldap->cd($this->dn);
263 $ldap->add($this->attrs);
264 $this->handle_post_events("add");
265 } else {
266 if ($this->orig_dn != $this->dn){
267 $this->move($this->orig_dn, $this->dn);
268 }
269 $ldap->cd($this->dn);
270 $ldap->modify($this->attrs);
271 $this->handle_post_events("modify");
272 }
273 show_ldap_error($ldap->get_error());
275 /* Optionally execute a command after we're done */
276 $this->postcreate();
277 }
279 }
281 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
282 ?>