Code

21bab42762ab4def6e20dde441f7dab6632511a2
[gosa.git] / plugins / admin / systems / class_goNtpServer.inc
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","goNtpServerStatus");
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;
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     $flag = $this->StatusFlag;
68     $fields['Status']      = $this->$flag;
69     $fields['Message']    = _("NTP service");
70     $fields['AllowStart'] = true;
71     $fields['AllowStop']  = true;
72     $fields['AllowRestart'] = true;
73     $fields['AllowRemove']= true;
74     $fields['AllowEdit']  = true;
75     return($fields);
76   }
79   function remove_from_parent()
80   {
81     plugin::remove_from_parent();
82     /* Check if this is a new entry ... add/modify */
83     $ldap = $this->config->get_ldap_link();
84     $ldap->cat($this->dn,array("objectClass"));
85     if($ldap->count()){
86       $ldap->cd($this->dn);
87       $ldap->modify($this->attrs);
88     }else{
89       $ldap->cd($this->dn);
90       $ldap->add($this->attrs);
91     }
92     show_ldap_error($ldap->get_error());
93     $this->handle_post_events("remove");
94   }
97   function save()
98   {
99     plugin::save();
100     $this->attrs['goTimeSource'] =array();
101     foreach($this->goTimeSource as $entry){
102       $this->attrs['goTimeSource'][] = $entry;
103     }
104     /* Check if this is a new entry ... add/modify */
105     $ldap = $this->config->get_ldap_link();
106     $ldap->cat($this->dn,array("objectClass"));
107     if($ldap->count()){
108       $ldap->cd($this->dn);
109       $ldap->modify($this->attrs);
110     }else{
111       $ldap->cd($this->dn);
112       $ldap->add($this->attrs);
113     }
114     show_ldap_error($ldap->get_error());
115     if($this->initially_was_account){
116       $this->handle_post_events("modify");
117     }else{
118       $this->handle_post_events("add");
119     }
120   }
123   /* Directly save new status flag */
124   function setStatus($value)
125   {
126     if($value == "none") return;
127     if(!$this->initially_was_account) return;
128     $ldap = $this->config->get_ldap_link();
129     $ldap->cd($this->dn);
130     $ldap->cat($this->dn,array("objectClass"));
131     if($ldap->count()){
133       $tmp = $ldap->fetch();
134       for($i = 0; $i < $tmp['objectClass']['count']; $i ++){
135         $attrs['objectClass'][] = $tmp['objectClass'][$i];
136       }
137       $flag = $this->StatusFlag;
138       $attrs[$flag] = $value;
139       $this->$flag = $value;
140       $ldap->modify($attrs);
141       show_ldap_error($ldap->get_error());
142       $this->action_hook();
143     }
144   }
146   function action_hook($add_attrs= array())
147   {
148     /* Find postcreate entries for this class */
149     $command= search_config($this->config->data['MENU'], get_class($this), "ACTION_HOOK");
150     if ($command == "" && isset($this->config->data['TABS'])){
151       $command= search_config($this->config->data['TABS'], get_class($this), "ACTION_HOOK");
152     }
153     if ($command != ""){
154       /* Walk through attribute list */
155       foreach ($this->attributes as $attr){
156         if (!is_array($this->$attr)){
157           $command= preg_replace("/%$attr/", $this->$attr, $command);
158         }
159       }
160       $command= preg_replace("/%dn/", $this->dn, $command);
161       /* Additional attributes */
162       foreach ($add_attrs as $name => $value){
163         $command= preg_replace("/%$name/", $value, $command);
164       }
165       if (check_command($command)){
166         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
167             $command, "Execute");
169         exec($command);
170       } else {
171         $message= sprintf(_("Command '%s', specified as ACTION_HOOK for plugin '%s' doesn't seem to exist."), $command, get_class($this));
172         print_red ($message);
173       }
174     }
175   }
177   function check(){ return array();}
179   function save_object(){;}
181 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
182 ?>