Skip to content

Commit 38e646f

Browse files
committed
Comments update to PEAR and define update
1 parent a159ead commit 38e646f

1 file changed

Lines changed: 82 additions & 31 deletions

File tree

syslog.class.php

Lines changed: 82 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,42 @@
11
<?php
2+
/**
3+
* Short description for file
4+
*
5+
* Long description for file (if any)...
6+
*
7+
* PHP version 5
8+
*
9+
* LICENSE: * Copyright 2013 Laurent Vromman
10+
*
11+
* This program is free software: you can redistribute it and/or modify
12+
* it under the terms of the GNU LesserGeneral Public License as published by
13+
* the Free Software Foundation, either version 3 of the License, or
14+
* (at your option) any later version.
15+
*
16+
* This program is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU Lesser General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU General Public License
22+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
23+
*
24+
* @category Networking
25+
* @package Net_Syslog
26+
* @author Laurent Vromman <laurent@vromman.org>
27+
* @copyright 2013 Laurent Vromman
28+
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 3
29+
* @version SVN: $Id$
30+
* @link http://pear.php.net/package/Net_Syslog
31+
*/
32+
33+
/*
34+
* Place includes, constant defines and $_GLOBAL settings here.
35+
* Make sure they have appropriate docblocks to avoid phpDocumentor
36+
* construing they are documented by the page-level docblock.
37+
*/
38+
39+
240
/**
341
*
442
* Description
@@ -124,24 +162,37 @@
124162
*
125163
*/
126164

127-
define("LOG_LINUX_NETWORD_INTERFACE", "eth0");
128-
define("LOG_NILVALUE", "-");
165+
define("NET_SYSLOG_LINUX_NETWORD_INTERFACE", "eth0");
166+
define("NET_SYSLOG_NILVALUE", "-");
129167

130168
define("LOG_FTP", 88);
131169
define("LOG_NTP", 96);
132170
define("LOG_LOG_AUDIT", 104);
133171
define("LOG_ALERT", 112);
134172
define("LOG_CLOCK", 120);
135173

136-
define("SYSLOG_TCP", "tcp");
137-
define("SYSLOG_UDP", "udp");
138-
define("SYSLOG_SSL", "ssl");
139-
define("SYSLOG_TLS", "tls");
174+
define("NET_SYSLOG_TCP", "tcp");
175+
define("NET_SYSLOG_UDP", "udp");
176+
define("NET_SYSLOG_SSL", "ssl");
177+
define("NET_SYSLOG_TLS", "tls");
140178
// Compatibility for RFC 5424, 5425 and 5426
141-
define("SYSLOG_RFC542X", 1);
142-
define("SYSLOG_RFC3164", 0);
179+
define("NET_SYSLOG_RFC542X", 1);
180+
define("NET_SYSLOG_RFC3164", 0);
143181

