• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

NathanGibbs3 / BASE / 590

pending completion
590

push

travis-ci-com

NathanGibbs3
20230420 Fix CI build breakage. 2

2755 of 16977 relevant lines covered (16.23%)

21.61 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/base_graph_display.php
1
<?php
2
/*******************************************************************************
3
** Basic Analysis and Security Engine (BASE)
4
** Copyright (C) 2004 BASE Project Team
5
** Copyright (C) 2000 Carnegie Mellon University
6
**
7
** (see the file 'base_main.php' for license details)
8
**
9
** Project Leads: Kevin Johnson <kjohnson@secureideas.net>
10
**                Sean Muller <samwise_diver@users.sourceforge.net>
11
** Built upon work by Roman Danyliw <rdd@cert.org>, <roman@danyliw.com>
12
**
13
** Purpose: Purpose: Displays the actual .GIF/.PNG/.TIFF image
14
**          of the chart
15
**
16
** Input GET/POST variables
17
**   - width: chart width
18
**   - height: chart width
19
**   - pmargin0-3: plot margins
20
**   - title: chart title
21
**   - xaxis_label: x-axis label
22
**   - yaxis_label: y-axis label
23
**   - xdata[][]: data and label array for the x-axis and the y-axis
24
**   - yaxis_scale: (boolean) 0: linear; 1: logarithmic
25
**   - rotate_xaxis_lbl: (boolean) rotate X-axis labels 90 degrees
26
**   - style: [bar|line|pie] chooses the style of the chart
27
********************************************************************************
28
** Authors:
29
********************************************************************************
30
** Kevin Johnson <kjohnson@secureideas.net
31
**
32
********************************************************************************
33
*/
34

35
require_once("base_conf.php");
×
36
include_once("$BASE_path/includes/base_constants.inc.php");
×
37
include_once("$BASE_path/includes/base_state_common.inc.php");
×
38
include_once("$BASE_path/base_graph_common.php");
×
39

