Example #1
0
def configureVPNClientForConnection(clientLink):
    "download client config from passed link, unzip, and copy to correct location"
    result = 1
    #download config
    subprocess.call("wget -o /dev/null -t 1 --timeout=3 http://localhost" +
                    clientLink + " -O /tmp/clientconfig.zip",
                    shell=True)
    #copy config to remote host
    subprocess.call(
        "scp -o 'StrictHostKeyChecking=no' -i " +
        global_functions.get_prefix() + remote_control.host_key_file +
        " /tmp/clientconfig.zip testshell@" + global_functions.VPN_CLIENT_IP +
        ":/tmp/>/dev/null 2>&1",
        shell=True)
    #unzip files
    unzipFiles = remote_control.run_command(
        "sudo unzip -o /tmp/clientconfig.zip -d /tmp/",
        host=global_functions.VPN_CLIENT_IP)
    #remove any existing openvpn config files
    removeOld = remote_control.run_command(
        "sudo rm -f /etc/openvpn/*.conf; sudo rm -f /etc/openvpn/*.ovpn; sudo rm -rf /etc/openvpn/keys",
        host=global_functions.VPN_CLIENT_IP)
    #move new config to directory
    moveNew = remote_control.run_command(
        "sudo mv -f /tmp/untangle-vpn/* /etc/openvpn/",
        host=global_functions.VPN_CLIENT_IP)
    if (unzipFiles == 0) and (removeOld == 0) and (moveNew == 0):
        result = 0
    return result
Example #2
0
    def test_101_email_admin_override_custom_report(self):
        """
        1. Use reportuser
        2. Reportuser overrides admin user address.
        3. Custom report with test not in default.
        """
        if (not can_relay):
            raise unittest.SkipTest('Unable to relay through ' +
                                    global_functions.TEST_SERVER_HOST)
        if runtests.quick_tests_only:
            raise unittest.SkipTest('Skipping a time consuming test')

        # Create settings to receive test_email_address
        configure_mail_relay()

        # add administrator
        adminsettings = uvmContext.adminManager().getSettings()
        orig_adminsettings = copy.deepcopy(adminsettings)
        adminsettings['users']['list'].append(
            create_admin_user(useremail=test_email_address))
        uvmContext.adminManager().setSettings(adminsettings)

        settings = app.getSettings()
        # add custom template with a test not in daily reports
        settings["emailTemplates"]["list"] = settings["emailTemplates"][
            "list"][:1]
        settings["emailTemplates"]["list"].append(create_email_template())

        # add report user with test_email_address
        settings["reportsUsers"]["list"] = settings["reportsUsers"]["list"][:1]
        settings["reportsUsers"]["list"].append(
            create_reports_user(profile_email=test_email_address,
                                email_template_id=2))
        app.setSettings(settings)

        # send email
        subprocess.call([
            global_functions.get_prefix() +
            "/usr/share/untangle/bin/reports-generate-fixed-reports.py"
        ],
                        stdout=subprocess.PIPE,
                        stderr=subprocess.PIPE)

        # look for email
        email_found = fetch_email(
            "/tmp/test_101_email_admin_override_custom_report_file",
            test_email_address)
        if email_found:
            email_context_found1 = remote_control.run_command(
                "grep -i 'Custom Report' /tmp/test_101_email_admin_override_custom_report_file 2>&1",
                stdout=True)
            email_context_found2 = remote_control.run_command(
                "grep -i 'Administration-VWuRol5uWw' /tmp/test_101_email_admin_override_custom_report_file 2>&1",
                stdout=True)

        # restore
        uvmContext.adminManager().setSettings(orig_adminsettings)

        assert (email_found)
        assert ((email_context_found1) and (email_context_found2))
