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 /* attribute list for save action */
26 var $attributes= array("FTPQuotaFiles","FTPQuotaMBytes","FTPUploadRatio","FTPDownloadRatio",
27 "FTPUploadBandwidth","FTPDownloadBandwidth","FTPStatus","FTPuid","FTPgid");
28 var $objectclasses= array("PureFTPdUser");
30 function pureftpdAccount ($config, $dn= NULL)
31 {
32 plugin::plugin ($config, $dn);
33 }
35 function execute()
36 {
37 /* Call parent execute */
38 // plugin::execute();
40 /* Show tab dialog headers */
41 $display= "";
43 /* Show main page */
44 $smarty= get_smarty();
46 /* Load attributes */
47 foreach($this->attributes as $val){
48 $smarty->assign("$val", $this->$val);
49 $smarty->assign($val."ACL", chkacl($this->acl, "$val"));
50 }
51 $smarty->assign("fstate", "");
52 if ($this->is_account){
53 $smarty->assign("pureftpdState", "checked");
54 $smarty->assign("fstate", "");
55 } else {
56 $smarty->assign("pureftpdState", "");
57 if($_SESSION['js']==1){
58 if($this->acl!="#none#")
59 $smarty->assign("fstate", "disabled");
60 }else{
61 $smarty->assign("fstate", "");
62 }
63 }
64 $smarty->assign("use_FTPStatus", ($this->FTPStatus == "disabled") ? "checked" : "");
66 $smarty->assign("pureftpdACL", chkacl($this->acl, 'pureftpd'));
68 $changeState = "";
69 foreach($this->attributes as $attr){
70 $smarty->assign($attr."ACL",chkacl($this->acl,$attr));
71 if(chkacl($this->acl,$attr)==""){
72 $changeState .= "changeState('".$attr."');\n";
73 }
74 }
75 $smarty->assign("changeState",$changeState);
76 $display.= $smarty->fetch (get_template_path('pureftpd.tpl', TRUE, dirname(__FILE__)));
77 return ($display);
78 }
80 function remove_from_parent()
81 {
82 /* Cancel if there's nothing to do here */
83 if (!$this->initially_was_account){
84 return;
85 }
87 plugin::remove_from_parent();
88 $ldap= $this->config->get_ldap_link();
90 $ldap->cd($this->dn);
91 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
92 $this->attributes, "Save");
93 $this->cleanup();
94 $ldap->modify ($this->attrs);
96 show_ldap_error($ldap->get_error());
98 /* Optionally execute a command after we're done */
99 $this->handle_post_events('remove');
100 }
103 /* Save data to object */
104 function save_object()
105 {
106 /* Do we need to flip is_account state? */
107 if (isset($_POST['connectivityTab'])){
108 if (isset($_POST['pureftpd'])){
109 if (!$this->is_account && $_POST['pureftpd'] == "B"){
110 $this->is_account= TRUE;
111 }
112 } else {
113 $this->is_account= FALSE;
114 }
115 }
117 plugin::save_object();
119 $old= $this->FTPStatus;
120 if (isset($_POST["FTPStatus"])){
121 $this->FTPStatus = "disabled";
122 } else {
123 $this->FTPStatus = "enabled";
124 }
125 $this->is_modified= ($old != $this->FTPStatus)?TRUE:$this->is_modified;
126 }
129 /* Check values */
130 function check()
131 {
132 $message= array();
134 /* Check for positive integer values */
135 if ($this->is_account){
136 if ((!is_id($this->FTPUploadBandwidth))&&(chkacl($this->acl,"FTPUploadBandwidth")=="")){
137 $message[]= _("Value specified as 'Upload bandwidth' is not valid.");
138 }
139 if ((!is_id($this->FTPDownloadBandwidth))&&(chkacl($this->acl,"FTPDownloadBandwidth")=="")){
140 $message[]= _("Value specified as 'Download bandwidth' is not valid.");
141 }
142 if ((!is_id($this->FTPQuotaFiles))&&(chkacl($this->acl,"FTPQuotaFiles")=="")){
143 $message[]= _("Value specified as 'Files' is not valid.");
144 }
145 if ((!is_id($this->FTPQuotaMBytes))&&(chkacl($this->acl,"FTPQuotaMBytes")=="")){
146 $message[]= _("Value specified as 'Size' is not valid.");
147 }
148 if ((!is_id($this->FTPUploadRatio) || !is_id($this->FTPDownloadRatio))&&(chkacl($this->acl,"FTPUploadRatio")=="")&&(chkacl($this->acl,"FTPDownloadRatio")=="")){
149 $message[]= _("Value specified as 'Ratio' is not valid.");
150 }
151 }
153 return $message;
154 }
157 /* Save to LDAP */
158 function save()
159 {
160 plugin::save();
162 foreach($this->attributes as $attr){
163 if(chkacl($this->acl,$attr)!=""){
164 unset($this->attrs[$attr]);
165 }
166 }
168 /* Write back to ldap */
169 $ldap= $this->config->get_ldap_link();
170 $ldap->cd($this->dn);
171 $this->cleanup();
172 $ldap->modify ($this->attrs);
174 show_ldap_error($ldap->get_error());
176 /* Optionally execute a command after we're done */
177 if ($this->initially_was_account == $this->is_account){
178 if ($this->is_modified){
179 $this->handle_post_events("mofify");
180 }
181 } else {
182 $this->handle_post_events("add");
183 }
185 }
187 }
189 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
190 ?>