#!/bin/bash

#================================================================================
# Инициализация
#================================================================================
SUCCESS=0
ERROR=1

function disconnect_not_mpl() {
    return $ERROR
}

function disconnect_openconnect_impl() {
    local exit_code=$SUCCESS
    local PID="$(pidof openconnect)"

    if ! [ -z "$PID" ]; then
        kill "$PID"
        exit_code=$?
    fi

    return $exit_code
}

function disconnect_vipnet_impl() {
    local exit_code=$SUCCESS

    if [ -z "$(command -v vipnetclient)" ]; then
        exit_code=$ERROR
    else
        vipnetclient stop
        exit_code=$?
    fi

    return $exit_code
}

function disconnect_continent_ap_impl() {
    local exit_code=$SUCCESS
    local CTS_PATH='/usr/share/cts/bin'
    PATH="$PATH:$CTS_PATH"

    if [ -z "$(command -v cts)" ]; then
        exit_code=$ERROR
    else
         cts disconnect
         exit_code=$?
    fi

    return $exit_code
}

function disconnect_imitation_impl() {
    echo 1 > '/tmp/test.vpn'
    return $SUCCESS
}

#================================================================================
# Функции
#================================================================================
function main() {
#     ВЫБОР РЕАЛИЗАЦИИ
    disconnect_not_mpl
#     disconnect_openconnect_impl
#     disconnect_vipnet_impl
#     disconnect_continent_ap_impl
#     disconnect_imitation_impl

    return $?
}

#================================================================================
# main
#================================================================================
main
exit $?
