diff --git a/Makefile.in b/Makefile.in index fbc896958..32648b42e 100644 --- a/Makefile.in +++ b/Makefile.in @@ -241,7 +241,6 @@ IS_LSCPD = @IS_LSCPD@ LD = @LD@ LDFLAGS = @LDFLAGS@ LIBBROTLI = @LIBBROTLI@ -LIBGEOIP = @LIBGEOIP@ LIBMMDB = @LIBMMDB@ LIBOBJS = @LIBOBJS@ LIBS = @LIBS@ diff --git a/configure b/configure index a78c355b7..0736f8c11 100755 --- a/configure +++ b/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.69 for openlitespeed 1.5.7. +# Generated by GNU Autoconf 2.69 for openlitespeed 1.5.8. # # Report bugs to . # @@ -590,8 +590,8 @@ MAKEFLAGS= # Identity of this package. PACKAGE_NAME='openlitespeed' PACKAGE_TARNAME='openlitespeed' -PACKAGE_VERSION='1.5.7' -PACKAGE_STRING='openlitespeed 1.5.7' +PACKAGE_VERSION='1.5.8' +PACKAGE_STRING='openlitespeed 1.5.8' PACKAGE_BUGREPORT='info@litespeedtech.com' PACKAGE_URL='http://www.litespeedtech.com/' @@ -664,7 +664,6 @@ USE_DYN_OSSL_FALSE USE_DYN_OSSL_TRUE OPENLSWS_BSSL LIBMMDB -LIBGEOIP LIBBROTLI HAVE_LIBLUA_FALSE HAVE_LIBLUA_TRUE @@ -833,7 +832,6 @@ enable_debug enable_profiling with_lua with_brotli -enable_iptogeo with_iptogeo2 with_bssl enable_recaptcha @@ -1401,7 +1399,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures openlitespeed 1.5.7 to adapt to many kinds of systems. +\`configure' configures openlitespeed 1.5.8 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1471,7 +1469,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of openlitespeed 1.5.7:";; + short | recursive ) echo "Configuration of openlitespeed 1.5.8:";; esac cat <<\_ACEOF @@ -1500,9 +1498,6 @@ Optional Features: default) --enable-profiling Enable cpu profiling (profiling is disabled by default) - --enable-iptogeo=[yes/no] - Enable iptogeo which need to have Geoip library - installed [default=yes] --enable-recaptcha=[yes/no] Enable recaptcha [default=yes] --disable-rpath Disable rpath (It is 'no' by default) @@ -1630,7 +1625,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -openlitespeed configure 1.5.7 +openlitespeed configure 1.5.8 generated by GNU Autoconf 2.69 Copyright (C) 2012 Free Software Foundation, Inc. @@ -2304,7 +2299,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by openlitespeed $as_me 1.5.7, which was +It was created by openlitespeed $as_me 1.5.8, which was generated by GNU Autoconf 2.69. Invocation command line was $ $0 $@ @@ -3170,7 +3165,7 @@ fi # Define the identity of the package. PACKAGE='openlitespeed' - VERSION='1.5.7' + VERSION='1.5.8' # Some tools Automake needs. @@ -16102,30 +16097,6 @@ echo "LIBBROTLI=$LIBBROTLI" -LIBGEOIP=" -lGeoIP " -OPENLSWS_IPTOGEO=yes -# Check whether --enable-iptogeo was given. -if test "${enable_iptogeo+set}" = set; then : - enableval=$enable_iptogeo; OPENLSWS_IPTOGEO="$enableval" -fi - - -if test "$OPENLSWS_IPTOGEO" = "no" ; then - echo "iptogeo disabled!!!" - LIBGEOIP= -else - -cat >>confdefs.h <<_ACEOF -#define ENABLE_IPTOGEO 1 -_ACEOF - - LIBGEOIP=" -lGeoIP " - echo "iptogeo enabled!!!" -fi -echo "LIBGEOIP=$LIBGEOIP" - - - LIBMMDB= OPENLSWS_IPTOGEO2=no @@ -18945,7 +18916,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by openlitespeed $as_me 1.5.7, which was +This file was extended by openlitespeed $as_me 1.5.8, which was generated by GNU Autoconf 2.69. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -19012,7 +18983,7 @@ _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ -openlitespeed config.status 1.5.7 +openlitespeed config.status 1.5.8 configured by $0, generated by GNU Autoconf 2.69, with options \\"\$ac_cs_config\\" diff --git a/configure.ac b/configure.ac index b819fffe9..8b0298ec4 100644 --- a/configure.ac +++ b/configure.ac @@ -7,7 +7,7 @@ m4_include(ax_check_libudns.m4) m4_include(ax_check_ip2location.m4) dnl Process this file with autoconf to produce a configure script. -AC_INIT([openlitespeed],[1.5.7],[info@litespeedtech.com],[openlitespeed],[http://www.litespeedtech.com/]) +AC_INIT([openlitespeed],[1.5.8],[info@litespeedtech.com],[openlitespeed],[http://www.litespeedtech.com/]) AM_INIT_AUTOMAKE([1.0 foreign no-define ]) AC_CONFIG_HEADERS(src/config.h:src/config.h.in) @@ -267,25 +267,6 @@ echo "LIBBROTLI=$LIBBROTLI" AC_SUBST([LIBBROTLI]) -LIBGEOIP=" -lGeoIP " -OPENLSWS_IPTOGEO=yes -AC_ARG_ENABLE([iptogeo], - [AS_HELP_STRING([--enable-iptogeo=@<:@yes/no@:>@], - [Enable iptogeo which need to have Geoip library installed @<:@default=yes@:>@])], - [OPENLSWS_IPTOGEO="$enableval"], []) - -if test "$OPENLSWS_IPTOGEO" = "no" ; then - echo "iptogeo disabled!!!" - LIBGEOIP= -else - AC_DEFINE_UNQUOTED([ENABLE_IPTOGEO], [1], [Defined to compile with iptogeo enabled]) - LIBGEOIP=" -lGeoIP " - echo "iptogeo enabled!!!" -fi -echo "LIBGEOIP=$LIBGEOIP" -AC_SUBST([LIBGEOIP]) - - LIBMMDB= OPENLSWS_IPTOGEO2=no AC_ARG_WITH(iptogeo2, diff --git a/dist/VERSION b/dist/VERSION index f01291b87..1cc9c180e 100644 --- a/dist/VERSION +++ b/dist/VERSION @@ -1 +1 @@ -1.5.7 +1.5.8 diff --git a/dist/add-ons/webcachemgr/src/Context/Context.php b/dist/add-ons/webcachemgr/src/Context/Context.php index 32c7eafee..ae46b49bf 100644 --- a/dist/add-ons/webcachemgr/src/Context/Context.php +++ b/dist/add-ons/webcachemgr/src/Context/Context.php @@ -64,13 +64,13 @@ class Context protected function __construct( ContextOption $contextOption ) { $this->options = $contextOption; - $this->dataDir = realpath(__DIR__ . '/../../../..') . '/admin/lscdata'; $this->init(); } protected function init() { + $this->dataDir = realpath(__DIR__ . '/../../../..') . '/admin/lscdata'; $this->dataFile = $this->dataDir . '/lscm.data'; $this->customDataFile = $this->dataDir . '/lscm.data.cust'; $this->isRoot = $this->options->isRoot(); diff --git a/dist/add-ons/webcachemgr/src/Context/RootCLIContextOption.php b/dist/add-ons/webcachemgr/src/Context/RootCLIContextOption.php index 43f4a9a45..2e92a0597 100644 --- a/dist/add-ons/webcachemgr/src/Context/RootCLIContextOption.php +++ b/dist/add-ons/webcachemgr/src/Context/RootCLIContextOption.php @@ -20,8 +20,8 @@ public function __construct() $invokerName = 'lscmctl'; $invokerType = parent::FROM_CLI; $isRoot = parent::IS_ROOT; - $logFileLvl = Logger::L_DEBUG;//INFO; - $logEchoLvl = Logger::L_DEBUG;//INFO; + $logFileLvl = Logger::L_INFO; + $logEchoLvl = Logger::L_INFO; $bufferedWrite = true; $bufferedEcho = false; parent::__construct($invokerName, $invokerType, $isRoot, $logFileLvl, diff --git a/dist/add-ons/webcachemgr/src/Context/RootPanelContextOption.php b/dist/add-ons/webcachemgr/src/Context/RootPanelContextOption.php index b01dd8561..2e8573fe5 100644 --- a/dist/add-ons/webcachemgr/src/Context/RootPanelContextOption.php +++ b/dist/add-ons/webcachemgr/src/Context/RootPanelContextOption.php @@ -24,7 +24,7 @@ public function __construct( $panelName ) $invokerName = $panelName; $invokerType = parent::FROM_CONTROL_PANEL; $isRoot = parent::IS_ROOT; - $logFileLvl = Logger::L_DEBUG;//INFO; + $logFileLvl = Logger::L_INFO; $logEchoLvl = Logger::L_NONE; $bufferedWrite = true; $bufferedEcho = true; diff --git a/dist/add-ons/webcachemgr/src/Panel/ControlPanel.php b/dist/add-ons/webcachemgr/src/Panel/ControlPanel.php index ff0e161a9..284d95787 100644 --- a/dist/add-ons/webcachemgr/src/Panel/ControlPanel.php +++ b/dist/add-ons/webcachemgr/src/Panel/ControlPanel.php @@ -19,20 +19,55 @@ abstract class ControlPanel /** * @deprecated + * + * @var string */ const PANEL_CPANEL = 'whm'; /** * @deprecated + * + * @var string */ const PANEL_PLESK = 'plesk'; + /** + * @var string + */ const PANEL_API_VERSION = '1.9'; + + /** + * @since 1.9 + * @var int + */ const PANEL_API_VERSION_SUPPORTED = 0; + + /** + * @since 1.9 + * @var int + */ const PANEL_API_VERSION_TOO_LOW = 1; + + /** + * @since 1.9 + * @var int + */ const PANEL_API_VERSION_TOO_HIGH = 2; + + /** + * @since 1.9 + * @var int + */ const PANEL_API_VERSION_UNKNOWN = 3; + + /** + * @var int + */ const PHP_TIMEOUT = 10; + + /** + * @var string + */ const NOT_SET = '__LSC_NOTSET__'; /** diff --git a/dist/add-ons/webcachemgr/src/Util.php b/dist/add-ons/webcachemgr/src/Util.php index eab9b6053..0bcd16ae6 100644 --- a/dist/add-ons/webcachemgr/src/Util.php +++ b/dist/add-ons/webcachemgr/src/Util.php @@ -433,9 +433,4 @@ public static function rrmdir( $dir, $keepParent = false ) return false; } - public static function writeToTestLog($msg) - { - file_put_contents('/tmp/test.log', "{$msg}\n", FILE_APPEND); - } - } diff --git a/dist/add-ons/webcachemgr/src/WPCaller.php b/dist/add-ons/webcachemgr/src/WPCaller.php index ded86a613..afde2361c 100644 --- a/dist/add-ons/webcachemgr/src/WPCaller.php +++ b/dist/add-ons/webcachemgr/src/WPCaller.php @@ -1095,7 +1095,7 @@ private function initWp() */ global $wpdb; - error_reporting(E_ALL & ~E_WARNING); + error_reporting(E_ALL); /** * Attempt to override any WordPress memory limits. diff --git a/dist/add-ons/webcachemgr/src/WPInstallStorage.php b/dist/add-ons/webcachemgr/src/WPInstallStorage.php index 1af5a2865..fb9456edd 100644 --- a/dist/add-ons/webcachemgr/src/WPInstallStorage.php +++ b/dist/add-ons/webcachemgr/src/WPInstallStorage.php @@ -282,7 +282,6 @@ public function getWorkingQueue() } /** - * Note: look into possibly removing this later. * * @param WPInstall $wpInstall */ diff --git a/dist/admin/html.open/lib/DTblDefBase.php b/dist/admin/html.open/lib/DTblDefBase.php index 7dd1b4526..242935b3c 100644 --- a/dist/admin/html.open/lib/DTblDefBase.php +++ b/dist/admin/html.open/lib/DTblDefBase.php @@ -991,7 +991,7 @@ protected function add_L_SSL_FEATURE($id) $this->_attrs['ssl_renegProtection'], $this->_attrs['sslSessionCache'], $this->_attrs['sslSessionTickets'], - self::NewCheckBoxAttr('enableSpdy', DMsg::ALbl('l_enablespdy'), array('1' => 'SPDY/2', '2' => 'SPDY/3', '4' => 'HTTP/2', '0' => DMsg::ALbl('o_none'))), + self::NewCheckBoxAttr('enableSpdy', DMsg::ALbl('l_enablespdy'), array('1' => 'SPDY/2', '2' => 'SPDY/3', '4' => 'HTTP/2', '8'=>'HTTP/3', '0' => DMsg::ALbl('o_none'))), self::NewBoolAttr('enableQuic', DMsg::ALbl('l_allowquic'), true, 'allowQuic'), ); $this->_tblDef[$id] = DTbl::NewRegular($id, DMsg::ALbl('l_securityandfeatures'), $attrs); @@ -1003,7 +1003,8 @@ protected function add_VT_SSL_FEATURE($id) $this->_attrs['ssl_renegProtection'], $this->_attrs['sslSessionCache'], $this->_attrs['sslSessionTickets'], - self::NewCheckBoxAttr('enableSpdy', DMsg::ALbl('l_enablespdy'), array('1' => 'SPDY/2', '2' => 'SPDY/3', '4' => 'HTTP/2', '0' => DMsg::ALbl('o_none'))), + + self::NewCheckBoxAttr('enableSpdy', DMsg::ALbl('l_enablespdy'), array('1' => 'SPDY/2', '2' => 'SPDY/3', '4' => 'HTTP/2', '8'=>'HTTP/3', '0' => DMsg::ALbl('o_none'))), self::NewBoolAttr('enableQuic', DMsg::ALbl('l_enablequic'), true, 'vhEnableQuic'), ); $this->_tblDef[$id] = DTbl::NewRegular($id, DMsg::UIStr('tab_sec'), $attrs); diff --git a/dist/admin/html.open/lib/util/build_php/BuildConfig.php b/dist/admin/html.open/lib/util/build_php/BuildConfig.php index 2d67c7a53..03dc37613 100644 --- a/dist/admin/html.open/lib/util/build_php/BuildConfig.php +++ b/dist/admin/html.open/lib/util/build_php/BuildConfig.php @@ -25,8 +25,8 @@ public static function GetVersion($field) case self::PHP_VERSION: return array( - '7.3.9', - '7.2.22', + '7.3.11', + '7.2.24', '7.1.32', '7.0.33', '5.6.40', diff --git a/dist/admin/html.open/res/lang/en-US_msg.php b/dist/admin/html.open/res/lang/en-US_msg.php index 3c2e14ac3..dc5aa67e6 100644 --- a/dist/admin/html.open/res/lang/en-US_msg.php +++ b/dist/admin/html.open/res/lang/en-US_msg.php @@ -257,7 +257,7 @@ $_gmsg['l_enablerailshosting'] = 'Enable Shared Hosting'; $_gmsg['l_enablerewrite'] = 'Enable Rewrite'; $_gmsg['l_enablescript'] = 'Enable Scripts/ExtApps'; -$_gmsg['l_enablespdy'] = 'Enable SPDY/HTTP2'; +$_gmsg['l_enablespdy'] = 'Enable SPDY/HTTP2/HTTP3'; $_gmsg['l_enablestapling'] = 'Enable OCSP Stapling'; $_gmsg['l_enablestderrlog'] = 'Enable stderr Log'; $_gmsg['l_env'] = 'Environment'; diff --git a/dist/admin/html.open/res/lang/en-US_tips.php b/dist/admin/html.open/res/lang/en-US_tips.php index bc87495f5..1a646c7ca 100644 --- a/dist/admin/html.open/res/lang/en-US_tips.php +++ b/dist/admin/html.open/res/lang/en-US_tips.php @@ -220,7 +220,7 @@ $_tipsdb['enableScript'] = new DAttrHelp("Enable Script", 'Specifies whether scripting (non-static pages) is allowed in this virtual host. If disabled, CGI, FastCGI, LSAPI, Servlet engines and other scripting languages will not be allowed in this virtual host. Therefore, if you want to use a script handler, you need to enable it here as well.', '', 'Select from radio box', ''); -$_tipsdb['enableSpdy'] = new DAttrHelp("Enable SPDY/HTTP2", 'HTTP/2 and SPDY are new versions of the HTTP network protocol with the goal of reducing page load times. More information can be found at http://en.wikipedia.org/wiki/HTTP/2.', 'This setting can be set at the listener and virtual host levels.', 'Check the protocol(s) you wish to enable. Leaving all boxes unchecked will enable SPDY and HTTP/2 support (the default). If you wish to disable SPDY and HTTP/2, check "None" only and leave all other boxes unchecked.', ''); +$_tipsdb['enableSpdy'] = new DAttrHelp("Enable SPDY/HTTP2/HTTP3", 'Selectively enable HTTP/3, HTTP/2, and SPDY HTTP network protocols.

