Code

2042f8a4014bc601dff1ca7c99a36627f81bc792
[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= "This does something";
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);
34     
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     /* Log view */
44     if($this->is_account && !$this->view_logged){
45       $this->view_logged = TRUE;
46       new log("view","users/".get_class($this),$this->dn);
47     }
49     /* Show tab dialog headers */
50     $display= "";
52     /* Show main page */
53     $smarty= get_smarty();
55     /* Load attributes */
56     foreach($this->attributes as $val){
57       $smarty->assign("$val", $this->$val);
58     }
61     $tmp = $this->plInfo();
62     $changeState = "";
63     if($this->multiple_support_active){
65       /* We do not need the attribute grey out in multiple edit */
66       foreach($tmp['plProvidedAcls'] as $key => $desc){
67         $smarty->assign($key."ACL", $this->getacl($key,$this->ReadOnly));
68       }
69       if ($this->is_account){
70         $smarty->assign("pureftpdState", "checked");
71       }else{
72         $smarty->assign("pureftpdState", "");
73       }
74       $smarty->assign("fstate", "");
75       $smarty->assign("changeState","");
77     }else{
78       foreach($tmp['plProvidedAcls'] as $key => $desc){
79         $smarty->assign($key."ACL", $this->getacl($key,$this->ReadOnly));
80         $smarty->assign($key."_W", $this->acl_is_writeable($key,$this->ReadOnly));
82         if($this->acl_is_writeable($key)){
83           $changeState.= " changeState('".$key."'); \n";
84         }
85       }
86       $smarty->assign("changeState",$changeState);
89       $smarty->assign("fstate", "");
90       if ($this->is_account){
91         $smarty->assign("pureftpdState", "checked");
92         $smarty->assign("fstate", "");
93       } else {
94         $smarty->assign("pureftpdState", "");
95         if(session::get('js')==1){
96           if($this->acl!="#none#")
97             $smarty->assign("fstate", "disabled");
98         }else{
99           $smarty->assign("fstate", "");
100         }
101       }
102     }
104     foreach($this->attributes as $attr){
105       if(in_array($attr,$this->multi_boxes)){
106         $smarty->assign("use_".$attr,TRUE);
107       }else{
108         $smarty->assign("use_".$attr,FALSE);
109       }
110     }
111     $smarty->assign("use_pureftpd",in_array("pureftpd",$this->multi_boxes)); 
112     $smarty->assign("multiple_support",$this->multiple_support_active);
113     $smarty->assign("FTPStatus", ($this->FTPStatus == "disabled") ? "checked" : "");
114     $smarty->assign('pureftpdACL', $this->getacl("",$this->ReadOnly));
115     $display.= $smarty->fetch (get_template_path('pureftpd.tpl', TRUE, dirname(__FILE__)));
116     return ($display);
117   }
119   function remove_from_parent()
120   {
121     /* Cancel if there's nothing to do here */
122     if ((!$this->initially_was_account) || (!$this->acl_is_removeable())){
123       return;
124     }
126     plugin::remove_from_parent();
127     $ldap= $this->config->get_ldap_link();
129     $ldap->cd($this->dn);
130     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
131         $this->attributes, "Save");
132     $this->cleanup();
133     $ldap->modify ($this->attrs); 
135     /* Log last action */
136     new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
137   
138     if (!$ldap->success()){
139       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
140     }
142     /* Optionally execute a command after we're done */
143     $this->handle_post_events('remove',array("uid" => $this->uid));
144   }
147   /* Save data to object */
148   function save_object()
149   {
150     /* Do we need to flip is_account state? */
151     if (isset($_POST['connectivityTab'])){
152       if (isset($_POST['pureftpd'])){
153         if (!$this->is_account && $_POST['pureftpd'] == "B"){
154           $this->is_account= TRUE;
155         }
156       } else {
157         $this->is_account= FALSE;
158       }
160       plugin::save_object();
162       $old= $this->FTPStatus;
163       if (isset($_POST["FTPStatus"])){
164         $this->FTPStatus = "disabled";
165       } else {
166         $this->FTPStatus = "enabled";
167       }
168       $this->is_modified= ($old != $this->FTPStatus)?TRUE:$this->is_modified;
170       /* Ensure that these vars are numeric. Values starting with 0 like '0123' cause ldap errors */
171       foreach(array("FTPQuotaFiles","FTPQuotaMBytes","FTPUploadRatio","FTPDownloadRatio",
172                     "FTPUploadBandwidth","FTPDownloadBandwidth") as $testVar){
173         if(!empty($this->$testVar)){
174           $this->$testVar = (int) ($this->$testVar);
175         }
176       }
177     }
178   }
181   /* Check values */
182   function check()
183   {
184     /* Call common method to give check the hook */
185     $message= plugin::check();
187     /* Check for positive integer values */
188     if ($this->is_account){
190       if($this->acl_is_writeable("FTPUploadBandwidth") && preg_match("/[^0-9]/",$this->FTPUploadBandwidth)){
191         $message[]= msgPool::invalid(_("Upload bandwidth"), $this->uid, "/^[0-9]+$/");
192       }
193       if($this->acl_is_writeable("FTPDownloadBandwidth") && preg_match("/[^0-9]/",$this->FTPDownloadBandwidth)){
194         $message[]= msgPool::invalid(_("Download bandwidth"), $this->uid, "/^[0-9]+$/");
195       }
197       if($this->acl_is_writeable("FTPQuotaFiles") && preg_match("/[^0-9]/",$this->FTPQuotaFiles)){
198         $message[]= msgPool::invalid(_("Quota file"), $this->uid, "/^[0-9]+$/");
199       }
200       if($this->acl_is_writeable("FTPQuotaMBytes") && preg_match("/[^0-9]/",$this->FTPQuotaMBytes)){
201         $message[]= msgPool::invalid(_("Quota size"), $this->uid, "/^[0-9]+$/");
202       }
203       if($this->acl_is_writeable("FTPUploadRatio") && preg_match("/[^0-9]/",$this->FTPUploadRatio)){
204         $message[]= msgPool::invalid(_("Upload ratio"), $this->uid, "/^[0-9]+$/");
205       }
206       if($this->acl_is_writeable("FTPDownloadRatio") && preg_match("/[^0-9]/",$this->FTPDownloadRatio)){
207         $message[]= msgPool::invalid(_("Download ratio"), $this->uid, "/^[0-9]+$/");
208       }
209     }
211     return $message;
212   }
215   /* Save to LDAP */
216   function save()
217   {
218     plugin::save();
221     /* Write back to ldap */
222     $ldap= $this->config->get_ldap_link();
223     $ldap->cd($this->dn);
224     $this->cleanup();
225     $ldap->modify ($this->attrs); 
226     
227     /* Log last action */
228     if($this->initially_was_account){
229       new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
230     }else{
231       new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
232     }
234     if (!$ldap->success()){
235       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
236     }
238     /* Optionally execute a command after we're done */
239     if ($this->initially_was_account == $this->is_account){
240       if ($this->is_modified){
241         $this->handle_post_events("modify",array("uid" => $this->uid));
242       }
243     } else {
244       $this->handle_post_events("add",array("uid" => $this->uid));
245     }
247   }
250   /* Return plugin informations for acl handling
251   #FIME There possibly some attributes that can be combined to one acl. */
252   static function plInfo()
253   {
254     return (array(
255           "plShortName"     => _("Ftp"),
256           "plDescription"   => _("Pure ftp account")."&nbsp;("._("Connectivity addon").")",
257           "plSelfModify"    => TRUE,
258           "plDepends"       => array("user"),
259           "plPriority"      => 22,                                 // Position in tabs
260           "plSection"     => array("personal" => _("My account")),
261           "plCategory"    => array("users"),
262           "plOptions"       => array(),
264           "plProvidedAcls"  => array(
265             "FTPQuotaFiles"         => _("Quota files"),
266             "FTPUploadRatio"        => _("Upload ratio"),
267             "FTPQuotaMBytes"        => _("Quota MBytes"),
268             "FTPDownloadRatio"      => _("Download ratio"),
269             "FTPUploadBandwidth"    => _("Upload bandwith"),
270             "FTPDownloadBandwidth"  => _("Download bandwith"),
271             "FTPStatus"             => _("Status"))
272           ));
273   }
275   function multiple_save_object()
276   {
277     if (isset($_POST['connectivityTab'])){
278       plugin::multiple_save_object();
279       if(isset($_POST['use_pureftpd'])){
280         $this->multi_boxes[] = "pureftpd";
281       }
282       $this->save_object();
283     }
284   }
286   function get_multi_init_values()
287   {
288     $ret = plugin::get_multi_init_values();
289     $ret['is_account'] = $this->is_account;
290     return($ret);
291   }
293   function init_multiple_support($attrs,$attr)
294   {
295     plugin::init_multiple_support($attrs,$attr);
297     if(isset($attrs['is_account'])){
298       $this->is_account = $attrs['is_account'];
299     }
300   }
302   function get_multi_edit_values()
303   {
304     $ret = plugin::get_multi_edit_values();
305     if(in_array("pureftpd",$this->multi_boxes)){
306       $ret['is_account'] = $this->is_account;
307     }
308     return($ret);
309   }
311   function set_multi_edit_values($values)
312   {
313     plugin::set_multi_edit_values($values);
314     if(isset($values['is_account'])){
315       $this->is_account = $values['is_account'];
316     }
317   }
321 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
322 ?>