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();
83 /* Check if this is a new entry ... add/modify */
84 $ldap = $this->config->get_ldap_link();
85 $ldap->cat($this->dn,array("objectClass"));
86 if($ldap->count()){
87 $ldap->cd($this->dn);
88 $ldap->modify($this->attrs);
89 }else{
90 $ldap->cd($this->dn);
91 $ldap->add($this->attrs);
92 }
93 show_ldap_error($ldap->get_error());
94 $this->handle_post_events("remove");
95 }
98 function save()
99 {
100 plugin::save();
101 $this->attrs['goTimeSource'] =array();
102 foreach($this->goTimeSource as $entry){
103 $this->attrs['goTimeSource'][] = $entry;
104 }
105 /* Check if this is a new entry ... add/modify */
106 $ldap = $this->config->get_ldap_link();
107 $ldap->cat($this->dn,array("objectClass"));
108 if($ldap->count()){
109 $ldap->cd($this->dn);
110 $ldap->modify($this->attrs);
111 }else{
112 $ldap->cd($this->dn);
113 $ldap->add($this->attrs);
114 }
115 show_ldap_error($ldap->get_error());
116 if($this->initially_was_account){
117 $this->handle_post_events("modify");
118 }else{
119 $this->handle_post_events("add");
120 }
121 }
124 /* Directly save new status flag */
125 function setStatus($value)
126 {
127 if($value == "none") return;
128 if(!$this->initially_was_account) return;
129 $ldap = $this->config->get_ldap_link();
130 $ldap->cd($this->dn);
131 $ldap->cat($this->dn,array("objectClass"));
132 if($ldap->count()){
134 $tmp = $ldap->fetch();
135 for($i = 0; $i < $tmp['objectClass']['count']; $i ++){
136 $attrs['objectClass'][] = $tmp['objectClass'][$i];
137 }
138 $flag = $this->StatusFlag;
139 $attrs[$flag] = $value;
140 $this->$flag = $value;
141 $ldap->modify($attrs);
142 show_ldap_error($ldap->get_error());
143 $this->action_hook();
144 }
145 }
147 function action_hook($add_attrs= array())
148 {
149 /* Find postcreate entries for this class */
150 $command= search_config($this->config->data['MENU'], get_class($this), "ACTION_HOOK");
151 if ($command == "" && isset($this->config->data['TABS'])){
152 $command= search_config($this->config->data['TABS'], get_class($this), "ACTION_HOOK");
153 }
154 if ($command != ""){
155 /* Walk through attribute list */
156 foreach ($this->attributes as $attr){
157 if (!is_array($this->$attr)){
158 $command= preg_replace("/%$attr/", $this->$attr, $command);
159 }
160 }
161 $command= preg_replace("/%dn/", $this->dn, $command);
162 /* Additional attributes */
163 foreach ($add_attrs as $name => $value){
164 $command= preg_replace("/%$name/", $value, $command);
165 }
167 /* If there are still some %.. in our command, try to fill these with some other class vars */
168 if(preg_match("/%/",$command)){
169 $attrs = get_object_vars($this);
170 foreach($attrs as $name => $value){
171 if(!is_string($value)) continue;
172 $command= preg_replace("/%$name/", $value, $command);
173 }
174 }
176 if (check_command($command)){
177 @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
178 $command, "Execute");
180 exec($command);
181 } else {
182 $message= sprintf(_("Command '%s', specified as ACTION_HOOK for plugin '%s' doesn't seem to exist."), $command, get_class($this));
183 print_red ($message);
184 }
185 }
186 }
189 /* Get updates for status flag */
190 function updateStatusState()
191 {
192 if(empty($this->StatusFlag)) return;
194 $attrs = array();
195 $flag = $this->StatusFlag;
196 $ldap = $this->config->get_ldap_link();
197 $ldap->cd($this->cn);
198 $ldap->cat($this->dn,array($flag));
199 if($ldap->count()){
200 $attrs = $ldap->fetch();
201 }
202 if(isset($attrs[$flag][0])){
203 $this->$flag = $attrs[$flag][0];
204 }
205 }
208 function check(){ return array();}
210 function save_object(){;}
211 }
212 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
213 ?>