OpenSecurity/bin/start_browsing.pyw
author Bartha Mihai <mihai.bartha@ait.ac.at>
Tue, 28 Oct 2014 15:20:42 +0100
changeset 238 d33edf5c2717
parent 199 26b9a95b0da1
child 240 d7ef04254e9c
permissions -rw-r--r--
modified start_browsing script to use the proxy settings
     1 # -*- coding: utf-8 -*-
     2 
     3 # ------------------------------------------------------------
     4 # directly start the browsing
     5 # 
     6 # Autor: Oliver Maurhart, <oliver.maurhart@ait.ac.at>
     7 #
     8 # Copyright (C) 2013 AIT Austrian Institute of Technology
     9 # AIT Austrian Institute of Technology GmbH
    10 # Donau-City-Strasse 1 | 1220 Vienna | Austria
    11 # http://www.ait.ac.at
    12 #
    13 # This program is free software; you can redistribute it and/or
    14 # modify it under the terms of the GNU General Public License
    15 # as published by the Free Software Foundation version 2.
    16 # 
    17 # This program is distributed in the hope that it will be useful,
    18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
    19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    20 # GNU General Public License for more details.
    21 # 
    22 # You should have received a copy of the GNU General Public License
    23 # along with this program; if not, write to the Free Software
    24 # Foundation, Inc., 51 Franklin Street, Fifth Floor, 
    25 # Boston, MA  02110-1301, USA.
    26 # ------------------------------------------------------------
    27 
    28 
    29 # ------------------------------------------------------------
    30 # imports
    31 
    32 import sys
    33 import urllib
    34 import urllib2
    35 
    36 from PyQt4 import QtCore
    37 from PyQt4 import QtGui
    38 
    39 # local
    40 import __init__ as opensecurity
    41 import proxy_getter
    42 
    43 if sys.platform == 'win32' or sys.platform == 'cygwin':
    44     from cygwin import Cygwin
    45 
    46 
    47 # ------------------------------------------------------------
    48 # code
    49 
    50 
    51 # start
    52 if __name__ == "__main__":
    53 
    54     if not (sys.platform == 'win32' or sys.platform == 'cygwin'):
    55         QtGui.QMessageBox.critical(None, 'OpenSecurity Error', 'This action is not supported on this platform.\nSorry.')
    56         sys.exit(1)
    57    
    58     try:
    59     
    60         # get a proper browsing VM
    61         Cygwin.start_X11()
    62         
    63         proxy_support = urllib2.ProxyHandler({})
    64         opener = urllib2.build_opener(proxy_support)
    65         urllib2.install_opener(opener)
    66 
    67         req_data = ""
    68         proxy = proxy_getter.getProxySettings()
    69         if proxy:
    70             req_data = '?' + urllib.urlencode(proxy) 
    71         req = 'http://127.0.0.1:8080/browsing'+ req_data
    72         browsing_vm = urllib2.urlopen(req).readline()
    73         print('Called '+ req + ' got: ' + str(browsing_vm))
    74         
    75     except:
    76         
    77         QtGui.QApplication.instance().processEvents()
    78         QtGui.QMessageBox.critical(None, 'Failed to invoke Safe Internet Browsing', 'OpenSecurity Error')
    79