[gosa.git] / trunk / 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 = "";
11 var $FTPQuotaMBytes = "";
12 var $FTPUploadRatio = "";
13 var $FTPDownloadRatio = "";
14 var $FTPUploadBandwidth = "";
15 var $FTPDownloadBandwidth = "";
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",
172 "FTPUploadBandwidth","FTPDownloadBandwidth") as $testVar){
173 if(!empty($this->$testVar)){
174 $this->$testVar = (int) ($this->$testVar);
175 }
176 }
177 }
178 }
181 /* Check values */
182 function check()
183 {
184 /* Call common method to give check the hook */
185 $message= plugin::check();
187 /* Check for positive integer values */
188 if ($this->is_account){
190 if($this->acl_is_writeable("FTPUploadBandwidth") && preg_match("/[^0-9]/",$this->FTPUploadBandwidth)){
191 $message[]= msgPool::invalid(_("Upload bandwidth"), $this->uid, "/^[0-9]+$/");
192 }
193 if($this->acl_is_writeable("FTPDownloadBandwidth") && preg_match("/[^0-9]/",$this->FTPDownloadBandwidth)){
194 $message[]= msgPool::invalid(_("Download bandwidth"), $this->uid, "/^[0-9]+$/");
195 }
197 if($this->acl_is_writeable("FTPQuotaFiles") && preg_match("/[^0-9]/",$this->FTPQuotaFiles)){
198 $message[]= msgPool::invalid(_("Quota file"), $this->uid, "/^[0-9]+$/");
199 }
200 if($this->acl_is_writeable("FTPQuotaMBytes") && preg_match("/[^0-9]/",$this->FTPQuotaMBytes)){
201 $message[]= msgPool::invalid(_("Quota size"), $this->uid, "/^[0-9]+$/");
202 }
203 if($this->acl_is_writeable("FTPUploadRatio") && preg_match("/[^0-9]/",$this->FTPUploadRatio)){
204 $message[]= msgPool::invalid(_("Upload ratio"), $this->uid, "/^[0-9]+$/");
205 }
206 if($this->acl_is_writeable("FTPDownloadRatio") && preg_match("/[^0-9]/",$this->FTPDownloadRatio)){
207 $message[]= msgPool::invalid(_("Download ratio"), $this->uid, "/^[0-9]+$/");
208 }
209 }
211 return $message;
212 }
215 /* Save to LDAP */
216 function save()
217 {
218 plugin::save();
220 $tmp = $this->plInfo();
221 foreach($tmp['plProvidedAcls'] as $key => $desc){
222 if(!$this->acl_is_writeable($key)){
223 unset($this->attrs[$key]);
224 }
225 }
227 /* Write back to ldap */
228 $ldap= $this->config->get_ldap_link();
229 $ldap->cd($this->dn);
230 $this->cleanup();
231 $ldap->modify ($this->attrs);
233 /* Log last action */
234 if($this->initially_was_account){
235 new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
236 }else{
237 new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
238 }
240 if (!$ldap->success()){
241 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
242 }
244 /* Optionally execute a command after we're done */
245 if ($this->initially_was_account == $this->is_account){
246 if ($this->is_modified){
247 $this->handle_post_events("modify",array("uid" => $this->uid));
248 }
249 } else {
250 $this->handle_post_events("add",array("uid" => $this->uid));
251 }
253 }
256 /* Return plugin informations for acl handling
257 #FIME There possibly some attributes that can be combined to one acl. */
258 static function plInfo()
259 {
260 return (array(
261 "plShortName" => _("Ftp"),
262 "plDescription" => _("Pure ftp account")." ("._("Connectivity addon").")",
263 "plSelfModify" => TRUE,
264 "plDepends" => array("user"),
265 "plPriority" => 22, // Position in tabs
266 "plSection" => array("personal" => _("My account")),
267 "plCategory" => array("users"),
268 "plOptions" => array(),
270 "plProvidedAcls" => array(
271 "FTPQuotaFiles" => _("Quota files"),
272 "FTPUploadRatio" => _("Upload ratio"),
273 "FTPQuotaMBytes" => _("Quota MBytes"),
274 "FTPDownloadRatio" => _("Download ratio"),
275 "FTPUploadBandwidth" => _("Upload bandwith"),
276 "FTPDownloadBandwidth" => _("Download bandwith"),
277 "FTPStatus" => _("Status"))
278 ));
279 }
281 function multiple_save_object()
282 {
283 if (isset($_POST['connectivityTab'])){
284 plugin::multiple_save_object();
285 if(isset($_POST['use_pureftpd'])){
286 $this->multi_boxes[] = "pureftpd";
287 }
288 $this->save_object();
289 }
290 }
292 function get_multi_init_values()
293 {
294 $ret = plugin::get_multi_init_values();
295 $ret['is_account'] = $this->is_account;
296 return($ret);
297 }
299 function init_multiple_support($attrs,$attr)
300 {
301 plugin::init_multiple_support($attrs,$attr);
303 if(isset($attrs['is_account'])){
304 $this->is_account = $attrs['is_account'];
305 }
306 }
308 function get_multi_edit_values()
309 {
310 $ret = plugin::get_multi_edit_values();
311 if(in_array("pureftpd",$this->multi_boxes)){
312 $ret['is_account'] = $this->is_account;
313 }
314 return($ret);
315 }
317 function set_multi_edit_values($values)
318 {
319 plugin::set_multi_edit_values($values);
320 if(isset($values['is_account'])){
321 $this->is_account = $values['is_account'];
322 }
323 }
325 }
327 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
328 ?>