aboutsummaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
authorflu0r1ne <flu0r1ne@flu0r1ne.net>2023-08-18 01:13:07 -0500
committerflu0r1ne <flu0r1ne@flu0r1ne.net>2023-08-18 01:13:07 -0500
commit2f0a9c87bd5acd8fc0852f599599d031cde44bbe (patch)
treec4adb81a041d3cb7428c7c11c9cf8d88751b9160 /src/main.cpp
parentd6e19ce0a112bd2403ad0cb274808ce3e749b459 (diff)
downloadwg2nd-2f0a9c87bd5acd8fc0852f599599d031cde44bbe.tar.xz
wg2nd-2f0a9c87bd5acd8fc0852f599599d031cde44bbe.zip
Add firewall rule generator
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/main.cpp b/src/main.cpp
index b592aa9..19b5ced 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -89,10 +89,11 @@ void err(char const * format, ...) {
}
void print_help(char const * prog) {
- err("Usage: %s [ -o OUTPUT_PATH ] CONFIG_FILE", prog);
+ err("Usage: %s [ -h | -f | -o OUTPUT_PATH ] CONFIG_FILE", prog);
err("Options:");
err("-o OUTPUT_PATH\tSet the output path (default is /etc/systemd/network)");
- err("-h\t\tDisplay this help message");
+ err("-f \tOutput firewall rules");
+ err("-h \tDisplay this help message");
exit(EXIT_SUCCESS);
}
@@ -144,12 +145,16 @@ void write_systemd_file(SystemdFilespec const & filespec, std::string output_pat
int main(int argc, char ** argv) {
int opt;
std::filesystem::path output_path = "/etc/systemd/network";
+ bool print_firewall_rules = false;
- while ((opt = getopt(argc, argv, "o:h")) != -1) {
+ while ((opt = getopt(argc, argv, "o:fh")) != -1) {
switch (opt) {
case 'o':
output_path = optarg;
break;
+ case 'f':
+ print_firewall_rules = true;
+ break;
case 'h':
print_help(argv[0]);
break;
@@ -186,6 +191,12 @@ int main(int argc, char ** argv) {
}
+ if(print_firewall_rules) {
+ fprintf(stdout, "%s", cfg.firewall.c_str());
+
+ return 0;
+ }
+
if(!std::filesystem::path(output_path).is_absolute()) {
output_path = std::filesystem::absolute(output_path);
}