40
$EMPfx = __FILE__ . ': '; // Error Message Prefix.
×
41
if ( VerifyGraphingLib() ){ // Graphics Libs Check
×
42
        require_once('Image/Graph.php');
×
43

44
  // One more time: A workaround for the inability of PEAR::Image_Canvas-0.3.1
45
  // to deal with strings as x-axis labels in a proper way in the case
46
  // of a logarithmic y-axis.
47
function replace_numbers( $value ){
48
        GLOBAL $xdata, $debug_mode, $EMPfx;
49
        if ($debug_mode > 1){
×
50
                error_log($EMPfx . "\$value = \"$value\"");
×
51
        }
52
        $str = $xdata[$value][0];
×
53
        return $str;
×
54
}
55

56
if ( isset($_SESSION['xdata']) ){
×
57
        $xdata = $_SESSION['xdata'];
×
58
}else{
×
59
        $xdata = array();
×
60
}
61
$width = ImportHTTPVar("width", VAR_DIGIT);
×
62
$height = ImportHTTPVar("height", VAR_DIGIT);
×
63
if ($width == ''){
×
64
        $width = 800;
×
65
}
66
if ($height == ''){
×
67
        $height = 600;
×
68
}
69
  $pmargin0 = ImportHTTPVar("pmargin0", VAR_DIGIT);
×
70
  $pmargin1 = ImportHTTPVar("pmargin1", VAR_DIGIT);
×
71
  $pmargin2 = ImportHTTPVar("pmargin2", VAR_DIGIT);
×
72
  $pmargin3 = ImportHTTPVar("pmargin3", VAR_DIGIT);
×
73
  $title = ImportHTTPVar("title", VAR_ALPHA | VAR_SPACE);
×
74
  $xaxis_label = ImportHTTPVar("xaxis_label", VAR_ALPHA | VAR_SPACE);
×
75
  $yaxis_label = ImportHTTPVar("yaxis_label", VAR_ALPHA | VAR_SPACE);
×
76
  $yaxis_scale = ImportHTTPVar("yaxis_scale", VAR_DIGIT);
×
77
  $xaxis_grid = ImportHTTPVar("xaxis_grid", VAR_DIGIT);
×
78
  $yaxis_grid = ImportHTTPVar("yaxis_grid", VAR_DIGIT);
×
79
  $rotate_xaxis_lbl = ImportHTTPVar("rotate_xaxis_lbl", VAR_DIGIT);
×
80
$style = ImportHTTPVar("style", VAR_ALPHA);
×
81
if ($style == ''){
×
82
        $style = 'pie';
×
83
}
84
$chart_type = ImportHTTPVar("chart_type", VAR_DIGIT);
×
85
$old_display_error_type = ini_get('display_errors');
×
86
if ( !empty($old_display_error_type) ){
×
87
        // Don't touch the screen when generating iamge.
88
        ini_set("display_errors", "0");
×
89
}
90
// Using the world map requires quite some memory. 100 MB should be more than
91
// enough, I would have thought after some tests.  However, even this amount
92
// of memory can be insufficient under certain circumstances, which are not
93
// quite clear to me (bugs in PEAR::Image::Graph? Or ::Canvas???).  So, let's
94
// try and ask for 256 MB:
95
ini_set("memory_limit", "256M");
×
96
if ($debug_mode > 1){
×
97
        error_log($EMPfx . "count(\$xdata) = " . count($xdata));
×
98
}
99
$WorldMap = false;
×
100
if ( $chart_type == 15 || $chart_type == 17 ){
×
101
        $WorldMap = true;
×
102
}
103
if ( $WorldMap ){
×
104
    // Number of alerts spread over a worldmap: width and height
105
    // MUST be constant. At least as of Image_Graph-0.7.2
106
    // Otherwise the coordinates file must be regenerated. And this
107
    // is NOT possible during runtime (as of version 0.7.2)
108
    $Graph =& Image_Graph::factory('graph', array(1800, 913));
×
109
    //$Graph =& Image_Graph::factory('graph', array(600, 300));
110
}elseif( $yaxis_scale == 1 && $style != 'pie' ){
×
111
    // the old form of instantiation does not seem to work
112
    // any more with PEAR::Image_Canvas-0.3.1 with logarithmic
113
    // y-axes. So factory-method is required.
114
    $Graph =& Image_Graph::factory('graph', array($width, $height));
×
115
}else{ // Create the graph area, legends on bottom -- Alejandro
×
116
        $Graph = new Image_Graph(
×
117
                array('driver'=>'gd', 'width'=>$width, 'height'=>$height)
×
118
        );
119
}
120
if ( $WorldMap ){ // A worldmap is to be drawn.
×
121
    $Graph->add(
×
122
      Image_Graph::vertical(
×
123
        Image_Graph::factory('title', array($title, 35)),
×
124
        Image_Graph::vertical(
×
125
          // create the plotarea
126
          $Plotarea = Image_Graph::factory('Image_Graph_Plotarea_Map', 'world_map6'),
×
127
          $Legend = Image_Graph::factory('legend'), // legend does not work, yet.
×
128
          90
129
        ),
130
        10
131
      )
132
    );
133
}elseif( $yaxis_scale == 1 ){ // A logarithmic y axis has been requested.
×
134
        if ($style == "pie"){ // Ignore logarithm in this case.
×
135
      $Graph->add(
×
136
        Image_Graph::vertical(
×
137
          Image_Graph::factory('title', array($title, 16)),
×
138
          Image_Graph::horizontal(
×
139
            $Plotarea = Image_Graph::factory('plotarea'),
×
140
            $Legend = Image_Graph::factory('legend'),
×
141
            80
142
          ),
143
          10
144
        )
145
      );
146
        }else{ // Bar & Line Charts
×
147
      $Graph->add(
×
148
        Image_Graph::vertical(
×
149
          Image_Graph::factory('title', array($title, 16)),
×
150
          Image_Graph::vertical(
×
151
            $Plotarea = Image_Graph::factory('plotarea' , array('axis', 'axis_log')),
×
152
            $Legend = Image_Graph::factory('legend'),
×
153
            80 // 85 
154
          ),
155
          10
156
        )
157
      );
158
        }
159
}else{ // linear y-axis.
×
160
        if ($style == "pie"){
×
161
      $Graph->add(
×
162
        Image_Graph::vertical(
×
163
          Image_Graph::factory('title', array($title, 16)),
×
164
          Image_Graph::horizontal(
×
165
            $Plotarea = Image_Graph::factory('plotarea'),
×
166
            $Legend = Image_Graph::factory('legend'),
×
167
            80  // 85
168
          ),
169
          10
170
        )
171
      );
172
        }else{ // bar, line
×
173
      $Graph->add(
×
174
        Image_Graph::vertical(
×
175
          Image_Graph::factory('title', array($title, 16)),
×
176
          Image_Graph::vertical(
×
177
            $Plotarea = Image_Graph::factory('plotarea'),
×
178
            $Legend = Image_Graph::factory('legend'),
×
179
            85
180
          ),
181
          10
182
        )
183
      );
184
        }
185
}
186
$rv = ini_get("safe_mode");
×
187
if ($rv != 1){ // normal mode
×
188
        GLOBAL $graph_font_name, $debug_mode;
189
    /* Say, $graph_font_name is being set to "DejaVuSans".  This means, that the
190
       IMAGE_CANVAS_SYSTEM_FONT_PATH constant in Canvas.php must be set
191
       to the directory, where "DejaVuSans.ttf" can be found.
192
       For example: vim Canvas.php
193

194
        define('IMAGE_CANVAS_SYSTEM_FONT_PATH', '/usr/share/fonts/dejavu/');
195
    */
196
        if ( !isset($graph_font_name) ){
×
197
                // "Image_Graph_Font" used to be a fail-safe font name.  But even this
198
                // does not seem to work, any more, for php >= 5.3.
199
                $graph_font_name = '';
×
200
        }
201
        if ($debug_mode > 0){
×
202
                error_log($EMPfx . "\$graph_font_name = \"$graph_font_name\"");
×
203
        }
204
        $Font =& $Graph->addNew('font', $graph_font_name);
×
205
        if ( $WorldMap ){ // Worldmap
×
206
      $Font->setSize(8);
×
207
        }else{ // all the other chart types
×
208
      $Font->setSize(8);
×
209
        }
210
    $Graph->setFont($Font);
×
211
}else{ // safe_mode
×
212
  $Font =& $Graph->addNew('Image_Graph_Font');
×
213
  $Font->setSize(8); // has no effect!
×
214
        if ($debug_mode > 0){
×
215
                error_log($EMPfx . "WARNING: safe_mode: Fall back to default font without ability to adjust font size.");
×
216
        }
217
}
218

219
// Configure plotarea
220
if ( $WorldMap ){ // Worldmap
×
221
  //  PHP Fatal error:  Allowed memory size of 104857600 bytes exhausted (tried to allocate 37 bytes) in /usr/share/pear/Image/Canvas.php on line 179
222
  //  ini_set("memory_limit", "100M");
223
  //  $Legend->setPlotarea($Plotarea);
224
}elseif($style == "pie"){
×
225
        $Legend->setPlotarea($Plotarea);
×
226
}else{
×
227
  $Plotarea->setAxisPadding(30, 'top');
×
228
  $Plotarea->setAxisPadding(30, 'bottom');
×
229
  $Plotarea->setAxisPadding(10, 'left');
×
230
  $Plotarea->setAxisPadding(10, 'right');
×
231
}
232

233
$AxisX =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_X);
×
234
$AxisY =& $Plotarea->getAxis(IMAGE_GRAPH_AXIS_Y);
×
235

