-
Notifications
You must be signed in to change notification settings - Fork 5
/
alst2address
executable file
·68 lines (64 loc) · 1.31 KB
/
alst2address
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/bash
#
# This script convert selected Mikrotik addresslists form rsc
# file to FortiGate CLI commands creates firewall address entrys
# and group entry.
#
# In the input rsc script one item must be in one line (without \),
# edit rsc and remove endlines with \ before using this script.
#
# Created Sep 7, 2016, author Piotr Najman
# Version 1.0.1
#
# Syntax: alst2address addresslists_filename addresslist_name
#
#
# Vars
#
DMASK="/32"
AGRP=""
#
# Converting
#
echo "config firewall address"
cat $1 | grep -i "$2" | grep -v disabled=yes | \
{ while read LINE
do
#
# get ip address
M="${LINE#*address=}"
IP="${M%% *}"
AGRP="${AGRP} \"${IP}\""
#
# check if comment exists
cx="${LINE%%comment*}"
[[ $cx = $LINE ]] && CEX=-1 || CEX=${#cx}
#
# check is subnet
sx="${LINE%%/*}"
[[ $sx = $LINE ]] && SEX=-1 || SEX=${#sx}
#
# set ip mask
[[ "$SEX" -gt "-1" ]] && SUBNET="" || SUBNET=${DMASK}
#
# get comment if exists
if [ "$CEX" -gt "-1" ]; then
M="${LINE#*comment=}"
M="${M%% list=*}"
M="${M#*\"}"
COMMENT="${M%\"*}"
else
COMMENT=""
fi
echo " edit \"$IP\"
set subnet $IP$SUBNET
set comment \"$COMMENT\"
next"
done
echo "end"
echo "config firewall addrgrp
edit \"$2\"
set member $AGRP
next
end"
}