a69b21f8ebbe1f6f885866573385717b67d38db9
[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("goSyslogServer");
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 = isset($this->attrs['objectClass']) &&in_array("goLogDBServer", $this->attrs['objectClass']);
32 if($this->use_database){
33 foreach($this->db_attributes as $attr){
34 if(isset($this->attrs[$attr][0])){
35 $this->$attr = $this->attrs[$attr][0];
36 }
37 }
38 }
39 }
42 function execute()
43 {
44 $smarty = get_smarty();
46 if($this->is_account && !$this->view_logged){
47 $this->view_logged = TRUE;
48 new log("view","server/".get_class($this),$this->dn);
49 }
51 $tmp = $this->plInfo();
52 foreach($tmp['plProvidedAcls'] as $name => $translation){
53 $smarty->assign($name."ACL",$this->getacl($name));
54 }
56 foreach($this->db_attributes as $attr){
57 $smarty->assign($attr,$this->$attr);
58 }
59 $smarty->assign("use_database" , $this->use_database);
60 return($smarty->fetch(get_template_path("rSyslogServer.tpl",TRUE,dirname(__FILE__))));
61 }
64 function getListEntry()
65 {
66 $fields = goService::getListEntry();
67 $fields['Message'] = _("Logging service");
68 #$fields['AllowEdit'] = true;
69 #$fields['AllowStart'] = FALSE;
70 #$fields['AllowStop'] = FALSE;
71 #$fields['AllowRestart'] = FALSE;
72 return($fields);
73 }
76 function check()
77 {
78 $message = plugin::check();
79 if($this->use_database){
80 if (empty($this->goLogAdmin)){
81 $message[]= msgPool::required(_("User"));
82 }
83 if (empty($this->gosaLogDB)){
84 $message[]= msgPool::required(_("Database"));
85 }
86 if (empty($this->goLogPassword)){
87 $message[]= msgPool::required(_("Password"));
88 }
89 }
90 return($message);
91 }
94 function save_object()
95 {
96 if(isset($_POST['rSyslogServerPosted'])){
97 plugin::save_object();
99 foreach($this->db_attributes as $attr){
100 if(isset($_POST[$attr])){
101 $this->$attr = get_post($attr);
102 }
103 }
104 $this->use_database = isset($_POST['use_database']);
105 }
106 }
109 function save()
110 {
111 // Store rSyslog database connection info if enabled.
112 if($this->use_database){
113 $this->attributes = array('gosaLogDB','goLogAdmin','goLogPassword');
114 $this->objectclasses = array('goSyslogServer','goLogDBServer');
115 }else{
116 $this->attributes = array();
117 $this->objectclasses = array('goSyslogServer');
119 }
121 plugin::save();
123 if(!$this->use_database && $this->initial_use_database){
124 $this->attrs['objectClass'] = array_remove_entries(array('goLogDBServer'),$this->attrs['objectClass']);
125 $this->attrs['objectClass'] = array_values($this->attrs['objectClass']);
126 foreach($this->db_attributes as $attr){
127 $this->attrs[$attr] = array();
128 }
129 }
131 /* Check if this is a new entry ... add/modify */
132 $ldap = $this->config->get_ldap_link();
133 $ldap->cat($this->dn,array("objectClass"));
134 if($ldap->count()){
135 $ldap->cd($this->dn);
136 $ldap->modify($this->attrs);
137 }else{
138 $ldap->cd($this->dn);
139 $ldap->add($this->attrs);
140 }
141 if($this->initially_was_account){
142 new log("modify","server/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
143 $this->handle_post_events("modify");
144 }else{
145 $this->handle_post_events("add");
146 new log("create","server/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
147 }
148 if (!$ldap->success()){
149 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
150 }
151 }
154 /* Remove service */
155 function remove_from_parent()
156 {
157 // Store rSyslog database connection info if enabled.
158 if($this->initial_use_database){
159 $this->attributes = array('gosaLogDB','goLogAdmin','goLogPassword');
160 $this->objectclasses = array('goSyslogServer','goLogDBServer');
161 }else{
162 $this->attributes = array();
163 $this->objectclasses = array('goSyslogServer');
164 }
166 goService::remove_from_parent();
167 }
170 /* Return plugin informations for acl handling */
171 static function plInfo()
172 {
173 return (array(
174 "plShortName" => _("Logging service"),
175 "plDescription" => _("Logging service")." ("._("Services").")",
176 "plSelfModify" => FALSE,
177 "plDepends" => array(),
178 "plPriority" => 99,
179 "plSection" => array("administration"),
180 "plCategory" => array("server"),
182 "plProvidedAcls"=> array(
183 "gosaLogDB" => _("Database"),
184 "goLogAdmin" => _("User"),
185 "goLogPassword" => _("Password"),
186 "viewEntries" => _("Allow view of entries on this server"))
187 ));
188 }
189 }
190 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
191 ?>