How to use the openpyn.__basefilepath__ function in openpyn

To help you get started, we’ve selected a few openpyn examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jotyGill / openpyn-nordvpn / openpyn / credentials.py View on Github external
import getpass
import logging
import os
import subprocess
import sys
from typing import Dict, List, Set

from openpyn import __basefilepath__, root

credentials_file_path = __basefilepath__ + "credentials"

logger = logging.getLogger(__package__)


def check_credentials() -> bool:
    return os.path.exists(credentials_file_path)


def save_credentials() -> None:
    if not sys.__stdin__.isatty():
        logger.critical("Please run %s in interactive mode", __name__)
        sys.exit(1)

    if root.verify_running_as_root() is False:
        logger.error("Please run as 'sudo openpyn --init' the first time. \
Root access is needed to store credentials in '%s'.", credentials_file_path)
github jotyGill / openpyn-nordvpn / openpyn / openpyn.py View on Github external
def update_config_files() -> None:
    root.verify_root_access("Root access needed to write files in " +
                            "'" + __basefilepath__ + "files/" + "'")
    try:
        zip_archive = __basefilepath__ + "ovpn.zip"
        if os.path.exists(zip_archive):
            print(Fore.BLUE + "Previous update file already exists, deleting..." + Style.RESET_ALL)
            os.remove(zip_archive)

        subprocess.check_call(
            ["sudo", "wget", "https://downloads.nordcdn.com/configs/archives/servers/ovpn.zip", "-P", __basefilepath__])
    except subprocess.CalledProcessError:
        logger.error("Exception occurred while wgetting zip, is the internet working? \
is nordcdn.com blocked by your ISP or Country?, If so use Privoxy \
[https://github.com/jotyGill/openpyn-nordvpn/issues/109]")
        sys.exit()
    try:
        subprocess.check_call(
            ["sudo", "unzip", "-q", "-u", "-o", __basefilepath__ +
                "ovpn", "-d", __basefilepath__ + "files/"],
            stderr=subprocess.DEVNULL)
github jotyGill / openpyn-nordvpn / openpyn / systemd.py View on Github external
def update_service(openpyn_options: str, run=False) -> None:
    if "-f" in openpyn_options or "--force-fw-rules" in openpyn_options:
        kill_option = " --kill-flush"
    else:
        kill_option = " --kill"
    openpyn_options = openpyn_options.replace("-d ", "")
    openpyn_options = openpyn_options.replace("--daemon", "")
    openpyn_location = str(subprocess.check_output(["which", "openpyn"]))[2:-3]
    sleep_location = str(subprocess.check_output(["which", "sleep"]))[2:-3]

    service_text = "[Unit]\nDescription=NordVPN connection manager\nWants=network-online.target\n" + \
        "After=network-online.target\nAfter=multi-user.target\n[Service]\nType=simple\nUser=root\n" + \
        "WorkingDirectory=" + __basefilepath__ + "\nExecStartPre=" + sleep_location + " 5\nExecStart=" + \
        openpyn_location + " " + openpyn_options + "\nExecStop=" + openpyn_location + kill_option + \
        "\nStandardOutput=syslog\nStandardError=syslog\n[Install]\nWantedBy=multi-user.target\n"

    with open("/etc/systemd/system/openpyn.service", "w+") as service_file:
        service_file.write(service_text)
        service_file.close()

    logger.notice("The Following config has been saved in openpyn.service. \
You can Run it or/and Enable it with: 'sudo systemctl start openpyn', \
'sudo systemctl enable openpyn' \n" + service_text)

    subprocess.run(["systemctl", "daemon-reload"])
    if run:
        daemon_running = subprocess.call(  # subprocess.run behaves differently
            ["systemctl", "is-active", "openpyn"],
            stdout=subprocess.DEVNULL,
github jotyGill / openpyn-nordvpn / openpyn / asus.py View on Github external
port = "tcp"
        port_name = "443"
        protocol_name = "tcp-client"
        folder = "ovpn_tcp/"

    vpn_config_file = server + ".nordvpn.com." + port + ".ovpn"

    c = Converter(debug)
    c.set_username(lines[0])
    c.set_password(lines[1])
    c.set_description("Client" + " " + country_name)
    c.set_port(port_name)
    c.set_protocol(protocol_name)

    c.set_name(server)
    c.set_source_folder(__basefilepath__ + "files/" + folder)
    c.set_certs_folder("/jffs/openvpn/")

    c.set_accept_dns_configuration(adns)
    c.set_compression(comp)
    c.set_redirect_gateway(rgw)
    c.set_client(client)

    extracted_info = c.extract_information(vpn_config_file)
    if not test:
        c.write_certificates(client)

    c.pprint(extracted_info)

    # 'vpn_client_unit'
    key = ""
    value = ""