1 <?php
3 class dfsgeneric extends plugin {
4 /* CLI vars */
5 var $cli_summary = "Manage terminal base objects";
6 var $cli_description = "Some longer text\nfor help";
7 var $cli_parameters = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
9 /* Needed values and lists */
10 var $base = "";
11 var $cn = "";
13 /* attribute list for save action */
14 var $attributes = array();
15 var $objectclasses = array();
17 function dfsgeneric($config, $dn) {
18 plugin::plugin($config, $dn);
19 $this->config = $config;
20 $this->dn = $dn;
21 $this->orig_dn = $dn;
22 }
24 function execute() {
25 /* Call parent execute */
26 plugin::execute();
28 $smarty= get_smarty();
30 if (($this->dn == "new") || ($this->dn == "")) {
31 $smarty->assign("sambasharename", "");
32 $smarty->assign("sharedescription", "");
33 $smarty->assign("fileserver", "");
34 $smarty->assign("fileservershare", "");
35 $smarty->assign("location", "");
36 $smarty->assign("dfsdescription", "");
37 } else {
38 $ldap = $this->config->get_ldap_link();
40 $base = get_base_from_people($this->dn);
41 $ou = get_ou("DFS");
43 $tmp = preg_split('/\//', $this->dn, 2);
44 $this->loc = $tmp[0];
45 $this->sambasharename = $tmp[1];
47 $ldap->cd("$ou $base");
48 $ldap->search(("ou=$this->loc"), array("description"));
49 $dfs_desc = $ldap->fetch();
50 $this->dfsdescription = $dfs_desc['description'][0];
52 $ldap->cd("ou=$this->loc, $ou $base");
53 $ldap->search("(&(sambaShareName=$this->sambasharename)(objectclass=sambaShare))", array("description", "documentLocation"));
55 $details = $ldap->fetch();
56 $this->sharedescription = $details['description'][0];
57 $tmp = preg_split('/\\\\/', $details['documentLocation'][0], 2);
59 $this->fileserver = preg_replace("/msdfs:/", "", $tmp[0]);
60 $this->share = preg_replace("/\\\/", "", $tmp[1]);
62 #var_dump($this->dn);
63 #echo "<BR>\n";
65 /* Fill array */
66 #$this->reload();
67 $smarty->assign("sambasharename", $this->sambasharename);
68 $smarty->assign("sharedescription", $this->sharedescription);
69 $smarty->assign("fileserver", $this->fileserver);
70 $smarty->assign("fileservershare", $this->share);
71 $smarty->assign("location", $this->loc);
72 $smarty->assign("dfsdescription", $this->dfsdescription);
73 }
75 /* Show main page */
76 return ($smarty->fetch (get_template_path('generic.tpl', TRUE)));
77 #, dirname(__FILE__))));
78 }
80 function check() {
81 plugin::check();
82 $message = array();
84 ## permission
85 #if (chkacl($this->acl, "create") != "") {
86 # $message[] = _("You have no premissions to create a dfs share.");
87 #}
89 # existance
91 $ldap = $this->config->get_ldap_link();
92 $base = get_base_from_people($this->ui->dn);
93 $ou = get_ou("DFS");
94 $dn_explode = explode("/", $this->dn);
95 $sub_ou = $dn_explode[0];
96 $sambaShareName = $dn_explode[1] . "/" . $dn_explode[2] . "/" . $dn_explode[3];
97 $dn = "sambaShareName=$sambaShareName,ou=$sub_ou,$ou$base";
98 $ldap->cat($dn);
99 $attrs = $ldap->fetch();
101 if ($this->orig_dn == "new" && !($attrs == FALSE)) {
102 $message[] = _("Dfs share already exists.");
103 } elseif ($this->orig_dn != $this->dn && !($attrs == FALSE)) {
104 $message[] = _("Dfs share already exists.");
105 }
107 if ($this->dn == "new" || $this->dn == "") {
108 $this->sambasharename = $_POST['sambaShareName'];
109 $this->sharedescription = $_POST['description'];
110 $this->fileserver = $_POST['fileserver'];
111 $this->share = $_POST['fileservershare'];
112 $this->loc = $_POST['location'];
113 }
115 # required fields set?
116 if ($this->sambasharename == "") {
117 $message[] = _("Required Field \"Name of dfs Share\" is not set.");
118 }
119 if ($this->sharedescription == "") {
120 $message[] = _("Required Field \"Description\" is not set.");
121 }
122 if ($this->fileserver == "") {
123 $message[] = _("Required Field \"Fileserver\" is not set.");
124 }
125 if ($this->share == "") {
126 $message[] = _("Required Field \"Share on fileserver\" is not set.");
127 }
128 if ($this->loc == "") {
129 $message[] = _("Required Field \"Location\" is not set.");
130 }
132 return $message;
133 }
135 function save() {
137 plugin::save();
139 # get the current values
140 $this->sambasharename = $_POST['sambaShareName'];
141 $this->sharedescription = $_POST['description'];
142 $this->fileserver = $_POST['fileserver'];
143 $this->share = $_POST['fileservershare'];
144 $this->loc = $_POST['location'];
146 # set the attribs
147 $this->attrs["sambaShareName"] = "$this->sambasharename,ou=$this->loc,$ou$base";
148 $this->attrs["objectClass"][] = "top";
149 $this->attrs["objectClass"][] = "SambaShare";
150 $this->attrs["objectClass"][] = "extensibleObject";
151 $this->attrs["sambaShareName"] = $this->sambasharename;
152 $this->attrs["description"] = $this->sharedescription;
153 $this->attrs["documentLocation"] = "msdfs:$this->fileserver\\\\$this->share";
155 $ldap = $this->config->get_ldap_link();
157 if ($this->dn == "new" || $this->dn == "") {
158 echo "new<br>\n";
159 $base = get_base_from_people($this->ui->dn);
160 $ou = get_ou("DFS");
161 $this->basedn = "sambaShareName=$this->sambasharename,ou=$this->loc,$ou$base";
162 $ldap->cd($this->basedn);
163 $ldap->add($this->attrs);
164 } else {
165 # try to find entry
166 $base = get_base_from_people($this->ui->dn);
167 $ou = get_ou("DFS");
168 #$dn_explode = explode("/", $this->sambasharename);
169 #$sub_ou = $dn_explode[0];
170 #$sambaShareName = $dn_explode[1] . "/" . $dn_explode[2] . "/" . $dn_explode[3];
171 $dn = "sambaShareName=$this->sambasharename,ou=$this->loc,$ou$base";
172 $ldap->cat($dn);
173 $attrs = $ldap->fetch();
175 $this->basedn = "sambaShareName=$this->sambasharename,ou=$this->loc,$ou$base";
176 $ldap->cd($this->basedn);
177 $nr = count($attrs);
179 if (count($attrs)) {
180 # modify if found
181 $ldap->modify($this->attrs);
182 } else {
183 # add
184 $ldap->add($this->attrs);
185 }
186 show_ldap_error($ldap->get_error(), sprintf(_("Saving dfs/generic with dn '%s' failed."),$this->basedn));
187 }
188 }
190 function save_object() {
191 #if (isset($_POST['base'])) {
192 plugin::save_object();
193 #echo "base = ".$_POST['base']."<br>\n";
194 #}
195 if (chkacl($this->acl, "create") == "") {
196 $this->base = $_POST['base'];
197 }
198 }
200 function delete() {
202 plugin::delete();
204 # get the current values
205 $this->sambasharename = $_POST['sambaShareName'];
206 $this->sharedescription = $_POST['description'];
207 $this->fileserver = $_POST['fileserver'];
208 $this->share = $_POST['fileservershare'];
209 $this->loc = $_POST['location'];
211 $base = get_base_from_people($this->ui->dn);
212 $ou = get_ou("DFS");
213 $this->basedn = "sambaShareName=$this->sambasharename,ou=$this->loc,$ou$base";
214 echo "BASEDN: $this->basedn<br>\n";
216 $ldap = $this->config->get_ldap_link();
217 $ldap->cd($this->basedn);
218 $ldap->rmdir($this->basedn);
219 show_ldap_error($ldap->get_error(), sprintf(_("Removing dfs/generic with dn '%s' failed."),$this->basedn));
220 }
222 }