Introducing new IP for students and a new tool to display them

This commit is contained in:
nemunaire 2023-02-21 13:22:08 +01:00
parent a7861b661b
commit 9d59aabe4b
3 changed files with 49 additions and 2 deletions

View File

@ -106,6 +106,9 @@ files:
- path: bin/progression
source: pkg/challenge/progression.sh
mode: "0755"
- path: bin/my_ips
source: pkg/challenge/my_ips.sh
mode: "0755"
- path: bin/wg-adlin
contents: |
#!/bin/sh

44
pkg/challenge/my_ips.sh Normal file
View File

@ -0,0 +1,44 @@
#!/bin/sh
# /proc/cmdline parser (from Gentoo Wiki)
cmdline() {
local value
value=" $(cat /proc/cmdline) "
value="${value##* $1=}"
value="${value%% *}"
[ "$value" != "" ] && echo "$value"
}
IPS=$(curl -s -f "http://172.23.0.1/api/students/$(cmdline adlin.login)/ips")
if [ $? -ne 0 ]
then
echo -e "Utilisez l'IP \e[01m$(cmdline adlin.ip)\e[0m pour vous connecter au réseau."
else
echo "Voici la liste des IP qui vous ont été attribuées :"
for KEY in vlan0 wg0 vlan7
do
[ $(echo "${IPS}" | jq -r ".${KEY}") != "null" ] && {
echo -en " - \e[01m"
case $KEY in
vlan0) echo -n "Services Router";;
wg0) echo -n "VPN";;
vlan7) echo -n "Internet Router";;
*) echo -n "Autre IP";;
esac
echo -en " :\e[0m "
echo "${IPS}" | jq -r ".${KEY}"
}
done
[ $# -gt 0 ] && [ "$1" == "-a" ] && {
INFOS=$(curl -s -f "http://172.23.0.1/api/students/$(cmdline adlin.login)/")
echo
echo -e "La MAC bénéficiant d'une protection est \e[01m$(echo "${IPS}" | jq -r .mac)\e[0m"
}
fi
echo
echo -e "\e[41;33;01m /!\\ \e[0m Attention à bien préciser la plage indiquée dans la topologie !"
echo

View File

@ -70,8 +70,8 @@ func GetStudentTunnelIPs(student *adlin.Student) (ips []string) {
func getStudentIPs(student *adlin.Student) (r map[string]string) {
r = make(map[string]string)
r["vlan0"] = IPSuffix(student, net.IPNet{IP: net.ParseIP("172.23.0.0"), Mask: net.CIDRMask(17, 32)}).String()
r["wg0"] = IPSuffix(student, net.IPNet{IP: net.ParseIP("172.17.0.0"), Mask: net.CIDRMask(16, 32)}).String()
r["vlan0"] = IPSuffix(student, net.IPNet{IP: net.ParseIP("172.23.12.0"), Mask: net.CIDRMask(17, 32)}).String()
r["wg0"] = IPSuffix(student, net.IPNet{IP: net.ParseIP("172.17.12.0"), Mask: net.CIDRMask(16, 32)}).String()
r["vlan7"] = IPSuffix(student, net.IPNet{IP: net.ParseIP("172.23.142.0"), Mask: net.CIDRMask(23, 32)}).String()
for d, ip := range GetStudentTunnelIPs(student) {