Code

checks for IP MAC commented out
[gosa.git] / plugins / admin / systems / class_winGeneric.inc
1 <?php
3 class wingeneric extends plugin
4 {
5   /* CLI vars */
6   var $cli_summary        = "Manage component 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 $interfaces= array();
13   /* Needed values and lists */
14   var $base= "";
15   var $cn= "";
16   var $description= "";
17   var $orig_dn= "";
18   var $shadowLastChange="";
19   var $uidNumber="";
20   var $gidNumber="";
21   var $loginShell="";
22   var $gecos="";
23   var $shadowMin="";
24   var $shadowWarning="";
25   var $shadowInactive="";
26   var $uid="";
27   var $sn="";
28   var $givenName="";
29   var $homeDirectory="";
30   var $sambaSID="";
31   var $sambaPrimaryGroupSID="";
32   var $displayName="";
33   var $sambaPwdMustChange="";
34   var $sambaNTPassword="";
35   var $sambaPwdLastSet="";
36   var $sambaAcctFlags="";
38   /* attribute list for save action */
39   var $ignore_account= TRUE;
40   var $attributes   = array("cn", "description","shadowLastChange",
41                             "uidNumber","gidNumber","loginShell","gecos","shadowMin","shadowWarning",
42                             "shadowInactive","uid","cn","sn","givenName","homeDirectory","sambaSID",
43                             "sambaPrimaryGroupSID","displayName", "sambaPwdMustChange",
44                             "sambaNTPassword","sambaPwdLastSet","sambaAcctFlags");
45   var $objectclasses= array("posixAccount","person","organizationalPerson","inetOrgPerson","gosaAccount","shadowAccount","sambaSamAccount","top");
48   function wingeneric ($config, $dn= NULL)
49   {
50     plugin::plugin ($config, $dn);
52     /* Set base */
53     if ($this->dn == "new"){
54       $ui= get_userinfo();
55       $this->base= dn2base($ui->dn);
56       $this->cn= "";
57     } else {
58       $this->base= preg_replace ("/^[^,]+,[^,]+,[^,]+,/", "", $this->dn);
59     }
61     /* Save dn for later references */
62     $this->orig_dn= $this->dn;
63   }
65   function execute()
66   {
67     /* Do we represent a valid phone? */
68     if (!$this->is_account && $this->parent == NULL){
69       $display= "<img alt=\"\" src=\"images/stop.png\" align=middle>&nbsp;<b>".
70         _("This 'dn' has no network features.")."</b>";
71       return($display);
72     }
74     /* Fill templating stuff */
75     $smarty= get_smarty();
76     $smarty->assign("bases", $this->config->idepartments);
78     /* Assign attributes */
79     foreach ($this->attributes as $attr){
80       $smarty->assign($attr."ACL", chkacl($this->acl, $attr));
81       $smarty->assign("$attr", $this->$attr);
82     }
83     
84     /* Show Asterisk for required attribute ipHostNumber and macAddress */
85     $smarty->assign("staticAddress", "<font class=\"must\">*</font>");
86     
87     $smarty->assign("base_select", $this->base);
89     /* Show main page */
90     $smarty->assign("netconfig", dirname(__FILE__)."/network.tpl");
91     return($smarty->fetch (get_template_path('wingeneric.tpl', TRUE)));
92   }
94   function remove_from_parent()
95   {
96     $ldap= $this->config->get_ldap_link();
97     $ldap->rmdir($this->dn);
98     show_ldap_error($ldap->get_error());
99     $this->handle_post_events("remove");
101     /* Delete references to object groups */
102     $ldap->cd ($this->config->current['BASE']);
103     $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
104     while ($ldap->fetch()){
105       $og= new ogroup($this->config, $ldap->getDN());
106       unset($og->member[$this->dn]);
107       $og->save ();
108     }
110   }
113   /* Save data to object */
114   function save_object()
115   {
116     plugin::save_object();
118     /* Save base, since this is no LDAP attribute */
119     if (isset($_POST['base']) && chkacl($this->acl, "create") == ""){
120       $this->base= $_POST['base'];
121     }
122   }
125   /* Check supplied data */
126   function check()
127   {
128     $message= array();
129     $this->dn= "cn=".$this->cn.",ou=netdevices,ou=systems,".$this->base;
132     /* must: cn, macAddress */
133     if ($this->cn == "" && chkacl ($this->acl, "cn") == ""){
134       $message[]= _("The required field 'Component name' is not set.");
135     }
137 /*    if ($this->macAddress == "" && chkacl ($this->acl, "macAddress") == ""){
138       $message[]= _("The required field 'MAC-address' is not set.");
139     }
140     if ($this->ipHostNumber == "" && chkacl ($this->acl, "ipHostNumber") == ""){
141       $message[]= _("The required field 'IP-address' is not set.");
142     }
143 */
144     $ui= get_userinfo();
145     $acl= get_permissions ($this->dn, $ui->subtreeACL);
146     $acl= get_module_permission($acl, "component", $this->dn);
147     if (chkacl($acl, "create") != ""){
148       $message[]= _("You have no permissions to create a component on this 'Base'.");
149     }
151     if ($this->orig_dn != $this->dn){
152       $ldap= $this->config->get_ldap_link();
153       $ldap->cd ($this->base);
154       $ldap->search ("(cn=".$this->cn.")", array("cn"));
155       if ($ldap->count() != 0){
156         while ($attrs= $ldap->fetch()){
157           if ($attrs['dn'] != $this->orig_dn){
158             $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
159             break;
160           }
161         }
162       }
163     }
165     return ($message);
166   }
169   /* Save to LDAP */
170   function save()
171   {
172     plugin::save();
174     /* Remove all empty values */
175     if ($this->orig_dn == 'new'){
176       $attrs= array();
177       foreach ($this->attrs as $key => $val){
178         if (is_array($val) && count($val) == 0){
179           continue;
180         }
181         $attrs[$key]= $val;
182       }
183       $this->attrs= $attrs;
184     }
186     /* Write back to ldap */
187     $ldap= $this->config->get_ldap_link();
188     if ($this->orig_dn == 'new'){
189       $ldap->cd($this->config->current['BASE']);
190       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
191       $ldap->cd($this->dn);
192       $ldap->add($this->attrs);
193       $this->handle_post_events("add");
194     } else {
195       if ($this->orig_dn != $this->dn){
196         $this->move($this->orig_dn, $this->dn);
197       }
199       $ldap->cd($this->dn);
200       $ldap->modify($this->attrs);
201       $this->handle_post_events("modify");
202     }
203     show_ldap_error($ldap->get_error());
205     /* Optionally execute a command after we're done */
206     $this->postcreate();
207   }
211 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
212 ?>