1 <?php
2 class proxyAccount extends plugin
3 {
4 /* Definitions */
5 var $plHeadline= "Proxy";
6 var $plDescription= "This does something";
8 /* Proxy attributes */
9 var $gosaProxyAcctFlags= "[N ]";
10 var $gosaProxyID= "";
11 var $gosaProxyWorkingStart= 420;
12 var $gosaProxyWorkingStop= 1020;
13 var $gosaProxyQuota= "5g";
14 var $gosaProxyQuotaPeriod= "m";
16 /* attribute list for save action */
17 var $attributes= array("gosaProxyID", "gosaProxyAcctFlags", "gosaProxyWorkingStart",
18 "gosaProxyWorkingStop", "gosaProxyQuota", "gosaProxyQuotaPeriod");
19 var $objectclasses= array("gosaProxyAccount");
21 function proxyAccount ($config, $dn= NULL)
22 {
23 plugin::plugin ($config, $dn);
24 }
26 function execute()
27 {
28 /* Call parent execute */
29 // plugin::execute();
31 $display= "";
33 /* Prepare templating */
34 $smarty= get_smarty();
37 if(($this->is_account && $this->acl_is_removeable()) || (!$this->is_account && $this->acl_is_createable())) {
38 $smarty->assign('proxyAccountACL', "");
39 }else{
40 $smarty->assign('proxyAccountACL', " disabled ");
41 }
43 /* Assign radio boxes */
44 foreach (array("F", "T", "B", "N") as $val){
46 if (is_integer(strpos($this->gosaProxyAcctFlags, "$val"))) {
47 $smarty->assign("filter$val", "checked");
49 /* Add state variables for on-the-fly state-changing of checkboxes */
50 $smarty->assign($val."state", "");
52 } else {
53 $smarty->assign("filter$val", "");
55 /* Same as above */
56 if($_SESSION['js']==1){
57 $smarty->assign($val."state", "disabled");
58 }else{
59 $smarty->assign($val."state", "");
60 }
61 }
62 }
64 $tmp = $this->plInfo();
65 foreach($tmp['plProvidedAcls'] as $acl => $desc){
66 $smarty->assign($acl."ACL",$this->getacl($acl));
67 $smarty->assign($acl."_W",$this->acl_is_writeable($acl));
68 }
70 /* Assign working time */
71 $smarty->assign("starthour", (int)($this->gosaProxyWorkingStart / 60));
72 $smarty->assign("startminute", (int)($this->gosaProxyWorkingStart % 60));
73 $smarty->assign("stophour", (int)($this->gosaProxyWorkingStop / 60));
74 $smarty->assign("stopminute", (int)($this->gosaProxyWorkingStop % 60));
75 $hours= array();
76 for($i=0; $i<24; $i++){
77 $hours[]= sprintf("%02d",$i);
78 }
79 $smarty->assign("hours", $hours);
80 $smarty->assign("minutes", array("00","15","30","45"));
82 /* Assign quota values */
83 $smarty->assign("quota_unit", array("k" => _("KB"), "m" => _("MB"), "g" => _("GB")));
84 $smarty->assign("quota_time", array("h" => _("hour"), "d" => _("day"), "w" => _("week"), "m" => _("month")));
85 $smarty->assign("gosaProxyQuotaPeriod", $this->gosaProxyQuotaPeriod);
86 $smarty->assign("quota_size", preg_replace("/[a-z]$/i", "", $this->gosaProxyQuota));
87 $smarty->assign("quota_u", preg_replace("/^[0-9]+/", "", $this->gosaProxyQuota));
88 if ($this->is_account){
89 $smarty->assign("proxyState", "checked");
90 } else {
91 $smarty->assign("proxyState", "");
92 }
94 /* Prepare correct state */
95 if (!$this->is_account){
96 $smarty->assign("pstate", "disabled");
97 } else {
98 $smarty->assign("pstate", "");
99 }
101 $changeA = "";
103 if($this->acl_is_writeable("gosaProxyFlag_F")){
104 $changeA .="changeState('filterF');\n";
105 }
106 $ProxyWorkingStateChange ="\n";
107 if($this->acl_is_writeable("gosaProxyWorkingTime")){
108 $changeA .= "changeState('filterT');\n";
109 $ProxyWorkingStateChange.= "changeState('startHour'); \n";
110 $ProxyWorkingStateChange.= "changeState('startMinute'); \n";
111 $ProxyWorkingStateChange.= "changeState('stopHour'); \n";
112 $ProxyWorkingStateChange.= "changeState('stopMinute'); \n";
113 }
115 $changeA .= $ProxyWorkingStateChange;
117 $smarty->assign("ProxyWorkingStateChange",$ProxyWorkingStateChange);
119 $changeB = "";
120 if($this->acl_is_writeable("gosaProxyQuota")){
121 $changeA .= "changeState('filterB');";
122 $changeB =
123 "changeSubselectState('filterB', 'quota_size');
124 changeSubselectState('filterB', 'quota_unit');
125 changeSubselectState('filterB', 'gosaProxyQuotaPeriod');";
126 }
128 $smarty->assign("changeB",$changeB);
129 $smarty->assign("changeA",$changeA);
131 /* Show main page */
132 $display.= $smarty->fetch(get_template_path('proxy.tpl', TRUE, dirname(__FILE__)));
133 return($display);
134 }
136 function remove_from_parent()
137 {
138 if($this->acl_is_removeable()){
140 plugin::remove_from_parent();
142 $ldap= $this->config->get_ldap_link();
143 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
144 $this->attributes, "Save");
145 $ldap->cd($this->dn);
146 $this->cleanup();
147 $ldap->modify ($this->attrs);
149 show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/proxy account with dn '%s' failed."),$this->dn));
151 /* Optionally execute a command after we're done */
152 $this->handle_post_events("remove");
153 }
154 }
156 /* Check values */
157 function check()
158 {
159 /* Call common method to give check the hook */
160 $message= plugin::check();
162 /* We've got only one value to check for positive integer or emtpy field */
163 if ($this->is_account){
164 if($this->acl_is_writeable("gosaProxyQuota")){
165 if (isset($_POST["quota_size"])){
166 if ($_POST["quota_size"] == "gosaProxyQuota"){
167 $message[]= _("Numerical value for Quota Setting is empty.");
168 }elseif ($_POST["quota_size"] <= 0){
169 $message[]= _("Numerical value for Quota Setting is not valid.");
170 }
171 }
172 }
173 }
175 return $message;
176 }
178 /* Save data to object */
179 function save_object()
180 {
181 /* Do we need to flip is_account state? */
182 if ($this->parent != NULL){
183 if (isset($_POST['connectivityTab'])){
184 if (isset($_POST['proxy'])){
185 if (!$this->is_account && $_POST['proxy'] == "B"){
186 if($this->acl_is_createable()){
187 $this->is_account= TRUE;
188 }
189 }
190 } else {
191 if($this->acl_is_removeable()){
192 $this->is_account= FALSE;
193 }
194 }
195 }
196 }
198 /* Save flag value */
199 if ($this->is_account){
202 $flags= "";
203 $acl= "";
204 foreach(array("F", "T", "B") as $key){
205 if($this->acl_is_writeable("gosaProxyFlag".$key)){
207 /* Add acl */
208 if (isset($_POST["filter$key"])){
209 $flags.= $key;
210 }
211 }else{
213 /* Keep all flags that can't be written*/
214 if(preg_match("/".$key."/",$this->gosaProxyAcctFlags)){
215 $flags .=$key;
216 }
217 }
218 }
219 if ("[$flags]" != $this->gosaProxyAcctFlags){
220 $this->is_modified= TRUE;
221 }
222 $this->gosaProxyAcctFlags= "[$flags]";
224 /* Save time values */
225 if ($this->acl_is_writeable("gosaProxyWorkingTime")){
226 if(isset($_POST['startMinute'])){
227 $old= $this->gosaProxyWorkingStart;
228 $this->gosaProxyWorkingStart= $_POST["startHour"] * 60 + $_POST["startMinute"];
229 $this->is_modified= ($old != $this->gosaProxyWorkingStart)?TRUE:$this->is_modified;
230 }
232 if (isset($_POST['stopMinute'])){
233 $old= $this->gosaProxyWorkingStop;
234 $this->gosaProxyWorkingStop = $_POST["stopHour"] * 60 + $_POST["stopMinute"];
235 $this->is_modified= ($old != $this->gosaProxyWorkingStop)?TRUE:$this->is_modified;
236 }
237 }
239 /* Save quota values */
240 if ($this->acl_is_writeable("gosaProxyQuota")){
241 if(isset($_POST["quota_size"]) && isset($_POST["quota_unit"])){
242 $this->gosaProxyQuota= $_POST["quota_size"].$_POST["quota_unit"];
243 }
244 }
246 /*Save quota period */
247 if($this->acl_is_writeable("gosaProxyQuotaPeriod")){
248 if(isset($_POST["gosaProxyQuotaPeriod"])){
249 $this->gosaProxyQuotaPeriod = $_POST["gosaProxyQuotaPeriod"];
250 }
251 }
252 }
253 }
256 /* Save to LDAP */
257 function save()
258 {
259 plugin::save();
261 /* Write back to ldap */
262 $ldap= $this->config->get_ldap_link();
263 $ldap->cd($this->dn);
264 $this->cleanup();
265 $ldap->modify ($this->attrs);
267 show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/proxy account with dn '%s' failed."),$this->dn));
269 /* Optionally execute a command after we're done */
270 if ($this->initially_was_account == $this->is_account){
271 if ($this->is_modified){
272 $this->handle_post_events("mofify");
273 }
274 } else {
275 $this->handle_post_events("add");
276 }
278 }
280 /* Return plugin informations for acl handling
281 #FIME There possibly some attributes that can be combined to one acl. */
282 function plInfo()
283 {
284 return (array(
285 "plShortName" => _("Proxy"),
286 "plDescription" => _("Proxy account"),
287 "plSelfModify" => TRUE,
288 "plDepends" => array("user"),
289 "plPriority" => 7, // Position in tabs
290 "plSection" => "personal", // This belongs to personal
291 "plCategory" => array("users"),
292 "plOptions" => array(),
294 "plProvidedAcls" => array(
295 "gosaProxyID" => _("gosaProxyID"),
297 "gosaProxyFlagF" => _("Filter unwanted content"),
298 "gosaProxyFlagT" => _("Limit proxy access"),
299 "gosaProxyFlagB" => _("Restrict proxy usage by quota"),
301 "gosaProxyWorkingTime" => _("Limit proxy access"),
302 "gosaProxyQuota" => _("Limit quota"),
303 "gosaProxyQuotaPeriod" => _("Quota limit period"))
304 ));
305 }
306 }
308 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
309 ?>