1 <?php
3 class dfsgeneric extends plugin {
4 /* Needed values and lists */
5 var $base = "";
6 var $cn = "";
8 /* attribute list for save action */
9 var $attributes = array();
10 var $objectclasses = array();
12 function dfsgeneric($config, $dn) {
13 plugin::plugin($config, $dn);
14 $this->config = $config;
15 $this->dn = $dn;
16 $this->orig_dn = $dn;
17 }
19 function execute() {
20 /* Call parent execute */
21 plugin::execute();
23 $smarty= get_smarty();
25 if (($this->dn == "new") || ($this->dn == "")) {
26 $smarty->assign("sambasharename", "");
27 $smarty->assign("sharedescription", "");
28 $smarty->assign("fileserver", "");
29 $smarty->assign("fileservershare", "");
30 $smarty->assign("location", "");
31 $smarty->assign("dfsdescription", "");
32 } else {
33 $ldap = $this->config->get_ldap_link();
35 $base = get_base_from_people($this->dn);
36 $ou = get_ou("DFS");
38 $tmp = preg_split('/\//', $this->dn, 2);
39 $this->loc = $tmp[0];
40 $this->sambasharename = $tmp[1];
42 $ldap->cd("$ou $base");
43 $ldap->search(("ou=$this->loc"), array("description"));
44 $dfs_desc = $ldap->fetch();
45 $this->dfsdescription = $dfs_desc['description'][0];
47 $ldap->cd("ou=$this->loc, $ou $base");
48 $ldap->search("(&(sambaShareName=$this->sambasharename)(objectclass=sambaShare))", array("description", "documentLocation"));
50 $details = $ldap->fetch();
51 $this->sharedescription = $details['description'][0];
52 $tmp = preg_split('/\\\\/', $details['documentLocation'][0], 2);
54 $this->fileserver = preg_replace("/msdfs:/", "", $tmp[0]);
55 $this->share = preg_replace("/\\\/", "", $tmp[1]);
57 #var_dump($this->dn);
58 #echo "<BR>\n";
60 /* Fill array */
61 #$this->reload();
62 $smarty->assign("sambasharename", $this->sambasharename);
63 $smarty->assign("sharedescription", $this->sharedescription);
64 $smarty->assign("fileserver", $this->fileserver);
65 $smarty->assign("fileservershare", $this->share);
66 $smarty->assign("location", $this->loc);
67 $smarty->assign("dfsdescription", $this->dfsdescription);
68 }
70 /* Show main page */
71 return ($smarty->fetch (get_template_path('generic.tpl', TRUE)));
72 #, dirname(__FILE__))));
73 }
75 function check() {
76 plugin::check();
77 $message = array();
79 ## permission
80 #if (chkacl($this->acl, "create") != "") {
81 # $message[] = _("You have no premissions to create a dfs share.");
82 #}
84 # existance
86 $ldap = $this->config->get_ldap_link();
87 $base = get_base_from_people($this->ui->dn);
88 $ou = get_ou("DFS");
89 $dn_explode = explode("/", $this->dn);
90 $sub_ou = $dn_explode[0];
91 $sambaShareName = $dn_explode[1] . "/" . $dn_explode[2] . "/" . $dn_explode[3];
92 $dn = "sambaShareName=$sambaShareName,ou=$sub_ou,$ou$base";
93 $ldap->cat($dn);
94 $attrs = $ldap->fetch();
96 if ($this->orig_dn == "new" && !($attrs == FALSE)) {
97 $message[] = _("Dfs share already exists.");
98 } elseif ($this->orig_dn != $this->dn && !($attrs == FALSE)) {
99 $message[] = _("Dfs share already exists.");
100 }
102 if ($this->dn == "new" || $this->dn == "") {
103 $this->sambasharename = $_POST['sambaShareName'];
104 $this->sharedescription = $_POST['description'];
105 $this->fileserver = $_POST['fileserver'];
106 $this->share = $_POST['fileservershare'];
107 $this->loc = $_POST['location'];
108 }
110 # required fields set?
111 if ($this->sambasharename == "") {
112 $message[] = _("Required Field \"Name of dfs Share\" is not set.");
113 }
114 if ($this->sharedescription == "") {
115 $message[] = _("Required Field \"Description\" is not set.");
116 }
117 if ($this->fileserver == "") {
118 $message[] = _("Required Field \"Fileserver\" is not set.");
119 }
120 if ($this->share == "") {
121 $message[] = _("Required Field \"Share on fileserver\" is not set.");
122 }
123 if ($this->loc == "") {
124 $message[] = _("Required Field \"Location\" is not set.");
125 }
127 return $message;
128 }
130 function save() {
132 plugin::save();
134 # get the current values
135 $this->sambasharename = $_POST['sambaShareName'];
136 $this->sharedescription = $_POST['description'];
137 $this->fileserver = $_POST['fileserver'];
138 $this->share = $_POST['fileservershare'];
139 $this->loc = $_POST['location'];
141 # set the attribs
142 $this->attrs["sambaShareName"] = "$this->sambasharename,ou=$this->loc,$ou$base";
143 $this->attrs["objectClass"][] = "top";
144 $this->attrs["objectClass"][] = "SambaShare";
145 $this->attrs["objectClass"][] = "extensibleObject";
146 $this->attrs["sambaShareName"] = $this->sambasharename;
147 $this->attrs["description"] = $this->sharedescription;
148 $this->attrs["documentLocation"] = "msdfs:$this->fileserver\\\\$this->share";
150 $ldap = $this->config->get_ldap_link();
152 if ($this->dn == "new" || $this->dn == "") {
153 echo "new<br>\n";
154 $base = get_base_from_people($this->ui->dn);
155 $ou = get_ou("DFS");
156 $this->basedn = "sambaShareName=$this->sambasharename,ou=$this->loc,$ou$base";
157 $ldap->cd($this->basedn);
158 $ldap->add($this->attrs);
159 } else {
160 # try to find entry
161 $base = get_base_from_people($this->ui->dn);
162 $ou = get_ou("DFS");
163 #$dn_explode = explode("/", $this->sambasharename);
164 #$sub_ou = $dn_explode[0];
165 #$sambaShareName = $dn_explode[1] . "/" . $dn_explode[2] . "/" . $dn_explode[3];
166 $dn = "sambaShareName=$this->sambasharename,ou=$this->loc,$ou$base";
167 $ldap->cat($dn);
168 $attrs = $ldap->fetch();
170 $this->basedn = "sambaShareName=$this->sambasharename,ou=$this->loc,$ou$base";
171 $ldap->cd($this->basedn);
172 $nr = count($attrs);
174 if (count($attrs)) {
175 # modify if found
176 $ldap->modify($this->attrs);
177 } else {
178 # add
179 $ldap->add($this->attrs);
180 }
181 show_ldap_error($ldap->get_error());
182 }
183 }
185 function save_object() {
186 #if (isset($_POST['base'])) {
187 plugin::save_object();
188 #echo "base = ".$_POST['base']."<br>\n";
189 #}
190 if (chkacl($this->acl, "create") == "") {
191 $this->base = $_POST['base'];
192 }
193 }
195 function delete() {
197 plugin::delete();
199 # get the current values
200 $this->sambasharename = $_POST['sambaShareName'];
201 $this->sharedescription = $_POST['description'];
202 $this->fileserver = $_POST['fileserver'];
203 $this->share = $_POST['fileservershare'];
204 $this->loc = $_POST['location'];
206 $base = get_base_from_people($this->ui->dn);
207 $ou = get_ou("DFS");
208 $this->basedn = "sambaShareName=$this->sambasharename,ou=$this->loc,$ou$base";
209 echo "BASEDN: $this->basedn<br>\n";
211 $ldap = $this->config->get_ldap_link();
212 $ldap->cd($this->basedn);
213 $ldap->rmdir($this->basedn);
214 show_ldap_error($ldap->get_error());
215 }
217 }