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 = 0;
11 var $FTPQuotaMBytes = 0;
12 var $FTPUploadRatio = 0;
13 var $FTPDownloadRatio = 0;
14 var $FTPUploadBandwidth = 0;
15 var $FTPDownloadBandwidth = 0;
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 function pureftpdAccount (&$config, $dn= NULL, $parent= NULL)
30 {
31 plugin::plugin ($config, $dn, $parent);
33 /* Setting uid to default */
34 if(isset($this->attrs['uid'][0])){
35 $this->uid = $this->attrs['uid'][0];
36 }
37 }
39 function execute()
40 {
41 /* Log view */
42 if($this->is_account && !$this->view_logged){
43 $this->view_logged = TRUE;
44 new log("view","users/".get_class($this),$this->dn);
45 }
47 /* Show tab dialog headers */
48 $display= "";
50 /* Show main page */
51 $smarty= get_smarty();
53 /* Load attributes */
54 foreach($this->attributes as $val){
55 $smarty->assign("$val", $this->$val);
56 }
59 $tmp = $this->plInfo();
60 $changeState = "";
61 foreach($tmp['plProvidedAcls'] as $key => $desc){
62 $smarty->assign($key."ACL", $this->getacl($key,$this->ReadOnly));
63 $smarty->assign($key."_W", $this->acl_is_writeable($key,$this->ReadOnly));
65 if($this->acl_is_writeable($key)){
66 $changeState.= " changeState('".$key."'); \n";
67 }
68 }
69 $smarty->assign("changeState",$changeState);
72 $smarty->assign("fstate", "");
73 if ($this->is_account){
74 $smarty->assign("pureftpdState", "checked");
75 $smarty->assign("fstate", "");
76 } else {
77 $smarty->assign("pureftpdState", "");
78 if($_SESSION['js']==1){
79 if($this->acl!="#none#")
80 $smarty->assign("fstate", "disabled");
81 }else{
82 $smarty->assign("fstate", "");
83 }
84 }
85 $smarty->assign("use_FTPStatus", ($this->FTPStatus == "disabled") ? "checked" : "");
87 if((!$this->ReadOnly)&&(($this->is_account && $this->acl_is_removeable()) || (!$this->is_account && $this->acl_is_createable())) ){
88 $smarty->assign('pureftpdACL', "");
89 }else{
90 $smarty->assign('pureftpdACL', " disabled ");
91 }
93 $display.= $smarty->fetch (get_template_path('pureftpd.tpl', TRUE, dirname(__FILE__)));
94 return ($display);
95 }
97 function remove_from_parent()
98 {
99 /* Cancel if there's nothing to do here */
100 if ((!$this->initially_was_account) || (!$this->acl_is_removeable())){
101 return;
102 }
104 plugin::remove_from_parent();
105 $ldap= $this->config->get_ldap_link();
107 $ldap->cd($this->dn);
108 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
109 $this->attributes, "Save");
110 $this->cleanup();
111 $ldap->modify ($this->attrs);
113 /* Log last action */
114 new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
116 show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/pureftpd account with dn '%s' failed."),$this->dn));
118 /* Optionally execute a command after we're done */
119 $this->handle_post_events('remove',array("uid" => $this->uid));
120 }
123 /* Save data to object */
124 function save_object()
125 {
126 /* Do we need to flip is_account state? */
127 if (isset($_POST['connectivityTab'])){
128 if (isset($_POST['pureftpd'])){
129 if (!$this->is_account && $_POST['pureftpd'] == "B"){
130 $this->is_account= TRUE;
131 }
132 } else {
133 $this->is_account= FALSE;
134 }
136 plugin::save_object();
138 $old= $this->FTPStatus;
139 if (isset($_POST["FTPStatus"])){
140 $this->FTPStatus = "disabled";
141 } else {
142 $this->FTPStatus = "enabled";
143 }
144 $this->is_modified= ($old != $this->FTPStatus)?TRUE:$this->is_modified;
146 /* Ensure that these vars are numeric. Values starting with 0 like '0123' cause ldap errors */
147 foreach(array("FTPQuotaFiles","FTPQuotaMBytes","FTPUploadRatio","FTPDownloadRatio","FTPUploadBandwidth","FTPDownloadBandwidth") as $testVar){
148 $this->$testVar = (int) ($this->$testVar);
149 }
152 }
153 }
156 /* Check values */
157 function check()
158 {
159 /* Call common method to give check the hook */
160 $message= plugin::check();
162 /* Check for positive integer values */
163 if ($this->is_account){
165 if($this->acl_is_writeable("FTPUploadBandwidth") && !is_id($this->FTPUploadBandwidth)){
166 $message[]= _("Value specified as 'Upload bandwidth' is not valid.");
167 }
168 if($this->acl_is_writeable("FTPDownloadBandwidth") && !is_id($this->FTPDownloadBandwidth)){
169 $message[]= _("Value specified as 'Download bandwidth' is not valid.");
170 }
172 if($this->acl_is_writeable("FTPQuotaFiles") && !is_id($this->FTPQuotaFiles)){
173 $message[]= _("Value specified as 'Quota files' is not valid.");
174 }
175 if($this->acl_is_writeable("FTPQuotaMBytes") && !is_id($this->FTPQuotaMBytes)){
176 $message[]= _("Value specified as 'Quota size' is not valid.");
177 }
178 if($this->acl_is_writeable("FTPUploadRatio") && !is_id($this->FTPUploadRatio)){
179 $message[]= _("Value specified as 'Upload ratio' is not valid.");
180 }
181 if($this->acl_is_writeable("FTPDownloadRatio") && !is_id($this->FTPDownloadRatio)){
182 $message[]= _("Value specified as 'Download ratio' is not valid.");
183 }
184 }
186 return $message;
187 }
190 /* Save to LDAP */
191 function save()
192 {
193 plugin::save();
195 $tmp = $this->plInfo();
196 foreach($tmp['plProvidedAcls'] as $key => $desc){
197 if(!$this->acl_is_writeable($key)){
198 unset($this->attrs[$key]);
199 }
200 }
202 /* Write back to ldap */
203 $ldap= $this->config->get_ldap_link();
204 $ldap->cd($this->dn);
205 $this->cleanup();
206 $ldap->modify ($this->attrs);
208 /* Log last action */
209 if($this->initially_was_account){
210 new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
211 }else{
212 new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
213 }
215 show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/pureftpd account with dn '%s' failed."),$this->dn));
217 /* Optionally execute a command after we're done */
218 if ($this->initially_was_account == $this->is_account){
219 if ($this->is_modified){
220 $this->handle_post_events("modify",array("uid" => $this->uid));
221 }
222 } else {
223 $this->handle_post_events("add",array("uid" => $this->uid));
224 }
226 }
229 /* Return plugin informations for acl handling
230 #FIME There possibly some attributes that can be combined to one acl. */
231 function plInfo()
232 {
233 return (array(
234 "plShortName" => _("Ftp"),
235 "plDescription" => _("Pure ftp account")." : <u>"._("Connectivity addon")."</u>",
236 "plSelfModify" => TRUE,
237 "plDepends" => array("user"),
238 "plPriority" => 22, // Position in tabs
239 "plSection" => array("personal" => _("My account")),
240 "plCategory" => array("users"),
241 "plOptions" => array(),
243 "plProvidedAcls" => array(
244 "FTPQuotaFiles" => _("Quota files"),
245 "FTPUploadRatio" => _("Upload ratio"),
246 "FTPQuotaMBytes" => _("Quota MBytes"),
247 "FTPDownloadRatio" => _("Download ratio"),
248 "FTPUploadBandwidth" => _("Upload bandwith"),
249 "FTPDownloadBandwidth" => _("Download bandwith"),
250 "FTPStatus" => _("Status"))
251 ));
252 }
253 }
255 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
256 ?>