6 |
rodolico |
1 |
<?php
|
|
|
2 |
/*
|
|
|
3 |
* This file is just an easy way to create the YAML configuration file.
|
|
|
4 |
* You, as a PHP programmer, are probably more familiar with PHP than
|
|
|
5 |
* YAML, so create an array, $configuration, below, then run this
|
|
|
6 |
* script (ie, php sysinfoRead.conf-creator.php). A properly formatted
|
|
|
7 |
* YAML configuration stream will be sent to STDOUT, where you can
|
|
|
8 |
* capture it.
|
|
|
9 |
* OF COURSE, you can definitely hand code the YAML. It is actually much
|
|
|
10 |
* simpler than doing the PHP, but not if you're familiar with PHP
|
|
|
11 |
* and not so good with YAML.
|
11 |
rodolico |
12 |
* Requires php-pear and libyaml under Debian Wheezy
|
|
|
13 |
*
|
|
|
14 |
* apt-get install php-pear php5-dev libyaml-dev libyaml-0-2 libyaml-0-2-dbg
|
|
|
15 |
* pecl install yaml
|
|
|
16 |
* echo 'extension=yaml.so' >> /etc/php5/cli/php.ini
|
|
|
17 |
* echo 'extension=yaml.so' >> /etc/apache2/cli/php.ini
|
|
|
18 |
*
|
6 |
rodolico |
19 |
*/
|
11 |
rodolico |
20 |
|
|
|
21 |
/*
|
|
|
22 |
I use a nowdoc to define this large block of code which evaluates an ini file.
|
|
|
23 |
(see http://php.net/manual/en/language.types.string.php#language.types.string.syntax.nowdoc
|
|
|
24 |
nowdoc's don't really work in an array, or at least I have not been able
|
|
|
25 |
to figure out the syntax, so I use the following to get the code into the variable
|
|
|
26 |
$eval_ini, then put that into the $configuration array.
|
|
|
27 |
Also, nowdoc's are pretty sloppy looking, so another reason to do it here :)
|
|
|
28 |
*/
|
|
|
29 |
$eval_ini = <<<'END'
|
|
|
30 |
$data = array();
|
|
|
31 |
preg_match( '/\[report date\](.*)[\r\n]/', $body, $_date );
|
|
|
32 |
preg_match( '/\[client name\](.*)[\r\n]/', $body, $_client );
|
|
|
33 |
preg_match( '/\[hostname\](.*)[\r\n]/', $body, $_host );
|
|
|
34 |
$data['report']['date'] = str_replace(array("\n", "\r"), '', $_date[1]);
|
|
|
35 |
$data['report']['client'] = str_replace(array("\n", "\r"), '', $_client[1]);
|
|
|
36 |
$data['system']['hostname'] = str_replace(array("\n", "\r"), '', $_host[1]);
|
|
|
37 |
return $data;
|
|
|
38 |
END;
|
|
|
39 |
// end of the nowdoc, now on to the regular stuff
|
|
|
40 |
|
6 |
rodolico |
41 |
// Configuration file for getSysinfoMail.php, parse_sysinfo.php and other files
|
|
|
42 |
$configuration = array(
|
|
|
43 |
// set this to where the files parsed from mail should be placed.
|
12 |
rodolico |
44 |
// note, outpath will be removed in the future. It should be 'datapath/unprocessed_path'
|
|
|
45 |
// until that is done.
|
|
|
46 |
// in the future, datapath will define a root, then everything will be a subdirectory
|
|
|
47 |
// of that; unprocessed, duplicate, and all processed files
|
|
|
48 |
// processed files will be in datapath/YYYY/MM/filename
|
|
|
49 |
'outpath' => '/path/to/unprocessed/email', // this should be 'datapath/unprocessed_path'
|
|
|
50 |
'logFile' => '/path/to/log/file/errors.log', // full path to an error file
|
|
|
51 |
'datapath' => '/path/to/root/of/reports', // the root of all files
|
|
|
52 |
'unprocessed_path' => 'unprocessed', // subdirectory of datapath
|
|
|
53 |
'getMailScript' => 'getSysinfoMail.php', // name of the mail getter script
|
|
|
54 |
'processMailScript' => 'parse_sysinfo.php', // name of the report parser
|
|
|
55 |
'reportScript' => 'sendReport.pl', // name of the report script
|
6 |
rodolico |
56 |
|
|
|
57 |
// server connection information
|
12 |
rodolico |
58 |
// you can check multiple servers, accounts and mailboxes (folders)
|
|
|
59 |
// only two are listed here, but it can be from one to however many you want
|
6 |
rodolico |
60 |
'servers' => array(
|
|
|
61 |
array (
|
12 |
rodolico |
62 |
'servername' => 'smtp.server.or.ip',
|
6 |
rodolico |
63 |
'port' => 143,
|
|
|
64 |
'ssl' => false,
|
12 |
rodolico |
65 |
'mailbox' => 'mailbox.name',
|
|
|
66 |
'username' => 'username',
|
|
|
67 |
'password' => 'password',
|
|
|
68 |
'deleteProcessed' => false, // true will delete once they are downloaded
|
|
|
69 |
'enabled' => false // false means this entry will be ignored
|
6 |
rodolico |
70 |
),
|
|
|
71 |
array (
|
12 |
rodolico |
72 |
'servername' => 'smtp.server.or.ip',
|
6 |
rodolico |
73 |
'port' => 143,
|
|
|
74 |
'ssl' => false,
|
12 |
rodolico |
75 |
'mailbox' => 'mailbox.name',
|
|
|
76 |
'username' => 'username',
|
|
|
77 |
'password' => 'password',
|
|
|
78 |
'deleteProcessed' => false, // true will delete once they are downloaded
|
|
|
79 |
'enabled' => false // false means this entry will be ignored
|
6 |
rodolico |
80 |
),
|
12 |
rodolico |
81 |
),
|
|
|
82 |
// your database connection information
|
13 |
rodolico |
83 |
'database' => array(
|
12 |
rodolico |
84 |
'databaseServer' => 'localhost',
|
|
|
85 |
'databaseUsername' => 'dbuser',
|
|
|
86 |
'databasePassword' => 'dbpass',
|
|
|
87 |
'database' => 'dbname',
|
|
|
88 |
),
|
|
|
89 |
// you really need sendEmail.pl for this to work, as I've really written this around that
|
|
|
90 |
// see README.txt. This sends the report at the end of the processing. You can comment out
|
|
|
91 |
// the call to sendReport.pl in doReports.pl or rewrite the former.
|
|
|
92 |
'sendReport' => array(
|
|
|
93 |
'emailScript'=>'/opt/sendEmail/sendEmail.pl',
|
|
|
94 |
'mailTo'=> 'who@gets.mail',
|
|
|
95 |
'mailServer' => 'smtp.server.com:587',
|
|
|
96 |
'mailSubject' => 'Sysinfo Report',
|
|
|
97 |
'mailFrom' => 'sysinfo@mydomain.org',
|
|
|
98 |
'logFile' => '/tmp/mail.log',
|
|
|
99 |
'tls' => "'auto'",
|
|
|
100 |
'smtpUser' => 'smtp@user.com', // for authenticated SMTP
|
|
|
101 |
'smtpPass' => 'password', // for authenticated SMTP
|
|
|
102 |
),
|
6 |
rodolico |
103 |
|
12 |
rodolico |
104 |
// You really should not modify the following unless you know what you are doing
|
6 |
rodolico |
105 |
|
|
|
106 |
// these are regex's that define what we want to capture. Everything between startKey and endKey, inclusive
|
|
|
107 |
// we then process it with eval, which is an anonymous function accepting one paramter (body) and returning
|
|
|
108 |
// the array represented by the associated data definition
|
|
|
109 |
'bodyContents' => array(
|
|
|
110 |
'xml' => array(
|
|
|
111 |
'startTag' => '\<sysinfo',
|
|
|
112 |
'endTag' => '\<\/sysinfo[^>]*\>',
|
|
|
113 |
// see http://stackoverflow.com/questions/6578832/how-to-convert-xml-into-array-in-php
|
11 |
rodolico |
114 |
'eval' => 'return(json_decode(json_encode((array)simplexml_load_string($body)),1));',
|
6 |
rodolico |
115 |
|
|
|
116 |
),
|
|
|
117 |
'yaml' => array(
|
|
|
118 |
'startTag' => '\-\-\-',
|
|
|
119 |
'endTag' => '\.\.\.',
|
11 |
rodolico |
120 |
'eval' => 'return( yaml_parse( $body, 0 ) );',
|
6 |
rodolico |
121 |
),
|
|
|
122 |
'ini' => array( # this is an older format which we don't support, so we'll just write it out
|
|
|
123 |
'startTag' => '\[sysinfo version\]',
|
11 |
rodolico |
124 |
'endTag' => '',
|
|
|
125 |
'eval' => $eval_ini,
|
6 |
rodolico |
126 |
)
|
|
|
127 |
),
|
|
|
128 |
|
|
|
129 |
);
|
|
|
130 |
|
|
|
131 |
// here is where we actually generate the YAML
|
|
|
132 |
print yaml_emit( $configuration );
|
|
|
133 |
|
|
|
134 |
|
|
|
135 |
?>
|