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