From f37b32b140f2f041968d50640a60ab739a476541 Mon Sep 17 00:00:00 2001 From: Justin Travis Date: Tue, 2 Aug 2022 18:33:01 +0000 Subject: [PATCH] Resolve KASM-1991 "Feature/ gamepad" --- .gitlab-ci.yml | 30 +- dockerfile-kasm-core | 8 +- dockerfile-kasm-core-centos | 8 +- dockerfile-kasm-core-oracle | 8 +- dockerfile-kasm-core-suse | 8 +- src/common/startup_scripts/vnc_startup.sh | 20 + src/ubuntu/install/gamepad/gamepad.svg | 530 ++++++++++++++++++ src/ubuntu/install/gamepad/install_gamepad.sh | 24 + src/ubuntu/install/xfce/install_xfce_ui.sh | 6 +- 9 files changed, 620 insertions(+), 22 deletions(-) create mode 100644 src/ubuntu/install/gamepad/gamepad.svg create mode 100644 src/ubuntu/install/gamepad/install_gamepad.sh diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 41ae178..75bb52b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -142,7 +142,7 @@ build_kali_rolling: - /^release\/.*$/ except: - schedules - tags: + tags: - aws-autoscale build_centos: @@ -220,10 +220,10 @@ build_ubuntu_bionic_dev: stage: build script: - > - docker build + docker build -t ${ORG_NAME}/core-ubuntu-bionic-private:$(arch)-$SANITIZED_BRANCH --build-arg START_PULSEAUDIO=1 - --build-arg START_XFCE4=1 + --build-arg START_XFCE4=1 --build-arg BASE_IMAGE="ubuntu:18.04" --build-arg BG_IMG=bg_bionic.png -f dockerfile-kasm-core . @@ -241,7 +241,7 @@ build_ubuntu_focal_dev: stage: build script: - > - docker build + docker build -t ${ORG_NAME}/core-ubuntu-focal-private:$(arch)-$SANITIZED_BRANCH --build-arg START_PULSEAUDIO=1 --build-arg BASE_IMAGE="ubuntu:20.04" @@ -283,7 +283,7 @@ build_cuda_focal_dev: stage: build script: - > - docker build + docker build -t ${ORG_NAME}/core-cuda-focal-private:$SANITIZED_BRANCH --build-arg START_PULSEAUDIO=1 --build-arg BASE_IMAGE="nvidia/cuda:11.6.2-cudnn8-devel-ubuntu20.04" @@ -301,7 +301,7 @@ build_remnux_bionic_dev: stage: build script: - > - docker build + docker build -t ${ORG_NAME}/core-remnux-bionic-private:$SANITIZED_BRANCH --build-arg BASE_IMAGE="remnux/remnux-distro:bionic" --build-arg START_PULSEAUDIO=1 @@ -320,7 +320,7 @@ build_remnux_focal_dev: stage: build script: - > - docker build + docker build -t ${ORG_NAME}/core-remnux-focal-private:$SANITIZED_BRANCH --build-arg START_PULSEAUDIO=1 --build-arg BASE_IMAGE="remnux/remnux-distro:focal" @@ -339,7 +339,7 @@ build_kali_rolling_dev: stage: build script: - > - docker build + docker build -t ${ORG_NAME}/core-kali-rolling-private:$(arch)-$SANITIZED_BRANCH --build-arg BASE_IMAGE="kalilinux/kali-rolling:latest" --build-arg START_PULSEAUDIO="1" @@ -363,7 +363,7 @@ build_centos_dev: stage: build script: - > - docker build + docker build -t ${ORG_NAME}/core-centos-7-private:$SANITIZED_BRANCH --build-arg BASE_IMAGE="centos:centos7" --build-arg START_PULSEAUDIO="1" @@ -384,7 +384,7 @@ build_oracle_7_dev: stage: build script: - > - docker build + docker build -t ${ORG_NAME}/core-oracle-7-private:$SANITIZED_BRANCH --build-arg BASE_IMAGE="oraclelinux:7" --build-arg START_PULSEAUDIO="1" @@ -405,7 +405,7 @@ build_oracle_8_dev: stage: build script: - > - docker build + docker build -t ${ORG_NAME}/core-oracle-8-private:$(arch)-$SANITIZED_BRANCH --build-arg START_PULSEAUDIO=1 --build-arg START_XFCE4=1 @@ -426,7 +426,7 @@ build_opensuse_15_dev: stage: build script: - > - docker build + docker build -t ${ORG_NAME}/core-opensuse-15-private:$(arch)-$SANITIZED_BRANCH --build-arg START_PULSEAUDIO=1 --build-arg START_XFCE4=1 @@ -674,7 +674,7 @@ build_kali_rolling_schedules: - docker buildx build --push --platform $BUILD_PLATFORMS -t ${ORG_NAME}/core-kali-rolling-private:$SANITIZED_ROLLING_BRANCH -t ${ORG_NAME}/core-kali-rolling:$SANITIZED_ROLLING_BRANCH --build-arg BASE_IMAGE="kalilinux/kali-rolling:latest" --build-arg START_PULSEAUDIO="1" --build-arg EXTRA_SH="kali.sh" --build-arg DISTRO="kali" --build-arg LANG="" --build-arg LANGUAGE="" --build-arg LC_ALL="" -f dockerfile-kasm-core . only: - schedules - tags: + tags: - aws-autoscale build_centos_schedules: @@ -744,7 +744,7 @@ update_readmes: -e DOCKER_PASSWORD="$README_PASSWORD" -e DOCKERHUB_REPOSITORY="${ORG_NAME}/$KASM_IMAGE-private" -e README_FILEPATH="/workspace/docs/$KASM_IMAGE/FULL_README.md" - -e DESCRIPTION_FILEPATH="/workspace/docs/$KASM_IMAGE/description.txt" + -e DESCRIPTION_FILEPATH="/workspace/docs/$KASM_IMAGE/description.txt" ${ORG_NAME}/dockerhub-updater:latest - > docker run -v $PWD:/workspace @@ -761,7 +761,7 @@ update_readmes: - $README_PASSWORD parallel: matrix: - - KASM_IMAGE: + - KASM_IMAGE: - core-centos-7 - core-oracle-7 - core-oracle-8 diff --git a/dockerfile-kasm-core b/dockerfile-kasm-core index 9b3ffaa..fe0277e 100644 --- a/dockerfile-kasm-core +++ b/dockerfile-kasm-core @@ -42,7 +42,8 @@ ENV DISPLAY=:1 \ LANGUAGE=$LANGUAGE \ LC_ALL=$LC_ALL \ KASMVNC_AUTO_RECOVER=true \ - PULSE_RUNTIME_PATH=/var/run/pulse + PULSE_RUNTIME_PATH=/var/run/pulse \ + SDL_GAMECONTROLLERCONFIG="030000005e040000be02000014010000,XInput Controller,platform:Linux,a:b0,b:b1,x:b2,y:b3,back:b8,guide:b16,start:b9,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:b12,dpdown:b13,dpleft:b14,dpright:b15,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7" EXPOSE $VNC_PORT \ $NO_VNC_PORT \ @@ -99,6 +100,10 @@ RUN bash $INST_SCRIPTS/audio/install_audio.sh && rm -rf $INST_SCRIPTS/audio/ COPY ./src/ubuntu/install/audio_input $INST_SCRIPTS/audio_input/ RUN bash $INST_SCRIPTS/audio_input/install_audio_input.sh && rm -rf $INST_SCRIPTS/audio_input/ +### Install Gamepad Service +COPY ./src/ubuntu/install/gamepad $INST_SCRIPTS/gamepad/ +RUN bash $INST_SCRIPTS/gamepad/install_gamepad.sh && rm -rf $INST_SCRIPTS/gamepad/ + ### Install custom cursors COPY ./src/ubuntu/install/cursors $INST_SCRIPTS/cursors/ RUN bash $INST_SCRIPTS/cursors/install_cursors.sh && rm -rf $INST_SCRIPTS/cursors/ @@ -155,6 +160,7 @@ RUN touch $STARTUPDIR/wm.log \ && find $STARTUPDIR -type f -iname "*.log" -exec chmod 666 {} \; \ && chmod 755 $STARTUPDIR/upload_server/kasm_upload_server \ && chmod 755 $STARTUPDIR/audio_input/kasm_audio_input_server \ + && chmod 755 $STARTUPDIR/gamepad/kasm_gamepad_server \ && chmod 755 $STARTUPDIR/generate_container_user \ && chmod +x $STARTUPDIR/jsmpeg/kasm_audio_out-linux \ && rm -rf $STARTUPDIR/install \ diff --git a/dockerfile-kasm-core-centos b/dockerfile-kasm-core-centos index f6ff23a..504d40e 100644 --- a/dockerfile-kasm-core-centos +++ b/dockerfile-kasm-core-centos @@ -56,7 +56,8 @@ ENV DISPLAY=:1 \ LC_ALL=$LC_ALL \ SINGLE_APPLICATION=0 \ KASMVNC_AUTO_RECOVER=true \ - PULSE_RUNTIME_PATH=/var/run/pulse + PULSE_RUNTIME_PATH=/var/run/pulse \ + SDL_GAMECONTROLLERCONFIG="030000005e040000be02000014010000,XInput Controller,platform:Linux,a:b0,b:b1,x:b2,y:b3,back:b8,guide:b16,start:b9,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:b12,dpdown:b13,dpleft:b14,dpright:b15,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7" EXPOSE $VNC_PORT \ $NO_VNC_PORT \ @@ -104,6 +105,10 @@ RUN bash $INST_SCRIPTS/audio/install_audio.sh && rm -rf $INST_SCRIPTS/audio/ COPY ./src/ubuntu/install/audio_input $INST_SCRIPTS/audio_input/ RUN bash $INST_SCRIPTS/audio_input/install_audio_input.sh && rm -rf $INST_SCRIPTS/audio_input/ +### Install Gamepad Service +COPY ./src/ubuntu/install/gamepad $INST_SCRIPTS/gamepad/ +RUN bash $INST_SCRIPTS/gamepad/install_gamepad.sh && rm -rf $INST_SCRIPTS/gamepad/ + ### Copy built Squid COPY --from=squid_builder /usr/local/squid /usr/local/squid @@ -155,6 +160,7 @@ RUN touch $STARTUPDIR/wm.log \ && find $STARTUPDIR -type f -iname "*.log" -exec chmod 666 {} \; \ && chmod 755 $STARTUPDIR/upload_server/kasm_upload_server \ && chmod 755 $STARTUPDIR/audio_input/kasm_audio_input_server \ + && chmod 755 $STARTUPDIR/gamepad/kasm_gamepad_server \ && chmod 755 $STARTUPDIR/generate_container_user \ && chmod +x $STARTUPDIR/jsmpeg/kasm_audio_out-linux \ && rm -rf $STARTUPDIR/install \ diff --git a/dockerfile-kasm-core-oracle b/dockerfile-kasm-core-oracle index ba02e4a..8441a98 100644 --- a/dockerfile-kasm-core-oracle +++ b/dockerfile-kasm-core-oracle @@ -65,7 +65,8 @@ ENV DISPLAY=:1 \ LC_ALL=$LC_ALL \ SINGLE_APPLICATION=0 \ KASMVNC_AUTO_RECOVER=true \ - PULSE_RUNTIME_PATH=/var/run/pulse + PULSE_RUNTIME_PATH=/var/run/pulse \ + SDL_GAMECONTROLLERCONFIG="030000005e040000be02000014010000,XInput Controller,platform:Linux,a:b0,b:b1,x:b2,y:b3,back:b8,guide:b16,start:b9,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:b12,dpdown:b13,dpleft:b14,dpright:b15,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7" EXPOSE $VNC_PORT \ $NO_VNC_PORT \ @@ -117,6 +118,10 @@ RUN bash $INST_SCRIPTS/audio/install_audio.sh && rm -rf $INST_SCRIPTS/audio/ COPY ./src/ubuntu/install/audio_input $INST_SCRIPTS/audio_input/ RUN bash $INST_SCRIPTS/audio_input/install_audio_input.sh && rm -rf $INST_SCRIPTS/audio_input/ +### Install Gamepad Service +COPY ./src/ubuntu/install/gamepad $INST_SCRIPTS/gamepad/ +RUN bash $INST_SCRIPTS/gamepad/install_gamepad.sh && rm -rf $INST_SCRIPTS/gamepad/ + ### Copy built Squid COPY --from=squid_builder /usr/local/squid /usr/local/squid @@ -168,6 +173,7 @@ RUN touch $STARTUPDIR/wm.log \ && find $STARTUPDIR -type f -iname "*.log" -exec chmod 666 {} \; \ && chmod 755 $STARTUPDIR/upload_server/kasm_upload_server \ && chmod 755 $STARTUPDIR/audio_input/kasm_audio_input_server \ + && chmod 755 $STARTUPDIR/gamepad/kasm_gamepad_server \ && chmod 755 $STARTUPDIR/generate_container_user \ && chmod +x $STARTUPDIR/jsmpeg/kasm_audio_out-linux \ && rm -rf $STARTUPDIR/install \ diff --git a/dockerfile-kasm-core-suse b/dockerfile-kasm-core-suse index 1db9156..f9ef80d 100644 --- a/dockerfile-kasm-core-suse +++ b/dockerfile-kasm-core-suse @@ -60,7 +60,8 @@ ENV DISPLAY=:1 \ LC_ALL=$LC_ALL \ SINGLE_APPLICATION=0 \ KASMVNC_AUTO_RECOVER=true \ - PULSE_RUNTIME_PATH=/var/run/pulse + PULSE_RUNTIME_PATH=/var/run/pulse \ + SDL_GAMECONTROLLERCONFIG="030000005e040000be02000014010000,XInput Controller,platform:Linux,a:b0,b:b1,x:b2,y:b3,back:b8,guide:b16,start:b9,leftstick:b10,rightstick:b11,leftshoulder:b4,rightshoulder:b5,dpup:b12,dpdown:b13,dpleft:b14,dpright:b15,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7" EXPOSE $VNC_PORT \ $NO_VNC_PORT \ @@ -101,6 +102,10 @@ RUN bash $INST_SCRIPTS/audio/install_audio.sh && rm -rf $INST_SCRIPTS/audio/ COPY ./src/ubuntu/install/audio_input $INST_SCRIPTS/audio_input/ RUN bash $INST_SCRIPTS/audio_input/install_audio_input.sh && rm -rf $INST_SCRIPTS/audio_input/ +### Install Gamepad Service +COPY ./src/ubuntu/install/gamepad $INST_SCRIPTS/gamepad/ +RUN bash $INST_SCRIPTS/gamepad/install_gamepad.sh && rm -rf $INST_SCRIPTS/gamepad/ + ### Copy built Squid COPY --from=squid_builder /usr/local/squid /usr/local/squid @@ -152,6 +157,7 @@ RUN touch $STARTUPDIR/wm.log \ && find $STARTUPDIR -type f -iname "*.log" -exec chmod 666 {} \; \ && chmod 755 $STARTUPDIR/upload_server/kasm_upload_server \ && chmod 755 $STARTUPDIR/audio_input/kasm_audio_input_server \ + && chmod 755 $STARTUPDIR/gamepad/kasm_gamepad_server \ && chmod 755 $STARTUPDIR/generate_container_user \ && chmod +x $STARTUPDIR/jsmpeg/kasm_audio_out-linux \ && rm -rf $STARTUPDIR/install \ diff --git a/src/common/startup_scripts/vnc_startup.sh b/src/common/startup_scripts/vnc_startup.sh index ccc1a4b..cc8486e 100755 --- a/src/common/startup_scripts/vnc_startup.sh +++ b/src/common/startup_scripts/vnc_startup.sh @@ -159,6 +159,20 @@ function start_upload (){ fi } +function start_gamepad (){ + if [[ ${KASM_SVC_GAMEPAD:-1} == 1 ]]; then + echo 'Starting gamepad server' + $STARTUPDIR/gamepad/kasm_gamepad_server --ssl --auth-token "kasm_user:$VNC_PW" --cert ${HOME}/.vnc/self.pem --certkey ${HOME}/.vnc/self.pem & + + KASM_PROCS['kasm_gamepad']=$! + + if [[ $DEBUG == true ]]; then + echo -e "\n------------------ Started Gamepad Websocket ----------------------------" + echo "Kasm Gamepad PID: ${KASM_PROCS['kasm_gamepad']}"; + fi + fi +} + function custom_startup (){ custom_startup_script=/dockerstartup/custom_startup.sh if [ -f "$custom_startup_script" ]; then @@ -223,6 +237,7 @@ start_audio_out_websocket start_audio_out start_audio_in start_upload +start_gamepad STARTUP_COMPLETE=1 @@ -283,6 +298,11 @@ do # TODO: This will only work if both processes are killed, requires more work start_upload ;; + kasm_gamepad) + echo "Gamepad Service Failed" + # TODO: Needs work in python project to support auto restart + # start_gamepad + ;; custom_script) echo "The custom startup script exited." # custom startup scripts track the target process on their own, they should not exit diff --git a/src/ubuntu/install/gamepad/gamepad.svg b/src/ubuntu/install/gamepad/gamepad.svg new file mode 100644 index 0000000..5909a53 --- /dev/null +++ b/src/ubuntu/install/gamepad/gamepad.svg @@ -0,0 +1,530 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + Input - Gaming + + + Jakub Steiner + + + + + gaming + controller + joystick + game + gaming + HID + + + + + http://jimmac.musichall.cz + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/ubuntu/install/gamepad/install_gamepad.sh b/src/ubuntu/install/gamepad/install_gamepad.sh new file mode 100644 index 0000000..b8b8086 --- /dev/null +++ b/src/ubuntu/install/gamepad/install_gamepad.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +### every exit != 0 fails the script +set -e + +if [ "${DISTRO}" == "oracle7" ]; then + DISTRO=centos +elif [ "${DISTRO}" == "oracle8" ]; then + DISTRO=oracle +fi + +COMMIT_ID="151399e32c159b590a31a3d20b883af7d9104643" +BRANCH="develop" +COMMIT_ID_SHORT=$(echo "${COMMIT_ID}" | cut -c1-6) + +ARCH=$(arch | sed 's/aarch64/arm64/g' | sed 's/x86_64/amd64/g') +mkdir -p $STARTUPDIR/gamepad +wget -qO- https://kasmweb-build-artifacts.s3.amazonaws.com/kasm_gamepad_server/${COMMIT_ID}/kasm_gamepad_server_${DISTRO/kali/ubuntu}_${ARCH}_${BRANCH}.${COMMIT_ID_SHORT}.tar.gz | tar -xvz -C $STARTUPDIR/gamepad/ + + +SCRIPT_PATH="$( cd "$(dirname "$0")" ; pwd -P )" +SCRIPT_PATH="$(realpath $SCRIPT_PATH)" + +mkdir -p /usr/share/extra/icons/ +cp ${SCRIPT_PATH}/gamepad.svg /usr/share/extra/icons/gamepad.svg \ No newline at end of file diff --git a/src/ubuntu/install/xfce/install_xfce_ui.sh b/src/ubuntu/install/xfce/install_xfce_ui.sh index b7605b7..fd736e8 100644 --- a/src/ubuntu/install/xfce/install_xfce_ui.sh +++ b/src/ubuntu/install/xfce/install_xfce_ui.sh @@ -67,18 +67,18 @@ then fi disable_epel_nss_wrapper_that_breaks_firefox yum groupinstall xfce -y - yum install -y wmctrl xset xclip + yum install -y wmctrl xset xclip xfce4-notifyd get_rid_of_policykit_error yum remove -y xfce4-power-manager elif [ "$DISTRO" = "oracle8" ]; then dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm dnf group install xfce -y - dnf install -y wmctrl xset xclip + dnf install -y wmctrl xset xclip xfce4-notifyd get_rid_of_policykit_error dnf remove -y xfce4-power-manager xfce4-screensaver elif [ "$DISTRO" = "opensuse" ]; then zypper install -yn -t pattern xfce - zypper install -yn xset xfce4-terminal xclip + zypper install -yn xset xfce4-terminal xclip xfce4-notifyd zypper remove -yn xfce4-power-manager get_rid_of_policykit_error fi