-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0727d82
commit eefa8f0
Showing
5 changed files
with
53 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
import hug | ||
import tables, chains, rules, sets, maps | ||
import tables, chains, rules, sets, maps, service | ||
|
||
api = hug.API(__name__) | ||
api.extend(tables, '/tables') | ||
api.extend(chains, '/chains') | ||
api.extend(rules, '/rules') | ||
api.extend(sets, '/sets') | ||
api.extend(maps, '/maps') | ||
api.extend(service, '/service') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import glob | ||
import json | ||
from nftables import Nftables | ||
import sys, os | ||
import hug | ||
|
||
@hug.get('/reload_service') | ||
def reload_service(): | ||
os.system("sudo systemctl restart nftables") | ||
return {"status": "success"} | ||
|
||
@hug.get('/save_service') | ||
def save_service(): | ||
os.system("sudo rm -f /etc/nftables.conf") | ||
os.system("sudo nft list ruleset > /etc/nftables.conf") | ||
os.system("sudo systemctl restart nftables") | ||
return {"status": "success"} | ||
|
||
@hug.get('/save_service_temp') | ||
def save_service_temp(): | ||
files = glob.glob("./temp_config/nftables_temp*.conf") | ||
numbers = [int(f.replace("./temp_config/nftables_temp", "").replace(".conf", "")) for f in files] | ||
highest_number = max(numbers) if numbers else 0 | ||
os.system(f"sudo nft list ruleset > ./temp_config/nftables_temp{highest_number + 1}.conf") |