You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					84 lines
				
				1.6 KiB
			
		
		
			
		
	
	
					84 lines
				
				1.6 KiB
			| 
								 
											2 years ago
										 
									 | 
							
								#!/bin/bash
							 | 
						||
| 
								 | 
							
								# info: list sshd port
							 | 
						||
| 
								 | 
							
								# options: [FORMAT]
							 | 
						||
| 
								 | 
							
								#
							 | 
						||
| 
								 | 
							
								# example: v-list-sys-sshd-port
							 | 
						||
| 
								 | 
							
								#
							 | 
						||
| 
								 | 
							
								# This function for obtainings the port of sshd listens to
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#----------------------------------------------------------#
							 | 
						||
| 
								 | 
							
								#                Variables & Functions                     #
							 | 
						||
| 
								 | 
							
								#----------------------------------------------------------#
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								# Argument definition
							 | 
						||
| 
								 | 
							
								format=${1-shell}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								# Includes
							 | 
						||
| 
								 | 
							
								# shellcheck source=/usr/local/hestia/func/main.sh
							 | 
						||
| 
								 | 
							
								source $HESTIA/func/main.sh
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								json_list() {
							 | 
						||
| 
								 | 
							
									sh_counter=$(echo "$ports" | wc -l)
							 | 
						||
| 
								 | 
							
									i=1
							 | 
						||
| 
								 | 
							
									echo '['
							 | 
						||
| 
								 | 
							
									for port in $ports; do
							 | 
						||
| 
								 | 
							
										if [ "$i" -lt "$sh_counter" ]; then
							 | 
						||
| 
								 | 
							
											echo -e "\t\"$port\","
							 | 
						||
| 
								 | 
							
										else
							 | 
						||
| 
								 | 
							
											echo -e "\t\"$port\""
							 | 
						||
| 
								 | 
							
										fi
							 | 
						||
| 
								 | 
							
										((++i))
							 | 
						||
| 
								 | 
							
									done
							 | 
						||
| 
								 | 
							
									echo "]"
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								# SHELL list function
							 | 
						||
| 
								 | 
							
								shell_list() {
							 | 
						||
| 
								 | 
							
									echo "PORT"
							 | 
						||
| 
								 | 
							
									echo "-----"
							 | 
						||
| 
								 | 
							
									for port in $ports; do
							 | 
						||
| 
								 | 
							
										echo "$port"
							 | 
						||
| 
								 | 
							
									done
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								# PLAIN list function
							 | 
						||
| 
								 | 
							
								plain_list() {
							 | 
						||
| 
								 | 
							
									for port in $ports; do
							 | 
						||
| 
								 | 
							
										echo "$port"
							 | 
						||
| 
								 | 
							
									done
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								# CSV list function
							 | 
						||
| 
								 | 
							
								csv_list() {
							 | 
						||
| 
								 | 
							
									echo "PORT"
							 | 
						||
| 
								 | 
							
									for port in $ports; do
							 | 
						||
| 
								 | 
							
										echo "$port"
							 | 
						||
| 
								 | 
							
									done
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#----------------------------------------------------------#
							 | 
						||
| 
								 | 
							
								#                       Action                             #
							 | 
						||
| 
								 | 
							
								#----------------------------------------------------------#
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								version=$(lsb_release -s -r)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								if [[ "$version" = 9 || "$version" = 10 ]]; then
							 | 
						||
| 
								 | 
							
									ports=$(sshd -T -C "user=root" | grep '^port' | cut -d ' ' -f2)
							 | 
						||
| 
								 | 
							
								else
							 | 
						||
| 
								 | 
							
									ports=$(sshd -T | grep '^port' | cut -d ' ' -f2)
							 | 
						||
| 
								 | 
							
								fi
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								# Listing data
							 | 
						||
| 
								 | 
							
								case $format in
							 | 
						||
| 
								 | 
							
									json) json_list ;;
							 | 
						||
| 
								 | 
							
									plain) plain_list ;;
							 | 
						||
| 
								 | 
							
									csv) csv_list ;;
							 | 
						||
| 
								 | 
							
									shell) shell_list ;;
							 | 
						||
| 
								 | 
							
								esac
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#----------------------------------------------------------#
							 | 
						||
| 
								 | 
							
								#                       Hestia                             #
							 | 
						||
| 
								 | 
							
								#----------------------------------------------------------#
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								exit
							 |