mirror of https://git.48k.eu/ogclient
Switch config file to json
This patch makes configuration parsing easier as well as making the full configuration available in many subclasses.more_events
parent
404b8c79d0
commit
38b6d77561
|
@ -1,15 +0,0 @@
|
||||||
[opengnsys]
|
|
||||||
ip=127.0.0.1
|
|
||||||
url=https://127.0.0.1/opengnsys/varios/menubrowser.php
|
|
||||||
url_log=http://localhost/cgi-bin/httpd-log.sh
|
|
||||||
port=8889
|
|
||||||
# Log Level, if ommited, will be set to INFO
|
|
||||||
log=DEBUG
|
|
||||||
# Supported modes are 'virtual' and 'linux'
|
|
||||||
mode=linux
|
|
||||||
|
|
||||||
# User and password for all samba repositories. This user requires read and
|
|
||||||
# write permission.
|
|
||||||
[samba]
|
|
||||||
user=opengnsys
|
|
||||||
pass=og
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
{
|
||||||
|
"opengnsys": {
|
||||||
|
"ip": "127.0.0.1",
|
||||||
|
"port": 8889,
|
||||||
|
"log": "DEBUG",
|
||||||
|
"mode": "linux",
|
||||||
|
"url": "https://127.0.0.1/opengnsys/varios/menubrowser.php",
|
||||||
|
"url_log": "http://localhost/cgi-bin/httpd-log.sh"
|
||||||
|
},
|
||||||
|
"samba": {
|
||||||
|
"activate": true
|
||||||
|
"user": "opengnsys",
|
||||||
|
"pass": "og"
|
||||||
|
},
|
||||||
|
"vnc": {
|
||||||
|
"activate": true,
|
||||||
|
"pass": "ogvnc"
|
||||||
|
}
|
||||||
|
}
|
28
main.py
28
main.py
|
@ -8,6 +8,7 @@
|
||||||
# Free Software Foundation, version 3.
|
# Free Software Foundation, version 3.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
import json
|
||||||
import subprocess
|
import subprocess
|
||||||
from src.ogClient import *
|
from src.ogClient import *
|
||||||
from src.ogConfig import *
|
from src.ogConfig import *
|
||||||
|
@ -15,27 +16,20 @@ from signal import signal, SIGPIPE, SIG_DFL
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
signal(SIGPIPE, SIG_DFL)
|
signal(SIGPIPE, SIG_DFL)
|
||||||
ogconfig = ogConfig()
|
config_path = f'{ogConfig.OG_PATH}ogclient/cfg/ogclient.json'
|
||||||
config_path = f'{ogConfig.OG_PATH}ogclient/cfg/ogclient.cfg'
|
try:
|
||||||
if (not ogconfig.parser_file(config_path)):
|
with open(config_path, 'r') as f:
|
||||||
|
CONFIG = json.load(f)
|
||||||
|
except:
|
||||||
print('Error: Parsing configuration file')
|
print('Error: Parsing configuration file')
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
ip = ogconfig.get_value_section('opengnsys', 'ip')
|
MODE = CONFIG['opengnsys']['mode']
|
||||||
port = ogconfig.get_value_section('opengnsys', 'port')
|
URL = CONFIG['opengnsys']['url']
|
||||||
url = ogconfig.get_value_section('opengnsys', 'url')
|
if MODE == 'linux':
|
||||||
mode = ogconfig.get_value_section('opengnsys', 'mode')
|
proc = subprocess.Popen(["browser", "-qws", URL])
|
||||||
samba_user = ogconfig.get_value_section('samba', 'user')
|
|
||||||
samba_pass = ogconfig.get_value_section('samba', 'pass')
|
|
||||||
|
|
||||||
samba_config = None
|
client = ogClient(config=CONFIG)
|
||||||
|
|
||||||
if mode == 'linux':
|
|
||||||
proc = subprocess.Popen(["browser", "-qws", url])
|
|
||||||
elif mode == 'virtual':
|
|
||||||
samba_config = {'user': samba_user, 'pass': samba_pass}
|
|
||||||
|
|
||||||
client = ogClient(ip, int(port), mode, samba_config)
|
|
||||||
client.connect()
|
client.connect()
|
||||||
client.run()
|
client.run()
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ import select
|
||||||
import socket
|
import socket
|
||||||
import time
|
import time
|
||||||
import email
|
import email
|
||||||
|
import platform
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
|
|
||||||
from src.restRequest import *
|
from src.restRequest import *
|
||||||
|
@ -23,19 +24,23 @@ class State(Enum):
|
||||||
FORCE_DISCONNECTED = 2
|
FORCE_DISCONNECTED = 2
|
||||||
|
|
||||||
class ogClient:
|
class ogClient:
|
||||||
def __init__(self, ip, port, mode, samba_config=None):
|
def __init__(self, config):
|
||||||
if mode not in {'virtual', 'linux'}:
|
self.CONFIG = config
|
||||||
|
|
||||||
|
self.mode = self.CONFIG['opengnsys']['mode']
|
||||||
|
if self.mode not in {'virtual', 'linux'}:
|
||||||
raise ValueError('Mode not supported.')
|
raise ValueError('Mode not supported.')
|
||||||
|
if self.mode == 'linux' and platform.system() != 'Linux':
|
||||||
|
raise ValueError('Linux mode not supported on '
|
||||||
|
'non-Linux platform.')
|
||||||
|
|
||||||
if samba_config:
|
if self.CONFIG['samba']['activate']:
|
||||||
assert('user' in samba_config)
|
assert('user' in self.CONFIG['samba'])
|
||||||
assert('pass' in samba_config)
|
assert('pass' in self.CONFIG['samba'])
|
||||||
|
|
||||||
self.ip = ip
|
self.ip = self.CONFIG['opengnsys']['ip']
|
||||||
self.port = port
|
self.port = self.CONFIG['opengnsys']['port']
|
||||||
self.mode = mode
|
self.ogrest = ogRest(self.CONFIG)
|
||||||
self.samba_config = samba_config
|
|
||||||
self.ogrest = ogRest(self.mode, self.samba_config)
|
|
||||||
|
|
||||||
def get_socket(self):
|
def get_socket(self):
|
||||||
return self.sock
|
return self.sock
|
||||||
|
|
|
@ -242,14 +242,15 @@ class ogResponses(Enum):
|
||||||
SERVICE_UNAVAILABLE=5
|
SERVICE_UNAVAILABLE=5
|
||||||
|
|
||||||
class ogRest():
|
class ogRest():
|
||||||
def __init__(self, mode, samba_config):
|
def __init__(self, config):
|
||||||
self.proc = None
|
self.proc = None
|
||||||
self.terminated = False
|
self.terminated = False
|
||||||
self.state = ThreadState.IDLE
|
self.state = ThreadState.IDLE
|
||||||
self.mode = mode
|
self.CONFIG = config
|
||||||
self.samba_config = samba_config
|
self.mode = self.CONFIG['opengnsys']['mode']
|
||||||
|
self.samba_config = self.CONFIG['samba']
|
||||||
|
|
||||||
if self.mode == 'linux' and platform.system() == 'Linux':
|
if self.mode == 'linux':
|
||||||
self.operations = OgLinuxOperations()
|
self.operations = OgLinuxOperations()
|
||||||
elif self.mode == 'virtual':
|
elif self.mode == 'virtual':
|
||||||
self.operations = OgVirtualOperations()
|
self.operations = OgVirtualOperations()
|
||||||
|
|
Loading…
Reference in New Issue