Code

Added some acls to connectivity addons
[gosa.git] / plugins / personal / connectivity / class_pureftpdAccount.inc
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         /* Call parent execute */
38 //      plugin::execute();
40     /* Show tab dialog headers */
41     $display= "";
43     /* Show main page */
44     $smarty= get_smarty();
46     /* Load attributes */
47     foreach($this->attributes as $val){
48       $smarty->assign("$val", $this->$val);
49       $smarty->assign($val."ACL", chkacl($this->acl, "$val"));
50     }
51     $smarty->assign("fstate", "");
52     if ($this->is_account){
53       $smarty->assign("pureftpdState", "checked");
54       $smarty->assign("fstate", "");
55     } else {
56       $smarty->assign("pureftpdState", "");
57       if($_SESSION['js']==1){
58         if($this->acl!="#none#")
59         $smarty->assign("fstate", "disabled");
60       }else{
61         $smarty->assign("fstate", "");
62       }
63     }
64     $smarty->assign("use_FTPStatus", ($this->FTPStatus == "disabled") ? "checked" : "");
66     $smarty->assign("pureftpdACL", chkacl($this->acl, 'pureftpd'));
68     $changeState = "";
69     foreach($this->attributes as $attr){
70       $smarty->assign($attr."ACL",chkacl($this->acl,$attr));
71       if(chkacl($this->acl,$attr)==""){
72         $changeState .= "changeState('".$attr."');\n";
73       }
74     }
75     $smarty->assign("changeState",$changeState);
76     $display.= $smarty->fetch (get_template_path('pureftpd.tpl', TRUE, dirname(__FILE__)));
77     return ($display);
78   }
80   function remove_from_parent()
81   {
82     /* Cancel if there's nothing to do here */
83     if (!$this->initially_was_account){
84       return;
85     }
87     plugin::remove_from_parent();
88     $ldap= $this->config->get_ldap_link();
90     $ldap->cd($this->dn);
91     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
92         $this->attributes, "Save");
93     $this->cleanup();
94     $ldap->modify ($this->attrs); 
96     show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/pureftpd account with dn '%s' failed."),$this->dn));
98     /* Optionally execute a command after we're done */
99     $this->handle_post_events('remove');
100   }
103   /* Save data to object */
104   function save_object()
105   {
106     /* Do we need to flip is_account state? */
107     if (isset($_POST['connectivityTab'])){
108       if (isset($_POST['pureftpd'])){
109         if (!$this->is_account && $_POST['pureftpd'] == "B"){
110           $this->is_account= TRUE;
111         }
112       } else {
113         $this->is_account= FALSE;
114       }
115     }
117     plugin::save_object();
119     $old= $this->FTPStatus;
120     if (isset($_POST["FTPStatus"])){
121       $this->FTPStatus = "disabled";
122     } else {
123       $this->FTPStatus = "enabled";
124     }
125     $this->is_modified= ($old != $this->FTPStatus)?TRUE:$this->is_modified;
126   }
129   /* Check values */
130   function check()
131   {
132     /* Call common method to give check the hook */
133     $message= plugin::check();
135     /* Check for positive integer values */
136     if ($this->is_account){
137       if ((!is_id($this->FTPUploadBandwidth))&&(chkacl($this->acl,"FTPUploadBandwidth")=="")){
138         $message[]= _("Value specified as 'Upload bandwidth' is not valid.");
139       }
140       if ((!is_id($this->FTPDownloadBandwidth))&&(chkacl($this->acl,"FTPDownloadBandwidth")=="")){
141         $message[]= _("Value specified as 'Download bandwidth' is not valid.");
142       }
143       if ((!is_id($this->FTPQuotaFiles))&&(chkacl($this->acl,"FTPQuotaFiles")=="")){
144         $message[]= _("Value specified as 'Files' is not valid.");
145       }
146       if ((!is_id($this->FTPQuotaMBytes))&&(chkacl($this->acl,"FTPQuotaMBytes")=="")){
147         $message[]= _("Value specified as 'Size' is not valid.");
148       }
149       if ((!is_id($this->FTPUploadRatio) || !is_id($this->FTPDownloadRatio))&&(chkacl($this->acl,"FTPUploadRatio")=="")&&(chkacl($this->acl,"FTPDownloadRatio")=="")){
150         $message[]= _("Value specified as 'Ratio' is not valid.");
151       }
152     }
154     return $message;
155   }
158   /* Save to LDAP */
159   function save()
160   {
161     plugin::save();
163     foreach($this->attributes as $attr){
164       if(chkacl($this->acl,$attr)!=""){
165         unset($this->attrs[$attr]);
166       }
167     }
169     /* Write back to ldap */
170     $ldap= $this->config->get_ldap_link();
171     $ldap->cd($this->dn);
172     $this->cleanup();
173     $ldap->modify ($this->attrs); 
175     show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/pureftpd account with dn '%s' failed."),$this->dn));
177     /* Optionally execute a command after we're done */
178     if ($this->initially_was_account == $this->is_account){
179       if ($this->is_modified){
180         $this->handle_post_events("mofify");
181       }
182     } else {
183       $this->handle_post_events("add");
184     }
186   }
189   function plInfo()
190   {
192     # FIXME We should combine some of the attributes liste below..
193     return (array(  "plDescription"   => _("Intranet account settings"),
194           "plSelfModify"    => TRUE,
195           "plDepends"       => array("objectClass" => "gosaAccount"),
197           "FTPQuotaFiles"         => _("Quota files"),
198           "FTPUploadRatio"        => _("Upload ratio"),
199           "FTPQuotaMBytes"        => _("Quota MBytes"),
200           "FTPDownloadRatio"      => _("Download ratio"),
201           "FTPUploadBandwidth"    => _("Upload bandwith"),
202           "FTPDownloadBandwidth"  => _("Download bandwith"),
203           "FTPStatus"             => _("Status")));
204   }
208 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
209 ?>