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 /* attribute list for save action */
21 var $attributes= array("FTPQuotaFiles","FTPQuotaMBytes","FTPUploadRatio","FTPDownloadRatio",
22 "FTPUploadBandwidth","FTPDownloadBandwidth","FTPStatus","FTPuid","FTPgid");
23 var $objectclasses= array("PureFTPdUser");
24 var $ReadOnly;
26 function pureftpdAccount ($config, $dn= NULL)
27 {
28 plugin::plugin ($config, $dn);
29 }
31 function execute()
32 {
33 /* Show tab dialog headers */
34 $display= "";
36 /* Show main page */
37 $smarty= get_smarty();
39 /* Load attributes */
40 foreach($this->attributes as $val){
41 $smarty->assign("$val", $this->$val);
42 }
45 $tmp = $this->plInfo();
46 $changeState = "";
47 foreach($tmp['plProvidedAcls'] as $key => $desc){
48 $smarty->assign($key."ACL", $this->getacl($key,$this->ReadOnly));
49 $smarty->assign($key."_W", $this->acl_is_writeable($key,$this->ReadOnly));
51 if($this->acl_is_writeable($key)){
52 $changeState.= " changeState('".$key."'); \n";
53 }
54 }
55 $smarty->assign("changeState",$changeState);
58 $smarty->assign("fstate", "");
59 if ($this->is_account){
60 $smarty->assign("pureftpdState", "checked");
61 $smarty->assign("fstate", "");
62 } else {
63 $smarty->assign("pureftpdState", "");
64 if($_SESSION['js']==1){
65 if($this->acl!="#none#")
66 $smarty->assign("fstate", "disabled");
67 }else{
68 $smarty->assign("fstate", "");
69 }
70 }
71 $smarty->assign("use_FTPStatus", ($this->FTPStatus == "disabled") ? "checked" : "");
73 if((!$this->ReadOnly)&&(($this->is_account && $this->acl_is_removeable()) || (!$this->is_account && $this->acl_is_createable())) ){
74 $smarty->assign('pureftpdACL', "");
75 }else{
76 $smarty->assign('pureftpdACL', " disabled ");
77 }
79 $display.= $smarty->fetch (get_template_path('pureftpd.tpl', TRUE, dirname(__FILE__)));
80 return ($display);
81 }
83 function remove_from_parent()
84 {
85 /* Cancel if there's nothing to do here */
86 if ((!$this->initially_was_account) || (!$this->acl_is_removeable())){
87 return;
88 }
90 plugin::remove_from_parent();
91 $ldap= $this->config->get_ldap_link();
93 $ldap->cd($this->dn);
94 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
95 $this->attributes, "Save");
96 $this->cleanup();
97 $ldap->modify ($this->attrs);
99 show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/pureftpd account with dn '%s' failed."),$this->dn));
101 /* Optionally execute a command after we're done */
102 $this->handle_post_events('remove');
103 }
106 /* Save data to object */
107 function save_object()
108 {
109 /* Do we need to flip is_account state? */
110 if (isset($_POST['connectivityTab'])){
111 if (isset($_POST['pureftpd'])){
112 if (!$this->is_account && $_POST['pureftpd'] == "B"){
113 $this->is_account= TRUE;
114 }
115 } else {
116 $this->is_account= FALSE;
117 }
119 plugin::save_object();
121 $old= $this->FTPStatus;
122 if (isset($_POST["FTPStatus"])){
123 $this->FTPStatus = "disabled";
124 } else {
125 $this->FTPStatus = "enabled";
126 }
127 $this->is_modified= ($old != $this->FTPStatus)?TRUE:$this->is_modified;
129 /* Ensure that these vars are numeric. Values starting with 0 like '0123' cause ldap errors */
130 foreach(array("FTPQuotaFiles","FTPQuotaMBytes","FTPUploadRatio","FTPDownloadRatio","FTPUploadBandwidth","FTPDownloadBandwidth") as $testVar){
131 $this->$testVar = (int) ($this->$testVar);
132 }
135 }
136 }
139 /* Check values */
140 function check()
141 {
142 /* Call common method to give check the hook */
143 $message= plugin::check();
145 /* Check for positive integer values */
146 if ($this->is_account){
148 if($this->acl_is_writeable("FTPUploadBandwidth") && !is_id($this->FTPUploadBandwidth)){
149 $message[]= _("Value specified as 'Upload bandwidth' is not valid.");
150 }
151 if($this->acl_is_writeable("FTPDownloadBandwidth") && !is_id($this->FTPDownloadBandwidth)){
152 $message[]= _("Value specified as 'Download bandwidth' is not valid.");
153 }
155 if($this->acl_is_writeable("FTPQuotaFiles") && !is_id($this->FTPQuotaFiles)){
156 $message[]= _("Value specified as 'Quota files' is not valid.");
157 }
158 if($this->acl_is_writeable("FTPQuotaMBytes") && !is_id($this->FTPQuotaMBytes)){
159 $message[]= _("Value specified as 'Quota size' is not valid.");
160 }
161 if($this->acl_is_writeable("FTPUploadRatio") && !is_id($this->FTPUploadRatio)){
162 $message[]= _("Value specified as 'Upload ratio' is not valid.");
163 }
164 if($this->acl_is_writeable("FTPDownloadRatio") && !is_id($this->FTPDownloadRatio)){
165 $message[]= _("Value specified as 'Download ratio' is not valid.");
166 }
167 }
169 return $message;
170 }
173 /* Save to LDAP */
174 function save()
175 {
176 plugin::save();
178 $tmp = $this->plInfo();
179 foreach($tmp['plProvidedAcls'] as $key => $desc){
180 if(!$this->acl_is_writeable($key)){
181 unset($this->attrs[$key]);
182 }
183 }
185 /* Write back to ldap */
186 $ldap= $this->config->get_ldap_link();
187 $ldap->cd($this->dn);
188 $this->cleanup();
189 $ldap->modify ($this->attrs);
191 show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/pureftpd account with dn '%s' failed."),$this->dn));
193 /* Optionally execute a command after we're done */
194 if ($this->initially_was_account == $this->is_account){
195 if ($this->is_modified){
196 $this->handle_post_events("mofify");
197 }
198 } else {
199 $this->handle_post_events("add");
200 }
202 }
205 /* Return plugin informations for acl handling
206 #FIME There possibly some attributes that can be combined to one acl. */
207 function plInfo()
208 {
209 return (array(
210 "plShortName" => _("Ftp"),
211 "plDescription" => _("Pure ftp account"),
212 "plSelfModify" => TRUE,
213 "plDepends" => array("user"),
214 "plPriority" => 8, // Position in tabs
215 "plSection" => "personal", // This belongs to personal
216 "plCategory" => array("users"),
217 "plOptions" => array(),
219 "plProvidedAcls" => array(
220 "FTPQuotaFiles" => _("Quota files"),
221 "FTPUploadRatio" => _("Upload ratio"),
222 "FTPQuotaMBytes" => _("Quota MBytes"),
223 "FTPDownloadRatio" => _("Download ratio"),
224 "FTPUploadBandwidth" => _("Upload bandwith"),
225 "FTPDownloadBandwidth" => _("Download bandwith"),
226 "FTPStatus" => _("Status"))
227 ));
228 }
229 }
231 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
232 ?>