1 <?php
3 /*
4 This code is part of GOsa (https://gosa.gonicus.de)
5 Copyright (C) 2005 Guillaume Delecourt
6 Copyright (C) 2005 Benoit Mortier
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
23 class pptpAccount extends plugin
24 {
25 /* Definitions */
26 var $plHeadline= "PPTP";
27 var $plDescription= "This does something";
29 /* attribute list for save action */
30 var $attributes= array();
31 var $objectclasses= array("pptpServerAccount");
33 var $ReadOnly = false;
34 var $view_logged = FALSE;
35 var $uid ="";
37 function pptpAccount (&$config, $dn= NULL)
38 {
39 plugin::plugin ($config, $dn);
41 /* Setting uid to default */
42 if(isset($this->attrs['uid'][0])){
43 $this->uid = $this->attrs['uid'][0];
44 }
45 }
47 function execute()
48 {
49 /* Call parent execute */
50 // plugin::execute();
52 /* Log view */
53 if($this->is_account && !$this->view_logged){
54 $this->view_logged = TRUE;
55 new log("view","users/".get_class($this),$this->dn);
56 }
58 /* Show tab dialog headers */
59 $display= "";
61 /* Show main page */
62 $smarty= get_smarty();
64 if ($this->is_account){
65 $smarty->assign("pptpState", "checked");
66 } else {
67 $smarty->assign("pptpState", "");
68 $smarty->assign("wstate", "disabled");
69 }
71 if((!$this->ReadOnly) && (($this->is_account && $this->acl_is_removeable()) || (!$this->is_account && $this->acl_is_createable()))) {
72 $smarty->assign('gosapptpACL', "");
73 }else{
74 $smarty->assign('gosapptpACL', " disabled ");
75 }
77 $display.= $smarty->fetch (get_template_path('pptp.tpl', TRUE, dirname(__FILE__)));
78 return ($display);
79 }
81 function remove_from_parent()
82 {
83 if($this->acl_is_removeable()){
84 /* Cancel if there's nothing to do here */
85 if (!$this->initially_was_account){
86 return;
87 }
89 plugin::remove_from_parent();
90 $ldap= $this->config->get_ldap_link();
92 $ldap->cd($this->dn);
93 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
94 $this->attributes, "Save");
95 $this->cleanup();
96 $ldap->modify ($this->attrs);
98 /* Log last action */
99 new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
101 if (!$ldap->success()){
102 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
103 }
105 /* Optionally execute a command after we're done */
106 $this->handle_post_events('remove',array("uid" => $this->uid));
107 }
108 }
111 /* Save data to object */
112 function save_object()
113 {
114 /* Do we need to flip is_account state? */
115 if (isset($_POST['connectivityTab'])){
116 if (isset($_POST['pptp'])){
117 if (!$this->is_account && $_POST['pptp'] == "B"){
118 if($this->acl_is_createable()){
119 $this->is_account= TRUE;
120 }
121 }
122 } else {
123 if($this->acl_is_removeable()){
124 $this->is_account= FALSE;
125 }
126 }
127 }
129 plugin::save_object();
130 if (isset($_POST["pptpStatus"])){
131 $this->pptpStatus = "disabled";
132 } else {
133 $this->pptpStatus = "enabled";
134 }
135 }
138 /* Save to LDAP */
139 function save()
140 {
141 if($this->acl_is_createable()){
142 plugin::save();
144 /* Write back to ldap */
145 $ldap= $this->config->get_ldap_link();
146 $ldap->cd($this->dn);
147 $this->cleanup();
148 $ldap->modify ($this->attrs);
150 /* Log last action */
151 if($this->initially_was_account){
152 new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
153 }else{
154 new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
155 }
157 if (!$ldap->success()){
158 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
159 }
161 /* Optionally execute a command after we're done */
162 if ($this->initially_was_account == $this->is_account){
163 if ($this->is_modified){
164 $this->handle_post_events("modify",array("uid" => $this->uid));
165 }
166 } else {
167 $this->handle_post_events("add",array("uid" => $this->uid));
168 }
169 }
170 }
173 /* Return plugin informations for acl handling */
174 static function plInfo()
175 {
176 return (array(
177 "plShortName" => _("PPTP"),
178 "plDescription" => _("PPTP account")." ("._("Connectivity addon").")",
179 "plSelfModify" => TRUE,
180 "plDepends" => array("user"),
181 "plPriority" => 28, // Position in tabs
182 "plSection" => array("personal" => _("My account")),
183 "plCategory" => array("users"),
184 "plOptions" => array(),
186 "plProvidedAcls" => array()
187 ));
188 }
189 }
191 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
192 ?>