If you wish to disable SPDY, HTTP/2, and HTTP3, check "None" and leave all other boxes unchecked.

Default value: All enabled', 'This setting can be set at the listener and virtual host levels.', 'Select from checkbox', ''); $_tipsdb['enableStapling'] = new DAttrHelp("Enable OCSP Stapling", 'Determines whether to enable OCSP stapling, a more efficient way of verifying public key certificates.', '', 'Select from radio box', ''); diff --git a/dist/admin/html.open/res/lang/zh-CN_tips.php b/dist/admin/html.open/res/lang/zh-CN_tips.php index f6104f6c5..de86c8258 100644 --- a/dist/admin/html.open/res/lang/zh-CN_tips.php +++ b/dist/admin/html.open/res/lang/zh-CN_tips.php @@ -220,7 +220,7 @@ $_tipsdb['enableScript'] = new DAttrHelp("启用脚本", '指定在这个虚拟主机中是否允许运行脚本(非静态页面)。 如果禁用,CGI, FastCGI, LSAPI, Servlet引擎 和其他脚本语言都将在这个虚拟机中不被允许使用。 因此如果你希望使用一个脚本处理程序,你需要启用本项。', '', '布尔值', ''); -$_tipsdb['enableSpdy'] = new DAttrHelp("Enable SPDY/HTTP2", 'HTTP/2 and SPDY are new versions of the HTTP network protocol with the goal of reducing page load times. More information can be found at http://en.wikipedia.org/wiki/HTTP/2.', 'This setting can be set at the listener and virtual host levels.', 'Check the protocol(s) you wish to enable. Leaving all boxes unchecked will enable SPDY and HTTP/2 support (the default). If you wish to disable SPDY and HTTP/2, check "None" only and leave all other boxes unchecked.', ''); +$_tipsdb['enableSpdy'] = new DAttrHelp("Enable SPDY/HTTP2/HTTP3", 'Selectively enable HTTP/3, HTTP/2, and SPDY HTTP network protocols.

If you wish to disable SPDY, HTTP/2, and HTTP3, check "None" and leave all other boxes unchecked.

