[ Avaa Bypassed ]




Upload:

Command:

hmhc3928@3.23.102.76: ~ $
#!/bin/bash
# Copyright (c) 1999-2017, Parallels International GmbH
# Copyright (c) 2017-2019 Virtuozzo International GmbH. All rights reserved.
#
# This script configure IP alias(es) inside RedHat like VM.
#
# Parameters: <dev> <MAC_addr> <IPs>
#   <dev>         - name of device. (example: eth2)
#   <MAC_addr>    - MAC address of device
#   <IP/MASKs>    - IP address(es) with MASK 
#                   (example: 192.169.1.30/255.255.255.0)
#                   (several addresses should be divided by space)
#  

prog="$0"
path="${prog%/*}"
funcs="$path/functions"

if [ -f "$funcs" ] ; then
	. $funcs
else
	echo "Program $0"
	echo "'$funcs' was not found"
	exit 1
fi


ETH_DEV=$1
ETH_MAC=$2
IP_MASKS=$3
OPTIONS=$4

IP4_COUNT=0
IP6_COUNT=0

set_options "${OPTIONS}"

uuid=`nm_check_and_create $ETH_DEV $ETH_MAC` ||
	exit $?

function mask_section2digit()
{
	dec=$1
	digit=0

	while [ $dec -ne 0 ]; do
		first=$((dec & 128))
		if [ $first -ne 128 ]; then
			echo -1
			return 1
		fi

		dec=$(((dec << 1) & 255))
		digit=$((digit + 1))
	done

	echo $digit
}

function mask2cidr()
{
	mask=$1
	cidr=0
	count=0
	end=0
	
	IFS="." read -ra sections <<< "$mask"
	for section in "${sections[@]}"; do
		digit=`mask_section2digit $section`

		if [ $end -ne 0 -a "$digit" -ne 0 ]; then
			echo -1
			return 1
		elif [ "$digit" -lt 0 ]; then
			echo -1
			return 1
		elif [ "$digit" -ne 8 ]; then
			end=1
		fi

		cidr=$((cidr + digit))
		count=$((count + 1))
	done

	[ $count -ne 4 ] && echo -1

	echo $cidr
}

function set_ip()
{
	local ip_mask ip mask
	local new_ips
	local plusv4=""
	local plusv6=""
	local errors=0

	for ip_mask in ${IP_MASKS}; do
		[ "${ip_mask}" = "remove" ] && continue
		if is_ipv6 ${ip_mask}; then
			let IP6_COUNT=IP6_COUNT+1
		else
			let IP4_COUNT=IP4_COUNT+1
		fi
		new_ips="${new_ips} ${ip_mask}"
	done

	if [ $USE_DHCPV4 -eq 1 ]; then
		call_nmcli c modify $uuid ipv4.method auto ||
			return $?
	else
		IPV4_MANUAL="ipv4.method manual"
	fi
	if [ $USE_DHCPV6 -eq 1 ]; then
		call_nmcli c modify $uuid ipv6.method auto ||
			return $?
	else
		IPV6_MANUAL="ipv6.method manual"
	fi

	for ip_mask in ${new_ips}; do
		if ! is_ipv6 ${ip_mask}; then
			if echo ${ip_mask} | grep -q '/' ; then
				mask=`mask2cidr ${ip_mask##*/}`
			else
				mask=32
			fi
			ip=${ip_mask%%/*}

			if [ "$mask" -ge 0 ]; then
				call_nmcli c modify $uuid ${plusv4}ipv4.address $ip/$mask $IPV4_MANUAL
				[ $? -ne 0 ] && errors=$((errors + 1))
				plusv4="+"
			fi
		else
			call_nmcli c modify $uuid ${plusv6}ipv6.address $ip_mask $IPV6_MANUAL
			[ $? -ne 0 ] && errors=$((errors + 1))
			plusv6="+"
		fi
	done

	if [ $IP4_COUNT -eq 0 ]; then
		METHOD=""
		if [ $USE_DHCPV4 -eq 0 ]; then
			METHOD="ipv4.method link-local"
		fi
		call_nmcli c modify $uuid ipv4.address "" ipv4.gateway "" $METHOD ||
			return $?
	fi

	if [ $IP6_COUNT -eq 0 ]; then
		METHOD=""
		if [ $USE_DHCPV6 -eq 0 ]; then
			METHOD="ipv6.method ignore"
		fi
		call_nmcli c modify $uuid ipv6.address "" ipv6.gateway "" $METHOD ||
			return $?
	fi

	call_nmcli c up $uuid || return $?

	return $errors
}

set_ip
# end of script

Filemanager

Name Type Size Permission Actions
debian-get_dhcp.sh File 1.32 KB 0755
debian-netplan_restart.sh File 439 B 0755
debian-restart.sh File 1.34 KB 0755
debian-set_dhcp.sh File 1.62 KB 0755
debian-set_gateway.sh File 1.85 KB 0755
debian-set_ip.sh File 4.35 KB 0755
debian-set_route.sh File 2.06 KB 0755
functions File 20.34 KB 0755
netplan-cfg.py File 8.63 KB 0755
netplan-cfg.pyc File 10.45 KB 0644
netplan-cfg.pyo File 10.45 KB 0644
nm-get_dhcp.sh File 834 B 0755
nm-restart.sh File 488 B 0755
nm-set_dhcp.sh File 1.23 KB 0755
nm-set_dns.sh File 1.71 KB 0755
nm-set_gateway.sh File 1.11 KB 0755
nm-set_ip.sh File 3.02 KB 0755
nm-set_route.sh File 1.12 KB 0755
redhat-get_dhcp.sh File 1.58 KB 0755
redhat-restart.sh File 429 B 0755
redhat-set_dhcp.sh File 2 KB 0755
redhat-set_gateway.sh File 1.54 KB 0755
redhat-set_ip.sh File 5.36 KB 0755
redhat-set_route.sh File 1.33 KB 0755
set_dns.sh File 4.03 KB 0755
suse-get_dhcp.sh File 1 KB 0755
suse-restart.sh File 255 B 0755
suse-set_dhcp.sh File 1.7 KB 0755
suse-set_gateway.sh File 970 B 0755
suse-set_ip.sh File 3.01 KB 0755
suse-set_route.sh File 1.12 KB 0755