@@ -250,6 +250,13 @@ _dlg_versions() {
250250 socat -V 2>&1
251251 else
252252 _debug " socat doesn't exist."
253+ if _exists " python3" ; then
254+ python3 -V 2>&1
255+ elif _exists " python2" ; then
256+ python2 -V 2>&1
257+ elif _exists " python" ; then
258+ python -V 2>&1
259+ fi
253260 fi
254261}
255262
@@ -2559,41 +2566,76 @@ _startserver() {
25592566 _debug Le_Listen_V4 " $Le_Listen_V4 "
25602567 _debug Le_Listen_V6 " $Le_Listen_V6 "
25612568
2562- _NC=" socat"
2563- if [ " $Le_Listen_V6 " ]; then
2564- _NC=" $_NC -6"
2565- SOCAT_OPTIONS=TCP6-LISTEN
2566- elif [ " $Le_Listen_V4 " ]; then
2567- _NC=" $_NC -4"
2568- SOCAT_OPTIONS=TCP4-LISTEN
2569- else
2570- SOCAT_OPTIONS=TCP-LISTEN
2571- fi
2569+ if _exists " socat" ; then
2570+ _NC=" socat"
2571+ if [ " $Le_Listen_V6 " ]; then
2572+ _NC=" $_NC -6"
2573+ SOCAT_OPTIONS=TCP6-LISTEN
2574+ elif [ " $Le_Listen_V4 " ]; then
2575+ _NC=" $_NC -4"
2576+ SOCAT_OPTIONS=TCP4-LISTEN
2577+ else
2578+ SOCAT_OPTIONS=TCP-LISTEN
2579+ fi
25722580
2573- if [ " $DEBUG " ] && [ " $DEBUG " -gt " 1" ]; then
2574- _NC=" $_NC -d -d -v"
2575- fi
2581+ if [ " $DEBUG " ] && [ " $DEBUG " -gt " 1" ]; then
2582+ _NC=" $_NC -d -d -v"
2583+ fi
25762584
2577- SOCAT_OPTIONS=$SOCAT_OPTIONS :$Le_HTTPPort ,crlf,reuseaddr,fork
2585+ SOCAT_OPTIONS=$SOCAT_OPTIONS :$Le_HTTPPort ,crlf,reuseaddr,fork
25782586
2579- # Adding bind to local-address
2580- if [ " $ncaddr " ]; then
2581- SOCAT_OPTIONS=" $SOCAT_OPTIONS ,bind=${ncaddr} "
2582- fi
2587+ # Adding bind to local-address
2588+ if [ " $ncaddr " ]; then
2589+ SOCAT_OPTIONS=" $SOCAT_OPTIONS ,bind=${ncaddr} "
2590+ fi
25832591
2584- _content_len=" $( printf " %s" " $content " | wc -c) "
2585- _debug _content_len " $_content_len "
2586- _debug " _NC" " $_NC $SOCAT_OPTIONS "
2587- export _SOCAT_ERR=" $( _mktemp) "
2588- $_NC $SOCAT_OPTIONS SYSTEM:" sleep 1; \
2592+ _content_len=" $( printf " %s" " $content " | wc -c) "
2593+ _debug _content_len " $_content_len "
2594+ _debug " _NC" " $_NC $SOCAT_OPTIONS "
2595+ export _SOCAT_ERR=" $( _mktemp) "
2596+ $_NC $SOCAT_OPTIONS SYSTEM:" sleep 1; \
25892597echo 'HTTP/1.0 200 OK'; \
25902598echo 'Content-Length\: $_content_len '; \
25912599echo ''; \
25922600printf '%s' '$content ';" 2> " $_SOCAT_ERR " &
2593- serverproc=" $! "
2601+ serverproc=" $! "
2602+ else
2603+ _PYTHON=" "
2604+ if _exists " python3" ; then
2605+ _PYTHON=" python3"
2606+ elif _exists " python2" ; then
2607+ _PYTHON=" python2"
2608+ elif _exists " python" ; then
2609+ _PYTHON=" python"
2610+ fi
2611+ if [ " $_PYTHON " ]; then
2612+ _debug " Using python: $_PYTHON "
2613+ _AF=" socket.AF_INET"
2614+ _BIND_ADDR=" 0.0.0.0"
2615+ if [ " $Le_Listen_V6 " ]; then
2616+ _AF=" socket.AF_INET6"
2617+ _BIND_ADDR=" ::"
2618+ fi
2619+ if [ " $ncaddr " ]; then
2620+ _BIND_ADDR=" $ncaddr "
2621+ fi
2622+ export _SOCAT_ERR=" $( _mktemp) "
2623+ $_PYTHON -c " import socket,sys;s=socket.socket($_AF ,socket.SOCK_STREAM);s.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1);s.bind((sys.argv[2],int(sys.argv[1])));s.listen(5);res='HTTP/1.0 200 OK\r\nContent-Length: '+str(len(sys.argv[3]))+'\r\n\r\n'+sys.argv[3];
2624+ while True:
2625+ c,a=s.accept()
2626+ c.sendall(res.encode() if hasattr(res, 'encode') else res)
2627+ c.close()" " $Le_HTTPPort " " $_BIND_ADDR " " $content " 2> " $_SOCAT_ERR " &
2628+ serverproc=" $! "
2629+ _NC=" $_PYTHON "
2630+ else
2631+ _err " Please install socat or python first for standalone mode."
2632+ return 1
2633+ fi
2634+ fi
2635+
25942636 if [ -f " $_SOCAT_ERR " ]; then
25952637 if grep " Permission denied" " $_SOCAT_ERR " > /dev/null; then
2596- _err " socat : $( cat $_SOCAT_ERR ) "
2638+ _err " $_NC : $( cat $_SOCAT_ERR ) "
25972639 _err " Can not listen for user: $( whoami) "
25982640 _err " Maybe try with root again?"
25992641 rm -f " $_SOCAT_ERR "
@@ -3557,9 +3599,9 @@ _on_before_issue() {
35573599 fi
35583600 fi
35593601
3560- if _hasfield " $_chk_web_roots " " $NO_VALUE " ; then
3561- if ! _exists " socat" ; then
3562- _err " Please install socat tools first."
3602+ if _hasfield " $_chk_web_roots " " $NO_VALUE " && [ " $_chk_web_roots " = " $NO_VALUE " ] ; then
3603+ if ! _exists " socat" && ! _exists " python " && ! _exists " python2 " && ! _exists " python3 " ; then
3604+ _err " Please install socat or python tools first."
35633605 return 1
35643606 fi
35653607 fi
@@ -6664,9 +6706,9 @@ _precheck() {
66646706 return 1
66656707 fi
66666708
6667- if ! _exists " socat" ; then
6668- _err " It is recommended to install socat first."
6669- _err " We use socat for the standalone server, which is used for standalone mode."
6709+ if ! _exists " socat" && ! _exists " python " && ! _exists " python2 " && ! _exists " python3 " ; then
6710+ _err " It is recommended to install socat or python first."
6711+ _err " We use socat or python for the standalone server, which is used for standalone mode."
66706712 _err " If you don't want to use standalone mode, you may ignore this warning."
66716713 fi
66726714
0 commit comments