2a5096c02d1f31ea654b5e032f38254c5b5e961d
[gosa.git] / gosa-plugins / rsyslog / admin / systems / services / rsyslog / class_rSyslogServer.inc
1 <?php
3 class rSyslogServer extends goService{
5 /* This plugin only writes its objectClass */
6 var $objectclasses = array("goSyslogServer");
7 var $attributes = array();
8 var $db_attributes = array("gosaLogDB","goLogAdmin","goLogPassword");
9 var $StatusFlag = "";
11 /* This class can't be assigned twice so it conflicts with itsself */
12 var $conflicts = array("rSyslogServer");
14 var $DisplayName = "";
15 var $dn = NULL;
16 var $acl;
17 var $cn = "";
18 var $use_database = FALSE;
19 var $initial_use_database = FALSE;
20 var $gosaLogDB = "Syslog";
21 var $goLogAdmin = "rsyslog";
22 var $goLogPassword = "";
23 var $view_logged = FALSE;
26 function rSyslogServer(&$config,$dn)
27 {
28 goService::goService($config,$dn);
29 $this->DisplayName = _("Logging");
30 $this->initial_use_database = $this->use_database =
31 isset($this->attrs['objectClass']) &&in_array("goLogDBServer", $this->attrs['objectClass']);
33 if($this->use_database){
34 foreach($this->db_attributes as $attr){
35 if(isset($this->attrs[$attr][0])){
36 $this->$attr = $this->attrs[$attr][0];
37 }
38 }
39 }
40 }
43 function execute()
44 {
45 $smarty = get_smarty();
47 if($this->is_account && !$this->view_logged){
48 $this->view_logged = TRUE;
49 new log("view","server/".get_class($this),$this->dn);
50 }
52 $tmp = $this->plInfo();
53 foreach($tmp['plProvidedAcls'] as $name => $translation){
54 $smarty->assign($name."ACL",$this->getacl($name));
55 }
57 foreach($this->db_attributes as $attr){
58 $smarty->assign($attr,set_post($this->$attr));
59 }
60 $smarty->assign("use_database" , $this->use_database);
61 return($smarty->fetch(get_template_path("rSyslogServer.tpl",TRUE,dirname(__FILE__))));
62 }
65 function getListEntry()
66 {
67 $fields = goService::getListEntry();
68 $fields['Message'] = _("Logging service");
69 #$fields['AllowEdit'] = true;
70 #$fields['AllowStart'] = FALSE;
71 #$fields['AllowStop'] = FALSE;
72 #$fields['AllowRestart'] = FALSE;
73 return($fields);
74 }
77 function check()
78 {
79 $message = plugin::check();
80 if($this->use_database){
81 if (empty($this->goLogAdmin)){
82 $message[]= msgPool::required(_("User"));
83 }
84 if (empty($this->gosaLogDB)){
85 $message[]= msgPool::required(_("Database"));
86 }
87 if (empty($this->goLogPassword)){
88 $message[]= msgPool::required(_("Password"));
89 }
90 }
91 return($message);
92 }
95 function save_object()
96 {
97 if(isset($_POST['rSyslogServerPosted'])){
98 plugin::save_object();
100 foreach($this->db_attributes as $attr){
101 if(isset($_POST[$attr])){
102 $this->$attr = get_post($attr);
103 }
104 }
105 $this->use_database = isset($_POST['use_database']);
106 }
107 }
110 function save()
111 {
112 // Store rSyslog database connection info if enabled.
113 if($this->use_database){
114 $this->attributes = array('gosaLogDB','goLogAdmin','goLogPassword');
115 $this->objectclasses = array('goSyslogServer','goLogDBServer');
116 }else{
117 $this->attributes = array();
118 $this->objectclasses = array('goSyslogServer');
120 }
122 plugin::save();
124 if(!$this->use_database && $this->initial_use_database){
125 $this->attrs['objectClass'] = array_remove_entries(array('goLogDBServer'),$this->attrs['objectClass']);
126 $this->attrs['objectClass'] = array_values($this->attrs['objectClass']);
127 foreach($this->db_attributes as $attr){
128 $this->attrs[$attr] = array();
129 }
130 }
132 /* Check if this is a new entry ... add/modify */
133 $ldap = $this->config->get_ldap_link();
134 $ldap->cat($this->dn,array("objectClass"));
135 if($ldap->count()){
136 $ldap->cd($this->dn);
137 $ldap->modify($this->attrs);
138 }else{
139 $ldap->cd($this->dn);
140 $ldap->add($this->attrs);
141 }
142 if($this->initially_was_account){
143 new log("modify","server/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
144 $this->handle_post_events("modify");
145 }else{
146 $this->handle_post_events("add");
147 new log("create","server/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
148 }
149 if (!$ldap->success()){
150 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
151 }
152 }
155 /* Remove service */
156 function remove_from_parent()
157 {
158 // Store rSyslog database connection info if enabled.
159 if($this->initial_use_database){
160 $this->attributes = array('gosaLogDB','goLogAdmin','goLogPassword');
161 $this->objectclasses = array('goSyslogServer','goLogDBServer');
162 }else{
163 $this->attributes = array();
164 $this->objectclasses = array('goSyslogServer');
165 }
167 goService::remove_from_parent();
168 }
171 /* Return plugin informations for acl handling */
172 static function plInfo()
173 {
174 return (array(
175 "plShortName" => _("Logging service"),
176 "plDescription" => _("Logging service")." ("._("Services").")",
177 "plSelfModify" => FALSE,
178 "plDepends" => array(),
179 "plPriority" => 99,
180 "plRequirements"=> array(
181 'ldapSchema' => array('goSyslogServer' => '>=2.7','goLogDBServer' => '>=2.7'),
182 'onFailureDisablePlugin' => array(get_class(),'rsyslog'),
183 ),
184 "plSection" => array("administration"),
185 "plCategory" => array("server"),
187 "plProvidedAcls"=> array(
188 "gosaLogDB" => _("Database"),
189 "goLogAdmin" => _("User"),
190 "goLogPassword" => _("Password"),
191 "viewEntries" => _("Allow view of entries on this server"))
192 ));
193 }
194 }
195 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
196 ?>