Example #3
0
def configureVPNClientForConnection(clientLink):
    "download client config from passed link, unzip, and copy to correct location"
    result = 1
    #download config
    subprocess.call("wget -o /dev/null -t 1 --timeout=3 http://localhost" + clientLink + " -O /tmp/clientconfig.zip", shell=True)
    #copy config to remote host
    subprocess.call("scp -o 'StrictHostKeyChecking=no' -i " + global_functions.get_prefix() + remote_control.host_key_file + " /tmp/clientconfig.zip testshell@" + global_functions.VPN_CLIENT_IP + ":/tmp/>/dev/null 2>&1", shell=True)
    #unzip files
    unzipFiles = remote_control.run_command("sudo unzip -o /tmp/clientconfig.zip -d /tmp/", host=global_functions.VPN_CLIENT_IP)
    #remove any existing openvpn config files
    removeOld = remote_control.run_command("sudo rm -f /etc/openvpn/*.conf; sudo rm -f /etc/openvpn/*.ovpn; sudo rm -rf /etc/openvpn/keys", host=global_functions.VPN_CLIENT_IP)
    #move new config to directory
    moveNew = remote_control.run_command("sudo mv -f /tmp/untangle-vpn/* /etc/openvpn/", host=global_functions.VPN_CLIENT_IP)
    if(unzipFiles == 0) and (removeOld == 0) and (moveNew == 0):
        result = 0
    return result
Example #4
0
    def test_101_email_admin_override_custom_report(self):
        """
        1. Use reportuser
        2. Reportuser overrides admin user address.
        3. Custom report with test not in default.
        """
        if (not can_relay):
            raise unittest.SkipTest('Unable to relay through ' + global_functions.TEST_SERVER_HOST)
        if runtests.quick_tests_only:
            raise unittest.SkipTest('Skipping a time consuming test')

        # Create settings to receive test_email_address 
        configure_mail_relay()

        # add administrator
        adminsettings = uvmContext.adminManager().getSettings()
        orig_adminsettings = copy.deepcopy(adminsettings)
        adminsettings['users']['list'].append(create_admin_user(useremail=test_email_address))
        uvmContext.adminManager().setSettings(adminsettings)

        settings = app.getSettings()
        # add custom template with a test not in daily reports
        settings["emailTemplates"]["list"] = settings["emailTemplates"]["list"][:1]
        settings["emailTemplates"]["list"].append(create_email_template())

        # add report user with test_email_address
        settings["reportsUsers"]["list"] = settings["reportsUsers"]["list"][:1]
        settings["reportsUsers"]["list"].append(create_reports_user(profile_email=test_email_address, email_template_id=2))
        app.setSettings(settings)

        # send email
        subprocess.call([global_functions.get_prefix()+"/usr/share/untangle/bin/reports-generate-fixed-reports.py"],stdout=subprocess.PIPE,stderr=subprocess.PIPE)

        # look for email
        email_found = fetch_email( "/tmp/test_101_email_admin_override_custom_report_file", test_email_address )
        if email_found:
            email_context_found1 = remote_control.run_command("grep -i 'Custom Report' /tmp/test_101_email_admin_override_custom_report_file 2>&1", stdout=True)
            email_context_found2 = remote_control.run_command("grep -i 'Administration-VWuRol5uWw' /tmp/test_101_email_admin_override_custom_report_file 2>&1", stdout=True)

        # restore
        uvmContext.adminManager().setSettings(orig_adminsettings)

        assert(email_found)
        assert((email_context_found1) and (email_context_found2))
