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 /* Call parent execute */
33 // plugin::execute();
35 /* Show tab dialog headers */
36 $display= "";
38 /* Show main page */
39 $smarty= get_smarty();
41 /* Load attributes */
42 foreach($this->attributes as $val){
43 $smarty->assign("$val", $this->$val);
44 $smarty->assign($val."ACL", chkacl($this->acl, "$val"));
45 }
46 $smarty->assign("fstate", "");
47 if ($this->is_account){
48 $smarty->assign("pureftpdState", "checked");
49 $smarty->assign("fstate", "");
50 } else {
51 $smarty->assign("pureftpdState", "");
52 if($_SESSION['js']==1){
53 if($this->acl!="#none#")
54 $smarty->assign("fstate", "disabled");
55 }else{
56 $smarty->assign("fstate", "");
57 }
58 }
59 $smarty->assign("use_FTPStatus", ($this->FTPStatus == "disabled") ? "checked" : "");
61 $smarty->assign("pureftpdACL", chkacl($this->acl, 'pureftpd'));
63 $changeState = "";
64 foreach($this->attributes as $attr){
65 $smarty->assign($attr."ACL",chkacl($this->acl,$attr));
66 if(chkacl($this->acl,$attr)==""){
67 $changeState .= "changeState('".$attr."');\n";
68 }
69 }
70 $smarty->assign("changeState",$changeState);
71 $display.= $smarty->fetch (get_template_path('pureftpd.tpl', TRUE, dirname(__FILE__)));
72 return ($display);
73 }
75 function remove_from_parent()
76 {
77 /* Cancel if there's nothing to do here */
78 if (!$this->initially_was_account){
79 return;
80 }
82 plugin::remove_from_parent();
83 $ldap= $this->config->get_ldap_link();
85 $ldap->cd($this->dn);
86 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
87 $this->attributes, "Save");
88 $this->cleanup();
89 $ldap->modify ($this->attrs);
91 show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/pureftpd account with dn '%s' failed."),$this->dn));
93 /* Optionally execute a command after we're done */
94 $this->handle_post_events('remove');
95 }
98 /* Save data to object */
99 function save_object()
100 {
101 /* Do we need to flip is_account state? */
102 if (isset($_POST['connectivityTab'])){
103 if (isset($_POST['pureftpd'])){
104 if (!$this->is_account && $_POST['pureftpd'] == "B"){
105 $this->is_account= TRUE;
106 }
107 } else {
108 $this->is_account= FALSE;
109 }
110 }
112 plugin::save_object();
114 $old= $this->FTPStatus;
115 if (isset($_POST["FTPStatus"])){
116 $this->FTPStatus = "disabled";
117 } else {
118 $this->FTPStatus = "enabled";
119 }
120 $this->is_modified= ($old != $this->FTPStatus)?TRUE:$this->is_modified;
121 }
124 /* Check values */
125 function check()
126 {
127 /* Call common method to give check the hook */
128 $message= plugin::check();
130 /* Check for positive integer values */
131 if ($this->is_account){
132 if ((!is_id($this->FTPUploadBandwidth))&&(chkacl($this->acl,"FTPUploadBandwidth")=="")){
133 $message[]= _("Value specified as 'Upload bandwidth' is not valid.");
134 }
135 if ((!is_id($this->FTPDownloadBandwidth))&&(chkacl($this->acl,"FTPDownloadBandwidth")=="")){
136 $message[]= _("Value specified as 'Download bandwidth' is not valid.");
137 }
138 if ((!is_id($this->FTPQuotaFiles))&&(chkacl($this->acl,"FTPQuotaFiles")=="")){
139 $message[]= _("Value specified as 'Files' is not valid.");
140 }
141 if ((!is_id($this->FTPQuotaMBytes))&&(chkacl($this->acl,"FTPQuotaMBytes")=="")){
142 $message[]= _("Value specified as 'Size' is not valid.");
143 }
144 if ((!is_id($this->FTPUploadRatio) || !is_id($this->FTPDownloadRatio))&&(chkacl($this->acl,"FTPUploadRatio")=="")&&(chkacl($this->acl,"FTPDownloadRatio")=="")){
145 $message[]= _("Value specified as 'Ratio' is not valid.");
146 }
147 }
149 return $message;
150 }
153 /* Save to LDAP */
154 function save()
155 {
156 plugin::save();
158 foreach($this->attributes as $attr){
159 if(chkacl($this->acl,$attr)!=""){
160 unset($this->attrs[$attr]);
161 }
162 }
164 /* Write back to ldap */
165 $ldap= $this->config->get_ldap_link();
166 $ldap->cd($this->dn);
167 $this->cleanup();
168 $ldap->modify ($this->attrs);
170 show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/pureftpd account with dn '%s' failed."),$this->dn));
172 /* Optionally execute a command after we're done */
173 if ($this->initially_was_account == $this->is_account){
174 if ($this->is_modified){
175 $this->handle_post_events("mofify");
176 }
177 } else {
178 $this->handle_post_events("add");
179 }
181 }
184 /* Return plugin informations for acl handling
185 #FIME There possibly some attributes that can be combined to one acl. */
186 function plInfo()
187 {
188 return (array(
189 "plShortName" => _("Ftp"),
190 "plDescription" => _("Pure ftp account"),
191 "plSelfModify" => TRUE,
192 "plDepends" => array("connectivity"),
193 "plPriority" => 8, // Position in tabs
194 "plSection" => "personal", // This belongs to personal
195 "plCategory" => array("gosaAccount"),
196 "plOptions" => array(),
198 "plProvidedAcls" => array(
199 "FTPQuotaFiles" => "!!! FIXME "._("Quota files"),
200 "FTPUploadRatio" => _("Upload ratio"),
201 "FTPQuotaMBytes" => _("Quota MBytes"),
202 "FTPDownloadRatio" => _("Download ratio"),
203 "FTPUploadBandwidth" => _("Upload bandwith"),
204 "FTPDownloadBandwidth" => _("Download bandwith"),
205 "FTPStatus" => _("Status"))
206 ));
207 }
208 }
210 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
211 ?>