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

NathanGibbs3 / BASE / 624

pending completion
624

push

travis-ci-com

NathanGibbs3
Merge branch 'devel'

562 of 562 new or added lines in 28 files covered. (100.0%)

3145 of 17504 relevant lines covered (17.97%)

23.22 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
$sc = DIRECTORY_SEPARATOR;
×
36
require_once("includes$sc" . 'base_krnl.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
        $OUIM = $BCR->GetCap('UIMode');
×
44
        $BCR->AddCap('UIMode', 'Gfx');
×
45

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

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

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

221
// Configure plotarea
222
if ( $WorldMap ){ // Worldmap
×
223
  //  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
224
  //  ini_set("memory_limit", "100M");
225
  //  $Legend->setPlotarea($Plotarea);
226
}elseif($style == "pie"){
×
227
        $Legend->setPlotarea($Plotarea);
×
228
}else{
×
229
  $Plotarea->setAxisPadding(30, 'top');
×
230
  $Plotarea->setAxisPadding(30, 'bottom');
×
231
  $Plotarea->setAxisPadding(10, 'left');
×
232
  $Plotarea->setAxisPadding(10, 'right');
×
233
}
234

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

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

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