Example #5
0
    def test_103_email_report_verify_apps(self):
        """
        1) Install all apps
        2) Generate a report
        3) Verify that the emailed report contains a section for each app
        """
        global app, apps_list, apps_name_list
        if (not can_relay):
            raise unittest.SkipTest('Unable to relay through ' +
                                    global_functions.TEST_SERVER_HOST)
        if runtests.quick_tests_only:
            raise unittest.SkipTest('Skipping a time consuming test')

        # create settings to receive test_email_address
        configure_mail_relay()

        # add administrator
        adminsettings = uvmContext.adminManager().getSettings()
        orig_adminsettings = copy.deepcopy(adminsettings)
        adminsettings['users']['list'].append(
            create_admin_user(useremail=test_email_address))
        uvmContext.adminManager().setSettings(adminsettings)

        # clear all report users
        settings = self._app.getSettings()
        settings["reportsUsers"]["list"] = settings["reportsUsers"]["list"][:1]
        self._app.setSettings(settings)

        # install all the apps that aren't already installed
        system_stats = uvmContext.metricManager().getStats()
        # print system_stats
        system_memory = system_stats['systemStats']['MemTotal']
        if (int(system_memory) < 2200000000
            ):  # don't use high memory apps in devices with 2G or less.
            apps_list = apps_list_short
            apps_name_list = apps_name_list_short
        apps = []
        for name in apps_list:
            if (uvmContext.appManager().isInstantiated(name)):
                print("App %s already installed" % name)
            else:
                apps.append(uvmContext.appManager().instantiate(
                    name, default_policy_id))

        # create some traffic
        result = remote_control.is_online(tries=1)

        # flush out events
        self._app.flushEvents()

        # send emails
        subprocess.call([
            global_functions.get_prefix() +
            "/usr/share/untangle/bin/reports-generate-fixed-reports.py"
        ],
                        stdout=subprocess.PIPE,
                        stderr=subprocess.PIPE)

        # look for email
        email_found = fetch_email("/tmp/test_103_email_report_admin_file",
                                  test_email_address)

        # look for all the appropriate sections in the report email
        results = []
        if email_found:
            for str in apps_name_list:
                results.append(
                    remote_control.run_command(
                        "grep -q -i '%s' /tmp/test_103_email_report_admin_file 2>&1"
                        % str))

        # restore
        uvmContext.adminManager().setSettings(orig_adminsettings)

        # remove apps that were installed above
        for a in apps:
            uvmContext.appManager().destroy(a.getAppSettings()["id"])

        assert (email_found)
        for result in results:
            assert (result == 0)
Example #6
0
    def test_102_email_admin_override_custom_report_mobile(self):
        """
        1. Use reportuser
        2. Reportuser overrides admin user address.
        3. Custom report with test not in default.
        """
        if (not can_relay):
            raise unittest.SkipTest('Unable to relay through ' +
                                    global_functions.TEST_SERVER_HOST)
        if runtests.quick_tests_only:
            raise unittest.SkipTest('Skipping a time consuming test')

        # Create settings to receive test_email_address
        configure_mail_relay()
        subprocess.call(
            "rm /tmp/test_102_email_admin_override_custom_report_mobile_file > /dev/null 2>&1",
            shell=True)

        # add administrator
        adminsettings = uvmContext.adminManager().getSettings()
        orig_adminsettings = copy.deepcopy(adminsettings)
        adminsettings['users']['list'].append(
            create_admin_user(useremail=test_email_address))
        uvmContext.adminManager().setSettings(adminsettings)

        settings = app.getSettings()
        # add custom template with a test not in daily reports
        settings["emailTemplates"]["list"] = settings["emailTemplates"][
            "list"][:1]
        settings["emailTemplates"]["list"].append(
            create_email_template(mobile=True))

        # add report user with test_email_address
        settings["reportsUsers"]["list"] = settings["reportsUsers"]["list"][:1]
        settings["reportsUsers"]["list"].append(
            create_reports_user(profile_email=test_email_address,
                                email_template_id=2))
        app.setSettings(settings)

        # send email
        subprocess.call([
            global_functions.get_prefix() +
            "/usr/share/untangle/bin/reports-generate-fixed-reports.py"
        ],
                        stdout=subprocess.PIPE,
                        stderr=subprocess.PIPE)

        # look for email
        email_found = fetch_email(
            "/tmp/test_102_email_admin_override_custom_report_mobile_file",
            test_email_address)
        if email_found:
            email_context_found1 = remote_control.run_command(
                "grep -i 'Custom Report' /tmp/test_102_email_admin_override_custom_report_mobile_file 2>&1",
                stdout=True)
            email_context_found2 = remote_control.run_command(
                "grep -i 'Administration-VWuRol5uWw' /tmp/test_102_email_admin_override_custom_report_mobile_file 2>&1",
                stdout=True)

        # restore
        uvmContext.adminManager().setSettings(orig_adminsettings)

        assert (email_found)
        assert ((email_context_found1) and (email_context_found2))

        # Verify that all images are less than 3502350.
        # copy mail from remote client
        subprocess.call(
            "scp -q -i %s testshell@%s:/tmp/test_102_email_admin_override_custom_report_mobile_file /tmp/"
            % (remote_control.host_key_file, remote_control.client_ip),
            shell=True)
        fp = open(
            "/tmp/test_102_email_admin_override_custom_report_mobile_file")
        email_string = fp.read()
        fp.close()
        # Delete the first line as it is blank and throws off the parser
        email_string = '\n'.join(email_string.split('\n')[1:])
        msg = email.message_from_string(email_string)

        mime_content_ids = []
        for part in msg.walk():
            if part.get_content_maintype() == "image":
                # print("Image found")
                for index, key in enumerate(part.keys()):
                    if key == "Content-ID" and "untangle.int" in part.values(
                    )[index]:
                        email_image = part.get_payload(decode=True)
                        im = Image.open(BytesIO(email_image))
                        (image_width, image_height) = im.size
                        print(
                            "Image %s width: %d height: %d" %
                            (part.values()[index], image_width, image_height))
                        assert (image_width <= 350 and image_height <= 350)
