[gosa.git] / gosa-plugins / pureftpd / personal / connectivity / pureftpd / class_pureftpdAccount.inc
1 <?php
3 class pureftpdAccount extends plugin
4 {
5 /* Definitions */
6 var $plHeadline= "FTP";
7 var $plDescription= "Manage FTP user settings";
9 /* FTP attributes */
10 var $FTPQuotaFiles = "";
11 var $FTPQuotaMBytes = "";
12 var $FTPUploadRatio = "";
13 var $FTPDownloadRatio = "";
14 var $FTPUploadBandwidth = "";
15 var $FTPDownloadBandwidth = "";
16 var $FTPStatus = "enabled";
17 var $FTPuid = "";
18 var $FTPgid = "";
20 var $uid = "";
22 /* attribute list for save action */
23 var $attributes= array("FTPQuotaFiles","FTPQuotaMBytes","FTPUploadRatio","FTPDownloadRatio",
24 "FTPUploadBandwidth","FTPDownloadBandwidth","FTPStatus","FTPuid","FTPgid");
25 var $objectclasses= array("PureFTPdUser");
26 var $ReadOnly;
27 var $view_logged = FALSE;
29 var $multiple_support=TRUE;
31 function pureftpdAccount (&$config, $dn= NULL, $parent= NULL)
32 {
33 plugin::plugin ($config, $dn, $parent);
35 /* Setting uid to default */
36 if(isset($this->attrs['uid'][0])){
37 $this->uid = $this->attrs['uid'][0];
38 }
39 }
41 function execute()
42 {
43 plugin::execute();
44 /* Log view */
45 if($this->is_account && !$this->view_logged){
46 $this->view_logged = TRUE;
47 new log("view","users/".get_class($this),$this->dn);
48 }
50 /* Show tab dialog headers */
51 $display= "";
53 /* Show main page */
54 $smarty= get_smarty();
56 /* Load attributes */
57 foreach($this->attributes as $val){
58 $smarty->assign("$val", set_post($this->$val));
59 }
62 $tmp = $this->plInfo();
63 $changeState = "";
64 if($this->multiple_support_active){
66 /* We do not need the attribute grey out in multiple edit */
67 foreach($tmp['plProvidedAcls'] as $key => $desc){
68 $smarty->assign($key."ACL", $this->getacl($key,$this->ReadOnly));
69 }
70 if ($this->is_account){
71 $smarty->assign("pureftpdState", "checked");
72 }else{
73 $smarty->assign("pureftpdState", "");
74 }
75 $smarty->assign("fstate", "");
76 $smarty->assign("changeState","");
78 }else{
79 foreach($tmp['plProvidedAcls'] as $key => $desc){
80 $smarty->assign($key."ACL", $this->getacl($key,$this->ReadOnly));
81 $smarty->assign($key."_W", $this->acl_is_writeable($key,$this->ReadOnly));
83 if($this->acl_is_writeable($key)){
84 $changeState.= " changeState('".$key."'); \n";
85 }
86 }
87 $smarty->assign("changeState",$changeState);
90 $smarty->assign("fstate", "");
91 if ($this->is_account){
92 $smarty->assign("pureftpdState", "checked");
93 $smarty->assign("fstate", "");
94 } else {
95 $smarty->assign("pureftpdState", "");
96 if(session::get('js')==1){
97 if($this->acl!="#none#")
98 $smarty->assign("fstate", "disabled");
99 }else{
100 $smarty->assign("fstate", "");
101 }
102 }
103 }
105 foreach($this->attributes as $attr){
106 if(in_array_strict($attr,$this->multi_boxes)){
107 $smarty->assign("use_".$attr,TRUE);
108 }else{
109 $smarty->assign("use_".$attr,FALSE);
110 }
111 }
112 $smarty->assign("use_pureftpd",in_array_strict("pureftpd",$this->multi_boxes));
113 $smarty->assign("multiple_support",$this->multiple_support_active);
114 $smarty->assign("FTPStatus", ($this->FTPStatus == "disabled") ? "checked" : "");
115 $smarty->assign('pureftpdACL', $this->getacl("",$this->ReadOnly));
116 $display.= $smarty->fetch (get_template_path('pureftpd.tpl', TRUE, dirname(__FILE__)));
117 return ($display);
118 }
120 function remove_from_parent()
121 {
122 /* Cancel if there's nothing to do here */
123 if ((!$this->initially_was_account) || (!$this->acl_is_removeable())){
124 return;
125 }
127 plugin::remove_from_parent();
128 $ldap= $this->config->get_ldap_link();
130 $ldap->cd($this->dn);
131 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
132 $this->attributes, "Save");
133 $this->cleanup();
134 $ldap->modify ($this->attrs);
136 /* Log last action */
137 new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
139 if (!$ldap->success()){
140 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
141 }
143 /* Optionally execute a command after we're done */
144 $this->handle_post_events('remove',array("uid" => $this->uid));
145 }
148 /* Save data to object */
149 function save_object()
150 {
151 /* Do we need to flip is_account state? */
152 if (isset($_POST['connectivityTab'])){
153 if (isset($_POST['pureftpd'])){
154 if (!$this->is_account && $_POST['pureftpd'] == "B"){
155 $this->is_account= TRUE;
156 }
157 } else {
158 $this->is_account= FALSE;
159 }
161 plugin::save_object();
163 $old= $this->FTPStatus;
164 if (isset($_POST["FTPStatus"])){
165 $this->FTPStatus = "disabled";
166 } else {
167 $this->FTPStatus = "enabled";
168 }
169 $this->is_modified= ($old != $this->FTPStatus)?TRUE:$this->is_modified;
171 /* Ensure that these vars are numeric. Values starting with 0 like '0123' cause ldap errors */
172 foreach(array("FTPQuotaFiles","FTPQuotaMBytes","FTPUploadRatio","FTPDownloadRatio",
173 "FTPUploadBandwidth","FTPDownloadBandwidth") as $testVar){
174 if(!empty($this->$testVar)){
175 $this->$testVar = (int) ($this->$testVar);
176 }
177 }
178 }
179 }
182 /* Check values */
183 function check()
184 {
185 /* Call common method to give check the hook */
186 $message= plugin::check();
188 /* Check for positive integer values */
189 if ($this->is_account){
191 if($this->acl_is_writeable("FTPUploadBandwidth") && preg_match("/[^0-9]/",$this->FTPUploadBandwidth)){
192 $message[]= msgPool::invalid(_("Upload bandwidth"), $this->uid, "/^[0-9]+$/");
193 }
194 if($this->acl_is_writeable("FTPDownloadBandwidth") && preg_match("/[^0-9]/",$this->FTPDownloadBandwidth)){
195 $message[]= msgPool::invalid(_("Download bandwidth"), $this->uid, "/^[0-9]+$/");
196 }
198 if($this->acl_is_writeable("FTPQuotaFiles") && preg_match("/[^0-9]/",$this->FTPQuotaFiles)){
199 $message[]= msgPool::invalid(_("Quota file"), $this->uid, "/^[0-9]+$/");
200 }
201 if($this->acl_is_writeable("FTPQuotaMBytes") && preg_match("/[^0-9]/",$this->FTPQuotaMBytes)){
202 $message[]= msgPool::invalid(_("Quota size"), $this->uid, "/^[0-9]+$/");
203 }
204 if($this->acl_is_writeable("FTPUploadRatio") && preg_match("/[^0-9]/",$this->FTPUploadRatio)){
205 $message[]= msgPool::invalid(_("Upload ratio"), $this->uid, "/^[0-9]+$/");
206 }
207 if($this->acl_is_writeable("FTPDownloadRatio") && preg_match("/[^0-9]/",$this->FTPDownloadRatio)){
208 $message[]= msgPool::invalid(_("Download ratio"), $this->uid, "/^[0-9]+$/");
209 }
210 }
212 return $message;
213 }
216 /* Save to LDAP */
217 function save()
218 {
219 plugin::save();
222 /* Write back to ldap */
223 $ldap= $this->config->get_ldap_link();
224 $ldap->cd($this->dn);
225 $this->cleanup();
226 $ldap->modify ($this->attrs);
228 /* Log last action */
229 if($this->initially_was_account){
230 new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
231 }else{
232 new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
233 }
235 if (!$ldap->success()){
236 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
237 }
239 /* Optionally execute a command after we're done */
240 if ($this->initially_was_account == $this->is_account){
241 if ($this->is_modified){
242 $this->handle_post_events("modify",array("uid" => $this->uid));
243 }
244 } else {
245 $this->handle_post_events("add",array("uid" => $this->uid));
246 }
248 }
251 /* Return plugin informations for acl handling
252 #FIME There possibly some attributes that can be combined to one acl. */
253 static function plInfo()
254 {
255 return (array(
256 "plShortName" => _("FTP"),
257 "plDescription" => _("Pure-FTPd account")." ("._("Connectivity add-on").")",
258 "plSelfModify" => TRUE,
259 "plDepends" => array("user"),
260 "plPriority" => 22, // Position in tabs
261 "plSection" => array("personal" => _("My account")),
262 "plCategory" => array("users"),
263 "plRequirements"=> array(
264 'ldapSchema' => array('PureFTPdUser' => ''),
265 'onFailureDisablePlugin' => array(get_class())
266 ),
267 "plOptions" => array(),
269 "plProvidedAcls" => array(
270 "FTPQuotaFiles" => _("Quota files"),
271 "FTPUploadRatio" => _("Upload ratio"),
272 "FTPQuotaMBytes" => _("Quota megabytes"),
273 "FTPDownloadRatio" => _("Download ratio"),
274 "FTPUploadBandwidth" => _("Upload bandwidth"),
275 "FTPDownloadBandwidth" => _("Download bandwidth"),
276 "FTPStatus" => _("Status"))
277 ));
278 }
280 function multiple_save_object()
281 {
282 if (isset($_POST['connectivityTab'])){
283 plugin::multiple_save_object();
284 if(isset($_POST['use_pureftpd'])){
285 $this->multi_boxes[] = "pureftpd";
286 }
287 $this->save_object();
288 }
289 }
291 function get_multi_init_values()
292 {
293 $ret = plugin::get_multi_init_values();
294 $ret['is_account'] = $this->is_account;
295 return($ret);
296 }
298 function init_multiple_support($attrs,$attr)
299 {
300 plugin::init_multiple_support($attrs,$attr);
302 if(isset($attrs['is_account'])){
303 $this->is_account = $attrs['is_account'];
304 }
305 }
307 function get_multi_edit_values()
308 {
309 $ret = plugin::get_multi_edit_values();
310 if(in_array_strict("pureftpd",$this->multi_boxes)){
311 $ret['is_account'] = $this->is_account;
312 }
313 return($ret);
314 }
316 function set_multi_edit_values($values)
317 {
318 plugin::set_multi_edit_values($values);
319 if(isset($values['is_account'])){
320 $this->is_account = $values['is_account'];
321 }
322 }
324 }
326 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
327 ?>