From b5388f033c51ba1102ec00d8c1d604c6ea39827d Mon Sep 17 00:00:00 2001 From: Renato Botelho Date: Mon, 24 Feb 2014 12:24:52 -0300 Subject: [PATCH] Fix #2302, save custom uploaded l7 pattern files on config.xml and replicate it to slave --- etc/inc/shaper.inc | 16 ++++++++++++++++ usr/local/www/diag_patterns.php | 5 +++++ 2 files changed, 21 insertions(+) diff --git a/etc/inc/shaper.inc b/etc/inc/shaper.inc index 4edd21c33f..9e06ab9de6 100644 --- a/etc/inc/shaper.inc +++ b/etc/inc/shaper.inc @@ -4084,6 +4084,17 @@ function read_layer7_config() { } } +function update_layer7_custom_patterns() { + global $config; + + if (!is_array($config['l7shaper']['custom_pat'])) + return; + + foreach ($config['l7shaper']['custom_pat'] as $filename => $filecontent) + if (!file_exists("/usr/local/share/protocols/" . $filename)) + @file_put_contents("/usr/local/share/protocols/" . $filename, base64_decode($filecontent)); +} + function generate_layer7_files() { global $layer7_rules_list, $g; @@ -4096,6 +4107,8 @@ function generate_layer7_files() { array_map('unlink', glob("{$g['tmp_path']}/*.l7")); } + update_layer7_custom_patterns(); + foreach($layer7_rules_list as $l7rules) { if($l7rules->GetREnabled()) { $filename = $l7rules->GetRName() . ".l7"; @@ -4140,6 +4153,9 @@ function layer7_start_l7daemon() { // This function uses /usr/local/share/protocols as a default directory for searching .pat files function generate_protocols_array() { + + update_layer7_custom_patterns(); + $protocols = return_dir_as_array("/usr/local/share/protocols"); $protocols_new = array(); if(is_array($protocols)) { diff --git a/usr/local/www/diag_patterns.php b/usr/local/www/diag_patterns.php index e545fc76e7..da7969e9e1 100755 --- a/usr/local/www/diag_patterns.php +++ b/usr/local/www/diag_patterns.php @@ -42,6 +42,11 @@ require("guiconfig.inc"); //Move the upload file to /usr/local/share/protocols (is_uploaded_file must use tmp_name as argument) if (($_POST['submit'] == gettext("Upload Pattern file")) && is_uploaded_file($_FILES['ulfile']['tmp_name'])) { if(fileExtension($_FILES['ulfile']['name'])) { + if (!is_array($config['l7shaper']['custom_pat'])) + $config['l7shaper']['custom_pat'] = array(); + + $config['l7shaper']['custom_pat'][$_FILES['ulfile']['name']] = base64_encode(file_get_contents($_FILES['ulfile']['tmp_name'])); + write_config(sprintf(gettext("Added custom l7 pattern %s"), $_FILES['ulfile']['name'])); move_uploaded_file($_FILES['ulfile']['tmp_name'], "/usr/local/share/protocols/" . $_FILES['ulfile']['name']); $ulmsg = gettext("Uploaded file to") . " /usr/local/share/protocols/" . htmlentities($_FILES['ulfile']['name']); }