aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeny Zinoviev <me@ch1p.io>2023-03-23 07:35:02 +0300
committerEvgeny Zinoviev <me@ch1p.io>2023-03-23 07:35:02 +0300
commitbe3701c55807336b9145994e621680f384090cbf (patch)
tree8c7c679873d519e9030dff4ff980d1ec3974a881
parent5e0d6a17ebfe7f008c53712d679a0b1bc090bcdc (diff)
openwrt utils upd
-rw-r--r--localwebsite/classes/MyOpenWrtUtils.php38
-rw-r--r--misc/openwrt/setup-routing.sh49
2 files changed, 68 insertions, 19 deletions
diff --git a/localwebsite/classes/MyOpenWrtUtils.php b/localwebsite/classes/MyOpenWrtUtils.php
index f83800a..ea467db 100644
--- a/localwebsite/classes/MyOpenWrtUtils.php
+++ b/localwebsite/classes/MyOpenWrtUtils.php
@@ -2,23 +2,23 @@
class MyOpenWrtUtils {
- public static function getRoutingTable($table = null) {
- $arguments = ['route-show'];
- if ($table)
- $arguments[] = $table;
-
- return self::toList(self::run($arguments));
- }
-
- public static function getRoutingRules() {
- return self::toList(self::run(['rule-show']));
- }
-
- public static function ipsetList($set_name) {
- return self::toList(self::run(['ipset-list', $set_name]));
- }
+ // public static function getRoutingTable(?string $table = null): array {
+ // $arguments = ['route-show'];
+ // if ($table)
+ // $arguments[] = $table;
+ //
+ // return self::toList(self::run($arguments));
+ // }
+ //
+ // public static function getRoutingRules(): array {
+ // return self::toList(self::run(['rule-show']));
+ // }
+ //
+ // public static function ipsetList(string $set_name): array {
+ // return self::toList(self::run(['ipset-list', $set_name]));
+ // }
- public static function ipsetListAll() {
+ public static function ipsetListAll(): array {
global $config;
$args = ['ipset-list-all'];
@@ -47,15 +47,15 @@ class MyOpenWrtUtils {
return $sets;
}
- public static function ipsetAdd($set_name, $ip) {
+ public static function ipsetAdd(string $set_name, string $ip) {
return self::run(['ipset-add', $set_name, $ip]);
}
- public static function ipsetDel($set_name, $ip) {
+ public static function ipsetDel(string $set_name, string $ip) {
return self::run(['ipset-del', $set_name, $ip]);
}
- public static function getDHCPLeases() {
+ public static function getDHCPLeases(): array {
$list = self::toList(self::run(['dhcp-leases']));
$list = array_map('self::toDHCPLease', $list);
return $list;
diff --git a/misc/openwrt/setup-routing.sh b/misc/openwrt/setup-routing.sh
new file mode 100644
index 0000000..97af514
--- /dev/null
+++ b/misc/openwrt/setup-routing.sh
@@ -0,0 +1,49 @@
+#!/bin/sh
+
+list_ipset() {
+ skip=1
+ while read -r line; do
+ if [ "$line" = "Members:" ]; then skip=0; continue; fi;
+ [ "$skip" = "1" ] && continue
+ echo "$line"
+ done
+}
+
+case "$1" in
+ dhcp-leases)
+ cat /tmp/dhcp.leases
+ ;;
+
+ ipset-add)
+ ipset add "$2" "$3"
+ ;;
+
+ ipset-del)
+ ipset del "$2" "$3"
+ ;;
+
+# ipset_list)
+# ipset list "$2" | list_ipset
+# ;;
+
+ ipset-list-all)
+ shift
+ while [ -n "$1" ]; do
+ echo ">$1"
+ skip=1
+ ipset list "$1" | list_ipset
+ shift
+ done
+ ;;
+
+# rule-show)
+# ;;
+#
+# route-show)
+# ;;
+
+ *)
+ 2>&1 echo "error: invalid command"
+ exit 1
+ ;;
+esac \ No newline at end of file