1 <?php
3 class goNtpServer extends plugin{
5 var $cli_summary = "This pluign is used within the ServerService Pluign \nand indicates that this server supports NTP service.";
6 var $cli_description = "Some longer text\nfor help";
7 var $cli_parameters = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
9 /* This plugin only writes its objectClass */
10 var $objectclasses = array("goNtpServer");
11 var $attributes = array("goTimeSource");
12 var $StatusFlag = "goNtpServerStatus";
14 /* This class can't be assigned twice so it conflicts with itsself */
15 var $conflicts = array("goNtpServer");
17 var $DisplayName = "";
18 var $dn = NULL;
19 var $goTimeSource = array();
20 var $goNtpServerStatus= "";
21 var $acl;
22 var $cn = "";
24 function goNtpServer($config,$dn)
25 {
26 plugin::plugin($config,$dn);
27 $this->DisplayName = _("Time service");
29 /* Load arrays */
30 $tmp = array();
31 if (isset($this->attrs['goTimeSource'])){
32 for ($i= 0; $i<$this->attrs['goTimeSource']['count']; $i++){
33 $tmp[$this->attrs['goTimeSource'][$i]]= $this->attrs['goTimeSource'][$i];
34 }
35 }
36 $this->goTimeSource= $tmp;
37 }
40 function execute()
41 {
42 $smarty = get_smarty();
44 /* Here we add a new entry */
45 if(isset($_POST['NewNTPAdd']) && $_POST['NewNTPExport'] != "") {
46 $this->goTimeSource[$_POST['NewNTPExport']]= $_POST['NewNTPExport'];
47 asort($this->goTimeSource);
48 }
50 /* Deleting an Entry, is a bit more complicated than adding one*/
51 if((isset($_POST['DelNTPEnt'])) && (isset($_POST['goTimeSource']))) {
52 foreach ($_POST['goTimeSource'] as $entry){
53 if (isset($this->goTimeSource[$entry])){
54 unset($this->goTimeSource[$entry]);
55 }
56 }
57 }
59 $smarty->assign("goNtpServerACL",chkacl($this->acl,"goNtpServer")) ;
60 $smarty->assign("goTimeSource" , $this->goTimeSource);
61 return($smarty->fetch(get_template_path("goNtpServer.tpl",TRUE,dirname(__FILE__))));
62 }
65 function getListEntry()
66 {
67 $this->updateStatusState();
68 $flag = $this->StatusFlag;
69 $fields['Status'] = $this->$flag;
70 $fields['Message'] = _("NTP service");
71 $fields['AllowStart'] = true;
72 $fields['AllowStop'] = true;
73 $fields['AllowRestart'] = true;
74 $fields['AllowRemove']= true;
75 $fields['AllowEdit'] = true;
76 return($fields);
77 }
80 function remove_from_parent()
81 {
82 plugin::remove_from_parent();
84 /* Remove status flag, it is not a memeber of
85 this->attributes, so ensure that it is deleted too */
86 if(!empty($this->StatusFlag)){
87 $this->attrs[$this->StatusFlag] = array();
88 }
90 /* Check if this is a new entry ... add/modify */
91 $ldap = $this->config->get_ldap_link();
92 $ldap->cat($this->dn,array("objectClass"));
93 if($ldap->count()){
94 $ldap->cd($this->dn);
95 $ldap->modify($this->attrs);
96 }else{
97 $ldap->cd($this->dn);
98 $ldap->add($this->attrs);
99 }
100 show_ldap_error($ldap->get_error());
101 $this->handle_post_events("remove");
102 }
105 function save()
106 {
107 plugin::save();
108 $this->attrs['goTimeSource'] =array();
109 foreach($this->goTimeSource as $entry){
110 $this->attrs['goTimeSource'][] = $entry;
111 }
112 /* Check if this is a new entry ... add/modify */
113 $ldap = $this->config->get_ldap_link();
114 $ldap->cat($this->dn,array("objectClass"));
115 if($ldap->count()){
116 $ldap->cd($this->dn);
117 $ldap->modify($this->attrs);
118 }else{
119 $ldap->cd($this->dn);
120 $ldap->add($this->attrs);
121 }
122 show_ldap_error($ldap->get_error());
123 if($this->initially_was_account){
124 $this->handle_post_events("modify");
125 }else{
126 $this->handle_post_events("add");
127 }
128 }
131 /* Directly save new status flag */
132 function setStatus($value)
133 {
134 if($value == "none") return;
135 if(!$this->initially_was_account) return;
136 $ldap = $this->config->get_ldap_link();
137 $ldap->cd($this->dn);
138 $ldap->cat($this->dn,array("objectClass"));
139 if($ldap->count()){
141 $tmp = $ldap->fetch();
142 for($i = 0; $i < $tmp['objectClass']['count']; $i ++){
143 $attrs['objectClass'][] = $tmp['objectClass'][$i];
144 }
145 $flag = $this->StatusFlag;
146 $attrs[$flag] = $value;
147 $this->$flag = $value;
148 $ldap->modify($attrs);
149 show_ldap_error($ldap->get_error());
150 $this->action_hook();
151 }
152 }
154 function action_hook($add_attrs= array())
155 {
156 /* Find postcreate entries for this class */
157 $command= search_config($this->config->data['MENU'], get_class($this), "ACTION_HOOK");
158 if ($command == "" && isset($this->config->data['TABS'])){
159 $command= search_config($this->config->data['TABS'], get_class($this), "ACTION_HOOK");
160 }
161 if ($command != ""){
162 /* Walk through attribute list */
163 foreach ($this->attributes as $attr){
164 if (!is_array($this->$attr)){
165 $command= preg_replace("/%$attr/", $this->$attr, $command);
166 }
167 }
168 $command= preg_replace("/%dn/", $this->dn, $command);
169 /* Additional attributes */
170 foreach ($add_attrs as $name => $value){
171 $command= preg_replace("/%$name/", $value, $command);
172 }
174 /* If there are still some %.. in our command, try to fill these with some other class vars */
175 if(preg_match("/%/",$command)){
176 $attrs = get_object_vars($this);
177 foreach($attrs as $name => $value){
178 if(!is_string($value)) continue;
179 $command= preg_replace("/%$name/", $value, $command);
180 }
181 }
183 if (check_command($command)){
184 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
185 $command, "Execute");
187 exec($command);
188 } else {
189 $message= sprintf(_("Command '%s', specified as ACTION_HOOK for plugin '%s' doesn't seem to exist."), $command, get_class($this));
190 print_red ($message);
191 }
192 }
193 }
196 /* Get updates for status flag */
197 function updateStatusState()
198 {
199 if(empty($this->StatusFlag)) return;
201 $attrs = array();
202 $flag = $this->StatusFlag;
203 $ldap = $this->config->get_ldap_link();
204 $ldap->cd($this->cn);
205 $ldap->cat($this->dn,array($flag));
206 if($ldap->count()){
207 $attrs = $ldap->fetch();
208 }
209 if(isset($attrs[$flag][0])){
210 $this->$flag = $attrs[$flag][0];
211 }
212 }
215 function check(){ return array();}
217 function save_object(){;}
218 }
219 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
220 ?>