Skip to content
This repository was archived by the owner on Jul 15, 2025. It is now read-only.

Commit 7719051

Browse files
committed
chore: split functions
1 parent c677b97 commit 7719051

4 files changed

Lines changed: 39 additions & 36 deletions

File tree

src/usr/local/emhttp/plugins/tailscale/include/common.php

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,42 +8,6 @@
88
}
99
}
1010

11-
function logmsg($message, $priority = LOG_INFO)
12-
{
13-
$timestamp = date('Y/m/d H:i:s');
14-
$filename = basename($_SERVER['PHP_SELF']);
15-
file_put_contents("/var/log/tailscale-utils.log", "{$timestamp} {$filename}: {$message}" . PHP_EOL, FILE_APPEND);
16-
}
17-
18-
function run_command($command, $alwaysShow = false, $show = true)
19-
{
20-
$output = array();
21-
$retval = null;
22-
if ($show) {
23-
logmsg($command);
24-
}
25-
exec("{$command} 2>&1", $output, $retval);
26-
27-
if (($retval != 0) || $alwaysShow) {
28-
logmsg("Command returned {$retval}" . PHP_EOL . implode(PHP_EOL, $output));
29-
}
30-
31-
return $output;
32-
}
33-
34-
function ip4_in_network($ip, $network)
35-
{
36-
if (strpos($network, '/') === false) {
37-
return false;
38-
}
39-
40-
list($subnet, $mask) = explode('/', $network, 2);
41-
$ip_bin_string = sprintf("%032b", ip2long($ip));
42-
$net_bin_string = sprintf("%032b", ip2long($subnet));
43-
44-
return (substr_compare($ip_bin_string, $net_bin_string, 0, $mask) === 0);
45-
}
46-
4711
$plugin = "tailscale";
4812
$ifname = 'tailscale1';
4913

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
function ip4_in_network($ip, $network)
4+
{
5+
if (strpos($network, '/') === false) {
6+
return false;
7+
}
8+
9+
list($subnet, $mask) = explode('/', $network, 2);
10+
$ip_bin_string = sprintf("%032b", ip2long($ip));
11+
$net_bin_string = sprintf("%032b", ip2long($subnet));
12+
13+
return (substr_compare($ip_bin_string, $net_bin_string, 0, $mask) === 0);
14+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
function logmsg($message, $priority = LOG_INFO)
4+
{
5+
$timestamp = date('Y/m/d H:i:s');
6+
$filename = basename($_SERVER['PHP_SELF']);
7+
file_put_contents("/var/log/tailscale-utils.log", "{$timestamp} {$filename}: {$message}" . PHP_EOL, FILE_APPEND);
8+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
function run_command($command, $alwaysShow = false, $show = true)
4+
{
5+
$output = array();
6+
$retval = null;
7+
if ($show) {
8+
logmsg($command);
9+
}
10+
exec("{$command} 2>&1", $output, $retval);
11+
12+
if (($retval != 0) || $alwaysShow) {
13+
logmsg("Command returned {$retval}" . PHP_EOL . implode(PHP_EOL, $output));
14+
}
15+
16+
return $output;
17+
}

0 commit comments

Comments
 (0)