Example #7
0
    def test_100_email_report_admin(self):
        """
        The "default" configuration test:
        - Administrator email account gets
        """
        if (not can_relay):
            raise unittest.SkipTest('Unable to relay through ' +
                                    global_functions.TEST_SERVER_HOST)
        if runtests.quick_tests_only:
            raise unittest.SkipTest('Skipping a time consuming test')

        # create settings to receive test_email_address
        configure_mail_relay()
        subprocess.call(
            "rm /tmp/test_100_email_report_admin_file > /dev/null 2>&1",
            shell=True)

        # add administrator
        adminsettings = uvmContext.adminManager().getSettings()
        orig_adminsettings = copy.deepcopy(adminsettings)
        adminsettings['users']['list'].append(
            create_admin_user(useremail=test_email_address))
        uvmContext.adminManager().setSettings(adminsettings)

        # clear all report users
        settings = app.getSettings()
        settings["reportsUsers"]["list"] = settings["reportsUsers"]["list"][:1]
        app.setSettings(settings)

        # send emails
        subprocess.call([
            global_functions.get_prefix() +
            "/usr/share/untangle/bin/reports-generate-fixed-reports.py"
        ],
                        stdout=subprocess.PIPE,
                        stderr=subprocess.PIPE)

        # look for email
        email_found = fetch_email("/tmp/test_100_email_report_admin_file",
                                  test_email_address)
        email_context_found1 = ""
        email_context_found2 = ""
        if email_found:
            email_context_found1 = remote_control.run_command(
                "grep -i -e 'Reports:.*Daily.*' /tmp/test_100_email_report_admin_file 2>&1",
                stdout=True)
            email_context_found2 = remote_control.run_command(
                "grep -i -e 'Content-Type: image/png; name=' /tmp/test_100_email_report_admin_file 2>&1",
                stdout=True)

        # restore
        uvmContext.adminManager().setSettings(orig_adminsettings)

        assert (email_found)
        assert ((email_context_found1) and (email_context_found2))

        ## Verify that all images are intact.
        # copy mail from remote client
        subprocess.call(
            "scp -q -i %s testshell@%s:/tmp/test_100_email_report_admin_file /tmp/"
            % (remote_control.host_key_file, remote_control.client_ip),
            shell=True)
        fp = open("/tmp/test_100_email_report_admin_file")
        email_string = fp.read()
        fp.close()
        # Delete the first line as it is blank and throws off the parser
        email_string = '\n'.join(email_string.split('\n')[1:])
        msg = email.message_from_string(email_string)

        mime_content_ids = []
        parser = ContentIdParser()
        for part in msg.walk():
            if part.get_content_maintype() == "image":
                for index, key in enumerate(part.keys()):
                    if key == "Content-ID":
                        mime_content_ids.append(part.values()[index])
            elif part.get_content_maintype() == "text":
                parser.feed((part.get_payload(decode=True)).decode("utf-8"))

        assert (len(parser.content_ids) == len(mime_content_ids))
