histogram: Make histograms crash less
[ninja.git] / application / controllers / public.php
blobc31573ce17a1edfbb86ad81cae13eef07f200a48
1 <?php defined('SYSPATH') OR die('No direct access allowed.');
3 /**
4 * A controller that is sometimes available without authorization.
6 * That is, things here shouldn't expose secrets, but for DoS reasons,
7 * they're still not available from anybody who's both non-localhost (reports)
8 * and non-logged-in (actual users)
9 */
10 class Public_Controller extends Controller {
11 public function __construct()
13 // No current user
14 if (!Auth::instance()->get_user()) {
15 // And we don't come from ::1 or 127.0.0.0/8
16 if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) || !($_SERVER['REMOTE_ADDR'] == '::1' || (ip2long($_SERVER['REMOTE_ADDR']) & (127 << 24)) !== (127 << 24))) {
17 // So we won't do anything
18 die("Invalid request");
23 /**
24 * Create a piechart
26 public function piechart()
28 $this->auto_render = false;
29 charts::load('Pie');
30 $graph = new PieChart(300, 200);
31 $graph->set_data($_GET, 'pie');
32 $graph->set_margins(43);
33 $graph->set_legend_precision(3);
35 $graph->draw();
36 $graph->display();
39 /**
40 * Create a barchart
42 public function barchart()
44 $this->auto_render = false;
45 charts::load('MultipleBar');
46 $graph = new MultipleBarChart(800, 600);
48 $barvalues = false;
49 $barcolors = false;
50 foreach ($_GET as $tmpkey => $tmpval) {
51 $barvalues[$tmpkey] = array(
52 str_replace(',', '.', $tmpval[1]),
53 str_replace(',', '.', $tmpval[0])
55 $barcolors[] = false;
56 $barcolors[] = $tmpval[2] ? reports::$colors['red'] : reports::$colors['green'];
59 $graph->add_bar_colors($barcolors);
60 $graph->set_background_style(null);
61 $graph->set_plot_bg_color('#fff');
62 $graph->set_data($barvalues);
63 $graph->set_margins(7, 20);
64 $graph->set_approx_line_gap(50);
65 $graph->set_legend_y(_('Percent (%)'));
66 $graph->set_legend_x(_('Period'));
68 $graph->draw();
69 $graph->display();