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 /* Show tab dialog headers */
38 $display= "";
40 /* Show main page */
41 $smarty= get_smarty();
43 /* Load attributes */
44 foreach($this->attributes as $val){
45 $smarty->assign("$val", $this->$val);
46 $smarty->assign($val."ACL", chkacl($this->acl, "$val"));
47 }
48 if ($this->is_account){
49 $smarty->assign("pureftpdState", "checked");
50 } else {
51 $smarty->assign("pureftpdState", "");
52 $smarty->assign("fstate", "disabled");
53 }
54 $smarty->assign("use_FTPStatus", ($this->FTPStatus == "disabled") ? "checked" : "");
56 if ($this->parent != NULL){
57 $smarty->assign("tabbed", 1);
58 }
59 $smarty->assign("pureftpdACL", chkacl($this->acl, 'pureftpd'));
61 $display.= $smarty->fetch (get_template_path('pureftpd.tpl', TRUE, dirname(__FILE__)));
62 return ($display);
63 }
65 function remove_from_parent()
66 {
67 /* Cancel if there's nothing to do here */
68 if (!$this->initially_was_account){
69 return;
70 }
72 plugin::remove_from_parent();
73 $ldap= $this->config->get_ldap_link();
75 $ldap->cd($this->dn);
76 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
77 $this->attributes, "Save");
78 $ldap->modify($this->attrs);
79 show_ldap_error($ldap->get_error());
81 /* Optionally execute a command after we're done */
82 $this->handle_post_events('remove');
83 }
86 /* Save data to object */
87 function save_object()
88 {
89 /* Do we need to flip is_account state? */
90 if (isset($_POST['connectivityTab'])){
91 if (isset($_POST['pureftpd'])){
92 if (!$this->is_account && $_POST['pureftpd'] == "B"){
93 $this->is_account= TRUE;
94 }
95 } else {
96 $this->is_account= FALSE;
97 }
98 }
100 plugin::save_object();
102 $old= $this->FTPStatus;
103 if (isset($_POST["FTPStatus"])){
104 $this->FTPStatus = "disabled";
105 } else {
106 $this->FTPStatus = "enabled";
107 }
108 $this->is_modified= ($old != $this->FTPStatus)?TRUE:$this->is_modified;
109 }
112 /* Check values */
113 function check()
114 {
115 $message= array();
117 /* Check for positive integer values */
118 if ($this->is_account){
119 if (!is_id($this->FTPUploadBandwidth)){
120 $message[]= _("Value specified as 'Upload bandwidth' is not valid.");
121 }
122 if (!is_id($this->FTPDownloadBandwidth)){
123 $message[]= _("Value specified as 'Download bandwidth' is not valid.");
124 }
125 if (!is_id($this->FTPQuotaFiles)){
126 $message[]= _("Value specified as 'Files' is not valid.");
127 }
128 if (!is_id($this->FTPQuotaMBytes)){
129 $message[]= _("Value specified as 'Size' is not valid.");
130 }
131 if (!is_id($this->FTPUploadRatio) || !is_id($this->FTPDownloadRatio)){
132 $message[]= _("Value specified as 'Ratio' is not valid.");
133 }
134 }
136 return $message;
137 }
140 /* Save to LDAP */
141 function save()
142 {
143 plugin::save();
145 /* Write back to ldap */
146 $ldap= $this->config->get_ldap_link();
147 $ldap->cd($this->dn);
148 $ldap->modify($this->attrs);
149 show_ldap_error($ldap->get_error());
151 /* Optionally execute a command after we're done */
152 if ($this->initially_was_account == $this->is_account){
153 if ($this->is_modified){
154 $this->handle_post_events("mofify");
155 }
156 } else {
157 $this->handle_post_events("add");
158 }
160 }
162 }
164 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
165 ?>