Example #8
0
    def test_103_email_report_verify_apps(self):
        """
        1) Install all apps
        2) Generate a report
        3) Verify that the emailed report contains a section for each app
        """
        global app,apps_list,apps_name_list
        if (not can_relay):
            raise unittest.SkipTest('Unable to relay through ' + global_functions.TEST_SERVER_HOST)
        if runtests.quick_tests_only:
            raise unittest.SkipTest('Skipping a time consuming test')

        # create settings to receive test_email_address 
        configure_mail_relay()

        # add administrator
        adminsettings = uvmContext.adminManager().getSettings()
        orig_adminsettings = copy.deepcopy(adminsettings)
        adminsettings['users']['list'].append(create_admin_user(useremail=test_email_address))
        uvmContext.adminManager().setSettings(adminsettings)

        # clear all report users
        settings = app.getSettings()
        settings["reportsUsers"]["list"] = settings["reportsUsers"]["list"][:1]
        app.setSettings(settings)
        
        # install all the apps that aren't already installed
        system_stats = uvmContext.metricManager().getStats()
        # print system_stats
        system_memory = system_stats['systemStats']['MemTotal']
        if (int(system_memory) < 2200000000):   # don't use high memory apps in devices with 2G or less.
            apps_list = apps_list_short
            apps_name_list = apps_name_list_short
        apps = []
        for name in apps_list:
            if (uvmContext.appManager().isInstantiated(name)):
                print("App %s already installed" % name)
            else:
                apps.append( uvmContext.appManager().instantiate(name, default_policy_id) )
            
        # create some traffic 
        result = remote_control.is_online(tries=1)

        # flush out events
        app.flushEvents()

        # send emails
        subprocess.call([global_functions.get_prefix()+"/usr/share/untangle/bin/reports-generate-fixed-reports.py"],stdout=subprocess.PIPE,stderr=subprocess.PIPE)

        # look for email
        email_found = fetch_email( "/tmp/test_103_email_report_admin_file", test_email_address )

        # look for all the appropriate sections in the report email
        results = []
        if email_found:
            for str in apps_name_list:
                results.append(remote_control.run_command("grep -q -i '%s' /tmp/test_103_email_report_admin_file 2>&1"%str))

        # restore
        uvmContext.adminManager().setSettings(orig_adminsettings)

        # remove apps that were installed above
        for a in apps: uvmContext.appManager().destroy( a.getAppSettings()["id"] )
        
        assert(email_found)
        for result in results:
            assert(result == 0)
Example #9
0
    def test_102_email_admin_override_custom_report_mobile(self):
        """
        1. Use reportuser
        2. Reportuser overrides admin user address.
        3. Custom report with test not in default.
        """
        if (not can_relay):
            raise unittest.SkipTest('Unable to relay through ' + global_functions.TEST_SERVER_HOST)
        if runtests.quick_tests_only:
            raise unittest.SkipTest('Skipping a time consuming test')

        # Create settings to receive test_email_address 
        configure_mail_relay()

        # add administrator
        adminsettings = uvmContext.adminManager().getSettings()
        orig_adminsettings = copy.deepcopy(adminsettings)
        adminsettings['users']['list'].append(create_admin_user(useremail=test_email_address))
        uvmContext.adminManager().setSettings(adminsettings)

        settings = app.getSettings()
        # add custom template with a test not in daily reports
        settings["emailTemplates"]["list"] = settings["emailTemplates"]["list"][:1]
        settings["emailTemplates"]["list"].append(create_email_template(mobile=True))

        # add report user with test_email_address
        settings["reportsUsers"]["list"] = settings["reportsUsers"]["list"][:1]
        settings["reportsUsers"]["list"].append(create_reports_user(profile_email=test_email_address, email_template_id=2))
        app.setSettings(settings)

        # send email
        subprocess.call([global_functions.get_prefix()+"/usr/share/untangle/bin/reports-generate-fixed-reports.py"],stdout=subprocess.PIPE,stderr=subprocess.PIPE)

        # look for email
        email_found = fetch_email( "/tmp/test_102_email_admin_override_custom_report_mobile_file", test_email_address )
        if email_found:
            email_context_found1 = remote_control.run_command("grep -i 'Custom Report' /tmp/test_102_email_admin_override_custom_report_mobile_file 2>&1", stdout=True)
            email_context_found2 = remote_control.run_command("grep -i 'Administration-VWuRol5uWw' /tmp/test_102_email_admin_override_custom_report_mobile_file 2>&1", stdout=True)

        # restore
        uvmContext.adminManager().setSettings(orig_adminsettings)

        assert(email_found)
        assert((email_context_found1) and (email_context_found2))

        # Verify that all images are less than 3502350.
        # copy mail from remote client
        subprocess.call("scp -q -i %s testshell@%s:/tmp/test_102_email_admin_override_custom_report_mobile_file /tmp/" % (remote_control.host_key_file, remote_control.client_ip), shell=True)
        fp = open("/tmp/test_102_email_admin_override_custom_report_mobile_file")
        email_string = fp.read()
        fp.close()
        subprocess.call("rm /tmp/test_102_email_admin_override_custom_report_mobile_file", shell=True)
        # Delete the first line as it is blank and throws off the parser
        email_string = '\n'.join(email_string.split('\n')[1:])
        msg = email.message_from_string(email_string)

        mime_content_ids = []
        for part in msg.walk():
            if part.get_content_maintype() == "image":
                # print("Image found")
                for index, key in enumerate(part.keys()):
                    if key == "Content-ID" and "untangle.int" in part.values()[index]:
                        email_image = part.get_payload(decode=True)
                        im = Image.open(StringIO(email_image))
                        (image_width,image_height) = im.size
                        print("Image %s width: %d height: %d" % (part.values()[index], image_width, image_height))
                        assert(image_width <= 350 and image_height <= 350)
