Skip to content

Commit d5bc338

Browse files
authored
Merge pull request #5 from maryush/master
- fixed path to gnome-terminal
2 parents e9f101d + 6453149 commit d5bc338

File tree

4 files changed

+75
-42
lines changed

4 files changed

+75
-42
lines changed

iface.cfg

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[main]
2+
secret =
3+
home_path = /home/gynvael
4+
remote_ip_list = ( "192.168.56.1", "192.168.56.3" )
5+
bind_port = 33321
6+
terminal_cmd = /usr/bin/gnome-terminal

iface.py

+23-31
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,29 @@
6969
LOG_VERBOSE = 5
7070
LOG_DEBUG = 10
7171

72+
import os
73+
import pickle
74+
import select
75+
import socket
76+
import StringIO
77+
import struct
78+
import subprocess
79+
import sys
80+
import time
81+
import threading
82+
if sys.platform != 'win32':
83+
import fcntl
84+
from ifaceconfiglib import cfg
85+
7286
# -------------------------------------------------------------------
73-
# CONFIGURATION (please set this up before first use)
87+
# CONFIGURATION (set values from config file)
7488
# -------------------------------------------------------------------
7589

76-
# Put some random string here. It will be used as poor man's authentication.
77-
# Please put the same string in ifaceclientlib.py
78-
SECRET = ""
79-
80-
# Specify your default, fallback home directory at VM
81-
HOME_PATH_ON_VM="/home/gynvael"
90+
SECRET = cfg.get('main', 'secret')
91+
HOME_PATH_ON_VM = cfg.get('main', 'home_path')
92+
BIND_PORT = cfg.getInt('main', 'bind_port')
93+
TERMINAL_CMD = cfg.get('main', 'terminal_cmd')
94+
REMOTE_IP_LIST = eval(cfg.get('main', 'remote_ip_list'))
8295

8396
CMDS={
8497
"iface-info" : "CMD_iface_info", # Returns some info.
@@ -88,31 +101,11 @@
88101
"translate-path": "CMD_translate_path", # Translates path.
89102
}
90103

91-
# TODO move this to some kind of config.
92-
# TODO do the same in ifaceclientlib.py
93-
# IPs of HOST and VM (in that order)
94-
REMOTE_IP_LIST = ( "192.168.56.1", "192.168.56.3" )
95-
BIND_PORT = 33321
96-
97104
LOG_LEVEL = LOG_DEBUG
98-
99105
# -------------------------------------------------------------------
100106
# End of constants / configs.
101107
# -------------------------------------------------------------------
102108

103-
import os
104-
import pickle
105-
import select
106-
import socket
107-
import StringIO
108-
import struct
109-
import subprocess
110-
import sys
111-
import time
112-
import threading
113-
if sys.platform != 'win32':
114-
import fcntl
115-
116109
print "Windows/Linux iface by gynvael.coldwind//vx"
117110

118111
def Usage():
@@ -123,8 +116,7 @@ def Usage():
123116
if len(SECRET) == 0:
124117
print "This is your time running Windows/Linux iface. You first need to set "
125118
print "some things up before you can use it."
126-
print "Please open iface.py and ifaceclientlib.py and read the top comments on"
127-
print "how to begin."
119+
print "Please open iface.cfg and set needed values."
128120
sys.exit(1)
129121

130122
if len(sys.argv) != 2:
@@ -1348,7 +1340,7 @@ def translate_path_to_linux(path):
13481340
if not path[0].upper() in ['C', 'D', 'E', 'I', 'W', 'B']:
13491341

13501342
# Nothing we can do.
1351-
path = "/home/gynvael/"
1343+
path = HOME_PATH_ON_VM
13521344

13531345
# Done.
13541346
Log(LOG_INFO, "translate-path: [!] \"%s\" -> \"%s\"" % (
@@ -1472,7 +1464,7 @@ def CMD_l_cmd(info, cwd):
14721464

14731465
# Spawn the terminal.
14741466
cwd = cwd.replace("'", "\\'")
1475-
command = "(cd '%s'; /usr/local/bin/gnome-terminal &)" % cwd
1467+
command = "(cd '%s'; %s &)" % (cwd, TERMINAL_CMD)
14761468

14771469
# Spawn.
14781470
if subprocess.call(command, shell=True) == 0:

ifaceclientlib.py

+6-11
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import struct
1717
import sys
1818
import threading
19+
from ifaceconfiglib import cfg
1920

2021
# Constants for debug level in CONFIGURATION section.
2122
LOG_ERROR = 0
@@ -25,17 +26,12 @@
2526
LOG_DEBUG = 10
2627

2728
# -------------------------------------------------------------------
28-
# CONFIGURATION (please set this up before first use)
29+
# CONFIGURATION (set values from config file)
2930
# -------------------------------------------------------------------
3031

31-
# Put some random string here. It will be used as poor man's authentication.
32-
# Please put the same string in iface.py
33-
SECRET = ""
34-
35-
# TODO move this to some kind of config.
36-
# TODO do the same in iface.py
37-
# IPs of HOST and VM (in that order)
38-
BIND_PORT = 33321
32+
SECRET = cfg.get('main', 'secret')
33+
BIND_PORT = cfg.getInt('main', 'bind_port')
34+
3935
LOG_LEVEL = LOG_DEBUG
4036

4137
# -------------------------------------------------------------------
@@ -45,8 +41,7 @@
4541
if len(SECRET) == 0:
4642
print "This is your time running Windows/Linux iface. You first need to set "
4743
print "some things up before you can use it."
48-
print "Please open iface.py and ifaceclientlib.py and read the top comments on"
49-
print "how to begin."
44+
print "Please open iface.cfg and set needed values."
5045
sys.exit(1)
5146

5247
# -------------------------------------------------------------------

ifaceconfiglib.py

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# -*- coding: utf-8 -*-
2+
__author__ = 'Mariusz "maryush" Witkowski'
3+
4+
import os
5+
import sys
6+
import ConfigParser
7+
8+
config_file = os.path.dirname(__file__)+os.sep+"iface.cfg"
9+
10+
class Config(object):
11+
"""basic operations on config file"""
12+
cfg = None
13+
14+
def __init__(self, config_file):
15+
"""class initialization"""
16+
if not config_file:
17+
config_file = config_file
18+
19+
self.cfg = ConfigParser.RawConfigParser()
20+
self.cfg.read(config_file)
21+
22+
def get(self, section, name):
23+
"""read value from selected section"""
24+
try:
25+
value = self.cfg.get(section, name)
26+
except:
27+
value = None
28+
finally:
29+
return value
30+
31+
def getBoolean(self, section, name):
32+
"""getting boolean value"""
33+
return self.cfg.getboolean(section, name)
34+
35+
def getInt(self, section, name):
36+
"""getting int value"""
37+
return self.cfg.getint(section, name)
38+
39+
40+
cfg = Config(config_file)

0 commit comments

Comments
 (0)