144-
class Syslog
182+
/**
183+
* Short description for class
184+
*
185+
* Long description for class (if any)...
186+
*
187+
* @category Networking
188+
* @package Net_Syslog
189+
* @author Laurent Vromman <laurent@vromman.org>
190+
* @copyright 2013 Laurent Vromman
191+
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 3
192+
* @version SVN: $Id$
193+
* @link http://pear.php.net/package/Net_Syslog
194+
*/
195+
class Net_Syslog
145196
{
146197
private $_hostname; // no embedded space, no domain name, only a-z A-Z 0-9 and other authorized characters
147198
private $_server; // Syslog destination server
@@ -152,10 +203,10 @@ class Syslog
152203
private $_procid;
153204
private $_appname;
154205

155-
public function Syslog($hostname = "", $appname = LOG_NILVALUE,
156-
$protocol = SYSLOG_UDP, $procid = LOG_NILVALUE
206+
public function Syslog($hostname = "", $appname = NET_SYSLOG_NILVALUE,
207+
$protocol = NET_SYSLOG_UDP, $procid = NET_SYSLOG_NILVALUE
157208
) {
158-
$this->_rfc = SYSLOG_RFC3164;
209+
$this->_rfc = NET_SYSLOG_RFC3164;
159210
$this->_socket = FALSE;
160211
$this->_server = '127.0.0.1';
161212
$this->setProcid($procid);
@@ -166,27 +217,27 @@ public function Syslog($hostname = "", $appname = LOG_NILVALUE,
166217
if (strlen($hostname) == 0) {
167218
if (isset($_SERVER["SERVER_NAME"])) {
168219
$hostname = $_SERVER["SERVER_NAME"];
169-
if($this->_rfc == SYSLOG_RFC3164)
220+
if($this->_rfc == NET_SYSLOG_RFC3164)
170221
$hostname = substr($hostname, 0, strpos($hostname.".", "."));
171222
}
172223
elseif (isset($_SERVER["SERVER_ADDR"])) {
173224
$hostname = $_SERVER["SERVER_ADDR"];
174225
}
175226
else {
176-
if($this->_rfc == SYSLOG_RFC3164)
227+
if($this->_rfc == NET_SYSLOG_RFC3164)
177228
$hostname = "server";
178229
else
179-
$hostname = LOG_NILVALUE;
230+
$hostname = NET_SYSLOG_NILVALUE;
180231
}
181232
}
182233
$this->setHostname($hostname);
183234

184235
$this->setProtocol($protocol);
185-
if (!in_array($this->_protocol, array(SYSLOG_UDP, SYSLOG_TCP, SYSLOG_SSL, SYSLOG_TLS))) {
186-
$this->_protocol = SYSLOG_UDP;
236+
if (!in_array($this->_protocol, array(NET_SYSLOG_UDP, NET_SYSLOG_TCP, NET_SYSLOG_SSL, NET_SYSLOG_TLS))) {
237+
$this->_protocol = NET_SYSLOG_UDP;
187238
}
188239
// RFC5425
189-
if($this->_protocol == SYSLOG_TLS)
240+
if($this->_protocol == NET_SYSLOG_TLS)
190241
$this->_port = 6514;
191242
else
192243
$this->_port = 514;
@@ -204,7 +255,7 @@ private function getServerAddress()
204255
return gethostbyname(php_uname("n"));
205256
}
206257
else {
207-
$ifconfig = shell_exec('/sbin/ifconfig '.LOG_LINUX_NETWORD_INTERFACE);
258+
$ifconfig = shell_exec('/sbin/ifconfig '.NET_SYSLOG_LINUX_NETWORD_INTERFACE);
208259
preg_match('/addr:([\d\.]+)/', $ifconfig, $match);
209260
return $match[1];
210261
}
@@ -219,7 +270,7 @@ public function setRFC($rfc)
219270
public function setHostname($hostname)
220271
{
221272
$this->_hostname = substr($hostname, 0, 255);
222-
if(strlen($this->_hostname) == 0) $this->_hostname = LOG_NILVALUE;
273+
if(strlen($this->_hostname) == 0) $this->_hostname = NET_SYSLOG_NILVALUE;
223274
}
224275

225276
public function setServer($server)
@@ -236,7 +287,7 @@ public function setPort($port)
236287

237288
public function setProtocol($protocol)
238289
{
239-
if (in_array($protocol, array(SYSLOG_UDP, SYSLOG_TCP, SYSLOG_SSL, SYSLOG_TLS))) {
290+
if (in_array($protocol, array(NET_SYSLOG_UDP, NET_SYSLOG_TCP, NET_SYSLOG_SSL, NET_SYSLOG_TLS))) {
240291
$this->_protocol = $protocol;
241292
}
242293
}
@@ -249,13 +300,13 @@ public function setCAFile($cafile)
249300
public function setProcid($procid)
250301
{
251302
$this->_procid = substr($procid, 0, 128);
252-
if(strlen($this->_procid) == 0) $this->_procid = LOG_NILVALUE;
303+
if(strlen($this->_procid) == 0) $this->_procid = NET_SYSLOG_NILVALUE;
253304
}
254305

255306
public function setAppname($appname)
256307
{
257308
$this->_appname = substr($appname, 0, 48);
258-
if(strlen($this->_appname) == 0) $this->_appname = LOG_NILVALUE;
309+
if(strlen($this->_appname) == 0) $this->_appname = NET_SYSLOG_NILVALUE;
259310
}
260311

261312
private function openSocket ()
@@ -264,7 +315,7 @@ private function openSocket ()
264315
$this->closeSocket();
265316
$contextOptions = array();;
266317

267-
if($this->_protocol == SYSLOG_SSL && $this->_cafile != NULL) {
318+
if($this->_protocol == NET_SYSLOG_SSL && $this->_cafile != NULL) {
268319
//http://php.net/manual/en/context.ssl.php
269320
$contextOptions = array(
270321
'ssl' => array(
@@ -290,7 +341,7 @@ private function closeSocket ()
290341
public function logger3164($priority = 133, $content = "Default content")
291342
{
292343
$rfc = $this->_rfc;
293-
$this->_rfc = SYSLOG_RFC3164;
344+
$this->_rfc = NET_SYSLOG_RFC3164;
294345
$this->logger($priority, $content);
295346
$this->_rfc = $rfc;
296347
}
@@ -299,7 +350,7 @@ public function logger542X($priority = 133, $content = "Default content",
299350
$msgid = "-", $structured_data = "-"
300351
) {
301352
$rfc = $this->_rfc;
302-
$this->_rfc = SYSLOG_RFC542X;
353+
$this->_rfc = NET_SYSLOG_RFC542X;
303354
$this->logger($priority, $content, $msgid = "-", $structured_data);
304355
$this->_rfc = $rfc;
305356
}
@@ -309,8 +360,8 @@ public function logger($priority = 133, $content = "Default content",
309360
) {
310361
$this->_content = $content;
311362

312-
if(strlen($msgid) == 0) $msgid = LOG_NILVALUE;
313-
if(strlen($structured_data) == 0) $structured_data = LOG_NILVALUE;
363+
if(strlen($msgid) == 0) $msgid = NET_SYSLOG_NILVALUE;
364+
if(strlen($structured_data) == 0) $structured_data = NET_SYSLOG_NILVALUE;
314365

315366
$facility = floor($priority/8);
316367
$severity = $priority - $facility * 8;
@@ -325,7 +376,7 @@ public function logger($priority = 133, $content = "Default content",
325376
$timestamp = date("c");
326377

327378
$pri = "<$priority>";
328-
if($this->_rfc == SYSLOG_RFC542X) {
379+
if($this->_rfc == NET_SYSLOG_RFC542X) {
329380
$timestamp = date("c");
330381
$syslog_version = "1 ";
331382
}
@@ -335,7 +386,7 @@ public function logger($priority = 133, $content = "Default content",
335386
$syslog_version = "";
336387
}
337388
$header = $pri.$syslog_version.$timestamp." ".$this->_hostname." ";
338-
if($this->_rfc == SYSLOG_RFC542X) {
389+
if($this->_rfc == NET_SYSLOG_RFC542X) {
339390
$header .= $this->_appname." ".$this->_procid." ".substr($msgid, 0, 32);
340391
$message = $header. " ".$structured_data." ".$content;
341392
}
@@ -350,7 +401,7 @@ public function logger($priority = 133, $content = "Default content",
350401
$this->openSocket();
351402

352403
// RFC 5425
353-
if($this->_rfc == SYSLOG_RFC542X && $this->protocol == SYSLOG_TLS) {
404+
if($this->_rfc == NET_SYSLOG_RFC542X && $this->protocol == NET_SYSLOG_TLS) {
354405
$message = strlen($message)." ".$message;
355406
}
356407

0 commit comments

Comments
 (0)