update
This commit is contained in:
parent
b5cbb3f56d
commit
aa9fbd8a3a
|
|
@ -136,29 +136,26 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
|
|
||||||
$uses_vlan = ($primary_vlan !== '' || $secondary_vlan !== '');
|
$uses_vlan = ($primary_vlan !== '' || $secondary_vlan !== '');
|
||||||
|
|
||||||
/* ---------- No VLAN ---------- */
|
|
||||||
if (!$uses_vlan) {
|
if (!$uses_vlan) {
|
||||||
$netplan['network']['ethernets'][$iface] =
|
$netplan['network']['ethernets'][$iface] =
|
||||||
build_interface($data['primary'], 'primary');
|
build_interface($data['primary'], 'primary');
|
||||||
}
|
} else {
|
||||||
/* ---------- VLAN mode ---------- */ else {
|
|
||||||
// base interface must exist as {}
|
|
||||||
$netplan['network']['ethernets'][$iface] = new stdClass();
|
$netplan['network']['ethernets'][$iface] = new stdClass();
|
||||||
|
|
||||||
if ($primary_vlan !== '') {
|
if ($primary_vlan !== '') {
|
||||||
$vif = "{$iface}.{$primary_vlan}";
|
$netplan['network']['vlans']["{$iface}.{$primary_vlan}"] =
|
||||||
$netplan['network']['vlans'][$vif] = array_merge([
|
array_merge(
|
||||||
'id' => (int)$primary_vlan,
|
['id' => (int)$primary_vlan, 'link' => $iface],
|
||||||
'link' => $iface
|
build_interface($data['primary'], 'primary')
|
||||||
], build_interface($data['primary'], 'primary'));
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($secondary_vlan !== '') {
|
if ($secondary_vlan !== '') {
|
||||||
$vif = "{$iface}.{$secondary_vlan}";
|
$netplan['network']['vlans']["{$iface}.{$secondary_vlan}"] =
|
||||||
$netplan['network']['vlans'][$vif] = array_merge([
|
array_merge(
|
||||||
'id' => (int)$secondary_vlan,
|
['id' => (int)$secondary_vlan, 'link' => $iface],
|
||||||
'link' => $iface
|
build_interface($data['secondary'], 'secondary')
|
||||||
], build_interface($data['secondary'], 'secondary'));
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,7 @@ function build_interface(array $d, string $key): array
|
||||||
$addresses = [];
|
$addresses = [];
|
||||||
$routes = [];
|
$routes = [];
|
||||||
|
|
||||||
/* ---------- IPv4 ---------- */
|
/* IPv4 */
|
||||||
switch ($d['mode'] ?? 'disabled') {
|
switch ($d['mode'] ?? 'disabled') {
|
||||||
case 'dhcp':
|
case 'dhcp':
|
||||||
$cfg['dhcp4'] = true;
|
$cfg['dhcp4'] = true;
|
||||||
|
|
@ -89,14 +89,10 @@ function build_interface(array $d, string $key): array
|
||||||
|
|
||||||
case 'static':
|
case 'static':
|
||||||
if (!empty($d["network_{$key}_ip"]) && !empty($d["network_{$key}_subnet"])) {
|
if (!empty($d["network_{$key}_ip"]) && !empty($d["network_{$key}_subnet"])) {
|
||||||
$addresses[] =
|
$addresses[] = $d["network_{$key}_ip"] . '/' . $d["network_{$key}_subnet"];
|
||||||
$d["network_{$key}_ip"] . '/' . $d["network_{$key}_subnet"];
|
|
||||||
}
|
}
|
||||||
if (!empty($d["network_{$key}_gateway"])) {
|
if (!empty($d["network_{$key}_gateway"])) {
|
||||||
$routes[] = [
|
$routes[] = ['to' => 'default', 'via' => $d["network_{$key}_gateway"]];
|
||||||
'to' => 'default',
|
|
||||||
'via' => $d["network_{$key}_gateway"]
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
$cfg['dhcp4'] = false;
|
$cfg['dhcp4'] = false;
|
||||||
break;
|
break;
|
||||||
|
|
@ -105,9 +101,9 @@ function build_interface(array $d, string $key): array
|
||||||
$cfg['dhcp4'] = false;
|
$cfg['dhcp4'] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------- IPv6 ---------- */
|
/* IPv6 */
|
||||||
switch ($d['modev6'] ?? 'disabled') {
|
switch ($d['modev6'] ?? 'disabled') {
|
||||||
case 'auto': // SLAAC
|
case 'auto':
|
||||||
$cfg['accept-ra'] = true;
|
$cfg['accept-ra'] = true;
|
||||||
$cfg['dhcp6'] = false;
|
$cfg['dhcp6'] = false;
|
||||||
break;
|
break;
|
||||||
|
|
@ -119,14 +115,10 @@ function build_interface(array $d, string $key): array
|
||||||
|
|
||||||
case 'static':
|
case 'static':
|
||||||
if (!empty($d["network_{$key}_ipv6"]) && !empty($d["network_{$key}_ipv6_prefix"])) {
|
if (!empty($d["network_{$key}_ipv6"]) && !empty($d["network_{$key}_ipv6_prefix"])) {
|
||||||
$addresses[] =
|
$addresses[] = $d["network_{$key}_ipv6"] . '/' . $d["network_{$key}_ipv6_prefix"];
|
||||||
$d["network_{$key}_ipv6"] . '/' . $d["network_{$key}_ipv6_prefix"];
|
|
||||||
}
|
}
|
||||||
if (!empty($d["network_{$key}_ipv6_gateway"])) {
|
if (!empty($d["network_{$key}_ipv6_gateway"])) {
|
||||||
$routes[] = [
|
$routes[] = ['to' => '::/0', 'via' => $d["network_{$key}_ipv6_gateway"]];
|
||||||
'to' => '::/0',
|
|
||||||
'via' => $d["network_{$key}_ipv6_gateway"]
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
$cfg['dhcp6'] = false;
|
$cfg['dhcp6'] = false;
|
||||||
$cfg['accept-ra'] = false;
|
$cfg['accept-ra'] = false;
|
||||||
|
|
@ -153,9 +145,7 @@ function build_interface(array $d, string $key): array
|
||||||
]));
|
]));
|
||||||
|
|
||||||
if ($dns) {
|
if ($dns) {
|
||||||
$cfg['nameservers'] = [
|
$cfg['nameservers'] = ['addresses' => $dns];
|
||||||
'addresses' => $dns
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $cfg;
|
return $cfg;
|
||||||
|
|
@ -164,7 +154,6 @@ function build_interface(array $d, string $key): array
|
||||||
|
|
||||||
function netplan_yaml(array $data, int $indent = 0): string
|
function netplan_yaml(array $data, int $indent = 0): string
|
||||||
{
|
{
|
||||||
|
|
||||||
$yaml = '';
|
$yaml = '';
|
||||||
$pad = str_repeat(' ', $indent);
|
$pad = str_repeat(' ', $indent);
|
||||||
|
|
||||||
|
|
@ -175,11 +164,15 @@ function netplan_yaml(array $data, int $indent = 0): string
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_array($value) && array_keys($value) === range(0, count($value) - 1)) {
|
if (is_array($value) && !array_is_list($value)) {
|
||||||
|
$yaml .= "{$pad}{$key}:\n";
|
||||||
|
$yaml .= netplan_yaml($value, $indent + 1);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_array($value) && array_is_list($value)) {
|
||||||
foreach ($value as $item) {
|
foreach ($value as $item) {
|
||||||
if ($item instanceof stdClass) {
|
if (is_array($item)) {
|
||||||
$yaml .= "{$pad}- {}\n";
|
|
||||||
} elseif (is_array($item)) {
|
|
||||||
$yaml .= "{$pad}-\n";
|
$yaml .= "{$pad}-\n";
|
||||||
$yaml .= netplan_yaml($item, $indent + 1);
|
$yaml .= netplan_yaml($item, $indent + 1);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -189,12 +182,6 @@ function netplan_yaml(array $data, int $indent = 0): string
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_array($value)) {
|
|
||||||
$yaml .= "{$pad}{$key}:\n";
|
|
||||||
$yaml .= netplan_yaml($value, $indent + 1);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_bool($value)) {
|
if (is_bool($value)) {
|
||||||
$value = $value ? 'true' : 'false';
|
$value = $value ? 'true' : 'false';
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue