Skip to content

Instantly share code, notes, and snippets.

@tvlooy
Created October 1, 2024 13:14
Show Gist options
  • Save tvlooy/dc786ba6af15a8dd790559ec796416bc to your computer and use it in GitHub Desktop.
Save tvlooy/dc786ba6af15a8dd790559ec796416bc to your computer and use it in GitHub Desktop.
<?php
$name = 'POWERBI-AZURE';
$label = 'Allow Power BI Azure';
$port = '3306';
$ipAddresses = array_map('rtrim', file('ipaddresses'));
$maxIpLength = max(array_map('strlen', $ipAddresses));
$output = " iptables_rules_v4:\n";
foreach ($ipAddresses as $index => $ip) {
$pattern = "{$name}-" . str_pad($index + 1, 3, "0", STR_PAD_LEFT);
$padding = str_repeat(" ", $maxIpLength - strlen($ip));
$rule = "-A INPUT -s {$ip}{$padding} -p tcp -m multiport --dports {$port} -m comment --comment \"{$label} " . str_pad($index + 1, 3, "0", STR_PAD_LEFT) . "\" -j ACCEPT";
$output .= " - pattern: \"$pattern\"\n";
$output .= " rule: $rule\n";
}
echo $output;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment