From 6c2ba9a065ef2d20967140e82e43ce95add45016 Mon Sep 17 00:00:00 2001 From: Ayouuuu Date: Tue, 5 Jul 2022 16:31:01 +0800 Subject: [PATCH] init: init project --- Dockerfile | 11 +++++++++++ LICENSE | 21 +++++++++++++++++++++ README.md | 18 ++++++++++++++++++ action.yml | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ entrypoint.sh | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 146 insertions(+) create mode 100644 Dockerfile create mode 100644 LICENSE create mode 100644 README.md create mode 100644 action.yml create mode 100644 entrypoint.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b23baae --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM ubuntu:18.04 + +LABEL "com.github.actions.name"="ssh-socks-action" +LABEL "com.github.actions.description"="Setup ssh socks5 proxy that use proxy-connect" +LABEL "com.github.actions.icon"="code" +LABEL "com.github.actions.color"="black" + +RUN apt-get update && apt-get install -y sshpass connect-proxy + +COPY entrypoint.sh /entrypoint.sh +ENTRYPOINT ["/entrypoint.sh"] diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..de88db8 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 GitHub Actions + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..9225db9 --- /dev/null +++ b/README.md @@ -0,0 +1,18 @@ +## Example usage + +```yaml +- name: socks ssh action + uses: Ayouuuu/ssh-socks-action + with: + proxy_username: ${{ secrets.USER_NAME }} + proxy_server: ${{ secrets.SERVER }} + proxy_port: ${{ secrets.PORT }} + proxy_socks5_pwd: ${{ secrets.SOCKS5_PWD }} + host: 114.112.113.221 + port: 32200 + username: 'root' + key: ${{ secrets.KEY }} + run: | + ls + whoami +``` diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..11d6319 --- /dev/null +++ b/action.yml @@ -0,0 +1,50 @@ +name: 'ssh-socks-action' +description: 'Setup ssh socks5 proxy that use proxy-connect' +inputs: + proxy_username: + description: 'username' + required: true + proxy_server: + description: 'your server host or ip address' + required: true + proxy_port: + description: 'server port' + required: true + proxy_socks5_pwd: + description: 'socks5 protocol user password' + required: false + username: + description: 'ssh username' + required: true + default: 'root' + host: + description: 'ssh host or ip address' + required: true + port: + description: 'ssh port' + required: true + default: '21' + password: + description: 'ssh password' + required: true + key: + description: "ssh key" + required: false + run: + description: 'commands to run' + required: false + default: 'whoami' +runs: + using: 'docker' + image: 'Dockerfile' + env: + PROXY_SERVER: ${{ inputs.proxy_server }} + PROXY_PROT: ${{ inputs.proxy_port }} + PROXY_SOCKS5_PWD: ${{ inputs.proxy_socks5_pwd }} + PROXY_USERNAME: ${{ inputs.proxy_username }} + RUN: ${{ inputs.run }} + KEY: ${{ inputs.key }} + USERNAME: ${{ inputs.username }} + PASSWORD: ${{ inputs.password }} + PORT: ${{ inputs.port }} + HOST: ${{ inputs.host }} diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..f0511ca --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,46 @@ +#!/bin/sh -l + +set -e + +echo "#################################################" +echo "Starting ${GITHUB_WORKFLOW}:${GITHUB_ACTION}" + +#env +#echo "INPUT_SERVER : ${INPUT_PROXY_SERVER}" +#echo "INPUT_USERNAME : ${INPUT_PROXY_USERNAME}" +#echo "INPUT_PORT: ${INPUT_PROXY_PORT}" +#echo "INPUT_SOCKS5_PWD: ${INPUT_PROXY_SOCKS5_PWD}" +#echo "INPUT_KEY: ${INPUT_KEY}" +#echo "INPUT_RUN: ${INPUT_RUN}" +#echo "INPUT_SSH_HOST": "${INPUT_HOST}" +#echo "INPUT_SSH_PORT": "${INPUT_PORT}" +#echo "INPUT_SSH_USERNAME: ${INPUT_USERNAME}" +#echo "INPUT_SSH_PASSWORD": "${INPUT_PASSWORD}" + +CMD=`echo $INPUT_RUN | sed "s/ / %% /g"` + +mkdir "/root/.ssh" + +export SOCKS5_PASSWD=${INPUT_SOCKS5_PWD} +config='/root/.ssh/config' +echo "Host ${INPUT_HOST}" > $config +echo " User ${INPUT_USERNAME}" >> $config +echo " Port ${INPUT_PORT}" >> $config +echo " ProxyCommand connect -S ${INPUT_PROXY_USERNAME}@${INPUT_PROXY_SERVER}:${INPUT_PROXY_PORT} %h %p" >> $config + +if [ -z "$INPUT_KEY" ] +then + echo 'Using password' + export SSHPASS=$PASS + echo "sshpass -e ssh $INPUT_HOST "$CMD"" +else + echo 'Using private key' + echo "$INPUT_KEY" > "/root/.ssh/id_rsa" + chmod 400 "/root/.ssh/id_rsa" + + echo " IdentityFile /root/.ssh/id_rsa" >> $config + cat "/root/.ssh/config" + +# ls -lha "/root/.ssh/" + echo "sshpass ssh $INPUT_HOST "$CMD"" +fi \ No newline at end of file