07e1836bebf3781de9cc943cc9e2efe974ba15bc
1 <?php
2 class proxyAccount extends plugin
3 {
4 /* Definitions */
5 var $plHeadline = "Proxy";
6 var $plDescription= "Manage Proxy user settings";
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");
20 var $objectclasses = array("gosaProxyAccount");
21 var $ReadOnly = false;
22 var $uid = "";
23 var $view_logged = FALSE;
24 var $multiple_support = TRUE;
26 /*! \brief Initialize proxy acoount
27 @param $config GOsa configuration object
28 @param $dn Object dn
29 */
30 public function proxyAccount (&$config, $dn= NULL)
31 {
32 plugin::plugin ($config, $dn);
34 /* Setting uid to default */
35 if(isset($this->attrs['uid'][0])){
36 $this->uid = $this->attrs['uid'][0];
37 }
38 }
41 /*! \brief Create html output for this class
42 */
43 public function execute()
44 {
45 /* Call parent execute */
46 plugin::execute();
48 /* Log view */
49 if($this->is_account && !$this->view_logged){
50 $this->view_logged = TRUE;
51 new log("view","users/".get_class($this),$this->dn);
52 }
54 $display= "";
55 $smarty= get_smarty();
57 /* Assign radio boxes */
58 foreach (array("F", "T", "B", "N") as $val){
59 if (preg_match("/".$val."/",$this->gosaProxyAcctFlags)){
60 $smarty->assign("filter$val", "checked");
61 $smarty->assign($val."state", "");
62 } else {
63 $smarty->assign("filter$val", "");
64 if(session::get('js')==1){
65 $smarty->assign($val."state", "disabled");
66 }else{
67 $smarty->assign($val."state", "");
68 }
69 }
70 }
72 /* Assign ACLs */
73 $tmp = $this->plInfo();
74 foreach($tmp['plProvidedAcls'] as $acl => $desc){
75 $smarty->assign($acl."ACL",$this->getacl($acl,$this->ReadOnly));
76 $smarty->assign($acl."_W",$this->acl_is_writeable($acl,$this->ReadOnly));
77 }
79 /* Assign working time */
80 $smarty->assign("starthour" ,floor($this->gosaProxyWorkingStart / 60));
81 $smarty->assign("startminute", ($this->gosaProxyWorkingStart % 60));
82 $smarty->assign("stophour", floor($this->gosaProxyWorkingStop / 60));
83 $smarty->assign("stopminute", ($this->gosaProxyWorkingStop % 60));
84 $hours= array();
85 for($i=0; $i<24; $i++){
86 $hours[]= sprintf("%02d",$i);
87 }
88 $smarty->assign("hours", $hours);
89 $smarty->assign("minutes", array("00","15","30","45"));
91 /* Assign quota values */
92 $smarty->assign("quota_unit", array("k" => _("KB"), "m" => _("MB"), "g" => _("GB")));
93 $smarty->assign("quota_time", array("h" => _("hour"), "d" => _("day"), "w" => _("week"), "m" => _("month")));
94 $smarty->assign("gosaProxyQuotaPeriod", set_post($this->gosaProxyQuotaPeriod));
95 $smarty->assign("quota_size", set_post(preg_replace("/[a-z]$/i", "", $this->gosaProxyQuota)));
96 $smarty->assign("quota_u", set_post(preg_replace("/^[0-9]+/", "", $this->gosaProxyQuota)));
97 if ($this->is_account){
98 $smarty->assign("proxyState", "checked");
99 } else {
100 $smarty->assign("proxyState", "");
101 }
104 /* Handle input grey out and javascript enabled/disable of input fields
105 */
106 if($this->multiple_support_active){
108 /* In Multiple edit, everything is enabled */
109 $changeB = "";
110 $smarty->assign("pstate", "");
111 $smarty->assign("ProxyWorkingStateChange","");
112 }else{
114 /* Depeding on the account status, we disable or
115 * enable all input fields
116 */
117 if (!$this->is_account){
118 $smarty->assign("pstate", "disabled");
119 } else {
120 $smarty->assign("pstate", "");
121 }
123 /* Create JS activation string for everal input fields */
124 $ProxyWorkingStateChange ="\n";
125 if($this->acl_is_writeable("gosaProxyFlagT")){
126 $ProxyWorkingStateChange.= "changeState('startHour'); \n";
127 $ProxyWorkingStateChange.= "changeState('startMinute'); \n";
128 $ProxyWorkingStateChange.= "changeState('stopHour'); \n";
129 $ProxyWorkingStateChange.= "changeState('stopMinute'); \n";
130 }
131 $smarty->assign("ProxyWorkingStateChange",$ProxyWorkingStateChange);
132 $changeB = "";
133 if($this->acl_is_writeable("gosaProxyFlagB")){
134 $changeB =
135 "changeSubselectState('filterB', 'quota_size');
136 changeSubselectState('filterB', 'quota_unit');
137 changeSubselectState('filterB', 'gosaProxyQuotaPeriod');";
138 }
139 }
141 /* Assign filter settings */
142 $smarty->assign("changeB",$changeB);
143 foreach(array("T","B","F") as $attr){
144 if(in_array("filter".$attr,$this->multi_boxes)){
145 $smarty->assign("use_filter".$attr,TRUE);
146 }else{
147 $smarty->assign("use_filter".$attr,FALSE);
148 }
149 }
151 /* check if we are allowed to switch the checkbox.
152 */
153 $smarty->assign('proxyAccountACL', preg_replace("/w/","",$this->getacl("",$this->ReadOnly)));
154 if(($this->acl_is_removeable() && $this->is_account) ||
155 ($this->acl_is_createable() && !$this->is_account)){
156 $smarty->assign('proxyAccountACL', $this->getacl("",$this->ReadOnly));
157 }
159 $smarty->assign("use_proxy",in_array("proxy",$this->multi_boxes));
160 $smarty->assign("multiple_support",$this->multiple_support_active);
161 $display.= $smarty->fetch(get_template_path('proxy.tpl', TRUE, dirname(__FILE__)));
162 return($display);
163 }
166 /*! \brief Removes proxy account from current object
167 */
168 public function remove_from_parent()
169 {
170 if($this->acl_is_removeable() && $this->initially_was_account){
171 plugin::remove_from_parent();
172 $ldap= $this->config->get_ldap_link();
173 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
174 $this->attributes, "Save");
175 $ldap->cd($this->dn);
176 $this->cleanup();
177 $ldap->modify ($this->attrs);
179 /* Log last action */
180 new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
182 if (!$ldap->success()){
183 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
184 }
186 /* Optionally execute a command after we're done */
187 $this->handle_post_events("remove",array("uid" => $this->uid));
188 }
189 }
192 /*! \brief Check given input
193 @return array Returns an array of error messages
194 */
195 public function check()
196 {
197 /* Call common method to give check the hook */
198 $message= plugin::check();
200 /* We've got only one value to check for positive integer or emtpy field */
201 if ($this->is_account && $this->acl_is_writeable("gosaProxyQuota")){
202 if (isset($_POST["quota_size"])){
203 if ($_POST["quota_size"] == "gosaProxyQuota"){
204 $message[]= msgPool::invalid(_("Quota Setting"));
205 }elseif ($_POST["quota_size"] <= 0){
206 $message[]= msgPool::invalid(_("Quota Setting"),get_post("quota_size"),"/^[0-9]/");
207 }
208 }
209 }
210 return $message;
211 }
213 /*! \brief Save POST data to object
214 */
215 public function save_object()
216 {
217 /* Do we need to flip is_account state? */
218 if (isset($_POST['connectivityTab'])){
219 if (isset($_POST['proxy'])){
220 if (!$this->is_account && $_POST['proxy'] == "B"){
221 if($this->acl_is_createable()){
222 $this->is_account= TRUE;
223 }
224 }
225 } else {
226 if($this->acl_is_removeable()){
227 $this->is_account= FALSE;
228 }
229 }
230 }
232 /* Save flag value */
233 if ($this->is_account || $this->multiple_support_active){
235 $flags= "";
236 $acl= "";
237 foreach(array("F", "T", "B") as $key){
238 if($this->acl_is_writeable("gosaProxyFlag".$key)){
240 /* Add acl */
241 if (isset($_POST["filter$key"])){
242 $flags.= $key;
243 }
244 }else{
246 /* Keep all flags that can't be written*/
247 if(preg_match("/".$key."/",$this->gosaProxyAcctFlags)){
248 $flags .=$key;
249 }
250 }
251 }
252 if ("[$flags]" != $this->gosaProxyAcctFlags){
253 $this->is_modified= TRUE;
254 }
255 $this->gosaProxyAcctFlags= "[$flags]";
257 /* Save time values */
258 if ($this->acl_is_writeable("gosaProxyFlagT")){
259 if(isset($_POST['startMinute'])){
260 $old= $this->gosaProxyWorkingStart;
261 $this->gosaProxyWorkingStart= get_post('startHour') * 60 + get_post('startMinute');
262 $this->is_modified= ($old != $this->gosaProxyWorkingStart)?TRUE:$this->is_modified;
263 }
265 if (isset($_POST['stopMinute'])){
266 $old= $this->gosaProxyWorkingStop;
267 $this->gosaProxyWorkingStop = get_post('stopHour') * 60 + get_post('stopMinute');
268 $this->is_modified= ($old != $this->gosaProxyWorkingStop)?TRUE:$this->is_modified;
269 }
270 }
272 /* Save quota values */
273 if ($this->acl_is_writeable("gosaProxyFlagB")){
274 if(isset($_POST["quota_size"]) && isset($_POST["quota_unit"])){
275 $this->gosaProxyQuota= get_post("quota_size").get_post("quota_unit");
276 }
277 }
279 /*Save quota period */
280 if($this->acl_is_writeable("gosaProxyFlagB")){
281 if(isset($_POST["gosaProxyQuotaPeriod"])){
282 $this->gosaProxyQuotaPeriod = get_post("gosaProxyQuotaPeriod");
283 }
284 }
285 }
286 }
289 /*! \brief Save settings to ldap
290 */
291 public function save()
292 {
293 plugin::save();
295 /* Write back to ldap */
296 $ldap= $this->config->get_ldap_link();
297 $ldap->cd($this->dn);
298 $this->cleanup();
299 $ldap->modify ($this->attrs);
301 /* Log last action */
302 if($this->initially_was_account){
303 new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
304 }else{
305 new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
306 }
308 if (!$ldap->success()){
309 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
310 }
312 /* Optionally execute a command after we're done */
313 if ($this->initially_was_account == $this->is_account){
314 if ($this->is_modified){
315 $this->handle_post_events("modify",array("uid" => $this->uid));
316 }
317 } else {
318 $this->handle_post_events("add",array("uid" => $this->uid));
319 }
321 }
324 /*! \brief Static Function returning an ACL information array.
325 @return Array Returns an ACL array
326 */
327 static function plInfo()
328 {
329 return (array(
330 "plShortName" => _("Proxy"),
331 "plDescription" => _("Proxy account")." ("._("Connectivity add-on").")",
332 "plSelfModify" => TRUE,
333 "plDepends" => array("user"),
334 "plPriority" => 21, // Position in tabs
335 "plSection" => array("personal" => _("My account")),
336 "plCategory" => array("users"),
337 "plOptions" => array(),
338 "plRequirements"=> array(
339 'ldapSchema' => array('gosaProxyAccount' => '>=2.7'),
340 'onFailureDisablePlugin' => array(get_class())
341 ),
343 "plProvidedAcls" => array(
344 "gosaProxyQuota" => _("Quota"),
345 "gosaProxyFlagF" => _("Filter unwanted content"),
346 "gosaProxyFlagT" => _("Limit proxy access"),
347 "gosaProxyFlagB" => _("Restrict proxy usage by quota"))
348 ));
349 }
352 /*! \brief Save html POSTs in multiple edit.
353 */
354 public function multiple_save_object()
355 {
356 if (isset($_POST['connectivityTab'])){
357 plugin::multiple_save_object();
358 if(isset($_POST['use_proxy'])){
359 $this->multi_boxes[] = "proxy";
360 }
361 foreach(array("T","B","F") as $attr){
362 if(isset($_POST["use_filter".$attr])){
363 $this->multi_boxes[] = "filter".$attr;
364 }
365 }
366 $this->save_object();
367 }
368 }
371 /*! \brief Returns all modified values. \
372 All selected an modified values will be returned \
373 in an array.
374 @return array Returns an array containing all attribute modifications
375 */
376 public function get_multi_edit_values()
377 {
378 $ret = plugin::get_multi_edit_values();
379 if(in_array("proxy",$this->multi_boxes)){
380 $ret['is_account'] = $this->is_account;
381 }
383 if(in_array("filterT",$this->multi_boxes)){
384 $ret['gosaProxyWorkingStart'] = $this->gosaProxyWorkingStart;
385 $ret['gosaProxyWorkingStop'] = $this->gosaProxyWorkingStop;
386 }
387 if(in_array("filterB",$this->multi_boxes)){
388 $ret['gosaProxyQuota'] = $this->gosaProxyQuota;
389 $ret['gosaProxyQuotaPeriod'] = $this->gosaProxyQuotaPeriod;
390 }
392 foreach(array("B","T","F") as $attr){
393 $name = "filter".$attr;
394 if(in_array($name,$this->multi_boxes)){
395 $ret[$name] = preg_match("/".$attr."/",$this->gosaProxyAcctFlags);
396 }
397 }
399 return($ret);
400 }
403 /*! \brief Sets modified attributes in mutliple edit. \
404 All collected values from "get_multi_edit_values()" \
405 will be applied to this plugin.
406 @param array An array containing modified attributes returned by get_multi_edit_values();
407 */
408 public function set_multi_edit_values($values)
409 {
410 plugin::set_multi_edit_values($values);
411 if(isset($values['is_account'])){
412 $this->is_account = $values['is_account'];
413 }
414 foreach(array("B","T","F") as $attr){
415 $name = "filter".$attr;
416 if(isset($values[$name])){
417 if($values[$name] && !preg_match("/".$attr."/",$this->gosaProxyAcctFlags)){
418 $this->gosaProxyAcctFlags = preg_replace("/\]/",$attr."]",$this->gosaProxyAcctFlags);
419 }elseif(!$values[$name] && preg_match("/".$attr."/",$this->gosaProxyAcctFlags)){
420 $this->gosaProxyAcctFlags = preg_replace("/".$attr."/","",$this->gosaProxyAcctFlags);
421 }
422 }
423 }
424 }
427 /*! \brief Initialize multiple edit ui for this plugin. \
428 This function sets plugin defaults in multiple edit.
429 @param array Attributes used in all object
430 @param array All used attributes.
431 */
432 public function init_multiple_support($attrs,$all)
433 {
434 plugin::init_multiple_support($attrs,$all);
435 if(isset($attrs['objectClass']) && in_array("gosaProxyAccount",$attrs['objectClass'])){
436 $this->is_account = TRUE;
437 }
438 }
439 }
441 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
442 ?>