Skip to content

Instantly share code, notes, and snippets.

@tonygonzalez811
Forked from ww24/vpnclient
Last active January 20, 2020 03:02
Show Gist options
  • Save tonygonzalez811/67ae72c259bc124dd0b380ba5597a704 to your computer and use it in GitHub Desktop.
Save tonygonzalez811/67ae72c259bc124dd0b380ba5597a704 to your computer and use it in GitHub Desktop.

Revisions

  1. tonygonzalez811 revised this gist Jan 20, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion vpnclient.service
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@ After=network.target network-online.target
    Type=simple
    ExecStart=/usr/local/vpnclient/vpnclient execsvc
    ExecStartPost=/bin/sleep 3
    ExecStartPost=/sbin/ip addr add 172.24.24.240/24 dev vpn_cocoa
    ExecStartPost=/sbin/ip addr add 192.168.30.XX/24 dev vpn_vpn-autana
    ExecReload=/bin/kill -HUP $MAINPID
    KillMode=control-group
    Restart=on-failure
  2. tonygonzalez811 revised this gist Jan 20, 2020. 1 changed file with 52 additions and 106 deletions.
    158 changes: 52 additions & 106 deletions vpnclient
    Original file line number Diff line number Diff line change
    @@ -1,111 +1,57 @@
    #! /bin/sh
    #######################################################
    ### SoftEther Client
    #######################################################
    ### BEGIN INIT INFO
    # Provides: vpnclient
    # Required-Start: $remote_fs $local_fs $network $syslog
    # Required-Stop: $remote_fs $local_fs $network $syslog
    # Default-Start: 2 3 4 5
    # Default-Stop: 0 1 6
    # Short-Description: SoftEther VPN Client
    # Description: SoftEther VPN Client
    # Provides: vpnclient
    # Required-Start: $all
    # Required-Stop: $network $local_fs $remote_fs $syslog
    # Default-Start: 2 3 4 5
    # Default-Stop: 0 1 6
    # Short-Description: Start VPN Client at boot time
    # chkconfig: 345 44 56
    # description: Start VPN Client at boot time.
    # processname: vpnclient
    # 55.55.55.55 = VPN public IP
    ### END INIT INFO

    # PATH should only include /usr/* if it runs after the mountnfs.sh script
    PATH=/sbin:/usr/sbin:/bin:/usr/bin
    DESC="SoftEther VPN Client"
    NAME=vpnclient
    DAEMON=/usr/local/bin/$NAME
    SCRIPTNAME=/etc/init.d/$NAME

    # Exit if the package is not installed
    [ -x "$DAEMON" ] || exit 0

    # Read configuration variable file if it is present
    [ -r /etc/default/$NAME ] && . /etc/default/$NAME

    # Load the VERBOSE setting and other rcS variables
    . /lib/init/vars.sh

    # Define LSB log_* functions.
    # Depend on lsb-base (>= 3.2-14) to ensure that this file is present
    # and status_of_proc is working.
    . /lib/lsb/init-functions

    #
    # Function that starts the daemon/service
    #
    do_start()
    {
    # Return
    # 0 if daemon has been started
    # 1 if daemon was already running
    # 2 if daemon could not be started
    lsof $DAEMON | grep $DAEMON > /dev/null && return 1
    $DAEMON start || return 2
    # setup tap device IP address for local bridge
    #sleep 3
    #ifconfig tap_vpn 192.168.30.230 netmask 255.255.255.0
    }

    #
    # Function that stops the daemon/service
    #
    do_stop()
    {
    # Return
    # 0 if daemon has been stopped
    # 1 if daemon was already stopped
    # 2 if daemon could not be stopped
    # other if a failure occurred
    lsof $DAEMON | grep $DAEMON > /dev/null || return 1
    $DAEMON stop || return 2
    }

    # /etc/init.d/vpnclient.sh
    ###########################
    case "$1" in
    start)
    [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
    do_start
    case "$?" in
    0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
    2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
    esac
    ;;
    stop)
    [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
    do_stop
    case "$?" in
    0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
    2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
    esac
    ;;
    status)
    status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
    ;;
    restart|force-reload)
    #
    # If the "reload" option is implemented then remove the
    # 'force-reload' alias
    #
    log_daemon_msg "Restarting $DESC" "$NAME"
    do_stop
    case "$?" in
    0|1)
    do_start
    case "$?" in
    0) log_end_msg 0 ;;
    1) log_end_msg 1 ;; # Old process is still running
    *) log_end_msg 1 ;; # Failed to start
    esac
    ;;
    *)
    # Failed to stop
    log_end_msg 1
    ;;
    esac
    ;;
    *)
    echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
    exit 3
    ;;
    start)
    echo "Starting VPN Client"
    /usr/local/vpnclient/vpnclient start
    sleep 1
    if ifconfig -a | grep vpn_vpn-autana >/dev/null
    then
    echo "Setting up vpn_vpn..."
    else
    echo "Interface vpn_vpn not found" &1>2

    ifdown vpn_vpn-autana
    sleep 1
    ifup vpn_vpn-autana
    sleep 1
    echo "Setting up vpn_vpn..."
    exit 1
    fi

    #route add -host 55.55.55.55 gw $(ip route list exact 0.0.0.0/0 | grep wlan0 | xargs | awk '{print $3}')
    # route del default
    # route add default gw 192.168.30.1 dev vpn_vpn

    /usr/local/vpnclient/./vpncmd
    ;;
    stop)
    echo "Stopping VPN Client"
    /usr/local/vpnclient/vpnclient stop
    #route del -host 55.55.55.55

    #route del default
    #route add default gw $(ip route list exact 0.0.0.0/0 | grep wlan0 | xargs | awk '{print $3}') dev wlan0
    ;;
    *)
    echo "Usage: /etc/init.d/vpnclient {start|stop}"
    exit 1
    ;;
    esac

    :
    exit 0
  3. @ww24 ww24 revised this gist Sep 26, 2016. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions vpnserver.service
    Original file line number Diff line number Diff line change
    @@ -5,6 +5,8 @@ After=network.target network-online.target
    [Service]
    Type=simple
    ExecStart=/usr/local/vpnserver/vpnserver execsvc
    ExecStartPost=/bin/sleep 3
    ExecStartPost=/sbin/ip addr add 172.24.24.254/24 dev tap_vpn
    ExecReload=/bin/kill -HUP $MAINPID
    KillMode=control-group
    Restart=on-failure
  4. @ww24 ww24 revised this gist Sep 26, 2016. 2 changed files with 23 additions and 8 deletions.
    17 changes: 9 additions & 8 deletions vpnclient.service
    Original file line number Diff line number Diff line change
    @@ -1,15 +1,16 @@
    [Unit]
    Description=SoftEther VPN Client
    After=network.target auditd.service
    After=network.target network-online.target

    [Service]
    Type=oneshot
    ExecStart=/usr/local/bin/vpnclient start && sleep 3 && ip addr add 192.168.30.230/24 dev tap_vpn
    ExecReload=/usr/local/bin/vpnclient stop && /usr/local/bin/vpnclient start
    ExecStop=/usr/local/bin/vpnclient stop
    KillMode=none
    RemainAfterExit=yes
    Type=simple
    ExecStart=/usr/local/vpnclient/vpnclient execsvc
    ExecStartPost=/bin/sleep 3
    ExecStartPost=/sbin/ip addr add 172.24.24.240/24 dev vpn_cocoa
    ExecReload=/bin/kill -HUP $MAINPID
    KillMode=control-group
    Restart=on-failure

    [Install]
    WantedBy=multi-user.target
    Alias=vpnclient.service
    Alias=vpnclient.service
    14 changes: 14 additions & 0 deletions vpnserver.service
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    [Unit]
    Description=SoftEther VPN Server
    After=network.target network-online.target

    [Service]
    Type=simple
    ExecStart=/usr/local/vpnserver/vpnserver execsvc
    ExecReload=/bin/kill -HUP $MAINPID
    KillMode=control-group
    Restart=on-failure

    [Install]
    WantedBy=multi-user.target
    Alias=vpnserver.service
  5. @ww24 ww24 revised this gist Dec 23, 2015. 1 changed file with 7 additions and 5 deletions.
    12 changes: 7 additions & 5 deletions vpnclient.service
    Original file line number Diff line number Diff line change
    @@ -3,11 +3,13 @@ Description=SoftEther VPN Client
    After=network.target auditd.service

    [Service]
    ExecStart=/usr/local/bin/vpnclient start
    ExecReload=/usr/local/bin/vpnclient stop
    KillMode=process
    Restart=on-failure
    Type=oneshot
    ExecStart=/usr/local/bin/vpnclient start && sleep 3 && ip addr add 192.168.30.230/24 dev tap_vpn
    ExecReload=/usr/local/bin/vpnclient stop && /usr/local/bin/vpnclient start
    ExecStop=/usr/local/bin/vpnclient stop
    KillMode=none
    RemainAfterExit=yes

    [Install]
    WantedBy=multi-user.target
    Alias=vpnclient.service
    Alias=vpnclient.service
  6. @ww24 ww24 revised this gist Sep 24, 2015. 1 changed file with 13 additions and 0 deletions.
    13 changes: 13 additions & 0 deletions vpnclient.service
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    [Unit]
    Description=SoftEther VPN Client
    After=network.target auditd.service

    [Service]
    ExecStart=/usr/local/bin/vpnclient start
    ExecReload=/usr/local/bin/vpnclient stop
    KillMode=process
    Restart=on-failure

    [Install]
    WantedBy=multi-user.target
    Alias=vpnclient.service
  7. @ww24 ww24 revised this gist Jun 24, 2015. 2 changed files with 114 additions and 3 deletions.
    111 changes: 111 additions & 0 deletions vpnclient
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,111 @@
    #! /bin/sh
    ### BEGIN INIT INFO
    # Provides: vpnclient
    # Required-Start: $remote_fs $local_fs $network $syslog
    # Required-Stop: $remote_fs $local_fs $network $syslog
    # Default-Start: 2 3 4 5
    # Default-Stop: 0 1 6
    # Short-Description: SoftEther VPN Client
    # Description: SoftEther VPN Client
    ### END INIT INFO

    # PATH should only include /usr/* if it runs after the mountnfs.sh script
    PATH=/sbin:/usr/sbin:/bin:/usr/bin
    DESC="SoftEther VPN Client"
    NAME=vpnclient
    DAEMON=/usr/local/bin/$NAME
    SCRIPTNAME=/etc/init.d/$NAME

    # Exit if the package is not installed
    [ -x "$DAEMON" ] || exit 0

    # Read configuration variable file if it is present
    [ -r /etc/default/$NAME ] && . /etc/default/$NAME

    # Load the VERBOSE setting and other rcS variables
    . /lib/init/vars.sh

    # Define LSB log_* functions.
    # Depend on lsb-base (>= 3.2-14) to ensure that this file is present
    # and status_of_proc is working.
    . /lib/lsb/init-functions

    #
    # Function that starts the daemon/service
    #
    do_start()
    {
    # Return
    # 0 if daemon has been started
    # 1 if daemon was already running
    # 2 if daemon could not be started
    lsof $DAEMON | grep $DAEMON > /dev/null && return 1
    $DAEMON start || return 2
    # setup tap device IP address for local bridge
    #sleep 3
    #ifconfig tap_vpn 192.168.30.230 netmask 255.255.255.0
    }

    #
    # Function that stops the daemon/service
    #
    do_stop()
    {
    # Return
    # 0 if daemon has been stopped
    # 1 if daemon was already stopped
    # 2 if daemon could not be stopped
    # other if a failure occurred
    lsof $DAEMON | grep $DAEMON > /dev/null || return 1
    $DAEMON stop || return 2
    }

    case "$1" in
    start)
    [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
    do_start
    case "$?" in
    0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
    2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
    esac
    ;;
    stop)
    [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
    do_stop
    case "$?" in
    0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
    2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
    esac
    ;;
    status)
    status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
    ;;
    restart|force-reload)
    #
    # If the "reload" option is implemented then remove the
    # 'force-reload' alias
    #
    log_daemon_msg "Restarting $DESC" "$NAME"
    do_stop
    case "$?" in
    0|1)
    do_start
    case "$?" in
    0) log_end_msg 0 ;;
    1) log_end_msg 1 ;; # Old process is still running
    *) log_end_msg 1 ;; # Failed to start
    esac
    ;;
    *)
    # Failed to stop
    log_end_msg 1
    ;;
    esac
    ;;
    *)
    echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
    exit 3
    ;;
    esac

    :
    6 changes: 3 additions & 3 deletions vpnserver
    Original file line number Diff line number Diff line change
    @@ -5,13 +5,13 @@
    # Required-Stop: $remote_fs $local_fs $network $syslog
    # Default-Start: 2 3 4 5
    # Default-Stop: 0 1 6
    # Short-Description: SoftEther VPN
    # Description: SoftEther VPN
    # Short-Description: SoftEther VPN Server
    # Description: SoftEther VPN Server
    ### END INIT INFO

    # PATH should only include /usr/* if it runs after the mountnfs.sh script
    PATH=/sbin:/usr/sbin:/bin:/usr/bin
    DESC="SoftEther VPN"
    DESC="SoftEther VPN Server"
    NAME=vpnserver
    DAEMON=/usr/local/bin/$NAME
    SCRIPTNAME=/etc/init.d/$NAME
  8. @ww24 ww24 revised this gist May 12, 2015. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions vpnserver
    Original file line number Diff line number Diff line change
    @@ -41,6 +41,9 @@ do_start()
    # 2 if daemon could not be started
    lsof $DAEMON | grep $DAEMON > /dev/null && return 1
    $DAEMON start || return 2
    # setup tap device IP address for local bridge
    #sleep 3
    #ifconfig tap_vpn 192.168.30.254 netmask 255.255.255.0
    }

    #
  9. @ww24 ww24 revised this gist May 12, 2015. 1 changed file with 4 additions and 46 deletions.
    50 changes: 4 additions & 46 deletions vpnserver
    Original file line number Diff line number Diff line change
    @@ -14,8 +14,6 @@ PATH=/sbin:/usr/sbin:/bin:/usr/bin
    DESC="SoftEther VPN"
    NAME=vpnserver
    DAEMON=/usr/local/bin/$NAME
    DAEMON_ARGS="start"
    PIDFILE=/var/run/$NAME.pid
    SCRIPTNAME=/etc/init.d/$NAME

    # Exit if the package is not installed
    @@ -41,14 +39,8 @@ do_start()
    # 0 if daemon has been started
    # 1 if daemon was already running
    # 2 if daemon could not be started
    start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
    || return 1
    start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
    $DAEMON_ARGS \
    || return 2
    # Add code here, if necessary, that waits for the process to be ready
    # to handle requests from services started subsequently which depend
    # on this one. As a last resort, sleep for some time.
    lsof $DAEMON | grep $DAEMON > /dev/null && return 1
    $DAEMON start || return 2
    }

    #
    @@ -61,33 +53,8 @@ do_stop()
    # 1 if daemon was already stopped
    # 2 if daemon could not be stopped
    # other if a failure occurred
    start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
    RETVAL="$?"
    [ "$RETVAL" = 2 ] && return 2
    # Wait for children to finish too if this is a daemon that forks
    # and if the daemon is only ever run from this initscript.
    # If the above conditions are not satisfied then add some other code
    # that waits for the process to drop all resources that could be
    # needed by services started subsequently. A last resort is to
    # sleep for some time.
    start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
    [ "$?" = 2 ] && return 2
    # Many daemons don't delete their pidfiles when they exit.
    rm -f $PIDFILE
    return "$RETVAL"
    }

    #
    # Function that sends a SIGHUP to the daemon/service
    #
    do_reload() {
    #
    # If the daemon can reload its configuration without
    # restarting (for example, when it is sent a SIGHUP),
    # then implement that here.
    #
    start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
    return 0
    lsof $DAEMON | grep $DAEMON > /dev/null || return 1
    $DAEMON stop || return 2
    }

    case "$1" in
    @@ -110,15 +77,6 @@ case "$1" in
    status)
    status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
    ;;
    #reload|force-reload)
    #
    # If do_reload() is not implemented then leave this commented out
    # and leave 'force-reload' as an alias for 'restart'.
    #
    #log_daemon_msg "Reloading $DESC" "$NAME"
    #do_reload
    #log_end_msg $?
    #;;
    restart|force-reload)
    #
    # If the "reload" option is implemented then remove the
  10. @ww24 ww24 created this gist May 12, 2015.
    150 changes: 150 additions & 0 deletions vpnserver
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,150 @@
    #! /bin/sh
    ### BEGIN INIT INFO
    # Provides: vpnserver
    # Required-Start: $remote_fs $local_fs $network $syslog
    # Required-Stop: $remote_fs $local_fs $network $syslog
    # Default-Start: 2 3 4 5
    # Default-Stop: 0 1 6
    # Short-Description: SoftEther VPN
    # Description: SoftEther VPN
    ### END INIT INFO

    # PATH should only include /usr/* if it runs after the mountnfs.sh script
    PATH=/sbin:/usr/sbin:/bin:/usr/bin
    DESC="SoftEther VPN"
    NAME=vpnserver
    DAEMON=/usr/local/bin/$NAME
    DAEMON_ARGS="start"
    PIDFILE=/var/run/$NAME.pid
    SCRIPTNAME=/etc/init.d/$NAME

    # Exit if the package is not installed
    [ -x "$DAEMON" ] || exit 0

    # Read configuration variable file if it is present
    [ -r /etc/default/$NAME ] && . /etc/default/$NAME

    # Load the VERBOSE setting and other rcS variables
    . /lib/init/vars.sh

    # Define LSB log_* functions.
    # Depend on lsb-base (>= 3.2-14) to ensure that this file is present
    # and status_of_proc is working.
    . /lib/lsb/init-functions

    #
    # Function that starts the daemon/service
    #
    do_start()
    {
    # Return
    # 0 if daemon has been started
    # 1 if daemon was already running
    # 2 if daemon could not be started
    start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
    || return 1
    start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
    $DAEMON_ARGS \
    || return 2
    # Add code here, if necessary, that waits for the process to be ready
    # to handle requests from services started subsequently which depend
    # on this one. As a last resort, sleep for some time.
    }

    #
    # Function that stops the daemon/service
    #
    do_stop()
    {
    # Return
    # 0 if daemon has been stopped
    # 1 if daemon was already stopped
    # 2 if daemon could not be stopped
    # other if a failure occurred
    start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
    RETVAL="$?"
    [ "$RETVAL" = 2 ] && return 2
    # Wait for children to finish too if this is a daemon that forks
    # and if the daemon is only ever run from this initscript.
    # If the above conditions are not satisfied then add some other code
    # that waits for the process to drop all resources that could be
    # needed by services started subsequently. A last resort is to
    # sleep for some time.
    start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
    [ "$?" = 2 ] && return 2
    # Many daemons don't delete their pidfiles when they exit.
    rm -f $PIDFILE
    return "$RETVAL"
    }

    #
    # Function that sends a SIGHUP to the daemon/service
    #
    do_reload() {
    #
    # If the daemon can reload its configuration without
    # restarting (for example, when it is sent a SIGHUP),
    # then implement that here.
    #
    start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
    return 0
    }

    case "$1" in
    start)
    [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
    do_start
    case "$?" in
    0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
    2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
    esac
    ;;
    stop)
    [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
    do_stop
    case "$?" in
    0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
    2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
    esac
    ;;
    status)
    status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
    ;;
    #reload|force-reload)
    #
    # If do_reload() is not implemented then leave this commented out
    # and leave 'force-reload' as an alias for 'restart'.
    #
    #log_daemon_msg "Reloading $DESC" "$NAME"
    #do_reload
    #log_end_msg $?
    #;;
    restart|force-reload)
    #
    # If the "reload" option is implemented then remove the
    # 'force-reload' alias
    #
    log_daemon_msg "Restarting $DESC" "$NAME"
    do_stop
    case "$?" in
    0|1)
    do_start
    case "$?" in
    0) log_end_msg 0 ;;
    1) log_end_msg 1 ;; # Old process is still running
    *) log_end_msg 1 ;; # Failed to start
    esac
    ;;
    *)
    # Failed to stop
    log_end_msg 1
    ;;
    esac
    ;;
    *)
    echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
    exit 3
    ;;
    esac

    :