[gosa.git] / gosa-plugins / pureftpd / personal / connectivity / pureftpd / class_pureftpdAccount.inc
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 var $uid = "";
22 /* attribute list for save action */
23 var $attributes= array("FTPQuotaFiles","FTPQuotaMBytes","FTPUploadRatio","FTPDownloadRatio",
24 "FTPUploadBandwidth","FTPDownloadBandwidth","FTPStatus","FTPuid","FTPgid");
25 var $objectclasses= array("PureFTPdUser");
26 var $ReadOnly;
27 var $view_logged = FALSE;
29 var $multiple_support=TRUE;
31 function pureftpdAccount (&$config, $dn= NULL, $parent= NULL)
32 {
33 plugin::plugin ($config, $dn, $parent);
35 /* Setting uid to default */
36 if(isset($this->attrs['uid'][0])){
37 $this->uid = $this->attrs['uid'][0];
38 }
39 }
41 function execute()
42 {
43 /* Log view */
44 if($this->is_account && !$this->view_logged){
45 $this->view_logged = TRUE;
46 new log("view","users/".get_class($this),$this->dn);
47 }
49 /* Show tab dialog headers */
50 $display= "";
52 /* Show main page */
53 $smarty= get_smarty();
55 /* Load attributes */
56 foreach($this->attributes as $val){
57 $smarty->assign("$val", $this->$val);
58 }
61 $tmp = $this->plInfo();
62 $changeState = "";
63 if($this->multiple_support_active){
65 /* We do not need the attribute grey out in multiple edit */
66 foreach($tmp['plProvidedAcls'] as $key => $desc){
67 $smarty->assign($key."ACL", $this->getacl($key,$this->ReadOnly));
68 }
69 if ($this->is_account){
70 $smarty->assign("pureftpdState", "checked");
71 }else{
72 $smarty->assign("pureftpdState", "");
73 }
74 $smarty->assign("fstate", "");
75 $smarty->assign("changeState","");
77 }else{
78 foreach($tmp['plProvidedAcls'] as $key => $desc){
79 $smarty->assign($key."ACL", $this->getacl($key,$this->ReadOnly));
80 $smarty->assign($key."_W", $this->acl_is_writeable($key,$this->ReadOnly));
82 if($this->acl_is_writeable($key)){
83 $changeState.= " changeState('".$key."'); \n";
84 }
85 }
86 $smarty->assign("changeState",$changeState);
89 $smarty->assign("fstate", "");
90 if ($this->is_account){
91 $smarty->assign("pureftpdState", "checked");
92 $smarty->assign("fstate", "");
93 } else {
94 $smarty->assign("pureftpdState", "");
95 if(session::get('js')==1){
96 if($this->acl!="#none#")
97 $smarty->assign("fstate", "disabled");
98 }else{
99 $smarty->assign("fstate", "");
100 }
101 }
102 }
104 foreach($this->attributes as $attr){
105 if(in_array($attr,$this->multi_boxes)){
106 $smarty->assign("use_".$attr,TRUE);
107 }else{
108 $smarty->assign("use_".$attr,FALSE);
109 }
110 }
111 $smarty->assign("use_pureftpd",in_array("pureftpd",$this->multi_boxes));
112 $smarty->assign("multiple_support",$this->multiple_support_active);
113 $smarty->assign("FTPStatus", ($this->FTPStatus == "disabled") ? "checked" : "");
114 $smarty->assign('pureftpdACL', $this->getacl("",$this->ReadOnly));
115 $display.= $smarty->fetch (get_template_path('pureftpd.tpl', TRUE, dirname(__FILE__)));
116 return ($display);
117 }
119 function remove_from_parent()
120 {
121 /* Cancel if there's nothing to do here */
122 if ((!$this->initially_was_account) || (!$this->acl_is_removeable())){
123 return;
124 }
126 plugin::remove_from_parent();
127 $ldap= $this->config->get_ldap_link();
129 $ldap->cd($this->dn);
130 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
131 $this->attributes, "Save");
132 $this->cleanup();
133 $ldap->modify ($this->attrs);
135 /* Log last action */
136 new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
138 if (!$ldap->success()){
139 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
140 }
142 /* Optionally execute a command after we're done */
143 $this->handle_post_events('remove',array("uid" => $this->uid));
144 }
147 /* Save data to object */
148 function save_object()
149 {
150 /* Do we need to flip is_account state? */
151 if (isset($_POST['connectivityTab'])){
152 if (isset($_POST['pureftpd'])){
153 if (!$this->is_account && $_POST['pureftpd'] == "B"){
154 $this->is_account= TRUE;
155 }
156 } else {
157 $this->is_account= FALSE;
158 }
160 plugin::save_object();
162 $old= $this->FTPStatus;
163 if (isset($_POST["FTPStatus"])){
164 $this->FTPStatus = "disabled";
165 } else {
166 $this->FTPStatus = "enabled";
167 }
168 $this->is_modified= ($old != $this->FTPStatus)?TRUE:$this->is_modified;
170 /* Ensure that these vars are numeric. Values starting with 0 like '0123' cause ldap errors */
171 foreach(array("FTPQuotaFiles","FTPQuotaMBytes","FTPUploadRatio","FTPDownloadRatio","FTPUploadBandwidth","FTPDownloadBandwidth") as $testVar){
172 $this->$testVar = (int) ($this->$testVar);
173 }
176 }
177 }
180 /* Check values */
181 function check()
182 {
183 /* Call common method to give check the hook */
184 $message= plugin::check();
186 /* Check for positive integer values */
187 if ($this->is_account){
189 if($this->acl_is_writeable("FTPUploadBandwidth") && !tests::is_id($this->FTPUploadBandwidth)){
190 $message[]= msgPool::invalid(_("Upload bandwidth"), $this->uid, "/^[0-9]+$/");
191 }
192 if($this->acl_is_writeable("FTPDownloadBandwidth") && !tests::is_id($this->FTPDownloadBandwidth)){
193 $message[]= msgPool::invalid(_("Download bandwidth"), $this->uid, "/^[0-9]+$/");
194 }
196 if($this->acl_is_writeable("FTPQuotaFiles") && !tests::is_id($this->FTPQuotaFiles)){
197 $message[]= msgPool::invalid(_("Quota file"), $this->uid, "/^[0-9]+$/");
198 }
199 if($this->acl_is_writeable("FTPQuotaMBytes") && !tests::is_id($this->FTPQuotaMBytes)){
200 $message[]= msgPool::invalid(_("Quota size"), $this->uid, "/^[0-9]+$/");
201 }
202 if($this->acl_is_writeable("FTPUploadRatio") && !tests::is_id($this->FTPUploadRatio)){
203 $message[]= msgPool::invalid(_("Upload ratio"), $this->uid, "/^[0-9]+$/");
204 }
205 if($this->acl_is_writeable("FTPDownloadRatio") && !tests::is_id($this->FTPDownloadRatio)){
206 $message[]= msgPool::invalid(_("Download ratio"), $this->uid, "/^[0-9]+$/");
207 }
208 }
210 return $message;
211 }
214 /* Save to LDAP */
215 function save()
216 {
217 plugin::save();
219 $tmp = $this->plInfo();
220 foreach($tmp['plProvidedAcls'] as $key => $desc){
221 if(!$this->acl_is_writeable($key)){
222 unset($this->attrs[$key]);
223 }
224 }
226 /* Write back to ldap */
227 $ldap= $this->config->get_ldap_link();
228 $ldap->cd($this->dn);
229 $this->cleanup();
230 $ldap->modify ($this->attrs);
232 /* Log last action */
233 if($this->initially_was_account){
234 new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
235 }else{
236 new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
237 }
239 if (!$ldap->success()){
240 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
241 }
243 /* Optionally execute a command after we're done */
244 if ($this->initially_was_account == $this->is_account){
245 if ($this->is_modified){
246 $this->handle_post_events("modify",array("uid" => $this->uid));
247 }
248 } else {
249 $this->handle_post_events("add",array("uid" => $this->uid));
250 }
252 }
255 /* Return plugin informations for acl handling
256 #FIME There possibly some attributes that can be combined to one acl. */
257 static function plInfo()
258 {
259 return (array(
260 "plShortName" => _("Ftp"),
261 "plDescription" => _("Pure ftp account")." : <u>"._("Connectivity addon")."</u>",
262 "plSelfModify" => TRUE,
263 "plDepends" => array("user"),
264 "plPriority" => 22, // Position in tabs
265 "plSection" => array("personal" => _("My account")),
266 "plCategory" => array("users"),
267 "plOptions" => array(),
269 "plProvidedAcls" => array(
270 "FTPQuotaFiles" => _("Quota files"),
271 "FTPUploadRatio" => _("Upload ratio"),
272 "FTPQuotaMBytes" => _("Quota MBytes"),
273 "FTPDownloadRatio" => _("Download ratio"),
274 "FTPUploadBandwidth" => _("Upload bandwith"),
275 "FTPDownloadBandwidth" => _("Download bandwith"),
276 "FTPStatus" => _("Status"))
277 ));
278 }
280 function multiple_save_object()
281 {
282 if (isset($_POST['connectivityTab'])){
283 plugin::multiple_save_object();
284 if(isset($_POST['use_pureftpd'])){
285 $this->multi_boxes[] = "pureftpd";
286 }
287 $this->save_object();
288 }
289 }
291 function get_multi_init_values()
292 {
293 $ret = plugin::get_multi_init_values();
294 $ret['is_account'] = $this->is_account;
295 return($ret);
296 }
298 function init_multiple_support($attrs,$attr)
299 {
300 plugin::init_multiple_support($attrs,$attr);
302 if(isset($attrs['is_account'])){
303 $this->is_account = $attrs['is_account'];
304 }
305 }
307 function get_multi_edit_values()
308 {
309 $ret = plugin::get_multi_edit_values();
310 if(in_array("pureftpd",$this->multi_boxes)){
311 $ret['is_account'] = $this->is_account;
312 }
313 return($ret);
314 }
316 function set_multi_edit_values($values)
317 {
318 plugin::set_multi_edit_values($values);
319 if(isset($values['is_account'])){
320 $this->is_account = $values['is_account'];
321 }
322 }
324 }
326 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
327 ?>