Explorar el Código

* Versión 0.1

Guzmán Castanedo Villalba hace 5 años
padre
commit
4b0e485d68
Se han modificado 1 ficheros con 55 adiciones y 0 borrados
  1. 55 0
      check-virtualhosts

+ 55 - 0
check-virtualhosts

@@ -0,0 +1,55 @@
+#!/bin/bash
+
+sendEmail() {
+# sendEmail $to $from $pass $subject $host $port $message
+	if [ $# -ne 7 ]; then
+		echo -en "ERROR:\tError interno en sendEmail.\n"
+		exit 1
+	fi
+	to=$1
+	shift
+	from=$1
+	shift
+	pass=$1
+	shift
+	subject=$1
+	shift
+	host=$1
+	shift
+	port=$1
+	shift
+	message=$@
+	echo -en "$message" | mailx -s "$subject" -S smtp-use-starttls -S smtp-auth=login -S smtp=smtp://$host:$port -S from="$from" -S smtp-auth-user="$from" -S smtp-auth-password="$pass" $to >> $logFile 2>&1
+	unset to from pass subject host port message
+}
+
+getVirtualHosts() {
+# getVirtualHost $virtualHostPath
+	cont=1
+	for virtualHost in $(find -L "$virtualHostPath" -type f);do
+		grep ^[[:space:]]*auth_basic "$virtualHost" > /dev/null 2>&1
+		if [ $? -eq 0 ];then
+			# Si tiene la directiva "auth_basic" activada no lo comprobamos
+			continue
+		fi
+		linea=$(grep ^[[:space:]]*server_name "$virtualHost")
+		if [ $? -ne 0 ];then
+			# Si no tiene la directiva "server_name" no lo comprobamos
+			continue
+		fi
+		for hostname in $linea;do
+			if [ $hostname != "server_name" ];then
+				hostnames[$cont]=$hostname
+				cont=$((cont+1))
+			fi
+		done
+	done
+	echo -en "Hostnames: ""${hostnames[@]}""\n"
+	unset linea cont hostname
+}
+
+# Variables iniciales
+logFile="."$(basename $0)".log"
+hostnames=""
+
+getVirtualHosts "/etc/nginx/sites-enabled/"