From 923edfe43051890cebcab0f9b795c0ab0ad28800 Mon Sep 17 00:00:00 2001 From: Gabriel Adrian Samfira Date: Thu, 8 Oct 2020 11:55:59 +0300 Subject: [PATCH] Add snapcraft and small fixes * add install target to aid in packaging * add webroot files to INSTALL_DIR/share/wsgate * look for X-Forwarded-Proto when generating the ws(s):// URL. This allows WSS --> WS reverse proxy support. --- snap/snapcraft.yaml | 87 ++++++++++++++++ wsgate/CMakeLists.txt | 1 + wsgate/webroot/CMakeLists.txt | 184 +++++++++++++++++++--------------- wsgate/wsgateEHS.cpp | 10 +- 4 files changed, 198 insertions(+), 84 deletions(-) create mode 100644 snap/snapcraft.yaml diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml new file mode 100644 index 00000000..6a217f99 --- /dev/null +++ b/snap/snapcraft.yaml @@ -0,0 +1,87 @@ +name: wsgate +version: "1.2.0.444" +summary: FreeRDP WebConnect +description: A HTML5 gateway to FreeRDP +architectures: + - amd64 +confinement: strict +base: core18 +apps: + wsgate: + command: usr/bin/wsgate + plugs: + - network + - network-bind +grade: stable +parts: + ehs: + plugin: cmake + source: https://github.com/cloudbase/EHS.git + source-type: git + configflags: + - "-DCMAKE_INSTALL_PREFIX=/usr" + build-packages: + - cmake + - g++ + - pkg-config + - zlib1g-dev + - libssl-dev + - libboost-dev + - libboost-filesystem-dev + - libboost-program-options-dev + - libboost-system-dev + - libboost-regex-dev + wsgate: + plugin: cmake + after: [ehs] + source-subdir: wsgate + source: . + #source-type: git + configflags: + - "-DCMAKE_INSTALL_PREFIX=/usr" + build-packages: + - pkg-config + - libfreerdp-dev + - libcpprest-dev + - libpng-dev + stage-packages: + - libboost-filesystem1.65.1 + - libboost-program-options1.65.1 + - libboost-regex1.65.1 + - libboost-system1.65.1 + - libcpprest2.10 + - libfreerdp-cache1.1 + - libfreerdp-codec1.1 + - libfreerdp-common1.1.0 + - libfreerdp-core1.1 + - libfreerdp-crypto1.1 + - libfreerdp-gdi1.1 + - libfreerdp-locale1.1 + - libfreerdp-primitives1.1 + - libfreerdp-utils1.1 + - libicu60 + - libjpeg-turbo8 + - libwinpr-crt0.1 + - libwinpr-dsparse0.1 + - libwinpr-environment0.1 + - libwinpr-file0.1 + - libwinpr-handle0.1 + - libwinpr-heap0.1 + - libwinpr-input0.1 + - libwinpr-interlocked0.1 + - libwinpr-library0.1 + - libwinpr-path0.1 + - libwinpr-pool0.1 + - libwinpr-registry0.1 + - libwinpr-rpc0.1 + - libwinpr-sspi0.1 + - libwinpr-synch0.1 + - libwinpr-sysinfo0.1 + - libwinpr-thread0.1 + - libwinpr-utils0.1 + - libx11-6 + - libxau6 + - libxcb1 + - libxdmcp6 + - libxkbfile1 + diff --git a/wsgate/CMakeLists.txt b/wsgate/CMakeLists.txt index 4fd6d1a8..b3b93bcc 100644 --- a/wsgate/CMakeLists.txt +++ b/wsgate/CMakeLists.txt @@ -607,3 +607,4 @@ endif() add_executable(wsgate ${WSGATE_SOURCES}) target_link_libraries(wsgate ${LIBS}) +install(TARGETS wsgate DESTINATION bin) diff --git a/wsgate/webroot/CMakeLists.txt b/wsgate/webroot/CMakeLists.txt index a78411b3..efb1bf65 100644 --- a/wsgate/webroot/CMakeLists.txt +++ b/wsgate/webroot/CMakeLists.txt @@ -3,11 +3,13 @@ project("wsgate") # if MSVC, prevent it from capturing output if(MSVC) - set(ENV{VS_UNICODE_OUTPUT} "") + set(ENV{VS_UNICODE_OUTPUT} "") endif() # define js files set(JS_FILES modernizr-debug.js mootools-debug.js simpletabs-debug.js vkb-debug.js wsgate-debug.js) set(JS_STRIPPED_FILES) +set(IMAGE_FILES FreeRDP_Logo.png c_default.png c_none.png favicon.ico) +set(ASSET_DIRS fonts images) # create destionation dir for js files execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/js) @@ -24,99 +26,115 @@ find_package(Perl) find_package(Java) if (PERL_FOUND) - add_custom_command( - OUTPUT index.html - COMMAND ${PERL_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tools/strip-debug.pl ${CMAKE_CURRENT_SOURCE_DIR}/index-debug.html > ${CMAKE_CURRENT_BINARY_DIR}/index.html - #COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/index.html.tmp ${CMAKE_CURRENT_BINARY_DIR}/index.html - # clean-up tempfile - #COMMAND ${CMAKE_COMMAND} -E remove -f ${CMAKE_CURRENT_BINARY_DIR}/index.html.tmp - DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/index-debug.html - ) - - # strip debug and generate js files - foreach(js_file ${JS_FILES}) - string(REPLACE "-debug" "" stripped_js_file ${js_file}) - - add_custom_command( - OUTPUT js/${stripped_js_file} - COMMAND ${PERL_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tools/strip-debug.pl ${CMAKE_CURRENT_SOURCE_DIR}/js/${js_file} > ${CMAKE_CURRENT_BINARY_DIR}/js/${stripped_js_file} - DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/js/${js_file} - ) - - set(JS_STRIPPED_FILES ${JS_STRIPPED_FILES} js/${stripped_js_file}) - endforeach() - - # strip debug and generate css files - foreach(css_file ${CSS_FILES}) - string(REPLACE "-debug" "" stripped_css_file ${css_file}) - add_custom_command( - OUTPUT css/${stripped_css_file} - COMMAND ${PERL_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tools/strip-debug.pl ${CMAKE_CURRENT_SOURCE_DIR}/css/${css_file} > ${CMAKE_CURRENT_BINARY_DIR}/css/${stripped_css_file} - DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/css/${css_file} - ) - - set(CSS_STRIPPED_FILES ${CSS_STRIPPED_FILES} css/${stripped_css_file}) - endforeach() + add_custom_command( + OUTPUT index.html + COMMAND ${PERL_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tools/strip-debug.pl ${CMAKE_CURRENT_SOURCE_DIR}/index-debug.html > ${CMAKE_CURRENT_BINARY_DIR}/index.html + #COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/index.html.tmp ${CMAKE_CURRENT_BINARY_DIR}/index.html + # clean-up tempfile + #COMMAND ${CMAKE_COMMAND} -E remove -f ${CMAKE_CURRENT_BINARY_DIR}/index.html.tmp + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/index-debug.html + ) + + # strip debug and generate js files + foreach(js_file ${JS_FILES}) + string(REPLACE "-debug" "" stripped_js_file ${js_file}) + + add_custom_command( + OUTPUT js/${stripped_js_file} + COMMAND ${PERL_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tools/strip-debug.pl ${CMAKE_CURRENT_SOURCE_DIR}/js/${js_file} > ${CMAKE_CURRENT_BINARY_DIR}/js/${stripped_js_file} + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/js/${js_file} + ) + + set(JS_STRIPPED_FILES ${JS_STRIPPED_FILES} js/${stripped_js_file}) + endforeach() + + # strip debug and generate css files + foreach(css_file ${CSS_FILES}) + string(REPLACE "-debug" "" stripped_css_file ${css_file}) + add_custom_command( + OUTPUT css/${stripped_css_file} + COMMAND ${PERL_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tools/strip-debug.pl ${CMAKE_CURRENT_SOURCE_DIR}/css/${css_file} > ${CMAKE_CURRENT_BINARY_DIR}/css/${stripped_css_file} + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/css/${css_file} + ) + + set(CSS_STRIPPED_FILES ${CSS_STRIPPED_FILES} css/${stripped_css_file}) + endforeach() else() - message(WARNING "Perl not found. *-debug.{html|js|css} will only be renamed (not stripped).") - - # just copy index-debug.html and change its name to index.html - add_custom_command( - OUTPUT index.html - COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/index-debug.html ${CMAKE_CURRENT_BINARY_DIR}/index.html - DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/index-debug.html - ) - - # just copy *-debug.js and change its name to *.js - foreach(js_file ${JS_FILES}) - string(REPLACE "-debug" "" stripped_js_file ${js_file}) - add_custom_command( - OUTPUT js/${stripped_js_file} - COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/js/${js_file} ${CMAKE_CURRENT_BINARY_DIR}/js/${stripped_js_file} - DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/js/${js_file} - ) - set(JS_STRIPPED_FILES ${JS_STRIPPED_FILES} js/${stripped_js_file}) - endforeach() - - # just copy *-debug.css and change its name to *.css - foreach(css_file ${CSS_FILES}) - string(REPLACE "-debug" "" stripped_css_file ${css_file}) - add_custom_command( - OUTPUT css/${stripped_css_file} - COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/css/${css_file} ${CMAKE_CURRENT_BINARY_DIR}/css/${stripped_css_file} - DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/css/${css_file} - ) - set(CSS_STRIPPED_FILES ${CSS_STRIPPED_FILES} css/${stripped_css_file}) - endforeach() + message(WARNING "Perl not found. *-debug.{html|js|css} will only be renamed (not stripped).") + + # just copy index-debug.html and change its name to index.html + add_custom_command( + OUTPUT index.html + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/index-debug.html ${CMAKE_CURRENT_BINARY_DIR}/index.html + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/index-debug.html + ) + + # just copy *-debug.js and change its name to *.js + foreach(js_file ${JS_FILES}) + string(REPLACE "-debug" "" stripped_js_file ${js_file}) + add_custom_command( + OUTPUT js/${stripped_js_file} + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/js/${js_file} ${CMAKE_CURRENT_BINARY_DIR}/js/${stripped_js_file} + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/js/${js_file} + ) + set(JS_STRIPPED_FILES ${JS_STRIPPED_FILES} js/${stripped_js_file}) + endforeach() + + # just copy *-debug.css and change its name to *.css + foreach(css_file ${CSS_FILES}) + string(REPLACE "-debug" "" stripped_css_file ${css_file}) + add_custom_command( + OUTPUT css/${stripped_css_file} + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/css/${css_file} ${CMAKE_CURRENT_BINARY_DIR}/css/${stripped_css_file} + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/css/${css_file} + ) + set(CSS_STRIPPED_FILES ${CSS_STRIPPED_FILES} css/${stripped_css_file}) + endforeach() endif() # the following section has not been tested yet # if java found, use yuicompressor.jar to compress the js and css files if (JAVA_FOUND) - # use the same work-around as above for stdout redirection. - foreach(stripped_js_file ${JS_STRIPPED_FILES}) - add_custom_command( - OUTPUT js/${stripped_js_file} - COMMAND ${Java_JAVA_EXECUTABLE} -jar ${CMAKE_SOURCE_DIR}/tools/yuicompressor.jar --type js ${CMAKE_CURRENT_BINARY_DIR}/js/${stripped_js_file} > ${CMAKE_CURRENT_BINARY_DIR}/js/${stripped_js_file} - DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/js/${stripped_js_file} - ) - - endforeach() - - foreach(stripped_css_file ${CSS_STRIPPED_FILES}) - add_custom_command( - OUTPUT css/${stripped_css_file} - COMMAND ${Java_JAVA_EXECUTABLE} -jar ${CMAKE_SOURCE_DIR}/tools/yuicompressor.jar --type css ${CMAKE_CURRENT_BINARY_DIR}/css/${stripped_css_file} > ${CMAKE_CURRENT_BINARY_DIR}/css/${stripped_css_file} - DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/css/${stripped_css_file} - ) - endforeach() + # use the same work-around as above for stdout redirection. + foreach(stripped_js_file ${JS_STRIPPED_FILES}) + add_custom_command( + OUTPUT js/${stripped_js_file} + COMMAND ${Java_JAVA_EXECUTABLE} -jar ${CMAKE_SOURCE_DIR}/tools/yuicompressor.jar --type js ${CMAKE_CURRENT_BINARY_DIR}/js/${stripped_js_file} > ${CMAKE_CURRENT_BINARY_DIR}/js/${stripped_js_file} + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/js/${stripped_js_file} + ) + + endforeach() + + foreach(stripped_css_file ${CSS_STRIPPED_FILES}) + add_custom_command( + OUTPUT css/${stripped_css_file} + COMMAND ${Java_JAVA_EXECUTABLE} -jar ${CMAKE_SOURCE_DIR}/tools/yuicompressor.jar --type css ${CMAKE_CURRENT_BINARY_DIR}/css/${stripped_css_file} > ${CMAKE_CURRENT_BINARY_DIR}/css/${stripped_css_file} + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/css/${stripped_css_file} + ) + endforeach() else() - message(STATUS "Java executable not found. Files will not be compressed.") + message(STATUS "Java executable not found. Files will not be compressed.") endif() +foreach(img_file ${IMAGE_FILES}) + message(${img_file}) + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${img_file} ${CMAKE_CURRENT_BINARY_DIR}/${img_file} COPYONLY) +endforeach() + +foreach(asset_folder ${ASSET_DIRS}) + message(${asset_folder}) + file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/${asset_folder} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) +endforeach() + SET_SOURCE_FILES_PROPERTIES(${JS_STRIPPED_FILES} PROPERTIES GENERATED TRUE) SET_SOURCE_FILES_PROPERTIES(${CSS_STRIPPED_FILES} PROPERTIES GENERATED TRUE) -add_custom_target(strip_debug ALL DEPENDS index.html ${JS_STRIPPED_FILES} ${CMAKE_CURRENT_BINARY_DIR}/${CSS_STRIPPED_FILES}) \ No newline at end of file +add_custom_target(strip_debug ALL DEPENDS index.html ${JS_STRIPPED_FILES} ${CMAKE_CURRENT_BINARY_DIR}/${CSS_STRIPPED_FILES}) +install( + DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" + DESTINATION share/wsgate + PATTERN "Makefile" EXCLUDE + PATTERN "CMakeFiles" EXCLUDE + PATTERN "cmake_install.cmake" EXCLUDE) diff --git a/wsgate/wsgateEHS.cpp b/wsgate/wsgateEHS.cpp index 2244d58d..3bccbef1 100644 --- a/wsgate/wsgateEHS.cpp +++ b/wsgate/wsgateEHS.cpp @@ -537,7 +537,15 @@ namespace wsgate{ if (HTML == mt) { ostringstream oss; - oss << (request->Secure() ? "wss://" : "ws://") << thisHost << "/wsgate"; + if (request->Secure() || request->Headers("X-Forwarded-Proto") == "https") + { + oss << "wss://"; + } + else + { + oss << "ws://"; + } + oss << thisHost << "/wsgate"; replace_all(body, "%WSURI%", oss.str()); replace_all(body, "%JSDEBUG%", (bDynDebug ? "-debug" : ""));