Code

Added check for required attribute ipHostNumber.
[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 $macAddress= "";
17   var $ipHostNumber= "";
18   var $description= "";
19   var $orig_dn= "";
20   var $shadowLastChange="";
21   var $uidNumber="";
22   var $gidNumber="";
23   var $loginShell="";
24   var $gecos="";
25   var $shadowMin="";
26   var $shadowWarning="";
27   var $shadowInactive="";
28   var $uid="";
29   var $sn="";
30   var $givenName="";
31   var $homeDirectory="";
32   var $sambaSID="";
33   var $sambaPrimaryGroupSID="";
34   var $displayName="";
35   var $sambaPwdCanChange2="";
36   var $sambaPwdMustChange="";
37   var $sambaNTPassword="";
38   var $sambaPwdLastSet="";
39   var $sambaAcctFlags="";
41   /* attribute list for save action */
42   var $ignore_account= TRUE;
43   var $attributes   = array("cn", "description", "macAddress", "ipHostNumber","shadowLastChange",
44                             "uidNumber","gidNumber","loginShell","gecos","shadowMin","shadowWarning",
45                             "shadowInactive","uid","cn","sn","givenName","homeDirectory","sambaSID",
46                             "sambaPrimaryGroupSID","displayName", "sambaPwdCanChange2","sambaPwdMustChange",
47                             "sambaNTPassword","sambaPwdLastSet","sambaAcctFlags");
48   var $objectclasses= array("posixAccount","person","organizationalPerson","inetOrgPerson","gosaAccount","shadowAccount","sambaSamAccount","top", "device", "ipHost", "ieee802Device");
51   function wingeneric ($config, $dn= NULL)
52   {
53     plugin::plugin ($config, $dn);
55     /* Set base */
56     if ($this->dn == "new"){
57       $ui= get_userinfo();
58       $this->base= dn2base($ui->dn);
59       $this->cn= "";
60     } else {
61       $this->base= preg_replace ("/^[^,]+,[^,]+,[^,]+,/", "", $this->dn);
62     }
64     /* Save dn for later references */
65     $this->orig_dn= $this->dn;
66   }
68   function execute()
69   {
70     /* Do we represent a valid phone? */
71     if (!$this->is_account && $this->parent == NULL){
72       $display= "<img alt=\"\" src=\"images/stop.png\" align=middle>&nbsp;<b>".
73         _("This 'dn' has no network features.")."</b>";
74       return($display);
75     }
77     /* Fill templating stuff */
78     $smarty= get_smarty();
79     $smarty->assign("bases", $this->config->idepartments);
81     /* Assign attributes */
82     foreach ($this->attributes as $attr){
83       $smarty->assign($attr."ACL", chkacl($this->acl, $attr));
84       $smarty->assign("$attr", $this->$attr);
85     }
86     
87     
88     $smarty->assign("base_select", $this->base);
90     /* Show main page */
91     $smarty->assign("netconfig", dirname(__FILE__)."/network.tpl");
92     return($smarty->fetch (get_template_path('wingeneric.tpl', TRUE)));
93   }
95   function remove_from_parent()
96   {
97     $ldap= $this->config->get_ldap_link();
98     $ldap->rmdir($this->dn);
99     show_ldap_error($ldap->get_error());
100     $this->handle_post_events("remove");
102     /* Delete references to object groups */
103     $ldap->cd ($this->config->current['BASE']);
104     $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))", array("cn"));
105     while ($ldap->fetch()){
106       $og= new ogroup($this->config, $ldap->getDN());
107       unset($og->member[$this->dn]);
108       $og->save ();
109     }
111   }
114   /* Save data to object */
115   function save_object()
116   {
117     plugin::save_object();
119     /* Save base, since this is no LDAP attribute */
120     if (isset($_POST['base']) && chkacl($this->acl, "create") == ""){
121       $this->base= $_POST['base'];
122     }
123   }
126   /* Check supplied data */
127   function check()
128   {
129     $message= array();
130     $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     }
136     if ($this->macAddress == "" && chkacl ($this->acl, "macAddress") == ""){
137       $message[]= "The required field 'MAC-Address' is not set.";
138     }
139     if ($this->ipHostNumber == "" && chkacl ($this->acl, "ipHostNumber") == ""){
140       $message[]= "The required field 'IP-Address' is not set.";
141     }
143     $ui= get_userinfo();
144     $acl= get_permissions ($this->dn, $ui->subtreeACL);
145     $acl= get_module_permission($acl, "component", $this->dn);
146     if (chkacl($acl, "create") != ""){
147       $message[]= _("You have no permissions to create a component on this 'Base'.");
148     }
150     if ($this->orig_dn != $this->dn){
151       $ldap= $this->config->get_ldap_link();
152       $ldap->cd ($this->base);
153       $ldap->search ("(cn=".$this->cn.")", array("cn"));
154       if ($ldap->count() != 0){
155         while ($attrs= $ldap->fetch()){
156           if ($attrs['dn'] != $this->orig_dn){
157             $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
158             break;
159           }
160         }
161       }
162     }
164     return ($message);
165   }
168   /* Save to LDAP */
169   function save()
170   {
171     plugin::save();
173     /* Remove all empty values */
174     if ($this->orig_dn == 'new'){
175       $attrs= array();
176       foreach ($this->attrs as $key => $val){
177         if (is_array($val) && count($val) == 0){
178           continue;
179         }
180         $attrs[$key]= $val;
181       }
182       $this->attrs= $attrs;
183     }
185     /* Write back to ldap */
186     $ldap= $this->config->get_ldap_link();
187     if ($this->orig_dn == 'new'){
188       $ldap->cd($this->config->current['BASE']);
189       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
190       $ldap->cd($this->dn);
191       $ldap->add($this->attrs);
192       $this->handle_post_events("add");
193     } else {
194       if ($this->orig_dn != $this->dn){
195         $this->move($this->orig_dn, $this->dn);
196       }
198       $ldap->cd($this->dn);
199       $ldap->modify($this->attrs);
200       $this->handle_post_events("modify");
201     }
202     show_ldap_error($ldap->get_error());
204     /* Optionally execute a command after we're done */
205     $this->postcreate();
206   }
210 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
211 ?>