OpenSecurity/bin/start_browsing.pyw
author Oliver Maurhart <oliver.maurhart@ait.ac.at>
Wed, 29 Oct 2014 15:18:22 +0100
changeset 240 d7ef04254e9c
parent 238 d33edf5c2717
permissions -rw-r--r--
lizenz fixed in all files
     1 # -*- coding: utf-8 -*-
     2 
     3 # ------------------------------------------------------------
     4 # directly start the browsing
     5 # 
     6 # Autor: Oliver Maurhart, <oliver.maurhart@ait.ac.at>
     7 #        Mihai Bartha, <mihai.bartha@ait.ac.at>       
     8 #
     9 # Copyright 2013-2014 X-Net and AIT Austrian Institute of Technology
    10 # 
    11 # 
    12 #     X-Net Services GmbH
    13 #     Elisabethstrasse 1
    14 #     4020 Linz
    15 #     AUSTRIA
    16 #     https://www.x-net.at
    17 # 
    18 #     AIT Austrian Institute of Technology
    19 #     Donau City Strasse 1
    20 #     1220 Wien
    21 #     AUSTRIA
    22 #     http://www.ait.ac.at
    23 # 
    24 # 
    25 # Licensed under the Apache License, Version 2.0 (the "License");
    26 # you may not use this file except in compliance with the License.
    27 # You may obtain a copy of the License at
    28 # 
    29 #    http://www.apache.org/licenses/LICENSE-2.0
    30 # 
    31 # Unless required by applicable law or agreed to in writing, software
    32 # distributed under the License is distributed on an "AS IS" BASIS,
    33 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    34 # See the License for the specific language governing permissions and
    35 # limitations under the License.
    36 # ------------------------------------------------------------
    37 
    38 
    39 # ------------------------------------------------------------
    40 # imports
    41 
    42 import sys
    43 import urllib
    44 import urllib2
    45 
    46 from PyQt4 import QtCore
    47 from PyQt4 import QtGui
    48 
    49 # local
    50 import __init__ as opensecurity
    51 import proxy_getter
    52 
    53 if sys.platform == 'win32' or sys.platform == 'cygwin':
    54     from cygwin import Cygwin
    55 
    56 
    57 # ------------------------------------------------------------
    58 # code
    59 
    60 
    61 # start
    62 if __name__ == "__main__":
    63 
    64     if not (sys.platform == 'win32' or sys.platform == 'cygwin'):
    65         QtGui.QMessageBox.critical(None, 'OpenSecurity Error', 'This action is not supported on this platform.\nSorry.')
    66         sys.exit(1)
    67    
    68     try:
    69     
    70         # get a proper browsing VM
    71         Cygwin.start_X11()
    72         
    73         proxy_support = urllib2.ProxyHandler({})
    74         opener = urllib2.build_opener(proxy_support)
    75         urllib2.install_opener(opener)
    76 
    77         req_data = ""
    78         proxy = proxy_getter.getProxySettings()
    79         if proxy:
    80             req_data = '?' + urllib.urlencode(proxy) 
    81         req = 'http://127.0.0.1:8080/browsing'+ req_data
    82         browsing_vm = urllib2.urlopen(req).readline()
    83         print('Called '+ req + ' got: ' + str(browsing_vm))
    84         
    85     except:
    86         
    87         QtGui.QApplication.instance().processEvents()
    88         QtGui.QMessageBox.critical(None, 'Failed to invoke Safe Internet Browsing', 'OpenSecurity Error')
    89