diff --git a/doc/Installation/Installation-CentOS-7-Nginx.md b/doc/Installation/Installation-CentOS-7-Nginx.md index 0edd59042f..5a4ca2e79b 100644 --- a/doc/Installation/Installation-CentOS-7-Nginx.md +++ b/doc/Installation/Installation-CentOS-7-Nginx.md @@ -99,6 +99,8 @@ server { index index.php; access_log /opt/librenms/logs/access_log; error_log /opt/librenms/logs/error_log; + gzip on; + gzip_types text/css application/x-javascript text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon; location / { try_files $uri $uri/ @librenms; } diff --git a/doc/Installation/Installation-Ubuntu-1404-Nginx.md b/doc/Installation/Installation-Ubuntu-1404-Nginx.md index c13dc2966b..6e3c88dfcc 100644 --- a/doc/Installation/Installation-Ubuntu-1404-Nginx.md +++ b/doc/Installation/Installation-Ubuntu-1404-Nginx.md @@ -123,6 +123,8 @@ server { index index.php; access_log /opt/librenms/logs/access_log; error_log /opt/librenms/logs/error_log; + gzip on; + gzip_types text/css application/x-javascript text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon; location / { try_files $uri $uri/ @librenms; } diff --git a/doc/Installation/Installation-Ubuntu-1604-Nginx.md b/doc/Installation/Installation-Ubuntu-1604-Nginx.md index 02a840afa6..ef529b0f73 100644 --- a/doc/Installation/Installation-Ubuntu-1604-Nginx.md +++ b/doc/Installation/Installation-Ubuntu-1604-Nginx.md @@ -79,6 +79,8 @@ server { index index.php; access_log /opt/librenms/logs/access_log; error_log /opt/librenms/logs/error_log; + gzip on; + gzip_types text/css application/x-javascript text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon; location / { try_files $uri $uri/ @librenms; } diff --git a/html/.htaccess b/html/.htaccess index 44bd1687d2..692f5c2450 100644 --- a/html/.htaccess +++ b/html/.htaccess @@ -3,6 +3,9 @@ Options FollowSymlinks Multiviews +AddType image/svg+xml .svg +AddOutputFilterByType DEFLATE image/svg+xml + RewriteEngine on RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f diff --git a/html/includes/api_functions.inc.php b/html/includes/api_functions.inc.php index c5b357c799..3898ef239f 100644 --- a/html/includes/api_functions.inc.php +++ b/html/includes/api_functions.inc.php @@ -72,7 +72,7 @@ function get_graph_by_port_hostname() $vars['height'] = $_GET['height'] ?: 300; $auth = '1'; $vars['id'] = dbFetchCell("SELECT `P`.`port_id` FROM `ports` AS `P` JOIN `devices` AS `D` ON `P`.`device_id` = `D`.`device_id` WHERE `D`.`hostname`=? AND `P`.`$port`=? AND `deleted` = 0 LIMIT 1", array($hostname, $vars['port'])); - $app->response->headers->set('Content-Type', 'image/png'); + $app->response->headers->set(set_image_type()); rrdtool_initialize(false); include 'includes/graphs/graph.inc.php'; rrdtool_close(); @@ -149,7 +149,7 @@ function get_graph_generic_by_hostname() $vars['height'] = $_GET['height'] ?: 300; $auth = '1'; $vars['device'] = dbFetchCell('SELECT `D`.`device_id` FROM `devices` AS `D` WHERE `D`.`hostname`=?', array($hostname)); - $app->response->headers->set('Content-Type', 'image/png'); + $app->response->headers->set(set_image_type()); rrdtool_initialize(false); include 'includes/graphs/graph.inc.php'; rrdtool_close(); @@ -514,7 +514,7 @@ function get_graph_by_portgroup() unset($seperator); $vars['type'] = 'multiport_bits_separate'; $vars['id'] = $if_list; - $app->response->headers->set('Content-Type', 'image/png'); + $app->response->headers->set(set_image_type()); rrdtool_initialize(false); include 'includes/graphs/graph.inc.php'; rrdtool_close(); diff --git a/html/includes/functions.inc.php b/html/includes/functions.inc.php index 0c87c954c4..6aae40f280 100644 --- a/html/includes/functions.inc.php +++ b/html/includes/functions.inc.php @@ -1419,3 +1419,17 @@ function eventlog_severity($eventlog_severity) break; } } // end eventlog_severity + +/** + * + */ +function set_image_type() +{ + global $config; + + if ($config['webui']['graph_type'] === 'svg') { + return header('Content-type: image/svg+xml'); + } else { + return header('Content-type: image/png'); + } +} diff --git a/html/includes/graphs/common.inc.php b/html/includes/graphs/common.inc.php index 33f6002f09..fe9b264dc1 100644 --- a/html/includes/graphs/common.inc.php +++ b/html/includes/graphs/common.inc.php @@ -9,7 +9,7 @@ if ($_GET['to']) { } if ($_GET['width']) { - $width = mres($_GET['width']); + $width = mres($vars['width']); } if ($config['trim_tobias']) { @@ -17,7 +17,7 @@ if ($config['trim_tobias']) { } if ($_GET['height']) { - $height = mres($_GET['height']); + $height = mres($vars['height']); } if ($_GET['inverse']) { diff --git a/html/includes/graphs/graph.inc.php b/html/includes/graphs/graph.inc.php index e8091a5c9e..a69cad918b 100644 --- a/html/includes/graphs/graph.inc.php +++ b/html/includes/graphs/graph.inc.php @@ -31,7 +31,7 @@ $period = ($to - $from); $prev_from = ($from - $period); -$graphfile = $config['temp_dir'].'/'.strgen().'.png'; +$graphfile = $config['temp_dir'].'/'.strgen(); $type = $graphtype['type']; $subtype = $graphtype['subtype']; @@ -102,6 +102,10 @@ if ($error_msg) { } } else { // $rrd_options .= " HRULE:0#999999"; + if ($config['webui']['graph_type'] === 'svg') { + $rrd_options .= " --imgformat=SVG -m 0.75"; + } + if ($no_file) { if ($width < 200) { graph_error('No RRD'); @@ -125,8 +129,8 @@ if ($error_msg) { if (is_file($graphfile)) { if (!$debug) { - header('Content-type: image/png'); - if ($config['trim_tobias']) { + set_image_type(); + if ($config['trim_tobias'] && $config['webui']['graph_type'] !== 'svg') { list($w, $h, $type, $attr) = getimagesize($graphfile); $src_im = imagecreatefrompng($graphfile); $src_x = '0'; @@ -156,7 +160,7 @@ if ($error_msg) { } } else { echo `ls -l $graphfile`; - echo 'graph'; + echo 'graph'; } unlink($graphfile); } else { diff --git a/html/pages/settings/webui.inc.php b/html/pages/settings/webui.inc.php index b1ff79a24c..5689f9ae2c 100644 --- a/html/pages/settings/webui.inc.php +++ b/html/pages/settings/webui.inc.php @@ -12,9 +12,17 @@ $search_conf = array( ); $graph_conf = array( - array('name' => 'webui.min_graph_height', - 'descr' => 'Set the minimum graph height', - 'type' => 'text', + array('name' => 'webui.min_graph_height', + 'descr' => 'Set the minimum graph height', + 'type' => 'text', + ), + array('name' => 'webui.graph_type', + 'descr' => 'Set the graph type', + 'type' => 'select', + 'options' => array( + 'png' => 'png', + 'svg' => 'svg', + ), ), ); diff --git a/sql-schema/166.sql b/sql-schema/166.sql new file mode 100644 index 0000000000..97df71f53a --- /dev/null +++ b/sql-schema/166.sql @@ -0,0 +1 @@ +INSERT INTO config (config_name,config_value,config_default,config_descr,config_group,config_group_order,config_sub_group,config_sub_group_order,config_hidden,config_disabled) values ('webui.graph_type','png','png','Set the default graph type','webui',0,'graph',0,'0','0'); \ No newline at end of file