Code Monkey home page Code Monkey logo

vpn-shell-for-openconnect's Introduction

vpn-shell-for-openconnect

A VPN shell script for openconnect on Linux

Features

A shell script for openconnect which allows:

  • to define multiple VPN connections, using different protocols
  • to run openconnect without entering the username and password
  • to run in the background
  • to authenticate with a certiftcate
  • to check the status of the vpn connection

What's new

  • added support for using different protocols
  • added options (start, stop, status, restart)
  • can check status of the vpn connection

Last modifications

This code is modified by sorinipate's repository: [vpn-up-for-openconnect].

And I made the following modifications:

  • reformat all code style, refactor some variable name
  • reformat all the space characters to [Tab] character, although I prefer to use space characters
  • change the path of the PID file and log file, like "/run/xxxxx.pid", "/tmp/xxxxx.log"
  • split VPN server configuration to "open-vpn-conf.sh" file
  • added "install.sh" shell script

Last modified: shines77 / 2022-03-22

Sample VPN configuration

Copy the original configurtion file to open-vpn-my-conf.sh:

cp ./open-vpn-original-conf.sh ./open-vpn-my-conf.sh

Edit your configurtion file:

vim open-vpn-my-conf.sh

The content is modified to like below:

# If you don't want to run in background, so make this false
BACKGROUND=true

# Company VPN
export VPN1_NAME="My Company VPN"
export VPN1_PROTOCOL="anyconnect"
export VPN1_HOST="vpn.mycompany.com"
export VPN1_AUTHGROUP="developers"
export VPN1_USER="sorin.ipate"
export VPN1_PASSWD="MyPassword"
# If you don't have server certificate so don't fill this
export VPN1_SERVER_CERTIFICATE="SHA1-OtherCharachters"

How to install and use

Here just demonstrate how to use this script in Ubuntu server.

1. Install openconnect

sudo apt-get update
sudo apt-get install openconnect

2. Get this script

Two ways:

3. Install this script

Copy the original configurtion file to open-vpn-my-conf.sh:

cp ./open-vpn-original-conf.sh ./open-vpn-my-conf.sh

And then, edit your configurtion file:

vim open-vpn-my-conf.sh

The example configurtion file setting like "Sample VPN configuration" section above.

Finally, use this command to install, syntax is:

install.sh <folder_install_to>

Example:

# Install to default folder: /usr/sbin
sudo ./install.sh

or

# Install to system /usr/bin folder
sudo ./install.sh /usr/bin

or

# Install to current user's bin folder
sudo mkdir ~/bin
sudo ./install.sh ~/bin

Note: The path of <folder_install_to> must be existed. If you don't specified <folder_install_to>, the default value is "/usr/sbin".

The installation steps are as follows:

# Your script root folder
cd /xxxxxx/yyyyy/vpn-shell-for-openconnect

sudo cp open-vpn-cmd.sh /usr/bin/open-vpn-cmd.sh
sudo cp open-vpn-my-conf.sh /usr/bin/open-vpn-conf.sh

sudo chmod +x /usr/bin/open-vpn-cmd.sh

alias open-vpn-cmd='/usr/bin/open-vpn-cmd.sh'

4. VPN usage

4.1. Connect VPN

open-vpn-cmd.sh start

4.2. Disconnect VPN

open-vpn-cmd.sh stop

4.3. Restart VPN

open-vpn-cmd.sh restart

4.4. Query VPN status

open-vpn-cmd.sh status

Original usage

Run VPN shell script

  1. Please make sure you have openconnect installed before moving on. Follow the instructions here.

  2. Download the latest release.

  3. Copy the "open-vpn-cmd.sh" and "open-vpn-conf.sh" file to the "~/bin" folder.

  4. Update the "open-vpn-cmd.sh" file with the appropiate VPN connection information as shown above.

  5. Make an alias alias open-vpn-cmd='~/bin/open-vpn-cmd.sh' in bash or zsh shell. Follow the instructions here.

  6. Run open-vpn-cmd to start and voila.

vpn-shell-for-openconnect's People

Contributors

shines77 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.