1 <?php
3 class pureftpdAccount extends plugin
4 {
5 /* Definitions */
6 var $plHeadline= "FTP";
7 var $plDescription= "This does something";
9 /* CLI vars */
10 var $cli_summary= "Manage users ftp account";
11 var $cli_description= "Some longer text\nfor help";
12 var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
14 /* FTP attributes */
15 var $FTPQuotaFiles = 0;
16 var $FTPQuotaMBytes = 0;
17 var $FTPUploadRatio = 0;
18 var $FTPDownloadRatio = 0;
19 var $FTPUploadBandwidth = 0;
20 var $FTPDownloadBandwidth = 0;
21 var $FTPStatus = "enabled";
22 var $FTPuid = "";
23 var $FTPgid = "";
25 var $uid = "";
27 /* attribute list for save action */
28 var $attributes= array("FTPQuotaFiles","FTPQuotaMBytes","FTPUploadRatio","FTPDownloadRatio",
29 "FTPUploadBandwidth","FTPDownloadBandwidth","FTPStatus","FTPuid","FTPgid");
30 var $objectclasses= array("PureFTPdUser");
32 function pureftpdAccount ($config, $dn= NULL)
33 {
34 plugin::plugin ($config, $dn);
36 /* Setting uid to default */
37 if(isset($this->attrs['uid'][0])){
38 $this->uid = $this->attrs['uid'][0];
39 }
41 }
43 function execute()
44 {
45 /* Call parent execute */
46 // plugin::execute();
48 /* Show tab dialog headers */
49 $display= "";
51 /* Show main page */
52 $smarty= get_smarty();
54 /* Load attributes */
55 foreach($this->attributes as $val){
56 $smarty->assign("$val", $this->$val);
57 $smarty->assign($val."ACL", chkacl($this->acl, "$val"));
58 }
59 $smarty->assign("fstate", "");
60 if ($this->is_account){
61 $smarty->assign("pureftpdState", "checked");
62 $smarty->assign("fstate", "");
63 } else {
64 $smarty->assign("pureftpdState", "");
65 if($_SESSION['js']==1){
66 if($this->acl!="#none#")
67 $smarty->assign("fstate", "disabled");
68 }else{
69 $smarty->assign("fstate", "");
70 }
71 }
72 $smarty->assign("use_FTPStatus", ($this->FTPStatus == "disabled") ? "checked" : "");
74 $smarty->assign("pureftpdACL", chkacl($this->acl, 'pureftpd'));
76 $changeState = "";
77 foreach($this->attributes as $attr){
78 $smarty->assign($attr."ACL",chkacl($this->acl,$attr));
79 if(chkacl($this->acl,$attr)==""){
80 $changeState .= "changeState('".$attr."');\n";
81 }
82 }
83 $smarty->assign("changeState",$changeState);
84 $display.= $smarty->fetch (get_template_path('pureftpd.tpl', TRUE, dirname(__FILE__)));
85 return ($display);
86 }
88 function remove_from_parent()
89 {
90 /* Cancel if there's nothing to do here */
91 if (!$this->initially_was_account){
92 return;
93 }
95 plugin::remove_from_parent();
96 $ldap= $this->config->get_ldap_link();
98 $ldap->cd($this->dn);
99 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
100 $this->attributes, "Save");
101 $this->cleanup();
102 $ldap->modify ($this->attrs);
104 show_ldap_error($ldap->get_error(), _("Removing pureftpd account failed"));
106 /* Optionally execute a command after we're done */
107 $this->handle_post_events('remove',array("uid" => $this->uid));
108 }
111 /* Save data to object */
112 function save_object()
113 {
114 /* Do we need to flip is_account state? */
115 if (isset($_POST['connectivityTab'])){
116 if (isset($_POST['pureftpd'])){
117 if (!$this->is_account && $_POST['pureftpd'] == "B"){
118 $this->is_account= TRUE;
119 }
120 } else {
121 $this->is_account= FALSE;
122 }
123 }
125 plugin::save_object();
127 $old= $this->FTPStatus;
128 if (isset($_POST["FTPStatus"])){
129 $this->FTPStatus = "disabled";
130 } else {
131 $this->FTPStatus = "enabled";
132 }
133 $this->is_modified= ($old != $this->FTPStatus)?TRUE:$this->is_modified;
134 }
137 /* Check values */
138 function check()
139 {
140 /* Call common method to give check the hook */
141 $message= plugin::check();
143 /* Check for positive integer values */
144 if ($this->is_account){
145 if ((!is_id($this->FTPUploadBandwidth))&&(chkacl($this->acl,"FTPUploadBandwidth")=="")){
146 $message[]= _("Value specified as 'Upload bandwidth' is not valid.");
147 }
148 if ((!is_id($this->FTPDownloadBandwidth))&&(chkacl($this->acl,"FTPDownloadBandwidth")=="")){
149 $message[]= _("Value specified as 'Download bandwidth' is not valid.");
150 }
151 if ((!is_id($this->FTPQuotaFiles))&&(chkacl($this->acl,"FTPQuotaFiles")=="")){
152 $message[]= _("Value specified as 'Files' is not valid.");
153 }
154 if ((!is_id($this->FTPQuotaMBytes))&&(chkacl($this->acl,"FTPQuotaMBytes")=="")){
155 $message[]= _("Value specified as 'Size' is not valid.");
156 }
157 if ((!is_id($this->FTPUploadRatio) || !is_id($this->FTPDownloadRatio))&&(chkacl($this->acl,"FTPUploadRatio")=="")&&(chkacl($this->acl,"FTPDownloadRatio")=="")){
158 $message[]= _("Value specified as 'Ratio' is not valid.");
159 }
160 }
162 return $message;
163 }
166 /* Save to LDAP */
167 function save()
168 {
169 plugin::save();
171 foreach($this->attributes as $attr){
172 if(chkacl($this->acl,$attr)!=""){
173 unset($this->attrs[$attr]);
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(), _("Saving pureftpd account failed"));
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("modify",array("uid" => $this->uid));
189 }
190 } else {
191 $this->handle_post_events("add",array("uid" => $this->uid));
192 }
194 }
196 }
198 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
199 ?>