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 }
39 function execute()
40 {
41 /* Show tab dialog headers */
42 $display= "";
44 /* Show main page */
45 $smarty= get_smarty();
47 /* Load attributes */
48 foreach($this->attributes as $val){
49 $smarty->assign("$val", $this->$val);
50 }
53 $tmp = $this->plInfo();
54 $changeState = "";
55 foreach($tmp['plProvidedAcls'] as $key => $desc){
56 $smarty->assign($key."ACL", $this->getacl($key,$this->ReadOnly));
57 $smarty->assign($key."_W", $this->acl_is_writeable($key,$this->ReadOnly));
59 if($this->acl_is_writeable($key)){
60 $changeState.= " changeState('".$key."'); \n";
61 }
62 }
63 $smarty->assign("changeState",$changeState);
66 $smarty->assign("fstate", "");
67 if ($this->is_account){
68 $smarty->assign("pureftpdState", "checked");
69 $smarty->assign("fstate", "");
70 } else {
71 $smarty->assign("pureftpdState", "");
72 if($_SESSION['js']==1){
73 if($this->acl!="#none#")
74 $smarty->assign("fstate", "disabled");
75 }else{
76 $smarty->assign("fstate", "");
77 }
78 }
79 $smarty->assign("use_FTPStatus", ($this->FTPStatus == "disabled") ? "checked" : "");
81 if((!$this->ReadOnly)&&(($this->is_account && $this->acl_is_removeable()) || (!$this->is_account && $this->acl_is_createable())) ){
82 $smarty->assign('pureftpdACL', "");
83 }else{
84 $smarty->assign('pureftpdACL', " disabled ");
85 }
87 $display.= $smarty->fetch (get_template_path('pureftpd.tpl', TRUE, dirname(__FILE__)));
88 return ($display);
89 }
91 function remove_from_parent()
92 {
93 /* Cancel if there's nothing to do here */
94 if ((!$this->initially_was_account) || (!$this->acl_is_removeable())){
95 return;
96 }
98 plugin::remove_from_parent();
99 $ldap= $this->config->get_ldap_link();
101 $ldap->cd($this->dn);
102 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
103 $this->attributes, "Save");
104 $this->cleanup();
105 $ldap->modify ($this->attrs);
107 show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/pureftpd account with dn '%s' failed."),$this->dn));
109 /* Optionally execute a command after we're done */
110 $this->handle_post_events('remove',array("uid" => $this->uid));
111 }
114 /* Save data to object */
115 function save_object()
116 {
117 /* Do we need to flip is_account state? */
118 if (isset($_POST['connectivityTab'])){
119 if (isset($_POST['pureftpd'])){
120 if (!$this->is_account && $_POST['pureftpd'] == "B"){
121 $this->is_account= TRUE;
122 }
123 } else {
124 $this->is_account= FALSE;
125 }
127 plugin::save_object();
129 $old= $this->FTPStatus;
130 if (isset($_POST["FTPStatus"])){
131 $this->FTPStatus = "disabled";
132 } else {
133 $this->FTPStatus = "enabled";
134 }
135 $this->is_modified= ($old != $this->FTPStatus)?TRUE:$this->is_modified;
137 /* Ensure that these vars are numeric. Values starting with 0 like '0123' cause ldap errors */
138 foreach(array("FTPQuotaFiles","FTPQuotaMBytes","FTPUploadRatio","FTPDownloadRatio","FTPUploadBandwidth","FTPDownloadBandwidth") as $testVar){
139 $this->$testVar = (int) ($this->$testVar);
140 }
143 }
144 }
147 /* Check values */
148 function check()
149 {
150 /* Call common method to give check the hook */
151 $message= plugin::check();
153 /* Check for positive integer values */
154 if ($this->is_account){
156 if($this->acl_is_writeable("FTPUploadBandwidth") && !is_id($this->FTPUploadBandwidth)){
157 $message[]= _("Value specified as 'Upload bandwidth' is not valid.");
158 }
159 if($this->acl_is_writeable("FTPDownloadBandwidth") && !is_id($this->FTPDownloadBandwidth)){
160 $message[]= _("Value specified as 'Download bandwidth' is not valid.");
161 }
163 if($this->acl_is_writeable("FTPQuotaFiles") && !is_id($this->FTPQuotaFiles)){
164 $message[]= _("Value specified as 'Quota files' is not valid.");
165 }
166 if($this->acl_is_writeable("FTPQuotaMBytes") && !is_id($this->FTPQuotaMBytes)){
167 $message[]= _("Value specified as 'Quota size' is not valid.");
168 }
169 if($this->acl_is_writeable("FTPUploadRatio") && !is_id($this->FTPUploadRatio)){
170 $message[]= _("Value specified as 'Upload ratio' is not valid.");
171 }
172 if($this->acl_is_writeable("FTPDownloadRatio") && !is_id($this->FTPDownloadRatio)){
173 $message[]= _("Value specified as 'Download ratio' is not valid.");
174 }
175 }
177 return $message;
178 }
181 /* Save to LDAP */
182 function save()
183 {
184 plugin::save();
186 $tmp = $this->plInfo();
187 foreach($tmp['plProvidedAcls'] as $key => $desc){
188 if(!$this->acl_is_writeable($key)){
189 unset($this->attrs[$key]);
190 }
191 }
193 /* Write back to ldap */
194 $ldap= $this->config->get_ldap_link();
195 $ldap->cd($this->dn);
196 $this->cleanup();
197 $ldap->modify ($this->attrs);
199 show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/pureftpd account with dn '%s' failed."),$this->dn));
201 /* Optionally execute a command after we're done */
202 if ($this->initially_was_account == $this->is_account){
203 if ($this->is_modified){
204 $this->handle_post_events("modify",array("uid" => $this->uid));
205 }
206 } else {
207 $this->handle_post_events("add",array("uid" => $this->uid));
208 }
210 }
213 /* Return plugin informations for acl handling
214 #FIME There possibly some attributes that can be combined to one acl. */
215 function plInfo()
216 {
217 return (array(
218 "plShortName" => _("Ftp"),
219 "plDescription" => _("Pure ftp account")." : <u>"._("Connectivity addon")."</u>",
220 "plSelfModify" => TRUE,
221 "plDepends" => array("user"),
222 "plPriority" => 22, // Position in tabs
223 "plSection" => "personal", // This belongs to personal
224 "plCategory" => array("users"),
225 "plOptions" => array(),
227 "plProvidedAcls" => array(
228 "FTPQuotaFiles" => _("Quota files"),
229 "FTPUploadRatio" => _("Upload ratio"),
230 "FTPQuotaMBytes" => _("Quota MBytes"),
231 "FTPDownloadRatio" => _("Download ratio"),
232 "FTPUploadBandwidth" => _("Upload bandwith"),
233 "FTPDownloadBandwidth" => _("Download bandwith"),
234 "FTPStatus" => _("Status"))
235 ));
236 }
237 }
239 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
240 ?>