コード例 #1
0
 def apply(self, filename: str) -> None:
     """
     TODO: Doku
     """
     info("starting apply process from easywall")
     delete_file_if_exists(filename)
     self.easywall.apply()
コード例 #2
0
ファイル: acceptance.py プロジェクト: ptrifonov/easywall
    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
コード例 #3
0
ファイル: test_utility.py プロジェクト: weijian1989/easywall
 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")
コード例 #4
0
ファイル: __main__.py プロジェクト: zroorz/easywall
    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()
コード例 #5
0
ファイル: __init__.py プロジェクト: phonglh79/easywall
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)
コード例 #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
コード例 #7
0
ファイル: apply.py プロジェクト: jpylypiw/easywall-web
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))
コード例 #8
0
ファイル: __init__.py プロジェクト: 5l1v3r1/easywall
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)
コード例 #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")
コード例 #10
0
ファイル: test_utility.py プロジェクト: zroorz/easywall
 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"))
コード例 #11
0
ファイル: test_utility.py プロジェクト: weijian1989/easywall
 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")
コード例 #12
0
 def tearDown(self):
     delete_file_if_exists("acceptance.ini")
コード例 #13
0
 def setUp(self) -> None:
     delete_file_if_exists("./test.log")
     self.log = Log("INFO", True, True, ".", "test.log")
コード例 #14
0
ファイル: test_log.py プロジェクト: weijian1989/easywall
 def tearDown(self):
     delete_file_if_exists("test.log")
     self.log.close_logging()
コード例 #15
0
 def tearDown(self) -> None:
     self.log.close_logging()
     delete_file_if_exists("./test.log")
コード例 #16
0
ファイル: easywall.py プロジェクト: 5l1v3r1/easywall
 def delete_running_file(self):
     """the function deletes a file in the main directory called .running"""
     delete_file_if_exists(".running")
コード例 #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)
コード例 #18
0
ファイル: test_config.py プロジェクト: 5l1v3r1/easywall
 def tearDown(self):
     delete_file_if_exists("test.ini")
コード例 #19
0
 def tearDown(self):
     restore_configuration()
     delete_file_if_exists(".apply")
     delete_file_if_exists(".acceptance")
コード例 #20
0
ファイル: test_apply.py プロジェクト: zroorz/easywall
 def tearDown(self) -> None:
     """TODO: Doku."""
     restore_configuration()
     delete_file_if_exists(".apply")
     delete_file_if_exists(".acceptance")
コード例 #21
0
 def tearDown(self) -> None:
     """TODO: Doku."""
     delete_file_if_exists("test.ini")
コード例 #22
0
 def tearDown(self) -> None:
     """TODO: Doku."""
     delete_file_if_exists("test.log")
     delete_file_if_exists(".acceptance_status")
     restore_configuration()
コード例 #23
0
ファイル: test_easywall.py プロジェクト: ptrifonov/easywall
 def tearDown(self) -> None:
     delete_file_if_exists(self.config_file)
コード例 #24
0
 def tearDown(self) -> None:
     self.iptables.reset()
     delete_file_if_exists("iptables.ini")