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");
25 function pureftpdAccount ($config, $dn= NULL)
26 {
27 plugin::plugin ($config, $dn);
28 }
30 function execute()
31 {
32 /* Show tab dialog headers */
33 $display= "";
35 /* Show main page */
36 $smarty= get_smarty();
38 /* Load attributes */
39 foreach($this->attributes as $val){
40 $smarty->assign("$val", $this->$val);
41 }
44 $tmp = $this->plInfo();
45 $changeState = "";
46 foreach($tmp['plProvidedAcls'] as $key => $desc){
47 $smarty->assign($key."ACL", $this->getacl($key));
48 $smarty->assign($key."_W", $this->acl_is_writeable($key));
50 if($this->acl_is_writeable($key)){
51 $changeState.= " changeState('".$key."'); \n";
52 }
53 }
54 $smarty->assign("changeState",$changeState);
57 $smarty->assign("fstate", "");
58 if ($this->is_account){
59 $smarty->assign("pureftpdState", "checked");
60 $smarty->assign("fstate", "");
61 } else {
62 $smarty->assign("pureftpdState", "");
63 if($_SESSION['js']==1){
64 if($this->acl!="#none#")
65 $smarty->assign("fstate", "disabled");
66 }else{
67 $smarty->assign("fstate", "");
68 }
69 }
70 $smarty->assign("use_FTPStatus", ($this->FTPStatus == "disabled") ? "checked" : "");
72 if(($this->is_account && $this->acl_is_removeable()) || (!$this->is_account && $this->acl_is_createable())) {
73 $smarty->assign('pureftpdACL', "");
74 }else{
75 $smarty->assign('pureftpdACL', " disabled ");
76 }
78 $display.= $smarty->fetch (get_template_path('pureftpd.tpl', TRUE, dirname(__FILE__)));
79 return ($display);
80 }
82 function remove_from_parent()
83 {
84 /* Cancel if there's nothing to do here */
85 if ((!$this->initially_was_account) || (!$this->acl_is_removeable())){
86 return;
87 }
89 plugin::remove_from_parent();
90 $ldap= $this->config->get_ldap_link();
92 $ldap->cd($this->dn);
93 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
94 $this->attributes, "Save");
95 $this->cleanup();
96 $ldap->modify ($this->attrs);
98 show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/pureftpd account with dn '%s' failed."),$this->dn));
100 /* Optionally execute a command after we're done */
101 $this->handle_post_events('remove');
102 }
105 /* Save data to object */
106 function save_object()
107 {
108 /* Do we need to flip is_account state? */
109 if (isset($_POST['connectivityTab'])){
110 if (isset($_POST['pureftpd'])){
111 if (!$this->is_account && $_POST['pureftpd'] == "B"){
112 $this->is_account= TRUE;
113 }
114 } else {
115 $this->is_account= FALSE;
116 }
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;
128 }
131 /* Check values */
132 function check()
133 {
134 /* Call common method to give check the hook */
135 $message= plugin::check();
137 /* Check for positive integer values */
138 if ($this->is_account){
140 if($this->acl_is_writeable("FTPUploadBandwidth") && !is_id($this->FTPUploadBandwidth)){
141 $message[]= _("Value specified as 'Upload bandwidth' is not valid.");
142 }
143 if($this->acl_is_writeable("FTPDownloadBandwidth") && !is_id($this->FTPDownloadBandwidth)){
144 $message[]= _("Value specified as 'Download bandwidth' is not valid.");
145 }
147 if($this->acl_is_writeable("FTPQuotaFiles") && !is_id($this->FTPQuotaFiles)){
148 $message[]= _("Value specified as 'Quota files' is not valid.");
149 }
150 if($this->acl_is_writeable("FTPQuotaMBytes") && !is_id($this->FTPQuotaMBytes)){
151 $message[]= _("Value specified as 'Quota size' is not valid.");
152 }
153 if($this->acl_is_writeable("FTPUploadRatio") && !is_id($this->FTPUploadRatio)){
154 $message[]= _("Value specified as 'Upload ratio' is not valid.");
155 }
156 if($this->acl_is_writeable("FTPDownloadRatio") && !is_id($this->FTPDownloadRatio)){
157 $message[]= _("Value specified as 'Download ratio' is not valid.");
158 }
159 }
161 return $message;
162 }
165 /* Save to LDAP */
166 function save()
167 {
168 plugin::save();
170 $tmp = $this->plInfo();
171 foreach($tmp['plProvidedAcls'] as $key => $desc){
172 if(!$this->acl_is_writeable($key)){
173 unset($this->attrs[$key]);
174 }
175 }
177 /* Write back to ldap */
178 $ldap= $this->config->get_ldap_link();
179 $ldap->cd($this->dn);
180 $this->cleanup();
181 $ldap->modify ($this->attrs);
183 show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/pureftpd account with dn '%s' failed."),$this->dn));
185 /* Optionally execute a command after we're done */
186 if ($this->initially_was_account == $this->is_account){
187 if ($this->is_modified){
188 $this->handle_post_events("mofify");
189 }
190 } else {
191 $this->handle_post_events("add");
192 }
194 }
197 /* Return plugin informations for acl handling
198 #FIME There possibly some attributes that can be combined to one acl. */
199 function plInfo()
200 {
201 return (array(
202 "plShortName" => _("Ftp"),
203 "plDescription" => _("Pure ftp account"),
204 "plSelfModify" => TRUE,
205 "plDepends" => array("user"),
206 "plPriority" => 8, // Position in tabs
207 "plSection" => "personal", // This belongs to personal
208 "plCategory" => array("users"),
209 "plOptions" => array(),
211 "plProvidedAcls" => array(
212 "FTPQuotaFiles" => "!!! FIXME "._("Quota files"),
213 "FTPUploadRatio" => _("Upload ratio"),
214 "FTPQuotaMBytes" => _("Quota MBytes"),
215 "FTPDownloadRatio" => _("Download ratio"),
216 "FTPUploadBandwidth" => _("Upload bandwith"),
217 "FTPDownloadBandwidth" => _("Download bandwith"),
218 "FTPStatus" => _("Status"))
219 ));
220 }
221 }
223 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
224 ?>