diff options
-rw-r--r-- | config/haproxy-devel/haproxy.xml | 2 | ||||
-rw-r--r-- | config/haproxy-devel/pkg/haproxy.inc | 81 | ||||
-rw-r--r-- | config/haproxy-devel/pkg/haproxy_htmllist.inc | 4 | ||||
-rw-r--r-- | config/haproxy-devel/www/haproxy_files.php | 2 | ||||
-rw-r--r-- | config/haproxy-devel/www/haproxy_global.php | 113 | ||||
-rw-r--r-- | config/haproxy-devel/www/haproxy_pool_edit.php | 35 | ||||
-rw-r--r-- | pkg_config.10.xml | 2 | ||||
-rw-r--r-- | pkg_config.8.xml | 2 | ||||
-rw-r--r-- | pkg_config.8.xml.amd64 | 2 |
9 files changed, 220 insertions, 23 deletions
diff --git a/config/haproxy-devel/haproxy.xml b/config/haproxy-devel/haproxy.xml index 386e43a7..429b6c9f 100644 --- a/config/haproxy-devel/haproxy.xml +++ b/config/haproxy-devel/haproxy.xml @@ -42,7 +42,7 @@ ]]> </copyright> <name>haproxy</name> - <version>0.28</version> + <version>0.29</version> <title>HAProxy</title> <aftersaveredirect>/pkg_edit.php?xml=haproxy_pools.php</aftersaveredirect> <include_file>/usr/local/pkg/haproxy.inc</include_file> diff --git a/config/haproxy-devel/pkg/haproxy.inc b/config/haproxy-devel/pkg/haproxy.inc index eceef783..de1963b0 100644 --- a/config/haproxy-devel/pkg/haproxy.inc +++ b/config/haproxy-devel/pkg/haproxy.inc @@ -212,7 +212,18 @@ $a_error['500'] = array('descr' => "internal error"); $a_error['502'] = array('descr' => "server response invalid or blocked"); $a_error['503'] = array('descr' => "no server was available to handle the request"); $a_error['504'] = array('descr' => "timeout before the server responds"); - + +global $a_sysloglevel; +$a_sysloglevel = array(); +$a_sysloglevel['emerg'] = array('name' => "Emergency"); +$a_sysloglevel['alert'] = array('name' => "Alert"); +$a_sysloglevel['crit'] = array('name' => "Critical"); +$a_sysloglevel['err'] = array('name' => "Error"); +$a_sysloglevel['warning'] = array('name' => "Warning"); +$a_sysloglevel['notice'] = array('name' => "Notice"); +$a_sysloglevel['info'] = array('name' => "Informational"); +$a_sysloglevel['debug'] = array('name' => "Debugging"); + if(!function_exists('group_ports')){ // function group_ports() is present in pfSense 2.2 in util.inc /* create ranges of sequential port numbers (200:215) and remove duplicates */ @@ -264,6 +275,15 @@ function group_ports($ports) { } } +global $haproxy_version; +function haproxy_verion() { + global $haproxy_version; + if (empty($haproxy_version)) { + $haproxy_version = shell_exec("haproxy -v | head -n 1 | awk '{ print $3 }'"); + } + return $haproxy_version; +} + function haproxy_portoralias_to_list($port_or_alias) { // input: a port or aliasname: 80 https MyPortAlias // returns: a array of ports and portranges 80 443 8000:8010 @@ -592,8 +612,11 @@ function haproxy_find_acl($name) { } function write_backend($configpath, $fd, $name, $pool, $backendsettings) { + global $config; $frontend = $backendsettings['frontend']; $ipversion = $backendsettings['ipversion']; + $a_global = &$config['installedpackages']['haproxy']; + $a_mailers = &$config['installedpackages']['haproxy']['email_mailers']['items']; if(!is_array($pool['ha_servers']['item']) && !$pool['stats_enabled']=='yes') return; @@ -610,6 +633,36 @@ function write_backend($configpath, $fd, $name, $pool, $backendsettings) { $backend_mode = $frontendtype; } fwrite ($fd, "\tmode\t\t\t" . $backend_mode . "\n"); + + if (haproxy_verion() >= '1.6') { + $use_mailers = is_array($a_mailers) && count($a_mailers) > 0; + if ($use_mailers) { + fwrite ($fd, "\t# use mailers\n"); + if (empty($pool['email_level'])) { + $email_level = $a_global['email_level']; + } else { + $email_level = $pool['email_level']; + } + + fwrite ($fd, "\t# level $email_level \n"); + if (!empty($email_level) && $email_level != 'dontlog') { + if (empty($pool['email_to'])) { + $email_to = $a_global['email_to']; + } else { + $email_to = $pool['email_to']; + } + + fwrite ($fd, "\temail-alert mailers\t\t\tglobalmailers\n"); + fwrite ($fd, "\temail-alert level\t\t\t{$email_level}\n"); + fwrite ($fd, "\temail-alert from\t\t\t{$a_global['email_from']}\n"); + fwrite ($fd, "\temail-alert to\t\t\t{$email_to}\n"); + if (!empty($a_global['email_myhostname'])) { + fwrite ($fd, "\temail-alert myhostname\t\t\t{$a_global['email_myhostname']}\n"); + } + } + } + } + if ($pool['log-health-checks'] == 'yes') fwrite ($fd, "\toption\t\t\tlog-health-checks\n"); @@ -732,8 +785,6 @@ function write_backend($configpath, $fd, $name, $pool, $backendsettings) { if ($check_type == "Agent") { $checkport = " port " . $pool['monitor_agentport']; } - } else { - $optioncheck = "httpchk"; } if($pool['balance']) @@ -1049,9 +1100,9 @@ function haproxy_updateocsp($socketupdate = true) { haproxy_updateocsp_one($socketupdate, $filename, $frontend['name']); $subfolder = "$configpath/{$frontend['name']}"; - $certs = $frontend['ha_certificates']['item']; - if (is_array($certs)){ - foreach($certs as $cert){ + if (is_arrayset($frontend, 'ha_certificates', 'item')) { + $certs = $frontend['ha_certificates']['item']; + foreach($certs as $cert) { $filename = "$subfolder/{$cert['ssl_certificate']}.pem"; haproxy_updateocsp_one($socketupdate, $filename, $frontend['name']); } @@ -1075,6 +1126,7 @@ function haproxy_writeconf($configpath) { $a_global = &$config['installedpackages']['haproxy']; $a_frontends = &$config['installedpackages']['haproxy']['ha_backends']['item']; $a_backends = &$config['installedpackages']['haproxy']['ha_pools']['item']; + $a_mailers = &$config['installedpackages']['haproxy']['email_mailers']['items']; $fd = fopen($configfile, "w"); if(is_array($a_global)) { @@ -1130,6 +1182,17 @@ function haproxy_writeconf($configpath) { fwrite ($fd, "\n"); } } + + if (haproxy_verion() >= '1.6') { + $use_mailers = is_array($a_mailers) && count($a_mailers) > 0; + if ($use_mailers) { + fwrite ($fd, "mailers globalmailers\n"); + foreach($a_mailers as $mailer) { + fwrite ($fd, "\tmailer {$mailer['name']} {$mailer['mailserver']}:{$mailer['mailserverport']}\n"); + } + fwrite ($fd, "\n"); + } + } // Try and get a unique array for address:port as frontends can duplicate $a_bind = array(); @@ -1158,7 +1221,8 @@ function haproxy_writeconf($configpath) { haproxy_write_certificate_fullchain($filename, $frontend['ssloffloadcert']); if ($frontend['sslocsp'] == 'yes') { - if (!empty(haproxy_getocspurl($filename))) { + $ocspurl = haproxy_getocspurl($filename); + if (!empty($ocspurl)) { haproxy_write_certificate_issuer($filename . ".issuer", $frontend['ssloffloadcert']); touch($filename . ".ocsp");//create initial empty file. this will trigger updates, and inform haproxy it 'should' be using ocsp } @@ -1173,7 +1237,8 @@ function haproxy_writeconf($configpath) { $filenamefoldercert = "$subfolder/{$cert['ssl_certificate']}.pem"; haproxy_write_certificate_fullchain($filenamefoldercert, $cert['ssl_certificate']); if ($frontend['sslocsp'] == 'yes') { - if (!empty(haproxy_getocspurl($filenamefoldercert))) { + $ocspurl = haproxy_getocspurl($filenamefoldercert); + if (!empty($ocspurl)) { haproxy_write_certificate_issuer($filenamefoldercert . ".issuer", $cert['ssl_certificate']); touch($filenamefoldercert . ".ocsp"); } diff --git a/config/haproxy-devel/pkg/haproxy_htmllist.inc b/config/haproxy-devel/pkg/haproxy_htmllist.inc index f873028e..394f3ff6 100644 --- a/config/haproxy-devel/pkg/haproxy_htmllist.inc +++ b/config/haproxy-devel/pkg/haproxy_htmllist.inc @@ -114,7 +114,9 @@ class HaproxyHtmlList echo $itemvalue=='yes' ? gettext('yes') : gettext('no'); } else if ($itemtype == "textarea"){ - echo htmlspecialchars(base64_decode($itemvalue)); + echo '<div style="overlow:scroll;max-height:120px;overflow-y: scroll;">'; + echo str_replace("\n","<br/>", htmlspecialchars(base64_decode($itemvalue))); + echo '</div>'; } else echo htmlspecialchars($itemvalue); } diff --git a/config/haproxy-devel/www/haproxy_files.php b/config/haproxy-devel/www/haproxy_files.php index 4946a7be..12ab5a88 100644 --- a/config/haproxy-devel/www/haproxy_files.php +++ b/config/haproxy-devel/www/haproxy_files.php @@ -155,7 +155,7 @@ include("head.inc"); </tr> <tr> <td width="78%"> - <input name="Submit" type="submit" class="formbtn" value="Save" onClick="enable_change(true)" /> + <input name="Submit" type="submit" class="formbtn" value="Save" /> </td> </tr> </table> diff --git a/config/haproxy-devel/www/haproxy_global.php b/config/haproxy-devel/www/haproxy_global.php index 978d778d..2ae92256 100644 --- a/config/haproxy-devel/www/haproxy_global.php +++ b/config/haproxy-devel/www/haproxy_global.php @@ -35,13 +35,38 @@ require_once("haproxy.inc"); require_once("haproxy_utils.inc"); require_once("globals.inc"); require_once("pkg_haproxy_tabs.inc"); +require_once("haproxy_htmllist.inc"); -$simplefields = array('localstats_refreshtime','localstats_sticktable_refreshtime','log-send-hostname','ssldefaultdhparam'); +$simplefields = array('localstats_refreshtime', 'localstats_sticktable_refreshtime', 'log-send-hostname', 'ssldefaultdhparam', + 'email_level', 'email_myhostname', 'email_from', 'email_to'); + +$none = array(); +$none['']['name'] = "Dont log"; +$a_sysloglevel = $none + $a_sysloglevel; + +$fields_mailers = array(); +$fields_mailers[0]['name'] = "name"; +$fields_mailers[0]['columnheader'] = "Name"; +$fields_mailers[0]['colwidth'] = "30%"; +$fields_mailers[0]['type'] = "textbox"; +$fields_mailers[0]['size'] = "20"; +$fields_mailers[1]['name'] = "mailserver"; +$fields_mailers[1]['columnheader'] = "Mailserver"; +$fields_mailers[1]['colwidth'] = "60%"; +$fields_mailers[1]['type'] = "textbox"; +$fields_mailers[1]['size'] = "60"; +$fields_mailers[2]['name'] = "mailserverport"; +$fields_mailers[2]['columnheader'] = "Mailserverport"; +$fields_mailers[2]['colwidth'] = "10%"; +$fields_mailers[2]['type'] = "textbox"; +$fields_mailers[2]['size'] = "10"; + +$mailerslist = new HaproxyHtmlList("table_mailers", $fields_mailers); +$mailerslist->keyfield = "name"; if (!is_array($config['installedpackages']['haproxy'])) $config['installedpackages']['haproxy'] = array(); - if ($_POST) { unset($input_errors); $pconfig = $_POST; @@ -56,16 +81,12 @@ if ($_POST) { if ($result) unlink_if_exists($d_haproxyconfdirty_path); } else { - //if ($_POST['enable']) { - // $reqdfields = explode(" ", "maxconn"); - // $reqdfieldsn = explode(",", "Maximum connections"); - //} + $a_mailers = $mailerslist->haproxy_htmllist_get_values(); + $pool['ha_servers']['item'] = $a_servers; if ($_POST['carpdev'] == "disabled") unset($_POST['carpdev']); - //do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors); - if ($_POST['maxconn'] && (!is_numeric($_POST['maxconn']))) $input_errors[] = "The maximum number of connections should be numeric."; @@ -86,6 +107,8 @@ if ($_POST) { $input_errors[] = "Synchost3 needs to be an IPAddress.";*/ if (!$input_errors) { + $config['installedpackages']['haproxy']['email_mailers']['items'] = $a_mailers; + $config['installedpackages']['haproxy']['enable'] = $_POST['enable'] ? true : false; $config['installedpackages']['haproxy']['terminate_on_reload'] = $_POST['terminate_on_reload'] ? true : false; $config['installedpackages']['haproxy']['maxconn'] = $_POST['maxconn'] ? $_POST['maxconn'] : false; @@ -109,6 +132,8 @@ if ($_POST) { } } +$a_mailers = $config['installedpackages']['haproxy']['email_mailers']['items']; + $pconfig['enable'] = isset($config['installedpackages']['haproxy']['enable']); $pconfig['terminate_on_reload'] = isset($config['installedpackages']['haproxy']['terminate_on_reload']); $pconfig['maxconn'] = $config['installedpackages']['haproxy']['maxconn']; @@ -183,6 +208,12 @@ function enable_change(enable_change) { <strong>Enable HAProxy</strong></td> </tr> <tr> + <td width="22%" valign="top" class="vncell">Installed version:</td> + <td width="78%" class="vtable"> + <strong><?=haproxy_verion()?></strong> + </td> + </tr> + <tr> <td valign="top" class="vncell"> Maximum connections </td> @@ -368,6 +399,64 @@ function enable_change(enable_change) { <input name="log-send-hostname" type="text" <?if(isset($pconfig['log-send-hostname'])) echo "value=\"{$pconfig['log-send-hostname']}\"";?> size="18" maxlength="50" /> EXAMPLE: HaproxyMasterNode<br/>Sets the hostname field in the syslog header. If empty defaults to the system hostname. </td> </tr> + <tr><td> </td></tr> + <? if (haproxy_verion() >= '1.6' ) { ?> + <tr> + <td colspan="2" valign="top" class="listtopic">Email notifications</td> + </tr> + <tr> + <td valign="top" class="vncell"> + Mailer servers + </td> + <td class="vtable"> + It is possible to send email alerts when the state of servers changes. If configured email alerts are sent to each mailer that is configured in a mailers section. Email is sent to mailers using SMTP. + <br/> + <? + $counter=0; + $mailerslist->Draw($a_mailers); + ?> + </td> + </tr> + <tr> + <td valign="top" class="vncell"> + Mail level + </td> + <td class="vtable"> + <? + echo_html_select('email_level', $a_sysloglevel, $pconfig['email_level']); + ?> + Define the maximum loglevel to send emails for. + </td> + </tr> + <tr> + <td valign="top" class="vncell"> + Mail myhostname + </td> + <td class="vtable"> + <input name="email_myhostname" type="text" <?if(isset($pconfig['email_myhostname'])) echo "value=\"{$pconfig['email_myhostname']}\"";?> size="50" /><br/> + Define hostname to use as sending the emails. + </td> + </tr> + <tr> + <td valign="top" class="vncell"> + Mail from + </td> + <td class="vtable"> + <input name="email_from" type="text" <?if(isset($pconfig['email_from'])) echo "value=\"{$pconfig['email_from']}\"";?> size="50"/><br/> + Email address to be used as the sender of the emails. + </td> + </tr> + <tr> + <td valign="top" class="vncell"> + Mail to + </td> + <td class="vtable"> + <input name="email_to" type="text" <?if(isset($pconfig['email_to'])) echo "value=\"{$pconfig['email_to']}\"";?> size="50"/><br/> + Email address to send emails to. + </td> + </tr> + <? } ?> + <tr><td> </td></tr> <tr> <td colspan="2" valign="top" class="listtopic">Tuning</td> </tr> @@ -487,7 +576,15 @@ Minimum and default value is: 1024, bigger values might increase CPU usage.<br/> <?php endif; ?> </form> +<? +haproxy_htmllist_js(); +?> <script type="text/javascript"> + totalrows = <?php echo $counter; ?>; +<? + phparray_to_javascriptarray($fields_mailers,"fields_mailers",Array('/*','/*/name','/*/type','/*/size','/*/items','/*/items/*','/*/items/*/*','/*/items/*/*/name')); +?> + function scroll_after_fade() { scrollTo(0,99999999999); } diff --git a/config/haproxy-devel/www/haproxy_pool_edit.php b/config/haproxy-devel/www/haproxy_pool_edit.php index 0824e45c..6cd78741 100644 --- a/config/haproxy-devel/www/haproxy_pool_edit.php +++ b/config/haproxy-devel/www/haproxy_pool_edit.php @@ -65,7 +65,8 @@ $simplefields = array( "stats_enabled","stats_username","stats_password","stats_uri","stats_scope","stats_realm","stats_admin","stats_node","stats_desc","stats_refresh", "persist_stick_expire","persist_stick_tablesize","persist_stick_length","persist_stick_cookiename","persist_sticky_type", "persist_cookie_enabled","persist_cookie_name","persist_cookie_mode","persist_cookie_cachable", -"strict_transport_security","cookie_attribute_secure" +"strict_transport_security", "cookie_attribute_secure", +"email_level", "email_to" ); $primaryfrontends = get_haproxy_frontends(); @@ -73,6 +74,12 @@ $none = array(); $none['']['name']="Address+Port:"; $primaryfrontends = $none + $primaryfrontends; +$default = array(); +$default['']['name'] = "Default level from global"; +$none = array(); +$none['dontlog']['name'] = "Dont log"; +$a_sysloglevel = $default + $none + $a_sysloglevel; + $fields_servers=array(); $fields_servers[0]['name']="status"; $fields_servers[0]['columnheader']="Mode"; @@ -861,6 +868,32 @@ set by the 'retries' parameter.</div> </td> </tr> <tr><td> </td></tr> + <? if (haproxy_verion() >= '1.6' ) { ?> + <tr> + <td colspan="2" valign="top" class="listtopic">Email notifications</td> + </tr> + <tr> + <td valign="top" class="vncell"> + Mail level + </td> + <td class="vtable"> + <? + echo_html_select('email_level', $a_sysloglevel, $pconfig['email_level']); + ?> + Define the maximum loglevel to send emails for. + </td> + </tr> + <tr> + <td valign="top" class="vncell"> + Mail to + </td> + <td class="vtable"> + <input name="email_to" type="text" <?if(isset($pconfig['email_to'])) echo "value=\"{$pconfig['email_to']}\"";?> size="50"/><br/> + Email address to send emails to, defaults to the value set on the global settings tab. + </td> + </tr> + <tr><td> </td></tr> + <? } ?> <tr> <td colspan="2" valign="top" class="listtopic">Statistics</td> </tr> diff --git a/pkg_config.10.xml b/pkg_config.10.xml index 0ecde95c..48133931 100644 --- a/pkg_config.10.xml +++ b/pkg_config.10.xml @@ -143,7 +143,7 @@ </descr> <website>http://haproxy.1wt.eu/</website> <category>Services</category> - <version>0.28</version> + <version>0.29</version> <status>Release</status> <required_version>2.2</required_version> <config_file>https://packages.pfsense.org/packages/config/haproxy1_5/haproxy.xml</config_file> diff --git a/pkg_config.8.xml b/pkg_config.8.xml index ce02021b..1b5d6d58 100644 --- a/pkg_config.8.xml +++ b/pkg_config.8.xml @@ -166,7 +166,7 @@ Supports ACLs for smart backend switching.]]></descr> <website>http://haproxy.1wt.eu/</website> <category>Services</category> - <version>1.5.3 pkg v 0.27</version> + <version>1.5.3 pkg v 0.29</version> <status>Release</status> <required_version>2.1</required_version> <config_file>https://packages.pfsense.org/packages/config/haproxy1_5/haproxy.xml</config_file> diff --git a/pkg_config.8.xml.amd64 b/pkg_config.8.xml.amd64 index 9751fe3e..026b18fe 100644 --- a/pkg_config.8.xml.amd64 +++ b/pkg_config.8.xml.amd64 @@ -153,7 +153,7 @@ Supports ACLs for smart backend switching.]]></descr> <website>http://haproxy.1wt.eu/</website> <category>Services</category> - <version>1.5.3 pkg v 0.27</version> + <version>1.5.3 pkg v 0.29</version> <status>Release</status> <required_version>2.1</required_version> <config_file>https://packages.pfsense.org/packages/config/haproxy1_5/haproxy.xml</config_file> |