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