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 $smarty->assign("fstate", "");
51 } else {
52 $smarty->assign("pureftpdState", "");
53 $smarty->assign("fstate", "disabled");
54 }
55 $smarty->assign("use_FTPStatus", ($this->FTPStatus == "disabled") ? "checked" : "");
57 # Hickert, Added Else. Smarty have to know the variable in both cases
58 if ($this->parent != NULL){
59 $smarty->assign("tabbed", 1);
60 }else {
61 $smarty->assign("tabbed", 0);
62 }
64 $smarty->assign("pureftpdACL", chkacl($this->acl, 'pureftpd'));
66 $display.= $smarty->fetch (get_template_path('pureftpd.tpl', TRUE, dirname(__FILE__)));
67 return ($display);
68 }
70 function remove_from_parent()
71 {
72 /* Cancel if there's nothing to do here */
73 if (!$this->initially_was_account){
74 return;
75 }
77 plugin::remove_from_parent();
78 $ldap= $this->config->get_ldap_link();
80 $ldap->cd($this->dn);
81 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
82 $this->attributes, "Save");
83 $ldap->modify($this->attrs);
84 show_ldap_error($ldap->get_error());
86 /* Optionally execute a command after we're done */
87 $this->handle_post_events('remove');
88 }
91 /* Save data to object */
92 function save_object()
93 {
94 /* Do we need to flip is_account state? */
95 if (isset($_POST['connectivityTab'])){
96 if (isset($_POST['pureftpd'])){
97 if (!$this->is_account && $_POST['pureftpd'] == "B"){
98 $this->is_account= TRUE;
99 }
100 } else {
101 $this->is_account= FALSE;
102 }
103 }
105 plugin::save_object();
107 $old= $this->FTPStatus;
108 if (isset($_POST["FTPStatus"])){
109 $this->FTPStatus = "disabled";
110 } else {
111 $this->FTPStatus = "enabled";
112 }
113 $this->is_modified= ($old != $this->FTPStatus)?TRUE:$this->is_modified;
114 }
117 /* Check values */
118 function check()
119 {
120 $message= array();
122 /* Check for positive integer values */
123 if ($this->is_account){
124 if (!is_id($this->FTPUploadBandwidth)){
125 $message[]= _("Value specified as 'Upload bandwidth' is not valid.");
126 }
127 if (!is_id($this->FTPDownloadBandwidth)){
128 $message[]= _("Value specified as 'Download bandwidth' is not valid.");
129 }
130 if (!is_id($this->FTPQuotaFiles)){
131 $message[]= _("Value specified as 'Files' is not valid.");
132 }
133 if (!is_id($this->FTPQuotaMBytes)){
134 $message[]= _("Value specified as 'Size' is not valid.");
135 }
136 if (!is_id($this->FTPUploadRatio) || !is_id($this->FTPDownloadRatio)){
137 $message[]= _("Value specified as 'Ratio' is not valid.");
138 }
139 }
141 return $message;
142 }
145 /* Save to LDAP */
146 function save()
147 {
148 plugin::save();
150 /* Write back to ldap */
151 $ldap= $this->config->get_ldap_link();
152 $ldap->cd($this->dn);
153 $ldap->modify($this->attrs);
154 show_ldap_error($ldap->get_error());
156 /* Optionally execute a command after we're done */
157 if ($this->initially_was_account == $this->is_account){
158 if ($this->is_modified){
159 $this->handle_post_events("mofify");
160 }
161 } else {
162 $this->handle_post_events("add");
163 }
165 }
167 }
169 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
170 ?>