-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathgenacl-nginx.pl
More file actions
executable file
·44 lines (37 loc) · 970 Bytes
/
genacl-nginx.pl
File metadata and controls
executable file
·44 lines (37 loc) · 970 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env perl
use 5.010;
use strict;
use warnings;
use Socket;
use File::Slurp;
sub resolve_addr {
my $hostname = shift;
my ($error, @responses) = Socket::getaddrinfo(
$hostname,
"",
{ socktype => Socket::SOCK_RAW }
);
# FIXME: 엉망진창 오류 처리
map {
my (undef, $ipaddr) = Socket::getnameinfo(
$_->{addr},
Socket::NI_NUMERICHOST,
Socket::NIx_NOSERV
);
$_ = $ipaddr;
} @responses;
}
my @acl_list = read_file('acl.txt');
my $buffer = '';
for my $rule (@acl_list) {
chomp $rule;
my ($type, $addr) = $rule =~ m/^(\w+):(.+)$/ or next;
$buffer .= "# $rule\n";
if ($type eq 'domain') {
my @addresses = resolve_addr($addr);
$buffer .= sprintf("allow %s;\n", $_) for @addresses;
} elsif ($type eq 'ip') {
$buffer .= sprintf("allow %s;\n", $addr);
}
}
write_file('nginx-relay-acl.conf', $buffer);