1 <?php
3 class dfsgeneric extends plugin {
5 /* Needed values and lists */
6 var $base = "";
7 var $cn = "";
9 /* attribute list for save action */
10 var $attributes = array();
11 var $objectclasses = array();
13 function dfsgeneric(&$config, $dn) {
14 plugin::plugin($config, $dn);
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 /* Fill array */
58 $smarty->assign("sambasharename", $this->sambasharename);
59 $smarty->assign("sharedescription", $this->sharedescription);
60 $smarty->assign("fileserver", $this->fileserver);
61 $smarty->assign("fileservershare", $this->share);
62 $smarty->assign("location", $this->loc);
63 $smarty->assign("dfsdescription", $this->dfsdescription);
64 }
66 /* Show main page */
67 return ($smarty->fetch (get_template_path('generic.tpl', TRUE)));
68 }
70 function check()
71 {
72 plugin::check();
73 $message = array();
75 $ldap = $this->config->get_ldap_link();
76 $base = get_base_from_people($this->ui->dn);
77 $ou = get_ou("DFS");
78 $dn_explode = explode("/", $this->dn);
79 $sub_ou = $dn_explode[0];
80 $sambaShareName = $dn_explode[1] . "/" . $dn_explode[2] . "/" . $dn_explode[3];
81 $dn = "sambaShareName=$sambaShareName,ou=$sub_ou,$ou$base";
82 $ldap->cat($dn);
83 $attrs = $ldap->fetch();
85 if ($this->orig_dn == "new" && !($attrs == FALSE)) {
86 $message[] = msgPool::duplicated("Dfs Share");
87 } elseif ($this->orig_dn != $this->dn && !($attrs == FALSE)) {
88 $message[] = msgPool::duplicated("Dfs Share");
89 }
91 if ($this->dn == "new" || $this->dn == "") {
92 $this->sambasharename = $_POST['sambaShareName'];
93 $this->sharedescription = $_POST['description'];
94 $this->fileserver = $_POST['fileserver'];
95 $this->share = $_POST['fileservershare'];
96 $this->loc = $_POST['location'];
97 }
99 # required fields set?
100 if ($this->sambasharename == "") {
101 $message[] = msgPool::required("Name");
102 }
103 if ($this->sharedescription == "") {
104 $message[] = msgPool::required("Description");
105 }
106 if ($this->fileserver == "") {
107 $message[] = msgPool::required("Fileserver");
108 }
109 if ($this->share == "") {
110 $message[] = msgPool::required("Share");
111 }
112 if ($this->loc == "") {
113 $message[] = msgPool::required("Location");
114 }
116 return $message;
117 }
119 function save() {
121 plugin::save();
123 # get the current values
124 $this->sambasharename = $_POST['sambaShareName'];
125 $this->sharedescription = $_POST['description'];
126 $this->fileserver = $_POST['fileserver'];
127 $this->share = $_POST['fileservershare'];
128 $this->loc = $_POST['location'];
130 # set the attribs
131 $this->attrs["sambaShareName"] = "$this->sambasharename,ou=$this->loc,$ou$base";
132 $this->attrs["objectClass"][] = "top";
133 $this->attrs["objectClass"][] = "SambaShare";
134 $this->attrs["objectClass"][] = "extensibleObject";
135 $this->attrs["sambaShareName"] = $this->sambasharename;
136 $this->attrs["description"] = $this->sharedescription;
137 $this->attrs["documentLocation"] = "msdfs:$this->fileserver\\\\$this->share";
139 $ldap = $this->config->get_ldap_link();
141 if ($this->dn == "new" || $this->dn == "") {
142 $base = get_base_from_people($this->ui->dn);
143 $ou = get_ou("DFS");
144 $this->basedn = "sambaShareName=$this->sambasharename,ou=$this->loc,$ou$base";
145 $ldap->cd($this->basedn);
146 $ldap->add($this->attrs);
147 } else {
148 # try to find entry
149 $base = get_base_from_people($this->ui->dn);
150 $ou = get_ou("DFS");
151 #$dn_explode = explode("/", $this->sambasharename);
152 #$sub_ou = $dn_explode[0];
153 #$sambaShareName = $dn_explode[1] . "/" . $dn_explode[2] . "/" . $dn_explode[3];
154 $dn = "sambaShareName=$this->sambasharename,ou=$this->loc,$ou$base";
155 $ldap->cat($dn);
156 $attrs = $ldap->fetch();
158 $this->basedn = "sambaShareName=$this->sambasharename,ou=$this->loc,$ou$base";
159 $ldap->cd($this->basedn);
160 $nr = count($attrs);
162 if (count($attrs)) {
163 # modify if found
164 $ldap->modify($this->attrs);
165 } else {
166 # add
167 $ldap->add($this->attrs);
168 }
169 show_ldap_error($ldap->get_error(), sprintf(_("Saving dfs/generic with dn '%s' failed."),$this->basedn));
170 }
171 }
173 function save_object() {
174 plugin::save_object();
175 $this->base = $_POST['base'];
176 }
178 function delete() {
180 plugin::delete();
182 # get the current values
183 $this->sambasharename = $_POST['sambaShareName'];
184 $this->sharedescription = $_POST['description'];
185 $this->fileserver = $_POST['fileserver'];
186 $this->share = $_POST['fileservershare'];
187 $this->loc = $_POST['location'];
189 $base = get_base_from_people($this->ui->dn);
190 $ou = get_ou("DFS");
191 $this->basedn = "sambaShareName=$this->sambasharename,ou=$this->loc,$ou$base";
193 $ldap = $this->config->get_ldap_link();
194 $ldap->cd($this->basedn);
195 $ldap->rmdir($this->basedn);
196 show_ldap_error($ldap->get_error(), sprintf(_("Removing dfs/generic with dn '%s' failed."),$this->basedn));
197 }
199 }