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");
20 var $objectclasses= array("gosaProxyAccount");
21 var $ReadOnly = false;
23 var $uid = "";
25 function proxyAccount ($config, $dn= NULL)
26 {
27 plugin::plugin ($config, $dn);
29 /* Setting uid to default */
30 if(isset($this->attrs['uid'][0])){
31 $this->uid = $this->attrs['uid'][0];
32 }
34 /* Log view */
35 if($this->is_account){
36 @log::log("view","users/".get_class($this),$this->dn);
37 }
38 }
40 function execute()
41 {
42 /* Call parent execute */
43 plugin::execute();
45 $display= "";
47 /* Prepare templating */
48 $smarty= get_smarty();
50 $smarty->assign('proxyAccountACL', " disabled ");
52 if((!$this->ReadOnly)&& (($this->is_account && $this->acl_is_removeable()) || (!$this->is_account && $this->acl_is_createable()))){
53 $smarty->assign('proxyAccountACL', "");
54 }
56 /* Assign radio boxes */
57 foreach (array("F", "T", "B", "N") as $val){
59 if (is_integer(strpos($this->gosaProxyAcctFlags, "$val"))) {
60 $smarty->assign("filter$val", "checked");
62 /* Add state variables for on-the-fly state-changing of checkboxes */
63 $smarty->assign($val."state", "");
65 } else {
66 $smarty->assign("filter$val", "");
68 /* Same as above */
69 if($_SESSION['js']==1){
70 $smarty->assign($val."state", "disabled");
71 }else{
72 $smarty->assign($val."state", "");
73 }
74 }
75 }
77 $tmp = $this->plInfo();
78 foreach($tmp['plProvidedAcls'] as $acl => $desc){
79 $smarty->assign($acl."ACL",$this->getacl($acl,$this->ReadOnly));
80 $smarty->assign($acl."_W",$this->acl_is_writeable($acl,$this->ReadOnly));
81 }
83 /* Assign working time */
84 $smarty->assign("starthour", (int)($this->gosaProxyWorkingStart / 60));
85 $smarty->assign("startminute", (int)($this->gosaProxyWorkingStart % 60));
86 $smarty->assign("stophour", (int)($this->gosaProxyWorkingStop / 60));
87 $smarty->assign("stopminute", (int)($this->gosaProxyWorkingStop % 60));
88 $hours= array();
89 for($i=0; $i<24; $i++){
90 $hours[]= sprintf("%02d",$i);
91 }
92 $smarty->assign("hours", $hours);
93 $smarty->assign("minutes", array("00","15","30","45"));
95 /* Assign quota values */
96 $smarty->assign("quota_unit", array("k" => _("KB"), "m" => _("MB"), "g" => _("GB")));
97 $smarty->assign("quota_time", array("h" => _("hour"), "d" => _("day"), "w" => _("week"), "m" => _("month")));
98 $smarty->assign("gosaProxyQuotaPeriod", $this->gosaProxyQuotaPeriod);
99 $smarty->assign("quota_size", preg_replace("/[a-z]$/i", "", $this->gosaProxyQuota));
100 $smarty->assign("quota_u", preg_replace("/^[0-9]+/", "", $this->gosaProxyQuota));
101 if ($this->is_account){
102 $smarty->assign("proxyState", "checked");
103 } else {
104 $smarty->assign("proxyState", "");
105 }
107 /* Prepare correct state */
108 if (!$this->is_account){
109 $smarty->assign("pstate", "disabled");
110 } else {
111 $smarty->assign("pstate", "");
112 }
114 $changeA = "";
116 $ProxyWorkingStateChange ="\n";
117 if($this->acl_is_writeable("gosaProxyFlagT")){
118 $changeA .= "changeState('filterT');\n";
120 $ProxyWorkingStateChange.= "changeState('startHour'); \n";
121 $ProxyWorkingStateChange.= "changeState('startMinute'); \n";
122 $ProxyWorkingStateChange.= "changeState('stopHour'); \n";
123 $ProxyWorkingStateChange.= "changeState('stopMinute'); \n";
124 }
126 if(preg_match("/F/",$this->gosaProxyAcctFlags)){
127 $changeA .= $ProxyWorkingStateChange;
128 }
130 $smarty->assign("ProxyWorkingStateChange",$ProxyWorkingStateChange);
132 $changeB = "";
133 if($this->acl_is_writeable("gosaProxyFlagB")){
134 $changeA .= "changeState('filterB');";
135 $changeB =
136 "changeSubselectState('filterB', 'quota_size');
137 changeSubselectState('filterB', 'quota_unit');
138 changeSubselectState('filterB', 'gosaProxyQuotaPeriod');";
139 }
141 $smarty->assign("changeB",$changeB);
142 $smarty->assign("changeA",$changeA);
144 /* Show main page */
145 $display.= $smarty->fetch(get_template_path('proxy.tpl', TRUE, dirname(__FILE__)));
146 return($display);
147 }
149 function remove_from_parent()
150 {
151 if($this->acl_is_removeable() && $this->initially_was_account){
153 plugin::remove_from_parent();
155 $ldap= $this->config->get_ldap_link();
156 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
157 $this->attributes, "Save");
158 $ldap->cd($this->dn);
159 $this->cleanup();
160 $ldap->modify ($this->attrs);
162 /* Log last action */
163 @log::log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
165 show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/proxy account with dn '%s' failed."),$this->dn));
167 /* Optionally execute a command after we're done */
168 $this->handle_post_events("remove",array("uid" => $this->uid));
169 }
170 }
172 /* Check values */
173 function check()
174 {
175 /* Call common method to give check the hook */
176 $message= plugin::check();
178 /* We've got only one value to check for positive integer or emtpy field */
179 if ($this->is_account){
180 if($this->acl_is_writeable("gosaProxyQuota")){
181 if (isset($_POST["quota_size"])){
182 if ($_POST["quota_size"] == "gosaProxyQuota"){
183 $message[]= _("Numerical value for Quota Setting is empty.");
184 }elseif ($_POST["quota_size"] <= 0){
185 $message[]= _("Numerical value for Quota Setting is not valid.");
186 }
187 }
188 }
189 }
191 return $message;
192 }
194 /* Save data to object */
195 function save_object()
196 {
197 /* Do we need to flip is_account state? */
198 if (isset($_POST['connectivityTab'])){
199 if (isset($_POST['proxy'])){
200 if (!$this->is_account && $_POST['proxy'] == "B"){
201 if($this->acl_is_createable()){
202 $this->is_account= TRUE;
203 }
204 }
205 } else {
206 if($this->acl_is_removeable()){
207 $this->is_account= FALSE;
208 }
209 }
210 }
212 /* Save flag value */
213 if ($this->is_account){
215 $flags= "";
216 $acl= "";
217 foreach(array("F", "T", "B") as $key){
218 if($this->acl_is_writeable("gosaProxyFlag".$key)){
220 /* Add acl */
221 if (isset($_POST["filter$key"])){
222 $flags.= $key;
223 }
224 }else{
226 /* Keep all flags that can't be written*/
227 if(preg_match("/".$key."/",$this->gosaProxyAcctFlags)){
228 $flags .=$key;
229 }
230 }
231 }
232 if ("[$flags]" != $this->gosaProxyAcctFlags){
233 $this->is_modified= TRUE;
234 }
235 $this->gosaProxyAcctFlags= "[$flags]";
237 /* Save time values */
238 if ($this->acl_is_writeable("gosaProxyFlagT")){
239 if(isset($_POST['startMinute'])){
240 $old= $this->gosaProxyWorkingStart;
241 $this->gosaProxyWorkingStart= $_POST["startHour"] * 60 + $_POST["startMinute"];
242 $this->is_modified= ($old != $this->gosaProxyWorkingStart)?TRUE:$this->is_modified;
243 }
245 if (isset($_POST['stopMinute'])){
246 $old= $this->gosaProxyWorkingStop;
247 $this->gosaProxyWorkingStop = $_POST["stopHour"] * 60 + $_POST["stopMinute"];
248 $this->is_modified= ($old != $this->gosaProxyWorkingStop)?TRUE:$this->is_modified;
249 }
250 }
252 /* Save quota values */
253 if ($this->acl_is_writeable("gosaProxyFlagB")){
254 if(isset($_POST["quota_size"]) && isset($_POST["quota_unit"])){
255 $this->gosaProxyQuota= $_POST["quota_size"].$_POST["quota_unit"];
256 }
257 }
259 /*Save quota period */
260 if($this->acl_is_writeable("gosaProxyFlagB")){
261 if(isset($_POST["gosaProxyQuotaPeriod"])){
262 $this->gosaProxyQuotaPeriod = $_POST["gosaProxyQuotaPeriod"];
263 }
264 }
265 }
266 }
269 /* Save to LDAP */
270 function save()
271 {
272 plugin::save();
274 /* Write back to ldap */
275 $ldap= $this->config->get_ldap_link();
276 $ldap->cd($this->dn);
277 $this->cleanup();
278 $ldap->modify ($this->attrs);
280 /* Log last action */
281 if($this->initially_was_account){
282 @log::log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
283 }else{
284 @log::log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
285 }
287 show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/proxy account with dn '%s' failed."),$this->dn));
289 /* Optionally execute a command after we're done */
290 if ($this->initially_was_account == $this->is_account){
291 if ($this->is_modified){
292 $this->handle_post_events("modify",array("uid" => $this->uid));
293 }
294 } else {
295 $this->handle_post_events("add",array("uid" => $this->uid));
296 }
298 }
300 /* Return plugin informations for acl handling
301 #FIME There possibly some attributes that can be combined to one acl. */
302 function plInfo()
303 {
304 return (array(
305 "plShortName" => _("Proxy"),
306 "plDescription" => _("Proxy account")." : <u>"._("Connectivity addon")."</u>",
307 "plSelfModify" => TRUE,
308 "plDepends" => array("user"),
309 "plPriority" => 21, // Position in tabs
310 "plSection" => array("personal" => _("My account")),
311 "plCategory" => array("users"),
312 "plOptions" => array(),
314 "plProvidedAcls" => array(
315 "gosaProxyFlagF" => _("Filter unwanted content"),
316 "gosaProxyFlagT" => _("Limit proxy access"),
317 "gosaProxyFlagB" => _("Restrict proxy usage by quota"))
318 ));
319 }
320 }
322 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
323 ?>