Default value: All enabled', 'This setting can be set at the listener and virtual host levels.', 'Select from checkbox', ''); $_tipsdb['enableStapling'] = new DAttrHelp("Enable OCSP Stapling", 'Determines whether to enable OCSP stapling, a more efficient way of verifying public key certificates.', '', 'Select from radio box', ''); diff --git a/dist/admin/misc/lscmctl b/dist/admin/misc/lscmctl index 42b457813..66c7741a7 100755 --- a/dist/admin/misc/lscmctl +++ b/dist/admin/misc/lscmctl @@ -8,10 +8,13 @@ # *********************************************/ VERSION='1.9' -CURR_DIR=`pwd` -FILE_DIR=`dirname $0` -LSWS_DIR="${FILE_DIR}/../.." -SCRIPT=${LSWS_DIR}/add-ons/webcachemgr/bootstrap_cli.php +OS=$(uname -s) +SCRIPT_DIR=$(cd $(dirname ${0}) && pwd) + +cd $SCRIPT_DIR + +LSWS_DIR=$(cd "${SCRIPT_DIR}/../.." && pwd) +PHP_SCRIPT="${LSWS_DIR}/add-ons/webcachemgr/bootstrap_cli.php" YELLOW='\e[33m' CYAN='\e[36m' @@ -22,24 +25,24 @@ END_COLOR='\e[0m' printHeader() { # $1 title , $2 descr - printf "\n${YELLOW}$1${END_COLOR}\n$2\n" + printf "\n${YELLOW}${1}${END_COLOR}\n${2}\n" } printLabelDesc() { - printf "\n${YELLOW}$1${END_COLOR} $2\n\n" + printf "\n${YELLOW}${1}${END_COLOR} ${2}\n\n" } printCmdOption() { - printf "${CYAN}$1${END_COLOR} ${GREEN}$2${END_COLOR}\n" - printf " $3\n\n" | fold -sw 80 + printf "${CYAN}${1}${END_COLOR} ${GREEN}${2}${END_COLOR}\n" + printf " ${3}\n\n" | fold -sw 80 } printExample() { - printf " ${L_GRAY}$1:${END_COLOR}\n" - printf " ./lscmctl $2\n\n" + printf " ${L_GRAY}${1}:${END_COLOR}\n" + printf " ./lscmctl ${2}\n\n" } printHelp() @@ -84,14 +87,9 @@ printHelp() runUpdate() { - pushd `dirname "$0"` > /dev/null - - pushd ../../add-ons > /dev/null - ADDONS_DIR=$(pwd) - popd > /dev/null - - URL="https://shared.litespeed.sh/latest" + ADDONS_DIR=$(cd "${LSWS_DIR}/add-ons" && pwd) LOCAL_TAR_FILE="${ADDONS_DIR}/shared_latest.tar.gz" + URL="https://shared.litespeed.sh/latest" echo "Downloading latest shared code tar file..." wget -q --tries=1 --no-check-certificate "$URL" -O "$LOCAL_TAR_FILE" @@ -109,17 +107,21 @@ runUpdate() MD5_VALUE=$(wget -q https://shared.litespeed.sh/latest/md5 -O -) - if [ "$MD5_VALUE" == "" ] ; then + if [ "$MD5_VALUE" = "" ] ; then /bin/rm -f "$LOCAL_TAR_FILE" errorExit "Failed to wget latest shared code md5 value." fi - LOCAL_MD5_VAL=$(md5sum $LOCAL_TAR_FILE | awk '{ print $1 }') + if [ "x${OS}" = "xFreeBSD" ] ; then + LOCAL_MD5_VAL=$(md5 $LOCAL_TAR_FILE | awk '{ print $4 }') + else + LOCAL_MD5_VAL=$(md5sum $LOCAL_TAR_FILE | awk '{ print $1 }') + fi echo "Checking tar file md5..." if [ "$MD5_VALUE" != "$LOCAL_MD5_VAL" ] ; then - /bin/rm -f "${LOCAL_TAR_FILE}" + /bin/rm -f "$LOCAL_TAR_FILE" errorExit "Md5 mismatch for shared code! Aborting." fi @@ -136,24 +138,22 @@ runUpdate() RET=$? if [ "$RET" != "0" ] ; then - /bin/rm -f "${LOCAL_TAR_FILE}" + /bin/rm -f "$LOCAL_TAR_FILE" errorExit "Failed to extract tar.gz file with tar exit status ${RET}." fi echo "Removing local shared code tar file..." - /bin/rm -f "${LOCAL_TAR_FILE}" + /bin/rm -f "$LOCAL_TAR_FILE" echo "Updating lscmctl script..." /bin/mv -f "${ADDONS_DIR}/lscmctl" "${ADDONS_DIR}/../admin/misc/lscmctl" - popd > /dev/null - echo "Done!" } errorExit() { - printf "${YELLOW}ERROR: ${END_COLOR} $1\n\n" + printf "${YELLOW}ERROR: ${END_COLOR} ${1}\n\n" exit 1 } @@ -185,27 +185,39 @@ setPanelClassName() selectPHP() { - if [ "$1" == "-php" ] + if [ "$1" = "-php" ] then if [ -x "$2" ] ; then - PHP="$2 -d disable_functions=" + PHP_BIN="${2} -d disable_functions=" return 2 else - errorExit "$2 not detected as a valid php binary." + errorExit "${2} not detected as a valid php binary." fi else #Use default admin php binary - PHP="${LSWS_DIR}/admin/fcgi-bin/admin_php5 -c ${LSWS_DIR}/add-ons/webcachemgr/shared/webcachemgr.ini" + local DEFAULT_PHP_BIN="${LSWS_DIR}/admin/fcgi-bin/admin_php5" + local OLS_DA_PHP_BIN="${LSWS_DIR}/admin/fcgi-bin/admin_php" + + if [ ! -x "$DEFAULT_PHP_BIN" ] ; then + + if [ -x "$OLS_DA_PHP_BIN" ] ; then + DEFAULT_PHP_BIN="$OLS_DA_PHP_BIN" + else + errorExit "Could not find default admin PHP binary." + fi + fi + + PHP_BIN="${DEFAULT_PHP_BIN} -c ${LSWS_DIR}/add-ons/webcachemgr/shared/webcachemgr.ini" fi } -if [ "$1" == "--help" ] +if [ "$1" = "--help" ] then printHelp exit 0 fi -if [ "$1" == "--update-lib" ] +if [ "$1" = "--update-lib" ] then runUpdate exit 0; @@ -213,19 +225,18 @@ fi setPanelClassName -if [ "$PANEL_CLASS_NAME" == false ] ; then +if [ "$PANEL_CLASS_NAME" = false ] ; then errorExit 'Supported Control Panel not detected. Aborting!' fi selectPHP $1 $2 -if [ $? == 2 ] ; then +if [ $? = 2 ] ; then shift 2 fi -if [ $# == 0 ] ; then +if [ $# = 0 ] ; then errorExit "Missing input command. Try --help for a full list of available commands with examples." fi -$PHP $SCRIPT $PANEL_CLASS_NAME "$@" - +$PHP_BIN $PHP_SCRIPT $PANEL_CLASS_NAME "$@" diff --git a/dist/admin/misc/lshttpd.service.in b/dist/admin/misc/lshttpd.service.in index f18c2362b..56c822a44 100644 --- a/dist/admin/misc/lshttpd.service.in +++ b/dist/admin/misc/lshttpd.service.in @@ -6,7 +6,7 @@ Wants=network-online.target [Service] Type=forking -PIDFile=/var/run/lshttpd.pid +PIDFile=/tmp/lshttpd/lshttpd.pid ExecStart=%LSWS_CTRL% start ExecReload=%LSWS_CTRL% restart ExecStop=%LSWS_CTRL% delay-stop diff --git a/dist/functions.sh b/dist/functions.sh index 076c56589..2dc8f5ba3 100755 --- a/dist/functions.sh +++ b/dist/functions.sh @@ -996,7 +996,7 @@ installation() util_cpfile "$SDIR_OWN" $EXEC_MOD admin/misc/rc-inst.sh admin/misc/admpass.sh admin/misc/rc-uninst.sh admin/misc/uninstall.sh admin/misc/lsws.rc admin/misc/lsws.rc.gentoo admin/misc/enable_phpa.sh admin/misc/mgr_ver.sh admin/misc/gzipStatic.sh admin/misc/fp_install.sh admin/misc/create_admin_keypair.sh admin/misc/awstats_install.sh admin/misc/update.sh admin/misc/cleancache.sh admin/misc/lsup.sh admin/misc/testbeta.sh util_cpfile "$SDIR_OWN" $EXEC_MOD admin/misc/ap_lsws.sh.in admin/misc/build_ap_wrapper.sh admin/misc/cpanel_restart_httpd.in admin/misc/build_admin_php.sh admin/misc/convertxml.sh admin/misc/lscmctl util_cpfile "$SDIR_OWN" $DOC_MOD admin/misc/gdb-bt admin/misc/htpasswd.php admin/misc/php.ini admin/misc/genjCryptionKeyPair.php admin/misc/purge_cache_byurl.php - util_cpfile "$SDIR_OWN" $DOC_MOD admin/misc/convertxml.php + util_cpfile "$SDIR_OWN" $DOC_MOD admin/misc/convertxml.php admin/misc/lshttpd.service if [ $SET_LOGIN -eq 1 ]; then diff --git a/include/lsr/ls_log.h b/include/lsr/ls_log.h new file mode 100644 index 000000000..41105ece1 --- /dev/null +++ b/include/lsr/ls_log.h @@ -0,0 +1,97 @@ +/***************************************************************************** +* Open LiteSpeed is an open source HTTP server. * +* Copyright (C) 2013 - 2019 LiteSpeed Technologies, Inc. * +* * +* This program is free software: you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation, either version 3 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU General Public License * +* along with this program. If not, see http://www.gnu.org/licenses/. * +*****************************************************************************/ +#ifndef LS_LOG_H +#define LS_LOG_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +enum LS_LOG_LEVEL +{ + LS_LOG_FATAL = 0, + LS_LOG_ALERT = 1000, + LS_LOG_CRIT = 2000, + LS_LOG_ERROR = 3000, + LS_LOG_WARN = 4000, + LS_LOG_NOTICE = 5000, + LS_LOG_INFO = 6000, + LS_LOG_DEBUG = 7000, + LS_LOG_DBG_LOW = 7020, + LS_LOG_DBG_MED = 7050, + LS_LOG_DBG_HIGH = 7080, + LS_LOG_TRACE = 8000, + LS_LOG_NOTSET = 9000, + LS_LOG_UNKNOWN = 10000 +}; + + +#define LSR_DBG_H( ... ) \ + do { \ + c_log( LS_LOG_DBG_HIGH, __VA_ARGS__); \ + }while(0) + +#define LSR_DBG_M( ... ) \ + do { \ + c_log( LS_LOG_DBG_MED, __VA_ARGS__); \ + }while(0) + +#define LSR_DBG_L( ... ) \ + do { \ + c_log( LS_LOG_DBG_LOW, __VA_ARGS__); \ + }while(0) + +#define LSR_DBG( ... ) \ + do { \ + c_log( LS_LOG_DEBUG, __VA_ARGS__); \ + }while(0) + + +#define LSR_INFO( ... ) \ + do { \ + c_log( LS_LOG_INFO, __VA_ARGS__); \ + }while(0) + +#define LSR_NOTICE( ... ) \ + do { \ + c_log( LS_LOG_NOTICE, __VA_ARGS__); \ + }while(0) + +#define LSR_WARN( ... ) \ + do { \ + c_log( LSI_LOG_WARN, __VA_ARGS__); \ + }while(0) + +#define LSR_ERROR( ... ) \ + do { \ + c_log( LS_LOG_ERROR, __VA_ARGS__); \ + }while(0) + +void c_log(int level, const char *format, ...) +#if __GNUC__ + __attribute__((format(printf, 2, 3))) +#endif + ; + +#ifdef __cplusplus +} +#endif + +#endif //LS_LOG_H diff --git a/src/Makefile.am b/src/Makefile.am index 6224dd506..0be54981c 100755 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -119,7 +119,7 @@ openlitespeed_LDADD = ./main/libmain.a ./http/libhttp.a ./spdy/libspdy.a \ ./modules/libmodules.a ./shm/liblsshm.a ./adns/libadns.a \ $(LIBBROTLI) $(LIBMMDB) $(EXTRA_LIBS) \ $(AM_OPENSSL_LIBS) $(EXPAT_LIBS) $(PCRE_LIBS) ${IP2LOCATION_LIBS} \ - -ludns $(LIBGEOIP) -lz -lexpat -lpthread $(DL_LIB_OPTION) $(RT_LIB_OPTION) + -ludns -lz -lexpat -lpthread $(DL_LIB_OPTION) $(RT_LIB_OPTION) AM_LDFLAGS = $(OPENSSL_LDFLAGS) -L/usr/lib -L/usr/local/lib -L/usr/lib64 AM_CPPFLAGS = -std=c++0x -I$(top_srcdir)/ssl/include/ -I$(top_srcdir)/include -I$(top_srcdir)/src $(PCRE_CFLAGS) $(EXPAT_CFLAGS) diff --git a/src/Makefile.in b/src/Makefile.in index 0f688cb9b..b33a88786 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -153,8 +153,7 @@ openlitespeed_DEPENDENCIES = ./main/libmain.a ./http/libhttp.a \ $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ $(am__DEPENDENCIES_2) $(am__DEPENDENCIES_1) \ $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ - $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ - $(am__DEPENDENCIES_1) + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) AM_V_lt = $(am__v_lt_@AM_V@) am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) am__v_lt_0 = --silent @@ -331,7 +330,6 @@ IS_LSCPD = @IS_LSCPD@ LD = @LD@ LDFLAGS = @LDFLAGS@ LIBBROTLI = @LIBBROTLI@ -LIBGEOIP = @LIBGEOIP@ LIBMMDB = @LIBMMDB@ LIBOBJS = @LIBOBJS@ LIBS = @LIBS@ @@ -549,7 +547,7 @@ openlitespeed_LDADD = ./main/libmain.a ./http/libhttp.a ./spdy/libspdy.a \ ./modules/libmodules.a ./shm/liblsshm.a ./adns/libadns.a \ $(LIBBROTLI) $(LIBMMDB) $(EXTRA_LIBS) \ $(AM_OPENSSL_LIBS) $(EXPAT_LIBS) $(PCRE_LIBS) ${IP2LOCATION_LIBS} \ - -ludns $(LIBGEOIP) -lz -lexpat -lpthread $(DL_LIB_OPTION) $(RT_LIB_OPTION) + -ludns -lz -lexpat -lpthread $(DL_LIB_OPTION) $(RT_LIB_OPTION) AM_LDFLAGS = $(OPENSSL_LDFLAGS) -L/usr/lib -L/usr/local/lib -L/usr/lib64 AM_CPPFLAGS = -std=c++0x -I$(top_srcdir)/ssl/include/ -I$(top_srcdir)/include -I$(top_srcdir)/src $(PCRE_CFLAGS) $(EXPAT_CFLAGS) diff --git a/src/adns/Makefile.in b/src/adns/Makefile.in index d5670290b..50e8fdfda 100644 --- a/src/adns/Makefile.in +++ b/src/adns/Makefile.in @@ -216,7 +216,6 @@ IS_LSCPD = @IS_LSCPD@ LD = @LD@ LDFLAGS = @LDFLAGS@ LIBBROTLI = @LIBBROTLI@ -LIBGEOIP = @LIBGEOIP@ LIBMMDB = @LIBMMDB@ LIBOBJS = @LIBOBJS@ LIBS = @LIBS@ diff --git a/src/config.h.cmake b/src/config.h.cmake index 5fee5f8a2..b2fac8778 100644 --- a/src/config.h.cmake +++ b/src/config.h.cmake @@ -5,6 +5,6 @@ #define DEFAULT_TMP_DIR "/tmp/lshttpd" #define PID_FILE "/tmp/lshttpd/openlitespeed.pid" -#define PACKAGE_VERSION "1.5.7" +#define PACKAGE_VERSION "1.5.8" #define LS_MODULE_VERSION_INFO "\tmodpagespeed 2.2-1.11.33.4\n\tcache 1.61\n\tmodinspector 1.1\n\tuploadprogress LSIAPI_VERSION_STRING\n\tmod_security 1.1\n" #endif diff --git a/src/config.h.in b/src/config.h.in index 0c92fa768..ed0474c29 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -3,9 +3,6 @@ /* Defined the temprary directory */ #undef DEFAULT_TMP_DIR -/* Defined to compile with iptogeo enabled */ -#undef ENABLE_IPTOGEO - /* Defined to compile with iptogeo2 enabled */ #undef ENABLE_IPTOGEO2 diff --git a/src/edio/Makefile.in b/src/edio/Makefile.in index af376d7c0..5af3d60db 100644 --- a/src/edio/Makefile.in +++ b/src/edio/Makefile.in @@ -227,7 +227,6 @@ IS_LSCPD = @IS_LSCPD@ LD = @LD@ LDFLAGS = @LDFLAGS@ LIBBROTLI = @LIBBROTLI@ -LIBGEOIP = @LIBGEOIP@ LIBMMDB = @LIBMMDB@ LIBOBJS = @LIBOBJS@ LIBS = @LIBS@ diff --git a/src/extensions/Makefile.in b/src/extensions/Makefile.in index e42c11f33..2288ba757 100644 --- a/src/extensions/Makefile.in +++ b/src/extensions/Makefile.in @@ -231,7 +231,6 @@ IS_LSCPD = @IS_LSCPD@ LD = @LD@ LDFLAGS = @LDFLAGS@ LIBBROTLI = @LIBBROTLI@ -LIBGEOIP = @LIBGEOIP@ LIBMMDB = @LIBMMDB@ LIBOBJS = @LIBOBJS@ LIBS = @LIBS@ diff --git a/src/extensions/cgi/lscgid.cpp b/src/extensions/cgi/lscgid.cpp index e2fd64533..f91b918da 100644 --- a/src/extensions/cgi/lscgid.cpp +++ b/src/extensions/cgi/lscgid.cpp @@ -326,12 +326,30 @@ static int applyLimits(lscgid_req *pCGI) } +static int changeStderrLog(const char *path) +{ + int newfd = open(path, O_WRONLY | O_CREAT | O_APPEND, 0644); + if (newfd == -1) + { + fprintf(stderr, "lscgid (%d): failed to change stderr log to: %s\n", + getpid(), path); + return -1; + } + if (newfd != 2) + { + dup2(newfd, 2); + close(newfd); + } + return 0; +} + + #if defined(linux) || defined(__linux) || defined(__linux__) || defined(__gnu_linux__) static int cgroup_env(lscgid_t *pCGI) { if (getuid()) return -1; - + char **env_arr = pCGI->m_env; char *prefix = (char *)"LS_CGROUP="; int prefix_len = 10; @@ -357,7 +375,7 @@ static int cgroup_activate(lscgid_t *pCGI) int rc = -1; CGroupUse *use; CGroupConn *conn; - + int uid = geteuid(); seteuid(0); conn = new CGroupConn(); @@ -386,22 +404,26 @@ static int cgroup_process(lscgid_t *pCGI) if (!cgroup_env(pCGI)) return cgroup_activate(pCGI); return 0; -} +} #endif - - + + static int execute_cgi(lscgid_t *pCGI) { char ch; #if defined(linux) || defined(__linux) || defined(__linux__) || defined(__gnu_linux__) cgroup_process(pCGI); #endif - - + + if (setpriority(PRIO_PROCESS, 0, pCGI->m_data.m_priority)) perror("lscgid: setpriority()"); applyLimits(&pCGI->m_data); + if (pCGI->m_stderrPath) + changeStderrLog(pCGI->m_stderrPath); + + #ifdef HAS_CLOUD_LINUX #if defined(linux) || defined(__linux) || defined(__linux__) || defined(__gnu_linux__) @@ -567,6 +589,12 @@ static int process_req_data(lscgid_t *cgi_req) cgi_req->m_env[i] = p; if (*p == 'L') { + if (strncasecmp(p, "LS_STDERR_LOG=", 14) == 0) + { + --i; + --cgi_req->m_data.m_nenv; + cgi_req->m_stderrPath = p + 14; + } if (strncasecmp(p, "LS_CWD=", 7) == 0) { --i; @@ -898,7 +926,7 @@ int lscgid_main(int fd, char *argv0, const char *secret, char *pSock) #ifdef HAS_CLOUD_LINUX #if defined(linux) || defined(__linux) || defined(__linux__) || defined(__gnu_linux__) - + if ((sEnv = getenv("LVE_ENABLE")) != NULL) { s_enable_lve = atol(sEnv); @@ -920,12 +948,12 @@ int lscgid_main(int fd, char *argv0, const char *secret, char *pSock) //setproctitle( "%s", "httpd" ); #else memset(argv0, 0, strlen(argv0)); - -#ifdef IS_LSCPD + +#ifdef IS_LSCPD strcpy(argv0, "lscpd (lscgid)"); #else strcpy(argv0, "openlitespeed (lscgid)"); -#endif +#endif #endif ret = run(fd); diff --git a/src/extensions/cgi/lscgid.h b/src/extensions/cgi/lscgid.h index 1a32afb9a..b7d4702d7 100644 --- a/src/extensions/cgi/lscgid.h +++ b/src/extensions/cgi/lscgid.h @@ -36,6 +36,7 @@ typedef struct char *m_pCGIDir; char **m_argv; char **m_env; + char *m_stderrPath; char *m_cwdPath; int m_fdReceived; diff --git a/src/extensions/lsapi/lsapiconn.cpp b/src/extensions/lsapi/lsapiconn.cpp index 30c4cdeb2..aadbb8be6 100644 --- a/src/extensions/lsapi/lsapiconn.cpp +++ b/src/extensions/lsapi/lsapiconn.cpp @@ -1012,6 +1012,7 @@ int LsapiConn::readStderrStream() && (memcmp(achBuf, "\0PID", 4) == 0)) { //ignore this packet for now. + setCPState(1); } else if (pHEC) pHEC->processErrData(pBuf, packetLen); diff --git a/src/http/CMakeLists.txt b/src/http/CMakeLists.txt index f9d6bcb49..784de2376 100644 --- a/src/http/CMakeLists.txt +++ b/src/http/CMakeLists.txt @@ -75,7 +75,6 @@ SET(http_STAT_SRCS httpresp.cpp httpreq.cpp httpsession.cpp - iptogeo.cpp iptogeo2.cpp iptoloc.cpp moov.cpp diff --git a/src/http/Makefile.am b/src/http/Makefile.am index 3ccf0b5d4..e3b2fb0a3 100755 --- a/src/http/Makefile.am +++ b/src/http/Makefile.am @@ -13,7 +13,7 @@ libhttp_a_SOURCES = httpstatuscode.cpp moduserdir.cpp contextnode.cpp phpconfig. staticfilecachedata.cpp staticfilecache.cpp cacheelement.cpp httpcache.cpp chunkoutputstream.cpp chunkinputstream.cpp httplog.cpp \ httpmime.cpp sendfileinfo.cpp httpcontext.cpp httpserverversion.cpp vhostmap.cpp eventdispatcher.cpp staticfilehandler.cpp reqhandler.cpp \ httpvhost.cpp httpresourcemanager.cpp ntwkiolink.cpp httpmethod.cpp httpver.cpp httpstatusline.cpp httpheader.cpp \ - smartsettings.cpp httplistener.cpp httpresp.cpp httpreq.cpp httpsession.cpp iptogeo.cpp moov.cpp hiostream.cpp hiohandlerfactory.cpp \ + smartsettings.cpp httplistener.cpp httpresp.cpp httpreq.cpp httpsession.cpp moov.cpp hiostream.cpp hiohandlerfactory.cpp \ httprespheaders.cpp l4handler.cpp httpaiosendfile.cpp serverprocessconfig.cpp httpstats.cpp reqparser.cpp subrequest.cpp hiochainstream.cpp \ iptoloc.cpp iptogeo2.cpp recaptcha.cpp diff --git a/src/http/Makefile.in b/src/http/Makefile.in index 68434473f..720e0ea04 100644 --- a/src/http/Makefile.in +++ b/src/http/Makefile.in @@ -134,11 +134,10 @@ am_libhttp_a_OBJECTS = httpstatuscode.$(OBJEXT) moduserdir.$(OBJEXT) \ httpstatusline.$(OBJEXT) httpheader.$(OBJEXT) \ smartsettings.$(OBJEXT) httplistener.$(OBJEXT) \ httpresp.$(OBJEXT) httpreq.$(OBJEXT) httpsession.$(OBJEXT) \ - iptogeo.$(OBJEXT) moov.$(OBJEXT) hiostream.$(OBJEXT) \ - hiohandlerfactory.$(OBJEXT) httprespheaders.$(OBJEXT) \ - l4handler.$(OBJEXT) httpaiosendfile.$(OBJEXT) \ - serverprocessconfig.$(OBJEXT) httpstats.$(OBJEXT) \ - reqparser.$(OBJEXT) subrequest.$(OBJEXT) \ + moov.$(OBJEXT) hiostream.$(OBJEXT) hiohandlerfactory.$(OBJEXT) \ + httprespheaders.$(OBJEXT) l4handler.$(OBJEXT) \ + httpaiosendfile.$(OBJEXT) serverprocessconfig.$(OBJEXT) \ + httpstats.$(OBJEXT) reqparser.$(OBJEXT) subrequest.$(OBJEXT) \ hiochainstream.$(OBJEXT) iptoloc.$(OBJEXT) iptogeo2.$(OBJEXT) \ recaptcha.$(OBJEXT) libhttp_a_OBJECTS = $(am_libhttp_a_OBJECTS) @@ -254,7 +253,6 @@ IS_LSCPD = @IS_LSCPD@ LD = @LD@ LDFLAGS = @LDFLAGS@ LIBBROTLI = @LIBBROTLI@ -LIBGEOIP = @LIBGEOIP@ LIBMMDB = @LIBMMDB@ LIBOBJS = @LIBOBJS@ LIBS = @LIBS@ @@ -376,7 +374,7 @@ libhttp_a_SOURCES = httpstatuscode.cpp moduserdir.cpp contextnode.cpp phpconfig. staticfilecachedata.cpp staticfilecache.cpp cacheelement.cpp httpcache.cpp chunkoutputstream.cpp chunkinputstream.cpp httplog.cpp \ httpmime.cpp sendfileinfo.cpp httpcontext.cpp httpserverversion.cpp vhostmap.cpp eventdispatcher.cpp staticfilehandler.cpp reqhandler.cpp \ httpvhost.cpp httpresourcemanager.cpp ntwkiolink.cpp httpmethod.cpp httpver.cpp httpstatusline.cpp httpheader.cpp \ - smartsettings.cpp httplistener.cpp httpresp.cpp httpreq.cpp httpsession.cpp iptogeo.cpp moov.cpp hiostream.cpp hiohandlerfactory.cpp \ + smartsettings.cpp httplistener.cpp httpresp.cpp httpreq.cpp httpsession.cpp moov.cpp hiostream.cpp hiohandlerfactory.cpp \ httprespheaders.cpp l4handler.cpp httpaiosendfile.cpp serverprocessconfig.cpp httpstats.cpp reqparser.cpp subrequest.cpp hiochainstream.cpp \ iptoloc.cpp iptogeo2.cpp recaptcha.cpp @@ -484,7 +482,6 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/httpver.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/httpvhost.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/httpvhostlist.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/iptogeo.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/iptogeo2.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/iptoloc.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/l4handler.Po@am__quote@ diff --git a/src/http/clientinfo.cpp b/src/http/clientinfo.cpp index 2a2b4c85a..5f03b15a1 100644 --- a/src/http/clientinfo.cpp +++ b/src/http/clientinfo.cpp @@ -248,9 +248,9 @@ LocInfo *ClientInfo::allocateLocInfo() static inline int isGoog(const char *pHost, int iHostLen) { - if (!strncmp("googlebot.com", pHost + iHostLen - 13, 13)) + if (iHostLen > 13 && !strncmp("googlebot.com", pHost + iHostLen - 13, 13)) return 1; - return (strncmp("google.com", pHost + iHostLen - 10, 10) == 0); + return (iHostLen > 10 && strncmp("google.com", pHost + iHostLen - 10, 10) == 0); } diff --git a/src/http/httplistenerlist.cpp b/src/http/httplistenerlist.cpp index 7c7648f98..485866e5f 100644 --- a/src/http/httplistenerlist.cpp +++ b/src/http/httplistenerlist.cpp @@ -224,7 +224,7 @@ void HttpListenerList::passListeners() if ((*iter)->getfd() != -1) { --count; - LS_INFO("Pass listener %s, copy fd %d to %d.", (*iter)->getAddrStr(), + LS_NOTICE("Pass listener %s, copy fd %d to %d.", (*iter)->getAddrStr(), (*iter)->getfd(), startfd + count); dup2((*iter)->getfd(), startfd + count); } @@ -420,7 +420,6 @@ const ServerAddrInfo *ServerAddrRegistry::get(const struct sockaddr *pAddr, (unsigned)GSockAddr::getPort(pAddr)); } pListener = m_pListenerList->get(sAddr, sAddr); - assert(pListener != NULL); } if (pListener) diff --git a/src/http/httpsession.cpp b/src/http/httpsession.cpp index 08093f2f9..abfc480f3 100644 --- a/src/http/httpsession.cpp +++ b/src/http/httpsession.cpp @@ -751,6 +751,14 @@ int HttpSession::reqBodyDone() } +int HttpSession::call_onRead(lsi_session_t *p, long , void *) +{ + HttpSession *pSession = (HttpSession *)p; + pSession->onReadEx(); + return 0; +} + + int HttpSession::readReqBody() { char *pBuf; @@ -773,7 +781,11 @@ int HttpSession::readReqBody() if (!endBody) { if ((ret < (int)size) || (++count == 10 && !isspdy)) + { + if (count == 10) + EvtcbQue::getInstance().schedule(call_onRead, this, 0, NULL, false); return 0; + } } if (pParser && pParser->isParsePost() && pParser->isParseUploadByFilePath()) @@ -1731,12 +1743,12 @@ bool HttpSession::shouldAvoidRecaptcha() return true; } - if (getStream() && getStream()->isFromLocalAddr()) - { - LS_DBG_M(getLogSession(), "[RECAPTCHA] %.*s is from local address, skip recaptcha.", - pClientInfo->getAddrStrLen(), pClientInfo->getAddrString()); - return true; - } +// if (getStream() && getStream()->isFromLocalAddr()) +// { +// LS_DBG_M(getLogSession(), "[RECAPTCHA] %.*s is from local address, skip recaptcha.", +// pClientInfo->getAddrStrLen(), pClientInfo->getAddrString()); +// return true; +// } const char *pUserAgent = m_request.getUserAgent(); int iUserAgentLen = m_request.getUserAgentLen(); diff --git a/src/http/httpsession.h b/src/http/httpsession.h index 51d185cf4..20d763a80 100644 --- a/src/http/httpsession.h +++ b/src/http/httpsession.h @@ -274,6 +274,7 @@ class HttpSession static int readReqBodyTermination(LsiSession *pSession, char *pBuf, int size); + static int call_onRead(lsi_session_t *p, long , void *); char getSsiStackDepth() const; diff --git a/src/http/iptogeo.cpp b/src/http/iptogeo.cpp deleted file mode 100644 index a007b070a..000000000 --- a/src/http/iptogeo.cpp +++ /dev/null @@ -1,639 +0,0 @@ -/***************************************************************************** -* Open LiteSpeed is an open source HTTP server. * -* Copyright (C) 2013 - 2018 LiteSpeed Technologies, Inc. * -* * -* This program is free software: you can redistribute it and/or modify * -* it under the terms of the GNU General Public License as published by * -* the Free Software Foundation, either version 3 of the License, or * -* (at your option) any later version. * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU General Public License * -* along with this program. If not, see http://www.gnu.org/licenses/. * -*****************************************************************************/ - -#include "iptogeo.h" - -#ifdef ENABLE_IPTOGEO - -#include -#include -#include
-#include -#include - -#include -#include -#include -#include - -#include -#include -#include - - -GeoIpData::GeoIpData() - : m_netspeed(-1) -{ - memset(&m_countryId, 0, (char *)(&m_pIsp + 1) - (char *)&m_countryId); -} - - -GeoIpData::~GeoIpData() -{ - release(); -} - -void GeoIpData::reset() -{ - release(); - m_netspeed = -1; - memset(&m_countryId, 0, (char *)(&m_pIsp + 1) - (char *)&m_countryId); -} - -void GeoIpData::release() -{ - if (m_pRegion) - GeoIPRegion_delete(m_pRegion); - if (m_pCity) - GeoIPRecord_delete(m_pCity); - if (m_pOrg) - free(m_pOrg); - if (m_pIsp) - free(m_pIsp); -} - - -const char *GeoIpData::getGeoEnv(const char *pEnvName) -{ - static char s_achBuf[15]; - if (strncasecmp(pEnvName, "GEOIP_", 6) == 0) - pEnvName += 6; - else if (strncasecmp(pEnvName, "GEO:", 4) == 0) - pEnvName += 4; - else - return NULL; - - if (strncasecmp(pEnvName, "COUNTRY_", 8) == 0) - { - pEnvName += 8; - if (strncasecmp(pEnvName, "CODE", 4) == 0) - { - - if ((m_countryId > 0) - && (m_countryId < (int)(sizeof(GeoIP_country_name) / sizeof( - const char *)))) - { - if (*(pEnvName + 4) == '3') - return GeoIP_country_code3[m_countryId]; - else - return GeoIP_country_code[m_countryId]; - } - else if (m_pRegion) - return m_pRegion->country_code; - else if (m_pCity) - return m_pCity->country_code; - } - else if (strcasecmp(pEnvName, "NAME") == 0) - { - if ((m_countryId > 0) - && (m_countryId < (int)(sizeof(GeoIP_country_name) / sizeof( - const char *)))) - return GeoIP_country_name[m_countryId]; - else if (m_pCity) - return m_pCity->country_name; - } - else if (strcasecmp(pEnvName, "CONTINENT") == 0) - { - if ((m_countryId > 0) - && (m_countryId < (int)(sizeof(GeoIP_country_name) / sizeof( - const char *)))) - return GeoIP_country_continent[ m_countryId ]; - else if (m_pCity) - return m_pCity->continent_code; - - } - } - else if (strcasecmp(pEnvName, "REGION") == 0) - { - if (m_pRegion) - { - if (m_pRegion->region[0]) - return m_pRegion->region; - } - if (m_pCity) - return m_pCity->region; - } - else if (strcasecmp(pEnvName, "CONTINENT_CODE") == 0) - { - if ((m_countryId > 0) - && (m_countryId < (int)(sizeof(GeoIP_country_name) / sizeof( - const char *)))) - return GeoIP_country_continent[m_countryId]; - else if (m_pCity) - return m_pCity->continent_code; - } - else if (strcasecmp(pEnvName, "CITY") == 0) - { - if (m_pCity) - return m_pCity->city; - } - else if (strcasecmp(pEnvName, "POSTAL_CODE") == 0) - { - if (m_pCity && m_pCity->postal_code) - return m_pCity->postal_code; - } - else if (strcasecmp(pEnvName, "NETSPEED") == 0) - { - switch (m_netspeed) - { - case GEOIP_DIALUP_SPEED: - return "dialup"; - case GEOIP_CABLEDSL_SPEED: - return "cabledsl"; - case GEOIP_CORPORATE_SPEED: - return "corporate"; - case GEOIP_UNKNOWN_SPEED: - case -1: - return NULL; - default: - return "unknown"; - } - } - else if (strcasecmp(pEnvName, "ORGANIZATION") == 0) - return m_pOrg; - else if (strcasecmp(pEnvName, "ISP") == 0) - return m_pIsp; - else if ((strcasecmp(pEnvName, "AREA_CODE") == 0) || - (strcasecmp(pEnvName, "DMA_CODE") == 0)) - { - snprintf(s_achBuf, 15, "%d", m_pCity->area_code); - return s_achBuf; - } - return NULL; -} - - -int GeoIpData::addGeoEnv(IEnv *pEnv) -{ - int count = 0; - const char *pStr; - int len; - if ((m_countryId > 0) - && (m_countryId < (int)(sizeof(GeoIP_country_name) / sizeof( - const char *)))) - { - pStr = GeoIP_country_name[m_countryId]; - pEnv->add("GEOIP_COUNTRY_CODE", 18, GeoIP_country_code[m_countryId], 2); - pEnv->add("GEOIP_COUNTRY_NAME", 18, pStr, strlen(pStr)); - pStr = GeoIP_country_continent[ m_countryId ]; - pEnv->add("GEOIP_CONTINENT_CODE", 20, pStr, 2); - - count += 3; - } - - if (m_netspeed != -1) - { - switch (m_netspeed) - { - case GEOIP_DIALUP_SPEED: - pStr = "dialup"; - len = 6; - break; - - case GEOIP_CABLEDSL_SPEED: - pStr = "cabledsl"; - len = 8; - break; - - case GEOIP_CORPORATE_SPEED: - pStr = "corporate"; - len = 9; - break; - - case GEOIP_UNKNOWN_SPEED: - default: - pStr = "unknown"; - len = 7; - break; - } - pEnv->add("GEOIP_NETSPEED", 14, pStr, len); - ++count; - } - - if (m_pRegion) - { - pEnv->add("GEOIP_COUNTRY_CODE", 18, m_pRegion->country_code, 2); - ++count; - if (m_pRegion->region[0]) - { - pEnv->add("GEOIP_REGION", 12, m_pRegion->region, - strlen(m_pRegion->region)); - ++count; - pStr = GeoIP_region_name_by_code(m_pRegion->country_code, - m_pRegion->region); - if (pStr) - { - pEnv->add("GEOIP_REGION_NAME", 17, pStr, strlen(pStr)); - ++count; - } - } - } - - if (m_pCity) - { - char achBuf[256]; - len = snprintf(achBuf, 256, "%d", m_pCity->dma_code); - pEnv->add("GEOIP_DMA_CODE", 14, achBuf, len); - pEnv->add("GEOIP_METRO_CODE", 16, achBuf, len); - - len = snprintf(achBuf, 256, "%d", m_pCity->area_code); - pEnv->add("GEOIP_AREA_CODE", 15, achBuf, len); - - len = snprintf(achBuf, 256, "%f", m_pCity->latitude); - pEnv->add("GEOIP_LATITUDE", 14, achBuf, len); - - len = snprintf(achBuf, 256, "%f", m_pCity->longitude); - pEnv->add("GEOIP_LONGITUDE", 15, achBuf, len); - - pEnv->add("GEOIP_COUNTRY_CODE", 18, m_pCity->country_code, 2); - - if (m_pCity->country_name) - { - pEnv->add("GEOIP_COUNTRY_NAME", 18, m_pCity->country_name, - strlen(m_pCity->country_name)); - pEnv->add("GEOIP_CONTINENT_CODE", 20, m_pCity->continent_code, 2); - count += 2; - } - - len = snprintf(achBuf, 256, "%d", m_pCity->area_code); - pEnv->add("GEOIP_AREA_CODE", 15, achBuf, len); - count += 7; - - if (m_pCity->postal_code) - { - pEnv->add("GEOIP_POSTAL_CODE", 17, m_pCity->postal_code, - strlen(m_pCity->postal_code)); - ++count; - } - - if (m_pCity->region) - { - pEnv->add("GEOIP_REGION", 12, m_pCity->region, - strlen(m_pCity->region)); - ++count; - pStr = GeoIP_region_name_by_code(m_pCity->country_code, m_pCity->region); - if (pStr) - { - pEnv->add("GEOIP_REGION_NAME", 17, pStr, strlen(pStr)); - ++count; - } - } - - if (m_pCity->city) - { - pEnv->add("GEOIP_CITY", 10, m_pCity->city, - strlen(m_pCity->city)); - ++count; - } - } - - if (m_pOrg) - { - pEnv->add("GEOIP_ORGANIZATION", 18, m_pOrg, strlen(m_pOrg)); - ++count; - } - - if (m_pIsp) - { - pEnv->add("GEOIP_ISP", 9, m_pIsp, strlen(m_pIsp)); - ++count; - } - return count; -} - - -/* -void GeoInfo::addGeoEnv( HttpReq * pReq ) -{ - const char * pStr; - int len; - if ( m_countryId ) - { - pStr = GeoIP_country_name[m_countryId]; - pReq->addEnv( "GEOIP_COUNTRY_CODE", 18, GeoIP_country_code[m_countryId], 2 ); - pReq->addEnv( "GEOIP_COUNTRY_NAME", 18, pStr, strlen( pStr ) ); - } - - if ( m_netspeed != -1) - { - switch( m_netspeed ) - { - case GEOIP_DIALUP_SPEED: - pStr = "dialup"; - len = 6; - break; - - case GEOIP_CABLEDSL_SPEED: - pStr = "cabledsl"; - len = 8; - break; - - case GEOIP_CORPORATE_SPEED: - pStr = "corporate"; - len = 9; - break; - - case GEOIP_UNKNOWN_SPEED: - default: - pStr = "unknown"; - len = 7; - break; - } - pReq->addEnv( "GEOIP_NETSPEED", 14, pStr, len ); - } - - if ( m_pRegion ) - { - pReq->addEnv( "GEOIP_COUNTRY_CODE", 18, m_pRegion->country_code, 2 ); - if (m_pRegion->region[0]) - { - pReq->addEnv( "GEOIP_REGION", 12, m_pRegion->region, strlen( m_pRegion->region )); - } - } - - if ( m_pCity ) - { - char achBuf[256]; - len = snprintf( achBuf, 256, "%d", m_pCity->dma_code ); - pReq->addEnv( "GEOIP_DMA_CODE", 14, achBuf, len ); - - len = snprintf( achBuf, 256, "%d", m_pCity->area_code ); - pReq->addEnv( "GEOIP_AREA_CODE", 15, achBuf, len ); - - len = snprintf( achBuf, 256, "%f", m_pCity->latitude ); - pReq->addEnv( "GEOIP_LATITUDE", 14, achBuf, len ); - - len = snprintf( achBuf, 256, "%f", m_pCity->longitude ); - pReq->addEnv( "GEOIP_LONGITUDE", 15, achBuf, len ); - - pReq->addEnv( "GEOIP_POSTAL_CODE", 17, m_pCity->postal_code, - strlen( m_pCity->postal_code ) ); - - pReq->addEnv( "GEOIP_COUNTRY_CODE", 17, m_pCity->country_code, 2 ); - - pReq->addEnv( "GEOIP_COUNTRY_NAME", 17, m_pCity->country_name, - strlen( m_pCity->country_name ) ); - - pReq->addEnv( "GEOIP_REGION", 12, m_pCity->region, - strlen( m_pCity->region ) ); - - pReq->addEnv( "GEOIP_CITY", 17, m_pCity->city, - strlen( m_pCity->city ) ); - } - - if ( m_pOrg ) - { - pReq->addEnv( "GEOIP_ORGANIZATION", 18, m_pOrg, strlen( m_pOrg ) ); - } - - if ( m_pIsp ) - { - pReq->addEnv( "GEOIP_ISP", 18, m_pIsp, strlen( m_pIsp ) ); - } - -} -*/ - - -IpToGeo::IpToGeo() - : m_pLocation(NULL) - , m_pOrg(NULL) - , m_pIsp(NULL) - , m_pNetspeed(NULL) -{ -} - -IpToGeo::~IpToGeo() -{ - if (m_pLocation) - GeoIP_delete(m_pLocation); - if (m_pOrg) - GeoIP_delete(m_pOrg); - if (m_pIsp) - GeoIP_delete(m_pIsp); - if (m_pNetspeed) - GeoIP_delete(m_pNetspeed); -} - - -int IpToGeo::loadGeoIpDbFile(const char *pFile, int flag) -{ - GeoIP *pGip; - pGip = GeoIP_open(pFile, flag); - if (!pGip) - { - LS_ERROR("Failed to open GeoIP DB file: %s", pFile); - return LS_FAIL; - } - int fd = fileno(pGip->GeoIPDatabase); - if (fd != -1) - ::fcntl(fd, F_SETFD, FD_CLOEXEC); - - flag = GeoIP_database_edition(pGip); - switch (flag) - { - case GEOIP_COUNTRY_EDITION: - case GEOIP_REGION_EDITION_REV0: - case GEOIP_REGION_EDITION_REV1: - case GEOIP_CITY_EDITION_REV0: - case GEOIP_CITY_EDITION_REV1: - if (m_pLocation) - GeoIP_delete(m_pLocation); - m_pLocation = pGip; - m_locDbType = flag; - break; - - case GEOIP_ORG_EDITION: - if (m_pOrg) - GeoIP_delete(m_pOrg); - m_pOrg = pGip; - break; - - case GEOIP_ISP_EDITION: - if (m_pIsp) - GeoIP_delete(m_pIsp); - m_pIsp = pGip; - break; - - case GEOIP_NETSPEED_EDITION: - if (m_pNetspeed) - GeoIP_delete(m_pNetspeed); - m_pNetspeed = pGip; - break; - - default: - GeoIP_delete(pGip); - LS_ERROR("Unrecognized GeoIP DB file type (%d) in: %s", flag, pFile); - return LS_FAIL; - } - return 0; -} - - -int IpToGeo::testGeoIpDbFile(const char *pFile, int flag) -{ - pid_t pid = fork(); - if (pid < 0) - return -1; - if (pid == 0) - { - int ret = loadGeoIpDbFile(pFile, flag); - if (ret == 0) - { - unsigned char addr[4] = { 88, 252, 206, 167 }; - GeoInfo *info = NULL; - info = lookUp(*((int *)&addr)); - ret = (info == NULL); - if (info) - delete info; - } - exit(ret != 0); - } - else - { - int status; - int wpid = waitpid(pid, &status, 0); - if (wpid == pid && WIFEXITED(status) && WEXITSTATUS(status) == 0) - return 0; - LS_ERROR("GeoIP DB file test failed: '%s'\n", pFile); - } - return -1; -} - - -int IpToGeo::setGeoIpDbFile(const char *pFile, const char *cacheMode) -{ - int flag = GEOIP_MEMORY_CACHE; - if (!pFile) - return -1; - if (cacheMode) - { - if (strcasecmp(cacheMode, "Standard") == 0) - flag = GEOIP_STANDARD; - else if (strcasecmp(cacheMode, "MemoryCache") == 0) - flag = GEOIP_MEMORY_CACHE; - else if (strcasecmp(cacheMode, "CheckCache") == 0) - flag = GEOIP_CHECK_CACHE; - else if (strcasecmp(cacheMode, "IndexCache") == 0) - flag = GEOIP_INDEX_CACHE; - } - if (testGeoIpDbFile(pFile, flag) != 0) - return -1; - return loadGeoIpDbFile(pFile, flag); -} - - -GeoInfo *IpToGeo::lookUp(uint32_t addr) -{ - GeoIpData *pInfo = new GeoIpData(); - if (!pInfo) - { - LS_ERROR("Error allocating GeoIpData\n"); - return NULL; - } - addr = htonl(addr); - if (m_pLocation) - { - switch (m_locDbType) - { - case GEOIP_COUNTRY_EDITION: - pInfo->m_countryId = GeoIP_id_by_ipnum(m_pLocation, addr); - break; - - case GEOIP_REGION_EDITION_REV0: - case GEOIP_REGION_EDITION_REV1: - pInfo->m_pRegion = GeoIP_region_by_ipnum(m_pLocation, addr); - break; - - case GEOIP_CITY_EDITION_REV0: - case GEOIP_CITY_EDITION_REV1: - pInfo->m_pCity = GeoIP_record_by_ipnum(m_pLocation, addr); - break; - } - - } - if (m_pOrg) - pInfo->m_pOrg = GeoIP_name_by_ipnum(m_pOrg, addr); - if (m_pIsp) - pInfo->m_pIsp = GeoIP_name_by_ipnum(m_pIsp, addr); - if (m_pNetspeed) - pInfo->m_netspeed = GeoIP_id_by_ipnum(m_pNetspeed, addr); - return pInfo; -} - -GeoInfo *IpToGeo::lookUpV6(in6_addr addr) -{ - GeoIpData *pInfo = new GeoIpData(); - if (!pInfo) - { - LS_ERROR("Insufficient memory to lookup v6 addr\n"); - return NULL; - } - if (m_pLocation) - { - switch (m_locDbType) - { - case GEOIP_REGION_EDITION_REV0: - case GEOIP_REGION_EDITION_REV1: - pInfo->m_pRegion = GeoIP_region_by_ipnum_v6(m_pLocation, addr); - break; - case GEOIP_COUNTRY_EDITION_V6: - pInfo->m_countryId = GeoIP_id_by_ipnum_v6(m_pLocation, addr); - break; - } - - } - if (m_pOrg) - pInfo->m_pOrg = GeoIP_name_by_ipnum_v6(m_pOrg, addr); - if (m_pIsp) - pInfo->m_pIsp = GeoIP_name_by_ipnum_v6(m_pIsp, addr); - if (m_pNetspeed) - pInfo->m_netspeed = GeoIP_id_by_ipnum_v6(m_pNetspeed, addr); - return pInfo; -} - -int IpToGeo::config(const XmlNodeList *pList) -{ - XmlNodeList::const_iterator iter; - int succ = 0; - - for (iter = pList->begin(); iter != pList->end(); ++iter) - { - XmlNode *p = *iter; - const char *pFile = p->getValue(); - char achBufFile[MAX_PATH_LEN]; - - if ((!pFile) || - (ConfigCtx::getCurConfigCtx()->getValidFile(achBufFile, pFile, - "GeoIP DB") != 0)) - continue; - - if (setGeoIpDbFile(achBufFile, p->getChildValue("geoipDBCache")) == 0) - succ = 1; - } - - if (!succ) - { - LS_WARN(ConfigCtx::getCurConfigCtx(), - "Failed to setup a valid GeoIP DB file, Geolocation is disabled!"); - return LS_FAIL; - } - return 0; -} - -#endif // ENABLE_IPTOGEO diff --git a/src/http/iptogeo.h b/src/http/iptogeo.h deleted file mode 100644 index d5dac6059..000000000 --- a/src/http/iptogeo.h +++ /dev/null @@ -1,89 +0,0 @@ -/***************************************************************************** -* Open LiteSpeed is an open source HTTP server. * -* Copyright (C) 2013 - 2018 LiteSpeed Technologies, Inc. * -* * -* This program is free software: you can redistribute it and/or modify * -* it under the terms of the GNU General Public License as published by * -* the Free Software Foundation, either version 3 of the License, or * -* (at your option) any later version. * -* * -* This program is distributed in the hope that it will be useful, * -* but WITHOUT ANY WARRANTY; without even the implied warranty of * -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -* GNU General Public License for more details. * -* * -* You should have received a copy of the GNU General Public License * -* along with this program. If not, see http://www.gnu.org/licenses/. * -*****************************************************************************/ -#ifndef IPTOGEO_H -#define IPTOGEO_H - -#include -#ifdef ENABLE_IPTOGEO - - -#include - -#include -#include -#include "GeoIP.h" -#include "GeoIPCity.h" - -//class HttpReq; -class IEnv; -class IpToGeo; -class XmlNodeList; -class ConfigCtx; - -class GeoIpData : public GeoInfo -{ - friend class IpToGeo; -public: - GeoIpData(); - ~GeoIpData(); - const char *getGeoEnv(const char *pEnvName); - int addGeoEnv(IEnv *pEnv); - //void addGeoEnv( HttpReq * pReq ); - void reset(); - void release(); - -private: - - int m_netspeed; - int m_countryId; - - GeoIPRegion *m_pRegion; - GeoIPRecord *m_pCity; - - char *m_pOrg; - char *m_pIsp; - LS_NO_COPY_ASSIGN(GeoIpData); -}; - -class IpToGeo : public Ip2Geo -{ - -public: - IpToGeo(); - ~IpToGeo(); - - int setGeoIpDbFile(const char *pFile, const char *cacheMode); - - GeoInfo *lookUp(uint32_t addr); - GeoInfo *lookUpV6(in6_addr addr); - int config(const XmlNodeList *pList); - -private: - int loadGeoIpDbFile(const char *pFile, int flag); - int testGeoIpDbFile(const char *pFile, int flag); - - int m_locDbType; - GeoIP *m_pLocation; - GeoIP *m_pOrg; - GeoIP *m_pIsp; - GeoIP *m_pNetspeed; - LS_NO_COPY_ASSIGN(IpToGeo); -}; - -#endif //ENABLE_IPTOGEO -#endif diff --git a/src/log4cxx/Makefile.in b/src/log4cxx/Makefile.in index 594040cc5..101c488fd 100644 --- a/src/log4cxx/Makefile.in +++ b/src/log4cxx/Makefile.in @@ -223,7 +223,6 @@ IS_LSCPD = @IS_LSCPD@ LD = @LD@ LDFLAGS = @LDFLAGS@ LIBBROTLI = @LIBBROTLI@ -LIBGEOIP = @LIBGEOIP@ LIBMMDB = @LIBMMDB@ LIBOBJS = @LIBOBJS@ LIBS = @LIBS@ diff --git a/src/log4cxx/level.h b/src/log4cxx/level.h index 0ffc6ffb0..8d46648f6 100644 --- a/src/log4cxx/level.h +++ b/src/log4cxx/level.h @@ -20,6 +20,7 @@ #include +#include #include BEGIN_LOG4CXX_NS @@ -33,23 +34,23 @@ class Level public: enum { - FATAL = 0, - ALERT = 1000, - CRIT = 2000, - ERROR = 3000, - WARN = 4000, - NOTICE = 5000, - INFO = 6000, - DEBUG = 7000, - DBG_LESS = 7020, - DBG_LOW = 7020, - DBG_MEDIUM = 7050, - DBG_MORE = 7080, - DBG_HIGH = 7080, - DBG_IODATA = 7090, - TRACE = 8000, - NOTSET = 9000, - UNKNOWN = 10000 + FATAL = LS_LOG_FATAL, + ALERT = LS_LOG_ALERT, + CRIT = LS_LOG_CRIT, + ERROR = LS_LOG_ERROR, + WARN = LS_LOG_WARN, + NOTICE = LS_LOG_NOTICE, + INFO = LS_LOG_INFO, + DEBUG = LS_LOG_DEBUG, + DBG_LESS = LS_LOG_DBG_LOW, + DBG_LOW = LS_LOG_DBG_LOW, + DBG_MEDIUM = LS_LOG_DBG_MED, + DBG_MORE = LS_LOG_DBG_HIGH, + DBG_HIGH = LS_LOG_DBG_HIGH, + DBG_IODATA = LS_LOG_TRACE, + TRACE = LS_LOG_TRACE, + NOTSET = LS_LOG_NOTSET, + UNKNOWN = LS_LOG_UNKNOWN }; static const char *toString(int level) diff --git a/src/log4cxx/logger.cpp b/src/log4cxx/logger.cpp index 3e2e73de8..8e0c0574e 100644 --- a/src/log4cxx/logger.cpp +++ b/src/log4cxx/logger.cpp @@ -25,6 +25,8 @@ #include "tmplogid.h" #include "logsession.h" +#include + #include BEGIN_LOG4CXX_NS @@ -33,6 +35,25 @@ static int s_inited = 0; ::GFactory *s_pFactory = NULL; Logger *Logger::s_pDefault = NULL; +#ifdef __cplusplus +extern "C" { +#endif + +void c_log(int level, const char *format, ...) +{ + if ( log4cxx::Level::isEnabled( level ) ) + { + log4cxx::Logger *l = log4cxx::Logger::getDefault(); + va_list va; + va_start(va, format); + l->vlog(level, format, va); + va_end(va); + } +} + +#ifdef __cplusplus +} +#endif Logger::Logger(const char *pName) : Duplicable(pName) diff --git a/src/lsiapi/Makefile.in b/src/lsiapi/Makefile.in index 3650015f9..ced994577 100644 --- a/src/lsiapi/Makefile.in +++ b/src/lsiapi/Makefile.in @@ -220,7 +220,6 @@ IS_LSCPD = @IS_LSCPD@ LD = @LD@ LDFLAGS = @LDFLAGS@ LIBBROTLI = @LIBBROTLI@ -LIBGEOIP = @LIBGEOIP@ LIBMMDB = @LIBMMDB@ LIBOBJS = @LIBOBJS@ LIBS = @LIBS@ diff --git a/src/main/Makefile.in b/src/main/Makefile.in index a123ebbc4..ed33f95ed 100644 --- a/src/main/Makefile.in +++ b/src/main/Makefile.in @@ -220,7 +220,6 @@ IS_LSCPD = @IS_LSCPD@ LD = @LD@ LDFLAGS = @LDFLAGS@ LIBBROTLI = @LIBBROTLI@ -LIBGEOIP = @LIBGEOIP@ LIBMMDB = @LIBMMDB@ LIBOBJS = @LIBOBJS@ LIBS = @LIBS@ diff --git a/src/main/httpserver.cpp b/src/main/httpserver.cpp index ef1f961ff..0ae31570c 100644 --- a/src/main/httpserver.cpp +++ b/src/main/httpserver.cpp @@ -61,7 +61,6 @@ #include #include #include -#include #include #include #include @@ -694,7 +693,7 @@ HttpListener *HttpServerImpl::addListener(const char *pName, pListener = m_listeners.get(pName, pAddr); if (pListener) { - LS_DBG_L("Reuse existing Listener [%s] [%s].", pName, pAddr); + LS_NOTICE("Reuse existing Listener [%s] [%s].", pName, pAddr); return pListener; } pListener = m_oldListeners.get(pName, pAddr); @@ -702,7 +701,7 @@ HttpListener *HttpServerImpl::addListener(const char *pName, { pListener = newTcpListener(pName, pAddr); if (pListener) - LS_DBG_L("Created new Listener [%s].", pName); + LS_NOTICE("Created new Listener [%s].", pName); else { LS_ERROR("HttpServer::addListener(%s) failed to create new listener" @@ -714,7 +713,7 @@ HttpListener *HttpServerImpl::addListener(const char *pName, { pListener->beginConfig(); m_oldListeners.remove(pListener); - LS_DBG_L("Reuse current listener [%s].", pName); + LS_NOTICE("Reuse current listener [%s].", pName); } m_listeners.add(pListener); return pListener; @@ -3171,11 +3170,6 @@ int HttpServerImpl::configIpToGeo(const XmlNode *pNode) pIp2Geo = new IpToGeo2(); #endif -#ifdef ENABLE_IPTOGEO - if (!pIp2Geo) - pIp2Geo = new IpToGeo(); -#endif - if (!pIp2Geo) return LS_FAIL; diff --git a/src/main/lshttpdmain.cpp b/src/main/lshttpdmain.cpp index 8949dd75d..18b1da85d 100644 --- a/src/main/lshttpdmain.cpp +++ b/src/main/lshttpdmain.cpp @@ -80,7 +80,7 @@ /*** * Do not change the below format, it will be set correctly while packing the code */ -#define BUILDTIME " (built: Wed Oct 16 19:35:24 UTC 2019)" +#define BUILDTIME " (built: Tue Nov 5 15:37:06 UTC 2019)" #define GlobalServerSessionHooks (LsiApiHooks::getServerSessionHooks()) diff --git a/src/modules/Makefile.in b/src/modules/Makefile.in index 1eb554705..91616dbfa 100644 --- a/src/modules/Makefile.in +++ b/src/modules/Makefile.in @@ -260,7 +260,6 @@ IS_LSCPD = @IS_LSCPD@ LD = @LD@ LDFLAGS = @LDFLAGS@ LIBBROTLI = @LIBBROTLI@ -LIBGEOIP = @LIBGEOIP@ LIBMMDB = @LIBMMDB@ LIBOBJS = @LIBOBJS@ LIBS = @LIBS@ diff --git a/src/modules/cache/Makefile.in b/src/modules/cache/Makefile.in index 10c8ea879..f57eabb1b 100644 --- a/src/modules/cache/Makefile.in +++ b/src/modules/cache/Makefile.in @@ -244,7 +244,6 @@ IS_LSCPD = @IS_LSCPD@ LD = @LD@ LDFLAGS = @LDFLAGS@ LIBBROTLI = @LIBBROTLI@ -LIBGEOIP = @LIBGEOIP@ LIBMMDB = @LIBMMDB@ LIBOBJS = @LIBOBJS@ LIBS = @LIBS@ diff --git a/src/modules/cache/cache.cpp b/src/modules/cache/cache.cpp index 0547d8193..ff9f78a45 100644 --- a/src/modules/cache/cache.cpp +++ b/src/modules/cache/cache.cpp @@ -1275,12 +1275,24 @@ short lookUpCache(lsi_param_t *rec, MyMData *myData, int no_vary, { if ((*pEntry)->isStale() && !(*pEntry)->isUpdating()) { - myData->pEntry = myData->pConfig->getStore()->createCacheEntry( - myData->cePublicHash, &myData->cacheKey, 0); - return CE_STATE_UPDATE_STALE; + CacheEntry *pNewEntry = myData->pConfig->getStore()-> + createCacheEntry(myData->cePublicHash, + &myData->cacheKey, 0); + if (pNewEntry) + { + myData->pEntry = pNewEntry; + return CE_STATE_UPDATE_STALE; + } + else + { + + g_api->log(rec->session, LSI_LOG_ERROR, + "[%s] createEntry failed for update stale.\n", + ModuleNameStr); + } } - else - return CE_STATE_HAS_PUBLIC_CACHE; + + return CE_STATE_HAS_PUBLIC_CACHE; } } diff --git a/src/modules/lua/Makefile.in b/src/modules/lua/Makefile.in index 372b3fa50..e31e3080a 100644 --- a/src/modules/lua/Makefile.in +++ b/src/modules/lua/Makefile.in @@ -243,7 +243,6 @@ IS_LSCPD = @IS_LSCPD@ LD = @LD@ LDFLAGS = @LDFLAGS@ LIBBROTLI = @LIBBROTLI@ -LIBGEOIP = @LIBGEOIP@ LIBMMDB = @LIBMMDB@ LIBOBJS = @LIBOBJS@ LIBS = @LIBS@ diff --git a/src/modules/modinspector/Makefile.in b/src/modules/modinspector/Makefile.in index babb5d9bf..510c049fa 100644 --- a/src/modules/modinspector/Makefile.in +++ b/src/modules/modinspector/Makefile.in @@ -242,7 +242,6 @@ IS_LSCPD = @IS_LSCPD@ LD = @LD@ LDFLAGS = @LDFLAGS@ LIBBROTLI = @LIBBROTLI@ -LIBGEOIP = @LIBGEOIP@ LIBMMDB = @LIBMMDB@ LIBOBJS = @LIBOBJS@ LIBS = @LIBS@ diff --git a/src/modules/modreqparser/Makefile.in b/src/modules/modreqparser/Makefile.in index 7e8b05727..db6be2d71 100644 --- a/src/modules/modreqparser/Makefile.in +++ b/src/modules/modreqparser/Makefile.in @@ -242,7 +242,6 @@ IS_LSCPD = @IS_LSCPD@ LD = @LD@ LDFLAGS = @LDFLAGS@ LIBBROTLI = @LIBBROTLI@ -LIBGEOIP = @LIBGEOIP@ LIBMMDB = @LIBMMDB@ LIBOBJS = @LIBOBJS@ LIBS = @LIBS@ diff --git a/src/modules/modsecurity-ls/mod_security.cpp b/src/modules/modsecurity-ls/mod_security.cpp index 1ba3aecfa..7b09addd9 100644 --- a/src/modules/modsecurity-ls/mod_security.cpp +++ b/src/modules/modsecurity-ls/mod_security.cpp @@ -49,7 +49,9 @@ typedef struct msc_conf_t_{ typedef struct ModData_t { - Transaction *modsec_transaction; + Transaction *modsec_transaction; + int8_t chkReqBody; + int8_t chkRespBody; } ModData; @@ -487,19 +489,19 @@ static int UriMapHook(lsi_param_t *rec) } Rules *rules = myData->modsec_transaction->m_rules; - bool chkReqBody = rules->m_secRequestBodyAccess == CHECKBODYTRUE; - bool chkRespBody = rules->m_secResponseBodyAccess == CHECKBODYTRUE; + myData->chkReqBody = rules->m_secRequestBodyAccess == CHECKBODYTRUE; + myData->chkRespBody = rules->m_secResponseBodyAccess == CHECKBODYTRUE; g_api->log(session, LSI_LOG_DEBUG, "[Module:%s] RequestBodyAccess: %s " "ResponseBodyAccess: %s\n", ModuleNameStr, - chkReqBody ? "YES" : "NO", - chkRespBody ? "YES" : "NO"); + myData->chkReqBody ? "YES" : "NO", + myData->chkRespBody ? "YES" : "NO"); - if(chkReqBody && rules->m_requestBodyLimit.m_value > 3000) //at least set limit to 3000 + if(myData->chkReqBody && rules->m_requestBodyLimit.m_value > 3000) //at least set limit to 3000 { long reqbodySize = g_api->get_req_content_length(session); if (reqbodySize > rules->m_requestBodyLimit.m_value) { - chkReqBody = false; + myData->chkReqBody = false; g_api->log(session, LSI_LOG_DEBUG, "[Module:%s] RequestBodyAccess disabled due to size %ld > %ld.", ModuleNameStr, reqbodySize, @@ -508,17 +510,14 @@ static int UriMapHook(lsi_param_t *rec) } int aEnableHkpt[4] = {LSI_HKPT_RCVD_RESP_HEADER, - LSI_HKPT_HANDLER_RESTART, }; - int arrCount = 2; - if (chkReqBody) + LSI_HKPT_HANDLER_RESTART, + LSI_HKPT_RCVD_REQ_BODY, + LSI_HKPT_RCVD_RESP_BODY}; + if (myData->chkReqBody) { g_api->set_req_wait_full_body(session); - aEnableHkpt[arrCount ++] = LSI_HKPT_RCVD_REQ_BODY; } - if (chkRespBody) - aEnableHkpt[arrCount ++] = LSI_HKPT_RCVD_RESP_BODY; - - g_api->enable_hook(session, &MNAME, 1, aEnableHkpt, arrCount); + g_api->enable_hook(session, &MNAME, 1, aEnableHkpt, 4); return LSI_OK; } @@ -545,35 +544,42 @@ static int reqBodyHook(lsi_param_t *rec) g_api->log(session, LSI_LOG_DEBUG, "[Module:%s] reqBodyHook entry, len: %ld.\n", ModuleNameStr, len); - if (len == 0) - return LSI_OK; - - do + if (len > 0 && myData->chkReqBody) { - len = 0; - if ((pTmpBuf = g_api->acquire_body_buf_block(pBuf, offset, (int *)&len)) - == NULL) - break; - - //g_api->log(session, LSI_LOG_DEBUG, - // "[Module:%s] reqBodyHook data: %ld bytes.\n", ModuleNameStr, len); - - msc_append_request_body(myData->modsec_transaction, - (const unsigned char *)pTmpBuf, (size_t)len); - - int ret = process_intervention(myData->modsec_transaction, rec); - if (ret != STATUS_OK) { - g_api->log(session, LSI_LOG_DEBUG, - "[Module:%s] reqBodyHook failed.\n", ModuleNameStr); - return LSI_ERROR; + do + { + len = 0; + if ((pTmpBuf = g_api->acquire_body_buf_block(pBuf, offset, (int *)&len)) + == NULL) + break; + + //g_api->log(session, LSI_LOG_DEBUG, + // "[Module:%s] reqBodyHook data: %ld bytes.\n", ModuleNameStr, len); + + msc_append_request_body(myData->modsec_transaction, + (const unsigned char *)pTmpBuf, (size_t)len); + + int ret = process_intervention(myData->modsec_transaction, rec); + if (ret != STATUS_OK) { + g_api->log(session, LSI_LOG_DEBUG, + "[Module:%s] reqBodyHook failed.\n", ModuleNameStr); + return LSI_ERROR; + } + offset += len; } - offset += len; - } - while (!g_api->is_body_buf_eof(pBuf, offset)); - - g_api->log(session, LSI_LOG_DEBUG, + while (!g_api->is_body_buf_eof(pBuf, offset)); + + g_api->log(session, LSI_LOG_DEBUG, "[Module:%s] reqBodyHook used %ld bytes of %ld\n", ModuleNameStr, offset, len); + + } + else + { + g_api->log(session, LSI_LOG_DEBUG, + "[Module:%s] reqBodyHook bypass reqBody len %d.\n", + ModuleNameStr, len); + } g_api->log(session, LSI_LOG_DEBUG, "[Module:%s] reqBodyHook final body check.\n", ModuleNameStr); @@ -676,7 +682,7 @@ static int respHeaderHook(lsi_param_t *rec) int len = 0; void *pRespBodyBuf = g_api->get_resp_body_buf(rec->session); int ret; - while (!g_api->is_body_buf_eof(pRespBodyBuf, offset)) + while (myData->chkRespBody && !g_api->is_body_buf_eof(pRespBodyBuf, offset)) { len = 0; pBuf = g_api->acquire_body_buf_block(pRespBodyBuf, offset, &len); diff --git a/src/modules/uploadprogress/Makefile.in b/src/modules/uploadprogress/Makefile.in index feb7067aa..2bdc43e31 100644 --- a/src/modules/uploadprogress/Makefile.in +++ b/src/modules/uploadprogress/Makefile.in @@ -242,7 +242,6 @@ IS_LSCPD = @IS_LSCPD@ LD = @LD@ LDFLAGS = @LDFLAGS@ LIBBROTLI = @LIBBROTLI@ -LIBGEOIP = @LIBGEOIP@ LIBMMDB = @LIBMMDB@ LIBOBJS = @LIBOBJS@ LIBS = @LIBS@ diff --git a/src/shm/Makefile.in b/src/shm/Makefile.in index 7d7904efc..034adc383 100644 --- a/src/shm/Makefile.in +++ b/src/shm/Makefile.in @@ -218,7 +218,6 @@ IS_LSCPD = @IS_LSCPD@ LD = @LD@ LDFLAGS = @LDFLAGS@ LIBBROTLI = @LIBBROTLI@ -LIBGEOIP = @LIBGEOIP@ LIBMMDB = @LIBMMDB@ LIBOBJS = @LIBOBJS@ LIBS = @LIBS@ diff --git a/src/socket/Makefile.in b/src/socket/Makefile.in index f8c48a9c6..927621182 100644 --- a/src/socket/Makefile.in +++ b/src/socket/Makefile.in @@ -219,7 +219,6 @@ IS_LSCPD = @IS_LSCPD@ LD = @LD@ LDFLAGS = @LDFLAGS@ LIBBROTLI = @LIBBROTLI@ -LIBGEOIP = @LIBGEOIP@ LIBMMDB = @LIBMMDB@ LIBOBJS = @LIBOBJS@ LIBS = @LIBS@ diff --git a/src/spdy/Makefile.in b/src/spdy/Makefile.in index f681eeb0d..7ff1704c5 100644 --- a/src/spdy/Makefile.in +++ b/src/spdy/Makefile.in @@ -240,7 +240,6 @@ IS_LSCPD = @IS_LSCPD@ LD = @LD@ LDFLAGS = @LDFLAGS@ LIBBROTLI = @LIBBROTLI@ -LIBGEOIP = @LIBGEOIP@ LIBMMDB = @LIBMMDB@ LIBOBJS = @LIBOBJS@ LIBS = @LIBS@ diff --git a/src/ssi/Makefile.in b/src/ssi/Makefile.in index 131ff14bc..42e479917 100644 --- a/src/ssi/Makefile.in +++ b/src/ssi/Makefile.in @@ -217,7 +217,6 @@ IS_LSCPD = @IS_LSCPD@ LD = @LD@ LDFLAGS = @LDFLAGS@ LIBBROTLI = @LIBBROTLI@ -LIBGEOIP = @LIBGEOIP@ LIBMMDB = @LIBMMDB@ LIBOBJS = @LIBOBJS@ LIBS = @LIBS@ diff --git a/src/sslpp/Makefile.in b/src/sslpp/Makefile.in index feab71733..ec681beaf 100644 --- a/src/sslpp/Makefile.in +++ b/src/sslpp/Makefile.in @@ -240,7 +240,6 @@ IS_LSCPD = @IS_LSCPD@ LD = @LD@ LDFLAGS = @LDFLAGS@ LIBBROTLI = @LIBBROTLI@ -LIBGEOIP = @LIBGEOIP@ LIBMMDB = @LIBMMDB@ LIBOBJS = @LIBOBJS@ LIBS = @LIBS@ diff --git a/src/sslpp/ls_fdbuf_bio.c b/src/sslpp/ls_fdbuf_bio.c index d57fddfbb..23a14280e 100644 --- a/src/sslpp/ls_fdbuf_bio.c +++ b/src/sslpp/ls_fdbuf_bio.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -20,9 +21,9 @@ #include #include -#ifdef RUN_TEST +//#ifdef RUN_TEST #define DEBUGGING -#endif +//#endif #ifdef DEBUGGING @@ -30,9 +31,9 @@ #define DEBUG_MESSAGE(...) printf(__VA_ARGS__); #define INFO_MESSAGE(...) printf(__VA_ARGS__); #else -#include -#define DEBUG_MESSAGE(...) LSI_DBG(NULL, __VA_ARGS__); -#define INFO_MESSAGE(... ) LSI_INF(NULL, __VA_ARGS__); +#include +#define DEBUG_MESSAGE(...) LSR_DBG_H(__VA_ARGS__); +#define INFO_MESSAGE(... ) LSR_INFO(__VA_ARGS__); #endif #else @@ -77,29 +78,46 @@ void *BIO_get_data(BIO *a); void ls_fdbuf_bio_init(ls_fdbio_data *fdbio) { memset(fdbio, 0, sizeof(*fdbio)); + fdbio->m_rbuf_size = RBIO_BUF_SIZE; } - - -static int bio_fd_free(BIO *a) +int ls_fdbio_alloc_rbuff(ls_fdbio_data *fdbio, int size) { - ls_fdbio_data *fdbio; - DEBUG_MESSAGE("[BIO] bio_fd_free: %p\n", a); - if (a == NULL) - return 0; - fdbio = LS_FDBUF_FROM_BIO(a); - if (!fdbio) - return 1; - if (fdbio->m_rbioBuf) + DEBUG_MESSAGE("[FDBIO] alloc read buf %d\n", size); + assert(fdbio->m_rbuf_used == fdbio->m_rbuf_read); + if (fdbio->m_rbuf && fdbio->m_rbuf_size >= size) + return LS_OK; + void *buf = ls_palloc(size); + if (buf) { - ls_pfree(fdbio->m_rbioBuf); - fdbio->m_rbioBuf = NULL; + if (fdbio->m_rbuf) + ls_pfree(fdbio->m_rbuf); + fdbio->m_rbuf = (uint8_t *)buf; + fdbio->m_rbuf_size = size; + fdbio->m_rbuf_used = fdbio->m_rbuf_read = 0; + return LS_OK; + } + else + { + DEBUG_MESSAGE("Insufficient memory allocating rbuff %d bytes\n", size); + errno = ENOMEM; + return LS_FAIL; } - ls_fdbuf_bio_init(fdbio); - return 1; } + +void ls_fdbio_release_rbuff(ls_fdbio_data *fdbio) +{ + if (fdbio->m_rbuf == NULL) + return; + assert(fdbio->m_rbuf_used == fdbio->m_rbuf_read); + DEBUG_MESSAGE("[FDBIO] free rbuf %d\n", (int)fdbio->m_rbuf_size); + ls_pfree(fdbio->m_rbuf); + fdbio->m_rbuf = NULL; +} + + static int bio_fd_read(BIO *b, char *out, int outl) { int ret = 0; @@ -112,10 +130,10 @@ static int bio_fd_read(BIO *b, char *out, int outl) if ((out == NULL) || (!outl)) { INFO_MESSAGE("[BIO] bio_fd_read NO BUFFER!!\n"); - err = ENOMEM; + err = EINVAL; return -1; } - if (fdbio->m_rbioClosed) + if (fdbio->m_is_closed) { DEBUG_MESSAGE("[BIO] bio_fd_read: CLOSED ON PREVIOUS READ\n"); errno = 0; @@ -123,7 +141,7 @@ static int bio_fd_read(BIO *b, char *out, int outl) } while (total < outl) { - int buffered = fdbio->m_rbioBuffered - fdbio->m_rbioIndex; + int buffered = fdbio->m_rbuf_used - fdbio->m_rbuf_read; int rd_remaining = outl - total; int copy = 0; if (buffered) @@ -131,8 +149,8 @@ static int bio_fd_read(BIO *b, char *out, int outl) copy = (buffered > rd_remaining) ? rd_remaining : buffered; DEBUG_MESSAGE("[BIO] bio_fd_read: Use buffered %d of %d\n", copy, rd_remaining); - memcpy(&out[total], &fdbio->m_rbioBuf[fdbio->m_rbioIndex], copy); - fdbio->m_rbioIndex += copy; + memcpy(&out[total], &fdbio->m_rbuf[fdbio->m_rbuf_read], copy); + fdbio->m_rbuf_read += copy; total += copy; if (total >= outl) { @@ -140,16 +158,17 @@ static int bio_fd_read(BIO *b, char *out, int outl) total); return total; } - fdbio->m_rbioBuffered = 0; - fdbio->m_rbioIndex = 0; + fdbio->m_rbuf_used = 0; + fdbio->m_rbuf_read = 0; rd_remaining = outl - total; } - if ((rd_remaining < fdbio->m_rbioBufSz) && (fdbio->m_rbioBuf)) + if ((rd_remaining < fdbio->m_rbuf_size) + && (fdbio->m_rbuf || ls_fdbio_alloc_rbuff(fdbio, fdbio->m_rbuf_size) == LS_OK)) { DEBUG_MESSAGE("[BIO] bio_fd_read: Read into buffer\n"); - ret = ls_read(fd, fdbio->m_rbioBuf, fdbio->m_rbioBufSz); - if (ret < fdbio->m_rbioBufSz) - fdbio->m_rbioWaitEvent = 1; + ret = ls_read(fd, fdbio->m_rbuf, fdbio->m_rbuf_size); + if (ret < fdbio->m_rbuf_size) + fdbio->m_need_read_event = 1; buffered = ret; } else @@ -157,13 +176,13 @@ static int bio_fd_read(BIO *b, char *out, int outl) DEBUG_MESSAGE("[BIO] bio_fd_read: Read into data\n"); ret = ls_read(fd, out + total, rd_remaining); if (ret < rd_remaining) - fdbio->m_rbioWaitEvent = 1; + fdbio->m_need_read_event = 1; buffered = 0; } if (ret == 0) { DEBUG_MESSAGE("[BIO] bio_fd_read: CLOSED\n"); - fdbio->m_rbioClosed = 1; + fdbio->m_is_closed = 1; errno = 0; return total; } @@ -186,8 +205,8 @@ static int bio_fd_read(BIO *b, char *out, int outl) } if (buffered) { - fdbio->m_rbioBuffered = buffered; - fdbio->m_rbioIndex = 0; + fdbio->m_rbuf_used = buffered; + fdbio->m_rbuf_read = 0; DEBUG_MESSAGE("[BIO] bio_fd_read: Preserve read: %d\n", ret); } else @@ -200,19 +219,17 @@ static int bio_fd_read(BIO *b, char *out, int outl) } -#define LS_FDBIO_FULL 1 -#define LS_FDBIO_BUFFERING 2 int ls_fdbio_alloc_wbuff(ls_fdbio_data *fdbio, int size) { DEBUG_MESSAGE("[FDBIO] alloc write buf %d\n", size); assert(fdbio->m_wbuf_used == 0); if (fdbio->m_wbuf && fdbio->m_wbuf_size >= size) return LS_OK; - void *buf = ls_palloc_slab(size); + void *buf = ls_palloc(size); if (buf) { if (fdbio->m_wbuf) - ls_pfree_slab(fdbio->m_wbuf, fdbio->m_wbuf_size); + ls_pfree(fdbio->m_wbuf); fdbio->m_wbuf = (uint8_t *)buf; fdbio->m_wbuf_size = size; fdbio->m_wbuf_sent = 0; @@ -222,19 +239,14 @@ int ls_fdbio_alloc_wbuff(ls_fdbio_data *fdbio, int size) } -int ls_fdbio_is_idle(ls_fdbio_data *fdbio) -{ - return fdbio->m_wbuf && fdbio->m_wbuf_used == 0; -} - - -void ls_fdbio_relelase_wbuff(ls_fdbio_data *fdbio) +void ls_fdbio_release_wbuff(ls_fdbio_data *fdbio) { assert(fdbio->m_wbuf_used == 0); - DEBUG_MESSAGE("[FDBIO] free buf %d\n", (int)fdbio->m_wbuf_size); if (fdbio->m_wbuf == NULL) return; - ls_pfree_slab(fdbio->m_wbuf, fdbio->m_wbuf_size); + DEBUG_MESSAGE("[FDBIO] free wbuf %d\n", (int)fdbio->m_wbuf_size); + ls_pfree(fdbio->m_wbuf); + fdbio->m_wbuf_size = 0; fdbio->m_wbuf = NULL; } @@ -250,7 +262,7 @@ static int ls_fdbio_combine_write(ls_fdbio_data *fdbio, int fd, const void *buf, iov[1].iov_len = num; int ret = ls_writev(fd, iov, 2); DEBUG_MESSAGE("[FDBIO] ls_writev(%d + %d) ret: %d\n", - iov[0].iov_len, iov[1].iov_len, ret); + (int)iov[0].iov_len, (int)iov[1].iov_len, ret); if (ret > 0) { if (ret >= (int)iov[0].iov_len) @@ -277,12 +289,11 @@ static int ls_fdbio_combine_write(ls_fdbio_data *fdbio, int fd, const void *buf, } +#define TLS_RECORD_MAX_SIZE 16413 static int ls_fdbio_buff_write(ls_fdbio_data *fdbio, int fd, const void *buf, int num) { DEBUG_MESSAGE("[FDBIO] ls_fdbio_buff_write, to write: %d, used: %d, sent: %d\n", num, (int)fdbio->m_wbuf_used, (int)fdbio->m_wbuf_sent); - if (fdbio->m_flag & LS_FDBIO_FULL) - return 0; if (!fdbio->m_wbuf) { if (num < 4096) @@ -298,43 +309,26 @@ static int ls_fdbio_buff_write(ls_fdbio_data *fdbio, int fd, const void *buf, in ret = ls_fdbio_combine_write(fdbio, fd, buf, num); else ret = ls_write(fd, buf, num); - if (ret >= num && fdbio->m_wbuf_size < 16413 * 4) + if (ret >= num && fdbio->m_wbuf_size < TLS_RECORD_MAX_SIZE * 4) { - int new_size = fdbio->m_wbuf_size + 16413; - if (new_size < 16413 * 2) - new_size = 16413 * 2; + int new_size = fdbio->m_wbuf_size + TLS_RECORD_MAX_SIZE; + if (new_size < TLS_RECORD_MAX_SIZE * 2) + new_size = TLS_RECORD_MAX_SIZE * 2; ls_fdbio_alloc_wbuff(fdbio, new_size); } return ret; } memmove(fdbio->m_wbuf + fdbio->m_wbuf_used, buf, num); fdbio->m_wbuf_used += num; - DEBUG_MESSAGE("[FDBIO] lstls_buff_write, to write: %d, finished: %ld, used: %d, sent: %d\n", + DEBUG_MESSAGE("[FDBIO] lstls_buff_write, to write: %d, finished: %d, used: %d, sent: %d\n", num, num, (int)fdbio->m_wbuf_used, (int)fdbio->m_wbuf_sent); return num; } -int ls_fdbio_is_full(ls_fdbio_data *fdbio) -{ return fdbio->m_flag & LS_FDBIO_FULL; } - - -void ls_fdbio_clear_buff_full(ls_fdbio_data *fdbio) -{ fdbio->m_flag &= ~LS_FDBIO_FULL; } - - -void ls_fdbio_set_wbuff(ls_fdbio_data *fdbio, int dobuff) -{ - if (dobuff) - fdbio->m_flag |= LS_FDBIO_BUFFERING; - else - fdbio->m_flag &= ~LS_FDBIO_BUFFERING; -} - - int ls_fdbio_flush(ls_fdbio_data *fdbio, int fd) { - if (fdbio->m_flag & LS_FDBIO_FULL) + if (fdbio->m_flag & LS_FDBIO_WBLOCK) return 0; int pending = fdbio->m_wbuf_used - fdbio->m_wbuf_sent; if (pending <= 0) @@ -351,8 +345,8 @@ int ls_fdbio_flush(ls_fdbio_data *fdbio, int fd) } else { - DEBUG_MESSAGE("[FDBIO] partial write, mark buffer FULL.\n"); - fdbio->m_flag |= LS_FDBIO_FULL; + DEBUG_MESSAGE("[FDBIO] partial write, mark WBLOCK.\n"); + fdbio->m_flag |= LS_FDBIO_WBLOCK; if (ret > 0) { fdbio->m_wbuf_sent += ret; @@ -374,6 +368,14 @@ static int bio_fd_write(BIO *b, const char *in, int inl) ls_fdbio_data *fdbio = LS_FDBUF_FROM_BIO(b); DEBUG_MESSAGE("[FDBIO] bio_fd_write: %p, %d bytes on %d\n", b, inl, fd); + if (fdbio->m_flag & LS_FDBIO_WBLOCK) + { + DEBUG_MESSAGE("[FDBIO] bio_fd_write, FDBIO_WBLOCK flag is set, set errno to EAGAIN\n"); + BIO_set_retry_write(b); + errno = EAGAIN; + return -1; + } + if (fdbio->m_flag & LS_FDBIO_BUFFERING) { ret = ls_fdbio_buff_write(fdbio, fd, in, inl); @@ -553,19 +555,8 @@ BIO *ls_fdbio_create(int fd, ls_fdbio_data *fdbio) s_biom->destroy = bio_fd_free; #endif } - if (!fdbio->m_rbioBufSz) - fdbio->m_rbioBufSz = RBIO_BUF_SIZE; - - if (!fdbio->m_rbioBuf - && !(fdbio->m_rbioBuf = (char *)ls_palloc(fdbio->m_rbioBufSz))) - { - DEBUG_MESSAGE("Insufficient memory allocating %d bytes\n", - fdbio->m_rbioBufSz); - errno = ENOMEM; - return NULL; - } - fdbio->m_rbioBuffered = 0; - fdbio->m_rbioIndex = 0; + fdbio->m_rbuf_used = 0; + fdbio->m_rbuf_read = 0; BIO *bio = BIO_new(s_biom); if (!bio) @@ -589,4 +580,20 @@ BIO *ls_fdbio_create(int fd, ls_fdbio_data *fdbio) } +static int bio_fd_free(BIO *a) +{ + ls_fdbio_data *fdbio; + DEBUG_MESSAGE("[BIO] bio_fd_free: %p\n", a); + if (a == NULL) + return 0; + fdbio = LS_FDBUF_FROM_BIO(a); + if (!fdbio) + return 1; + fdbio->m_rbuf_used = fdbio->m_rbuf_read = 0; + ls_fdbio_release_rbuff(fdbio); + fdbio->m_wbuf_used = 0; + ls_fdbio_release_wbuff(fdbio); + ls_fdbuf_bio_init(fdbio); + return 1; +} diff --git a/src/sslpp/ls_fdbuf_bio.h b/src/sslpp/ls_fdbuf_bio.h index ef15a3323..747c5e194 100644 --- a/src/sslpp/ls_fdbuf_bio.h +++ b/src/sslpp/ls_fdbuf_bio.h @@ -6,7 +6,7 @@ #ifndef __LS_FDBUF_BIO_H__ #define __LS_FDBUF_BIO_H__ -#include +#include #ifdef __cplusplus extern "C" { @@ -19,12 +19,12 @@ extern "C" { */ typedef struct ls_fdbio_data { - char *m_rbioBuf; - uint16_t m_rbioBuffered; - uint16_t m_rbioIndex; - uint16_t m_rbioBufSz; - uint8_t m_rbioClosed; - uint8_t m_rbioWaitEvent; + uint8_t *m_rbuf; + uint16_t m_rbuf_used; + uint16_t m_rbuf_read; + uint16_t m_rbuf_size; + uint8_t m_is_closed; + uint8_t m_need_read_event; uint8_t *m_wbuf; int32_t m_wbuf_size; @@ -33,6 +33,9 @@ typedef struct ls_fdbio_data { int32_t m_flag; } ls_fdbio_data; +#define LS_FDBIO_WBLOCK 1 +#define LS_FDBIO_BUFFERING 2 + /** * @brief ls_fdbuf_bio_init called during the connection constructor, @@ -55,7 +58,40 @@ struct bio_st *ls_fdbio_create(int fd, ls_fdbio_data *fdbio); int ls_fdbio_flush(ls_fdbio_data *fdbio, int fd); -void ls_fdbio_set_wbuff(ls_fdbio_data *fdbio, int dobuff); +ls_inline void ls_fdbio_set_wbuff(ls_fdbio_data *fdbio, int dobuff) +{ + if (dobuff) + fdbio->m_flag |= LS_FDBIO_BUFFERING; + else + fdbio->m_flag &= ~LS_FDBIO_BUFFERING; +} + +void ls_fdbio_release_wbuff(ls_fdbio_data *fdbio); +void ls_fdbio_release_rbuff(ls_fdbio_data *fdbio); + +ls_inline int ls_fdbio_is_wbuf_idle(ls_fdbio_data *fdbio) +{ + return fdbio->m_wbuf && fdbio->m_wbuf_used == 0; +} + +ls_inline int ls_fdbio_is_rbuf_idle(ls_fdbio_data *fdbio) +{ + return fdbio->m_rbuf && fdbio->m_rbuf_used == fdbio->m_rbuf_read; +} + +ls_inline void ls_fdbio_release_idle_buffer(ls_fdbio_data *fdbio) +{ + if (ls_fdbio_is_wbuf_idle(fdbio)) + ls_fdbio_release_wbuff(fdbio); + if (ls_fdbio_is_rbuf_idle(fdbio)) + ls_fdbio_release_rbuff(fdbio); +} + +ls_inline int ls_fdbio_is_wblock(ls_fdbio_data *fdbio) +{ return fdbio->m_flag & LS_FDBIO_WBLOCK; } + +ls_inline void ls_fdbio_clear_wblock(ls_fdbio_data *fdbio) +{ fdbio->m_flag &= ~LS_FDBIO_WBLOCK; } #ifdef __cplusplus } diff --git a/src/sslpp/sslconnection.cpp b/src/sslpp/sslconnection.cpp index e0fcd8d7d..feeabe01a 100644 --- a/src/sslpp/sslconnection.cpp +++ b/src/sslpp/sslconnection.cpp @@ -103,7 +103,7 @@ int SslConnection::setfd(int fd) DEBUG_MESSAGE("[SSL: %p] setfd: %d\n", this, fd); if (m_ssl) { - if (fd != -1 && m_bio.m_rbioBuf == NULL) + if (fd != -1 && m_bio.m_rbuf == NULL) { BIO * bio = ls_fdbio_create(fd, &m_bio); SSL_set_bio(m_ssl, bio, bio); @@ -122,9 +122,9 @@ int SslConnection::read(char *pBuf, int len) char *p = pBuf; char *pEnd = pBuf + len; int ret; - m_bio.m_rbioWaitEvent = 0; - while(p < pEnd && (m_bio.m_rbioIndex < m_bio.m_rbioBuffered - || !m_bio.m_rbioWaitEvent)) + m_bio.m_need_read_event = 0; + while(p < pEnd && (m_bio.m_rbuf_read < m_bio.m_rbuf_used + || !m_bio.m_need_read_event)) { DEBUG_MESSAGE("[SSL: %p] SSL_read\n", this); ret = SSL_read(m_ssl, p, pEnd - p); @@ -237,6 +237,10 @@ int SslConnection::wpending() } +//return +// 0: not flushed +// 1: flushed +// -1: error int SslConnection::flush() { DEBUG_MESSAGE("[SSL: %p] flush\n", this); @@ -657,9 +661,9 @@ int SslConnection::getEnv(HioCrypto::ENV id, char *&pValue, int bufLen) char* SslConnection::getRawBuffer(int *len) { DEBUG_MESSAGE("[SSL: %p] getRawBuffer: len: %d\n", this, - m_bio.m_rbioBuffered); - *len = m_bio.m_rbioBuffered; - return m_bio.m_rbioBuf; + m_bio.m_rbuf_used); + *len = m_bio.m_rbuf_used; + return (char *)m_bio.m_rbuf; } @@ -720,3 +724,11 @@ void SslConnection::setWriteBuffering(int buffering) { ls_fdbio_set_wbuff(&m_bio, buffering); } + + +void SslConnection::releaseIdleBuffer() +{ + ls_fdbio_release_idle_buffer(&m_bio); +} + + diff --git a/src/sslpp/sslconnection.h b/src/sslpp/sslconnection.h index bc696df3c..dd8e24a97 100644 --- a/src/sslpp/sslconnection.h +++ b/src/sslpp/sslconnection.h @@ -47,6 +47,7 @@ class SslConnection : public HioCrypto char lastWrite() const { return m_iWant & LAST_WRITE; } char wantCert() const { return m_iWant & WANT_CERT; } void clearWantCert() { m_iWant &= ~WANT_CERT; } + void setAllowWrite() { ls_fdbio_clear_wblock(&m_bio); } int getFlag(int v) const { return m_flag & v; } void setFlag(int f, int v) { m_flag = (m_flag & ~f) | (v ? f : 0); } @@ -124,8 +125,9 @@ class SslConnection : public HioCrypto // raw data which can be used in a redirect (see ntwkiolink.cpp). char *getRawBuffer(int *len); bool hasPendingIn() const - { return m_bio.m_rbioBuffered > m_bio.m_rbioIndex; } + { return m_bio.m_rbuf_used > m_bio.m_rbuf_read; } + void releaseIdleBuffer(); bool isWaitingAsyncCert() const { return (getFlag(F_ASYNC_CERT | F_ASYNC_CERT_FAIL) == F_ASYNC_CERT); } diff --git a/src/util/httputil.cpp b/src/util/httputil.cpp index d369ccb42..12d982617 100644 --- a/src/util/httputil.cpp +++ b/src/util/httputil.cpp @@ -198,7 +198,7 @@ int HttpUtil::escapeQs(const char *pSrc, char *pDest, int iDestLen) case '=': case '%': case '\'': - if (iDestLen < 3) + if (iDestLen > 3) { *p++ = '%'; *p++ = StringTool::s_aHex[(ch >> 4) & 15];