#!/bin/bash
#***************************************************************#
# ScriptName: grade02.sh
# Author: xhy
# Create Date: 2025-07-01 21:00
# Modify Author: xhy
# Modify Date: 2025-07-02 20:06
# Version: v1
#***************************************************************#
# 初始化总分
total_score=0

mount -a

# a: 检查Nginx版本 (3分)
nginx_version=$(nginx -v 2>&1 | awk -F '/' '{print $2}' | cut -d '.' -f 2)
if [[ $nginx_version -ge 25 ]]; then
    echo "a: 正确 (3分)"
    total_score=$((total_score + 3))
else
    echo "a: Nginx版本不符合要求!"
fi

# b: 检查NFS持久挂载 (5分)
if grep "172.24.8.31:/datahttp" /etc/fstab | grep -q nfs; then
    echo "b: 正确 (5分)"
    total_score=$((total_score + 5))
else
    echo "b: NFS挂载配置错误!"
fi

# c: 检查防火墙规则 (5分)
if firewall-cmd --list-services | grep -qw http && 
   firewall-cmd --list-services | grep -qw https; then
    echo "c: 正确 (5分)"
    total_score=$((total_score + 5))
else
    echo "c: 防火墙规则配置不全!"
fi

# d: 检查文件服务器配置 (5分)
if curl -s -I http://file.linuxds.com/down.txt | grep -q "200 OK"; then
    echo "d: 正确 (5分)"
    total_score=$((total_score + 5))
else
    echo "d: 文件服务器配置错误!"
fi

# e: 检查HTTPS配置 (8分)
if curl -s -I http://www.linuxds.com | grep -q "301 Moved Permanently" && 
   curl -s -k https://www.linuxds.com | grep -q "welcome to my company"; then
    echo "e: 正确 (8分)"
    total_score=$((total_score + 8))
elif curl -s -k https://www.linuxds.com | grep -q "welcome to my company"; then
    echo "e: HTTPS内容正确但缺少HTTP跳转 (4分)"
    total_score=$((total_score + 4))
else
    echo "e: HTTPS配置未完成!"
fi

# 输出总分
echo -e "\n第二题得分/总分: $total_score/26分\n\n"
