Example #1
0
 def apply(self, filename: str) -> None:
     """
     TODO: Doku
     """
     info("starting apply process from easywall")
     delete_file_if_exists(filename)
     self.easywall.apply()
Example #2
0
    def status(self) -> str:
        """
        this function returns the current status of the acceptance process.
        this is useful for calls of external software.
        when the status is waited the file content is read and the final acceptance status is
        determined here. the temporary file is also deleted in this function.

        possible status values:
        - ready
        - disabled
        - started
        - waiting
        - waited
        - accepted
        - not accepted
        """

        if self.mystatus == "waited":
            content = file_get_contents(self.filename)
            content = content.replace("\n", "")
            content = content.replace("\t", "")

            if content.lower() == "true":
                info("acceptance result: Accepted")
                self.set_status("accepted")
            else:
                info("acceptance result: Not Accepted (file content: {})".
                     format(content))
                self.set_status("not accepted")

            delete_file_if_exists(self.filename)

        return self.mystatus
Example #3
0
 def test_execute_os_command(self):
     """
     TODO: Doku
     """
     self.assertTrue(execute_os_command("touch testfile"))
     self.assertTrue(file_exists("testfile"))
     delete_file_if_exists("testfile")
Example #4
0
    def shutdown(self) -> None:
        """Stop all threads and shut the software down gracefully."""
        info("starting shutdown")

        self.observer.stop()
        delete_file_if_exists(".acceptance")
        self.observer.join()

        info("shutdown completed")
        self.log.close_logging()
Example #5
0
def shutdown(observer, config, log):
    """this function executes a shutdown of easywall"""
    info("Shutting down easywall...")
    observer.stop()
    delete_file_if_exists(".running")
    delete_file_if_exists(config.get_value("ACCEPTANCE", "filename"))
    observer.join()
    log.close_logging()
    info("easywall was stopped gracefully")
    exit(0)
Example #6
0
 def status(self) -> str:
     """
     the function lists the iptables configuration as string
     this is not machine readable!
     """
     tmpfile = ".iptables_list"
     execute_os_command("{} -L > {}".format(self.iptables_bin, tmpfile))
     content = file_get_contents(tmpfile)
     delete_file_if_exists(tmpfile)
     return content
Example #7
0
def apply_step_two():
    """the function writes true into the accept file from easywall core"""
    try:
        utils = Webutils()
        filepath = "../" + utils.cfg.get_value("ACCEPTANCE", "filename")
        with open(filepath, mode='wt', encoding='utf-8') as acceptfile:
            acceptfile.write("true")
        for ruletype in ["blacklist", "whitelist", "tcp", "udp", "custom"]:
            delete_file_if_exists(utils.get_rule_file_path(ruletype, True))
    except Exception as exc:
        print("{}".format(exc))
Example #8
0
def shutdown(observer: Observer, config: Config, log: Log):
    """
    the function stops all threads and shuts the software down gracefully
    """
    info("starting shutdown...")
    observer.stop()
    delete_file_if_exists(".running")
    delete_file_if_exists(config.get_value("ACCEPTANCE", "filename"))
    observer.join()
    info("shutdown successfully completed")
    log.close_logging()
    exit(0)
Example #9
0
 def test_file(self):
     assert not file_exists("testfile")
     create_file_if_not_exists("testfile")
     assert file_exists("testfile")
     write_into_file("testfile", "testcontent")
     assert file_get_contents("testfile") == "testcontent"
     assert len(get_abs_path_of_filepath("testfile")) > 0
     rename_file("testfile", "testfilenew")
     assert not file_exists("testfile")
     assert file_exists("testfilenew")
     delete_file_if_exists("testfilenew")
     assert not file_exists("testfile")
     assert not file_exists("testfilenew")
Example #10
0
 def test_file(self) -> None:
     """TODO: Doku."""
     self.assertFalse(file_exists("testfile"))
     create_file_if_not_exists("testfile")
     self.assertTrue(file_exists("testfile"))
     write_into_file("testfile", "testcontent")
     self.assertEqual(file_get_contents("testfile"), "testcontent")
     self.assertGreater(len(get_abs_path_of_filepath("testfile")), 0)
     rename_file("testfile", "testfilenew")
     self.assertFalse(file_exists("testfile"))
     self.assertTrue(file_exists("testfilenew"))
     delete_file_if_exists("testfilenew")
     self.assertFalse(file_exists("testfile"))
     self.assertFalse(file_exists("testfilenew"))
Example #11
0
 def test_file(self):
     """
     TODO: Doku
     """
     assert not file_exists("testfile")
     create_file_if_not_exists("testfile")
     assert file_exists("testfile")
     write_into_file("testfile", "testcontent")
     assert file_get_contents("testfile") == "testcontent"
     self.assertGreater(len(get_abs_path_of_filepath("testfile")), 0)
     rename_file("testfile", "testfilenew")
     assert not file_exists("testfile")
     assert file_exists("testfilenew")
     delete_file_if_exists("testfilenew")
     assert not file_exists("testfile")
     assert not file_exists("testfilenew")
Example #12
0
 def tearDown(self):
     delete_file_if_exists("acceptance.ini")
Example #13
0
 def setUp(self) -> None:
     delete_file_if_exists("./test.log")
     self.log = Log("INFO", True, True, ".", "test.log")
Example #14
0
 def tearDown(self):
     delete_file_if_exists("test.log")
     self.log.close_logging()
Example #15
0
 def tearDown(self) -> None:
     self.log.close_logging()
     delete_file_if_exists("./test.log")
Example #16
0
 def delete_running_file(self):
     """the function deletes a file in the main directory called .running"""
     delete_file_if_exists(".running")
Example #17
0
 def tearDown(self) -> None:
     delete_file_if_exists("test.log")
     delete_file_if_exists(".acceptance_status")
     if file_exists(self.config_backup_path):
         rename_file(self.config_backup_path, CONFIG_PATH)
Example #18
0
 def tearDown(self):
     delete_file_if_exists("test.ini")
Example #19
0
 def tearDown(self):
     restore_configuration()
     delete_file_if_exists(".apply")
     delete_file_if_exists(".acceptance")
Example #20
0
 def tearDown(self) -> None:
     """TODO: Doku."""
     restore_configuration()
     delete_file_if_exists(".apply")
     delete_file_if_exists(".acceptance")
Example #21
0
 def tearDown(self) -> None:
     """TODO: Doku."""
     delete_file_if_exists("test.ini")
Example #22
0
 def tearDown(self) -> None:
     """TODO: Doku."""
     delete_file_if_exists("test.log")
     delete_file_if_exists(".acceptance_status")
     restore_configuration()
Example #23
0
 def tearDown(self) -> None:
     delete_file_if_exists(self.config_file)
 def tearDown(self) -> None:
     self.iptables.reset()
     delete_file_if_exists("iptables.ini")