예제 #1
0
 def __init__(self):
     self.path = var_path('config.json')
     if not os.path.exists(self.path):
         self.data = {}
     else:
         try:
             with open(self.path) as f:
                 self.data = json.load(f)
         except ValueError:
             l.error("Failed to load configuration file.  Using empty one "+
                     "instead.")
             self.data = {}
예제 #2
0
 def run(self):
     if onWindows:
         ensure_tap_installed()
         executable = static_path('openvpn/openvpn')
     else:
         executable = 'openvpn'
     self.p = subprocess.Popen([executable,
                                '--config', 'user.ovpn'],
                          cwd=var_path('user'),
                          stdout=subprocess.PIPE,
                          startupinfo=subprocess_sui)
     while True:
         line = self.p.stdout.readline()
         if line == '':
             break
         line = line.strip()
         l.debug(line)
         if "Initialization Sequence Completed" in line:
             if self.on_connected:
                 self.on_connected()
예제 #3
0
def _extract_zip(f):
    def extract(zipf, sn, td, tn):
        with zipf.open(sn) as fi:
            with open(os.path.join(td, tn), 'w') as fo:
                while True:
                    buf = fi.read(4096)
                    if not buf:
                        break
                    fo.write(buf)
    if not os.path.exists(var_path('user')):
        os.mkdir(var_path('user'), 0700)
    with zipfile.ZipFile(f, 'r') as zipf:
        for fn in zipf.namelist():
            if fn.endswith('.ovpn'):
                extract(zipf, fn, var_path('user'), 'user.ovpn')
            elif fn.endswith('ca.crt'):
                extract(zipf, fn, var_path('user'), 'ca.crt')
            elif fn.endswith('.crt'):
                extract(zipf, fn, var_path('user'), os.path.basename(fn))
            elif fn.endswith('.key'):
                extract(zipf, fn, var_path('user'), os.path.basename(fn))
            else:
                l.info('Stray file %s in zip', fn)
예제 #4
0
파일: main.py 프로젝트: karpenoktem/uiltje
            l.info("calling explorer")
            # WTF adding startupinfo breaks this.
            subprocess.call(['explorer', '\\\\' + SMB_HOSTNAME])
        else:
            attempts = [['gnome-open', 'smb://'+ SMB_HOSTNAME], ['nautilus', 'smb://'+ SMB_HOSTNAME]]
            for args in attempts:
                exepath = which(args[0])
                if exepath is not None:
                    l.info("Starting %s", exepath)
                    subprocess.call([exepath] + args[1:])
                    return
            l.warning("Could not found filebrowser")
    def toggle_connection(self):
        if self.state == STATE_CONNECTED:
            self.set_state(STATE_UNKNOWN)
            self.vpnconn.stop()
        elif self.state == STATE_DISCONNECTED:
            self.connect()

if __name__ == '__main__':
    if not os.path.exists(var_path('')):
        os.mkdir(var_path(''))
    logging.basicConfig(level=logging.DEBUG)
    fileHandler = logging.FileHandler(var_path('log.txt'), mode='a')
    formatter = logging.Formatter(
        "%(asctime)s %(name)s %(levelname)s %(message)s")
    fileHandler.setFormatter(formatter)
    logging.root.addHandler(fileHandler)
    p = Program()
    p.main()