U
    -lh                     @   sf  d dl Zd dlZe Zede d dlmZ d dlZe  e	de	de	de	de	de	d	d
dddddde	de	de	de	de	de	d	d
dddddde	de	de	de	de	de	dd
dddddde	de	de	de	de	d e	d!d
ddd"d#ddd$Z
d+d%d&ZG d'd( d(Zd)d* ZdS ),    Nz	Hostname:)load_dotenvZPROD_DB_USERZPROD_DB_PASSWORDZPROD_DB_NAMEZPROD_DB_HOSTZPROD_OVPN_TABLE_NAMEZPROD_COUNTRY_TABLE_NAMEzOvpn/Zmaster_tableZproject_keysz144.126.211.210z3LIVE MASTER TABLE scirpt for addding active serversz2http://localhost/ovpn/vpnGate/check_connection.php)userpassworddbnamehostovpn_table_namecountry_table_nameovpn_main_file_pathZmaster_table_nameZproject_key_table_name	server_ipscript_nameconnection_php_pathz13.127.118.90z:http://localhost/vpn-python-scripting/check_connection.phpZSTAG_DB_USERZSTAG_DB_PASSWORDZSTAG_DB_NAMEZSTAG_DB_HOSTZSTAG_OVPN_TABLE_NAMEZSTAG_COUNTRY_TABLE_NAMEz52.38.82.122z6STAGING MASTER TABLE scirpt for addding active serverszWhttp://52.38.82.122/vpn-api-python/vpn_server_main_script_research/check_connection.phpZLOCAL_DB_USERZLOCAL_DB_PASSWORDZLOCAL_DB_NAMEZLOCAL_DB_HOSTZLOCAL_OVPN_TABLE_NAMEZLOCAL_COUNTRY_TABLE_NAME	localhostz<LOCAL MASTER TABLE testing scirpt for addding active servers))
productionzubuntu-s-1vcpu-1gb-sfo3-01)zvpn-parallel-2zip-172-26-14-17)Zstagingzip-172-31-59-182)localZp210144c                 C   sN   | r
| }nt  }t D ] \}}||kr|d |f  S qtd| d S )Nr   z%No configuration found for hostname: )socketgethostname	DB_CONFIGitems
ValueError)modehostnamekv r   $/var/www/html/ovpn/vpnGate/config.py
get_configS   s    r   c                   @   sV   e Zd Zdd Zdd Zdd Zddd	Zd
d Zdd Zdd Z	dd Z
dd ZdS )DatabaseConnectionc                 C   s   || _ d | _d | _d S N)config
connectioncursor)selfr   r   r   r   __init__`   s    zDatabaseConnection.__init__c                 C   s,   t jjf | j| _| jjdd| _d| _d S )NT)
dictionaryF)mysqlZ	connectorconnectr   r   r    closedr!   r   r   r   r%   e   s    zDatabaseConnection.connectc                 C   s4   | j r| j   | jr0| j r0| j  d| _d S )NT)r    closer   Zis_connectedr&   r'   r   r   r   r(   j   s
    

zDatabaseConnection.closeNc                 C   s   | j || | j j| _d S r   )r    ZexecuteZ	lastrowidlast_row_idr!   querydatar   r   r   execute_queryq   s    z DatabaseConnection.execute_queryc                 C   s   | j || d | _d S r   )r    Zexecutemanyr)   r*   r   r   r   execute_manyu   s    zDatabaseConnection.execute_manyc                 C   s
   | j  S r   )r    Zfetchallr'   r   r   r   	fetch_ally   s    zDatabaseConnection.fetch_allc                 C   s
   | j  S r   )r    Zfetchoner'   r   r   r   	fetch_one|   s    zDatabaseConnection.fetch_onec                 C   s   | j S r   )r)   r'   r   r   r   get_last_row_id   s    z"DatabaseConnection.get_last_row_idc                 C   s   | j S r   )r&   r'   r   r   r   	is_closed   s    zDatabaseConnection.is_closed)N)__name__
__module____qualname__r"   r%   r(   r-   r.   r/   r0   r1   r2   r   r   r   r   r   _   s   
r   c                 C   s"   | d | d | d | d d}|S )Nr   r   r   r   )r   r   r   Zdatabaser   )r   	db_configr   r   r   get_database_config   s    	r7   )N)Zmysql.connectorr$   r   r   r   printZdotenvr   osgetenvr   r   r   r7   r   r   r   r   <module>   s|   
H
'