236
if ( $style != "pie" && !$WorldMap ){
×
237
  // Arrows
238
  $AxisX->showArrow();
×
239
  $AxisY->showArrow();
×
240
        if ($yaxis_grid == 1){ // Grid lines for y-axis requested?
×
241
    $GridY =& $Plotarea->addNew('bar_grid', IMAGE_GRAPH_AXIS_Y);
×
242
    $GridY->setFillStyle(Image_Graph::factory('gradient', array(IMAGE_GRAPH_GRAD_VERTICAL, 'white', 'lightgrey')));
×
243
        }
244
        if ($xaxis_grid == 1){ // Grid lines for x-axis requested?
×
245
    $Plotarea->addNew('line_grid', true, IMAGE_GRAPH_AXIS_X);
×
246
        }
247
}
248

249
// Create the dataset -- Alejandro
250
$Dataset =& Image_Graph::factory('dataset'); 
×
251
for ( $i = 0; $i < count($xdata); $i++ ){
×
252
        if ($debug_mode > 1){
×
253
                error_log($EMPfx . $i . ": \"" . $xdata[$i][0] . "\" - " . $xdata[$i][1]);
×
254
        }
255
        if ( $WorldMap ){ // Worldmap
×
256
      $tmp = $xdata[$i][0];
×
257
      $tmp_lower = strtolower($tmp);
×
258
                if ($debug_mode > 1){
×
259
        error_log("to be looked up: '$tmp', '$tmp_lower' ###");
×
260
                }
261
      // special case '"I0" => "private network (rfc 1918)"' and
262
      // '"** (private network) " => "private network (rfc 1918)"'
263
                if (preg_match("/rfc 1918/", $tmp, $substring) || (preg_match("/[*][*] \(private network\) /", $tmp_lower, $substring)))
×
264
      {
265
        $Dataset->addPoint("private network (rfc 1918)", $xdata[$i][1]);
×
266
      }
267
      // special case '?? (Not Found) ' => 'unknown'
268
                elseif(preg_match("/[?][?][ \t]+\(Not Found\)[ \t]*/", $tmp, $substring))
×
269
      {
270
        $Dataset->addPoint("unknown", $xdata[$i][1]);
×
271
      }
272
      // anything inside parentheses, following a 2-letter TLD:
273
                elseif (preg_match("/^[-a-zA-Z0-9]{2}[ \t]\((.+)\)[ \t]*$/", $tmp, $substring))
×
274
      {
275
        $Dataset->addPoint($substring[1], $xdata[$i][1]);
×
276
      }
277
      // anything after two-letter top level domain names and after one space or tab:
278
                elseif (preg_match("/[ \t]*[-a-zA-Z0-9]{2}[ \t]([-a-zA-Z0-9]+[-a-zA-Z0-9 ]*)/", $tmp, $substring))
×
279
      {
280
        $Dataset->addPoint($substring[1], $xdata[$i][1]);
×
281
      }
282
      // two-letter top level domain names right at the beginning:
283
                elseif (preg_match("/[ \t]*([-a-zA-Z0-9]{2})[ \t]/", $tmp_lower, $substring))
×
284
      {
285
        $Dataset->addPoint($substring[1], $xdata[$i][1]);
×
286
                }else{
×
287
        $Dataset->addPoint($tmp, $xdata[$i][1]);
×
288
                }
289
        }elseif (($yaxis_scale == 1) && ($style != 'pie')){
×
290
    // Logarithmic y-axis with PEAR::Image_Canvas-0.3.1 seems to be buggy:
291
    // It does not work with strings as x-axis labels. So a workaround
292
    // is necessary - once again.
293
      $Dataset->addPoint($i, $xdata[$i][1]);
×
294
        }else{
×
295
      $Dataset->addPoint($xdata[$i][0], $xdata[$i][1]);
×
296
        }
297
}
298
$number_elements = $i;
×
299
if ($debug_mode > 1){
×
300
        error_log("number_elements = $number_elements");
×
301
}
302
// Design plot: Should it be a bar, line or a pie chart?
303
if ( $WorldMap ){ // Worldmap
×
304
    $Plot =& $Plotarea->addNew('Image_Graph_Plot_Dot', array(&$Dataset));
×
305
}elseif ($style == "line"){ // Correct this style and replace it by "area":
×
306
    $Plot =& $Plotarea->addNew('area', $Dataset);
×
307
}else{
×
308
    $Plot =& $Plotarea->addNew($style, $Dataset);  
×
309
}
310
// Labelling of the axes?
311
if ( $WorldMap ){ // Worldmap
×
312
    // Well, nothing to do here.
313
}elseif ( $style == "pie" ){ // We don't need any axes
×
314
    $Plotarea->hideAxis();
×
315
    $Plot->explode(10);
×
316
}else{
×
317
        if ($chart_type == CHARTTYPE_CLASSIFICATION){
×
318
                $ArrayData =& Image_Graph::factory('Image_Graph_DataPreprocessor_Array',$xdata);
×
319
        }else{
×
320
                $ArrayData =& Image_Graph::factory('Image_Graph_DataPreprocessor_Array',$xdata[0]);
×
321
        }
322
        // Prepare x-axis labels
323
        $AxisX->setDataPreprocessor($ArrayData);
×
324
        if ($debug_mode > 1){
×
325
                error_log($EMPfx . "\$yaxis_scale = \"$yaxis_scale\"");
×
326
        }
327
    // Part of that workaround for PEAR::Image_Canvas being unable to
328
    // deal with strings as x-axis lables in a proper way
329
    // xxx jl: Hmmm. What has $yaxis_scale to do with AxisX??? Dead code, anyway.
330
        if ($yaxis_scale == 1){
×
331
      $AxisX->setDataPreprocessor(Image_Graph::factory('Image_Graph_DataPreprocessor_Function', 'replace_numbers'));
×
332
        }
333
        // Should they be rotated by 90 degress?
334
        if ($rotate_xaxis_lbl == 1){ // affects x-axis title and labels:
×
335
                $AxisX->setFontAngle('vertical');
×
336
                // x-axis title
337
                if ((isset($xaxis_label)) && (strlen($xaxis_label) > 0)){
×
338
                        $AxisX->setTitle($xaxis_label, array('angle' => 0, 'size' => 10));
×
339
                }
340
                // x-axis labels:
341
                // Workaround according to http://pear.php.net/bugs/bug.php?id=8675
342
                $AxisX->setLabelOption('showOffset', true);
×
343
                switch($chart_type){
×
344
                        case CHARTTYPE_HOUR; // For time labels:
×
345
                                $AxisX->setLabelOption('offset', 200);
×
346
                                break;
×
347
                        case CHARTTYPE_DAY;
×
348
                        case CHARTTYPE_WEEK; // For days:
×
349
                                $AxisX->setLabelOption('offset', 60);
×
350
                                break;
×
351
                        case CHARTTYPE_MONTH;
×
352
                        case CHARTTYPE_YEAR; // For months:
×
353
                                $AxisX->setLabelOption('offset', 40);
×
354
                                break;
×
355
                        case CHARTTYPE_SRC_IP;
×
356
                        case CHARTTYPE_DST_IP; // for ip addresses:
×
357
                                $AxisX->setLabelOption('offset', 90);
×
358
                                break;
×
359
                        case CHARTTYPE_DST_UDP_PORT;
×
360
                        case CHARTTYPE_DST_TCP_PORT;
×
361
                        case CHARTTYPE_SRC_UDP_PORT;
×
362
                        case CHARTTYPE_SRC_TCP_PORT; // for port numbers
×
363
                                $AxisX->setLabelOption('offset', 25);
×
364
                                break;
×
365
                        case CHARTTYPE_CLASSIFICATION; // for classifications
×
366
                                $AxisX->setLabelOption('offset', 210);
×
367
                                break;
×
368
                        case CHARTTYPE_SENSOR; // for host names of sensors
×
369
                                $AxisX->setLabelOption('offset', 90);
×
370
                                break;
×
371
                        case CHARTTYPE_SRC_COUNTRY;
×
372
                        case CHARTTYPE_SRC_COUNTRY_ON_MAP;
×
373
                        case CHARTTYPE_DST_COUNTRY;
×
374
                        case CHARTTYPE_DST_COUNTRY_ON_MAP;
×
375
                                // 2-letter contry name plus complete country name
376
                                $AxisX->setLabelOption('offset', 110);
×
377
                                break;
×
378
                        case CHARTTYPE_UNIQUE_SIGNATURE;
×
379
                                // for signature names vs. num of alerts
380
                                $AxisX->setLabelOption('offset', 400);
×
381
                                break;
×
382
                        default;
×
383
                                $AxisX->setLabelOption('offset', 70);
×
384
                }
385
        }else{ // x-axis title if no rotation is required
×
386
                if ((isset($xaxis_label)) && (strlen($xaxis_label) > 0) ){
×
387
                        $AxisX->setTitle($xaxis_label, array('size' => 10));
×
388
                }
389
        }
390
        // Prepare y-axis title
391
        if ((isset($yaxis_label)) && (strlen($yaxis_label) > 0) ){
×
392
                $AxisY->setTitle($yaxis_label, array('angle' => 90, 'size' => 10));
×
393
        }
394
}
395
// Set markers (small rectangular labels inside the plot)
396
if ( $WorldMap ){ // Worldmap
×
397
    $Marker =& $Plot->setMarker(Image_Graph::factory('Image_Graph_Marker_Bubble'));
×
398
    $ValueMarker =& Image_Graph::factory('Image_Graph_Marker_Value', IMAGE_GRAPH_VALUE_X);
×
399
    // Image_Graph_Marker_Pointing_Angular or Image_Graph_Marker_Pointing_Radial? Both of them are not perfect.
400
    $Marker->setSecondaryMarker(Image_Graph::factory('Image_Graph_Marker_Pointing_Radial', array(40, &$ValueMarker)));
×
401
}else{
×
402
    $Marker =& $Plot->addNew('Image_Graph_Marker_Value', IMAGE_GRAPH_PCT_Y_TOTAL);
×
403
    $PointingMarker =& $Plot->addNew('Image_Graph_Marker_Pointing_Angular', array(20, &$Marker));
×
404
    $Plot->setMarker($PointingMarker);    
×
405
    $Marker->setDataPreprocessor(Image_Graph::factory('Image_Graph_DataPreprocessor_Formatted', '%0.1f%%'));
×
406
}
407
// background of the whole drawing board:
408
$Graph->setBackground(Image_Graph::factory('gradient', array(IMAGE_GRAPH_GRAD_VERTICAL, 'silver@0.5', 'white')));
×
409
$Graph->setBorderColor('black');
×
410
$Graph->setPadding(10);
×
411
// background of the plotarea only:
412
if ( !$WorldMap ){
×
413
        $Plotarea->setBackgroundColor('white');
×
414
}else{ // worldmap:
×
415
    $Plotarea->setFillColor('white');
×
416
    $FillArray2 =& Image_Graph::factory('Image_Graph_Fill_Array');
×
417
    $FillArray2->addColor('white');
×
418
    $Plotarea->setFillStyle($FillArray2);
×
419
}
420
$Plotarea->setBorderColor('black');
×
421
$Plotarea->setPadding(20);
×
422
$Plotarea->showShadow();
×
423
// and now all the filling tasks (gradients and the like) of the plot:
424
if ( $WorldMap ){ // Worldmap
×
425
        $Plot->setLineColor('gray'); // set a line color
×
426
        // set a standard fill style
427
    $FillArray =& Image_Graph::factory('Image_Graph_Fill_Array');
×
428
    $Marker->setFillStyle($FillArray);
×
429
    $FillArray->addColor('orange@0.5');
×
430
    $FillArray->addColor('green@0.5');
×
431
    $FillArray->addColor('blue@0.5');
×
432
    $FillArray->addColor('yellow@0.5');
×
433
    $FillArray->addColor('red@0.5');
×
434
    $FillArray->addColor('black@0.5');
×
435
}elseif( $style == "bar" ){
×
436
        $Plot->setFillStyle(Image_Graph::factory('gradient', array(IMAGE_GRAPH_GRAD_VERTICAL, 'white', 'red')));
×
437
}elseif ( $style == "line" ){
×
438
        $Plot->setFillStyle(Image_Graph::factory('gradient', array(IMAGE_GRAPH_GRAD_VERTICAL, 'orange', 'lightyellow')));
×
439
}elseif ( $style == "pie" ){
×
440
        // colours are each time determined randomly:
441
        // TODO:
442
        // While each colour name is taken only once rather than twice or multiple
443
        // times, the colours for two different colour names may appear on the
444
        // screen as if they were identical. Some names may also simply be aliases.
445
        // This can only be solved by removing the corresponding colour names from
446
        // this list.
447
        $mycolors = "aliceblue aquamarine azure beige bisque black blanchedalmond blue blueviolet brown burlywood cadetblue chocolate coral cornflowerblue cornsilk crimson cyan darkcyan darkgoldenrod darkgray darkgreen darkkhaki darkmagenta darkolivegreen darkorange darkorchid darkred darksalmon darkseagreen darkslateblue darkslategray darkviolet deeppink deepskyblue dimgray dodgerblue firebrick forestgreen fuchsia gainsboro gold goldenrod gray green greenyellow honeydew hotpink indianred indigo khaki lavender lawngreen lemonchiffon lightblue lightcoral lightcyan lightgoldenrodyellow lightgreen lightgrey lightpink lightsalmon lightseagreen lightslategray lightsteelblue lightyellow lime limegreen linen magenta maroon mediumaquamarine mediumorchid mediumpurple mediumseagreen mediumslateblue mediumspringgreen mediumturquoise mediumvioletred mistyrose navy oldlace olive olivedrab orange orangered orchid palegoldenrod palegreen paleturquoise palevioletred papayawhip peru pink powderblue purple red rosybrown royalblue saddlebrown salmon sandybrown seagreen sienna silver skyblue slateblue slategray springgreen steelblue tan teal thistle tomato violet wheat white yellow yellowgreen";
×
448
        // Colors removed: darkblue, plum, chartreuse, antiquewhite,
449
        // blanchedalmond, navajowhite, moccasin, peachpuff, aqua, darkturquoise,
450
        // lavenderblush, turquoise, lightskyblue, mediumturquoise, paleturquoise,
451
        // mediumblue, midnightblue, floralwhite, ghostwhite, ivory, mintcream,
452
        // snow, whitesmoke, seashell
453
        $color_array = explode(" ", $mycolors);
×
454
        $num_colors = count($color_array);
×
455
        shuffle($color_array);
×
456
        $FillArray =& Image_Graph::factory('Image_Graph_Fill_Array');
×
457
        for (
×
458
                $n = 0, $array_index = 0; $n < $number_elements; $n++, $array_index++
×
459
        ){
460
                if ( $array_index >= $num_colors ){ // Restart from the beginning
×
461
                        $array_index = 0;
×
462
                }
463
                $color_to_use = $color_array[$array_index];
×
464
      $FillArray->addNew('gradient', array(IMAGE_GRAPH_GRAD_RADIAL, 'white', $color_to_use));
×
465
        }
466
        // If there are a lot elements, we need some more space at the bottom:
467
        // (not really a good solution)
468
//        if ( $number_elements >= 10 ){
469
//                $Graph->setPadding(90);
470
//        }
471
        $Plot->setFillStyle($FillArray);
×
472
        $Plot->Radius = 2;
×
473
}else{
×
474
        error_log($EMPfx . "$style is an unsupported chart style");
×
475
}
476
// Show time! -- Alejandro
477
if ( version_compare(PHP_VERSION, "5.0.0", "<") ){
×
478
        $rv =& $Graph->done();
×
479
        if ( PEAR::isError($rv) ){
×
480
                error_log( $EMPfx . "ERROR: \$Graph->done() has failed.");
×
481
        }
482
}else{
×
483
        try{
×
484
                // $error = 'Always throw this error (1)';
485
                // throw new Exception($error);
486
                if (!headers_sent()){
×
487
                        $rv = $Graph->done();
×
488
                }else{
×
489
                        $rv = false;
×
490
                }
491
                if ( PEAR::isError($rv) ){
×
492
                        error_log($EMPfx . "ERROR: \$Graph->done() has failed.");
×
493
                }
494
        }
495
        catch ( Exception $exc1 ){
×
496
                $error = $exc1->getMessage();
×
497
                // Write the error message to apache's error log
498
                if ( isset($error) ){
×
499
                        error_log($EMPfx . "ERROR: \$Graph->done() has failed: \"" . $error . "\"");
×
500
                }else{
×
501
                        error_log($EMPfx . "ERROR: \$Graph->done() has failed.");
×
502
                }
503
                // and try and write the error message in form of a png to the screen
504
                try{
×
505
                        // $error = 'Always throw this error (2)';
506
                        // throw new Exception($error);
507
                        $im = @imagecreate(600, 80);
×
508
                        if ( isset($im) ){
×
509
          $background_color = imagecolorallocate($im, 255, 255, 255);
×
510
          $text_color = imagecolorallocate($im, 233, 14, 91);
×
511
                                imagestring($im, 5, 10, 10, __FILE__ . ":", $text_color);
×
512
          imagestring($im, 5, 10, 30, "Graph->done() has failed:", $text_color);
×
513
                                if ( isset($error) ){
×
514
                  imagestring($im, 5, 10, 50, $error , $text_color);
×
515
                                }else{
×
516
                                        imagestring($im, 5, 10, 50, "Unknown error." , $text_color);
×
517
                                }
518
                                imagepng($im);
×
519
                                imagedestroy($im);
×
520
                        }
521
                }
522
                catch ( Exception $exc2 ){
×
523
                        $error = $exc2->getMessage();
×
524
                        if ( isset($error) ){
×
525
                                error_log($EMPfx . "ERROR: Creating the error png has ALSO failed: \"" . $error . "\"");
×
526
                        }else{
×
527
                                error_log($EMPfx . "ERROR: Creating the error png has ALSO failed.");
×
528
                        }
529
                } // try - catch
530
        } // try - catch 
531
} // if (version_compare(PHP_VERSION, "5.0.0", "<"))
532
if ( $debug_mode > 0 ){
×
533
        $peak_memory = number_format(memory_get_peak_usage(TRUE));
×
534
        error_log($EMPfx . "peak_memory = $peak_memory bytes");
×
535
}
536
// Now, that the png has been drawn, we can allow the old value, again.
537
if ( !empty($old_display_error_type) ){
×
538
        ini_set("display_errors", $old_display_error_type);
×
539
}
540
}else{ // Graphics Libs Check failed.
×
541
        // @codeCoverageIgnoreStart
542
        // Should never execute. Log it.
543
        error_log($EMPfx . 'Graphics Libs check failed.');
544
        base_header("Location: base_graph_main.php");
545
        // @codeCoverageIgnoreEnd
546
}
547
?>
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc