]> git.pld-linux.org Git - packages/cacti.git/blame - script_server_command_line_parse.patch
- Add patch from date 2010/07/27 more info http://www.cacti.net/download_patches.php
[packages/cacti.git] / script_server_command_line_parse.patch
CommitLineData
a60f27b1
JS
1--- cacti-0.8.7g/script_server.php 2010-07-09 18:33:46.000000000 -0400
2+++ cacti-0.8.7g-patched/script_server.php 2010-07-27 21:30:31.000000000 -0400
3@@ -72,7 +72,7 @@
4 }
5
6 /* record the script start time */
7-list($micro,$seconds) = split(" ", microtime());
8+list($micro,$seconds) = explode(" ", microtime());
9 $start = $seconds + $micro;
10
11 /* some debugging */
12@@ -171,7 +171,11 @@
13
14 if (isset($command_array[2])) {
15 $parameters = trim($command_array[2]);
16- $parameter_array = explode(" ", trim($command_array[2]));
17+ $parameter_array = array();
18+ if (!parseArgs($parameters, $parameter_array)) {
19+ cacti_log("WARNING: Script Server count not parse '$parameters' for $function", false, "PHPSVR");
20+ return "U";
21+ }
22 }else{
23 $parameters = "";
24 $parameters_array = array();
25@@ -236,3 +240,111 @@
26 exit (-1);
27 }
28 }
29+
30+function parseArgs($string, &$str_list, $debug = false) {
31+ $delimiters = array("'",'"');
32+ $delimited = false;
33+ $str_list = array();
34+
35+ if ($debug) echo "String: '" . $string . "'\n";
36+
37+ foreach($delimiters as $delimiter) {
38+ if (strpos($string, $delimiter) !== false) {
39+ $delimited = true;
40+ break;
41+ }
42+ }
43+
44+ /* process the simple case */
45+ if (!$delimited) {
46+ $str_list = explode(" ", $string);
47+
48+ if ($debug) echo "Output: '" . implode(",", $str_list) . "'\n";
49+
50+ return true;
51+ }
52+
53+ /* Break str down into an array of characters and process */
54+ $char_array = str_split($string);
55+ $escaping = false;
56+ $indelim = false;
57+ $parse_ok = true;
58+ $curstr = '';
59+ foreach($char_array as $char) {
60+ switch ($char) {
61+ case '\'':
62+ case '"':
63+ if (!$indelim) {
64+ if (!$escaping) {
65+ $indelim = true;
66+ }else{
67+ $curstr .= $char;
68+ $escaping = false;
69+ }
70+ }elseif (!$escaping) {
71+ $str_list[] = $curstr;
72+ $curstr = '';
73+ $indelim = false;
74+ }elseif ($escaping) {
75+ $curstr .= $char;
76+ $escaping = false;
77+ }
78+
79+ break;
80+ case '\\':
81+ if ($escaping) {
82+ $curstr .= $char;
83+ $escaping = false;
84+ }else{
85+ $escaping = true;
86+ }
87+
88+ break;
89+ case ' ':
90+ if ($escaping) {
91+ $parse_ok = false;
92+ $msg = 'Parse error attempting to parse string';
93+ }elseif ($indelim) {
94+ $curstr .= $char;
95+ }elseif (strlen($curstr)) {
96+ $str_list[] = $curstr;
97+ $curstr = '';
98+ }
99+
100+ break;
101+ case '`':
102+ $parse_ok = false;
103+ $msg = 'Backtic (`) characters not allowed';
104+
105+ break;
106+ default:
107+ if ($escaping) {
108+ $parse_ok = false;
109+ $msg = 'Parse error attempting to parse string';
110+ }else{
111+ $curstr .= $char;
112+ }
113+ break;
114+ }
115+
116+ if (!$parse_ok) {
117+ break;
118+ }
119+ }
120+
121+ /* Add the last str to the string array */
122+ if ($indelim || $escaping) {
123+ $parse_ok = false;
124+ $msg = 'Parse error attempting to parse string';
125+ }
126+
127+ if (!$parse_ok) {
128+ echo "ERROR: " . $msg . " '" . $string . "'\n";
129+ }else{
130+ $str_list[] = $curstr;
131+ }
132+
133+ if ($debug) echo "Output: '" . implode(",", $str_list) . "'\n";
134+
135+ return $parse_ok;
136+}
This page took 0.047646 seconds and 4 git commands to generate.