Example #10
0
    def test_100_email_report_admin(self):
        """
        The "default" configuration test:
        - Administrator email account gets
        """
        if (not can_relay):
            raise unittest.SkipTest('Unable to relay through ' + global_functions.TEST_SERVER_HOST)
        if runtests.quick_tests_only:
            raise unittest.SkipTest('Skipping a time consuming test')

        # create settings to receive test_email_address 
        configure_mail_relay()

        # add administrator
        adminsettings = uvmContext.adminManager().getSettings()
        orig_adminsettings = copy.deepcopy(adminsettings)
        adminsettings['users']['list'].append(create_admin_user(useremail=test_email_address))
        uvmContext.adminManager().setSettings(adminsettings)

        # clear all report users
        settings = app.getSettings()
        settings["reportsUsers"]["list"] = settings["reportsUsers"]["list"][:1]
        app.setSettings(settings)

        # send emails
        subprocess.call([global_functions.get_prefix()+"/usr/share/untangle/bin/reports-generate-fixed-reports.py"],stdout=subprocess.PIPE,stderr=subprocess.PIPE)

        # look for email
        email_found = fetch_email( "/tmp/test_100_email_report_admin_file", test_email_address )
        email_context_found1 = ""
        email_context_found2 = ""
        if email_found:
            email_context_found1 = remote_control.run_command("grep -i -e 'Reports:.*Daily.*' /tmp/test_100_email_report_admin_file 2>&1", stdout=True)
            email_context_found2 = remote_control.run_command("grep -i -e 'Content-Type: image/png; name=' /tmp/test_100_email_report_admin_file 2>&1", stdout=True)

        # restore
        uvmContext.adminManager().setSettings(orig_adminsettings)

        assert(email_found)
        assert((email_context_found1) and (email_context_found2))

        ## Verify that all images are intact.
        # copy mail from remote client
        subprocess.call("scp -q -i %s testshell@%s:/tmp/test_100_email_report_admin_file /tmp/" % (remote_control.host_key_file, remote_control.client_ip), shell=True)
        fp = open("/tmp/test_100_email_report_admin_file")
        email_string = fp.read()
        fp.close()
        subprocess.call("rm /tmp/test_100_email_report_admin_file", shell=True)
        # Delete the first line as it is blank and throws off the parser
        email_string = '\n'.join(email_string.split('\n')[1:])
        msg = email.message_from_string(email_string)

        mime_content_ids = []
        parser = ContentIdParser();
        for part in msg.walk():
            if part.get_content_maintype() == "image":
                for index, key in enumerate(part.keys()):
                    if key == "Content-ID":
                        mime_content_ids.append(part.values()[index])
            elif part.get_content_maintype() == "text":
                parser.feed(part.get_payload(decode=True))

        assert(len(parser.content_ids) == len(mime_content_ids))