开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
捐赠
捐赠前请先登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
1 Star 0 Fork 99

Gitee Tester/httpsok

forked from httpsok/httpsok
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
main
分支 (2)
标签 (16)
main
master
v1.18.2
v1.18.0
v1.17.0
v1.16.0
v1.15.0
v1.14.0
v1.13.0
v1.12.0
v1.11.0
v1.10.0
v1.9.2
v1.9.0
v1.8.2
v1.8.1
v1.8.0
v1.7.1
main
分支 (2)
标签 (16)
main
master
v1.18.2
v1.18.0
v1.17.0
v1.16.0
v1.15.0
v1.14.0
v1.13.0
v1.12.0
v1.11.0
v1.10.0
v1.9.2
v1.9.0
v1.8.2
v1.8.1
v1.8.0
v1.7.1
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
main
分支 (2)
标签 (16)
main
master
v1.18.2
v1.18.0
v1.17.0
v1.16.0
v1.15.0
v1.14.0
v1.13.0
v1.12.0
v1.11.0
v1.10.0
v1.9.2
v1.9.0
v1.8.2
v1.8.1
v1.8.0
v1.7.1
httpsok
/
httpsok.sh
httpsok
/
httpsok.sh
httpsok.sh 25.14 KB
一键复制 编辑 原始数据 按行查看 历史
thomas 提交于 2025年09月16日 14:27 +08:00 . v1.18.2 完善PRETTY_NAME, nginx -T
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003
#!/usr/bin/env bash
# WIKI: https://httpsok.com/doc/
# This script only supports bash, do not support posix sh.
# If you have the problem like Syntax error: "(" unexpected (expecting "fi"),
# Try to run "bash -version" to check the version.
# Try to visit WIKI to find a solution.
################################################
NGINX_BIN=nginx
# NGINX_CONFIG=/etc/nginx/nginx.conf
# NGINX_CONFIG_HOME=/etc/nginx
##################################################
VER=1.18.2
PROJECT_NAME="httpsok"
PROJECT_ENTRY="httpsok.sh"
PROJECT_HOME="$HOME/.httpsok"
PROJECT_BACKUPS="$HOME/.httpsok/backups"
PROJECT_ENTRY_BIN="$PROJECT_HOME/$PROJECT_ENTRY"
PROJECT_TOKEN_FILE="$PROJECT_HOME/token"
HTTPSOK_UUID_FILE="$PROJECT_HOME/uuid"
PROJECT_LOG_FILE="$PROJECT_HOME/$PROJECT_NAME.log"
HTTPSOK_TOKEN=""
HTTPSOK_UUID=""
HTTPSOK_HOME_URL="https://httpsok.com/"
BASE_API_URL="https://api.httpsok.com/v1/nginx"
SCRIPT_URL="https://get.httpsok.com/"
latest_code=""
preparse=""
OS=""
NGINX_VERSION=""
MODE="normal"
_upper_case() {
tr '[a-z]' '[A-Z]'
}
_lower_case() {
tr '[A-Z]' '[a-z]'
}
_startswith() {
_str="1ドル"
_sub="2ドル"
echo "$_str" | grep -- "^$_sub" >/dev/null 2>&1
}
_endswith() {
_str="1ドル"
_sub="2ドル"
echo "$_str" | grep -- "$_sub\$" >/dev/null 2>&1
}
_contains() {
_str="1ドル"
_sub="2ドル"
echo "$_str" | grep -- "$_sub" >/dev/null 2>&1
}
_time() {
date -u "+%s"
}
_math() {
_m_opts="$@"
printf "%s" "$(($_m_opts))"
}
_err() {
echo -e "0円33[31m$(date +"%F %T")$@0円33[0m" 1>&2
}
_info() {
echo -e "$(date +"%F %T")$@" 1>&2
}
_suc() {
echo -e "0円33[32m$(date +"%F %T")$@0円33[0m" 1>&2
}
_random_md5() {
head -c 32 /dev/urandom | md5sum | awk '{print 1ドル}'
}
TRACE_ID=$(_random_md5)
_exists() {
cmd="1ドル"
if [ -z "$cmd" ]; then
_usage "Usage: _exists cmd"
return 1
fi
if eval type type >/dev/null 2>&1; then
eval type "$cmd" >/dev/null 2>&1
elif command >/dev/null 2>&1; then
command -v "$cmd" >/dev/null 2>&1
else
which "$cmd" >/dev/null 2>&1
fi
ret="$?"
return $ret
}
showWelcome() {
echo
echo -e "0円33[1;36mHttpsok make SSL easy. $HTTPSOK_HOME_URL0円33[0m"
echo -e "0円33[1;36mversion: $VER0円33[0m"
echo -e "0円33[1;36mTraceID: $TRACE_ID0円33[0m"
echo
}
_mkdirs() {
_dir="1ドル"
if [ ! "$_dir" = "" ]; then
if [ ! -d "$_dir" ]; then
mkdir -p "$_dir" && _suc "Create directory $_dir success."
fi
fi
}
_initpath() {
_mkdirs "$PROJECT_HOME"
_mkdirs "$PROJECT_BACKUPS"
}
_no_nginx_here(){
echo
_err "Can’t detected nginx\n"
_err "Please confirm that nginx has been successfully installed on your system"
_detected_is_root_run
echo
echo
exit
}
_detected_is_root_run(){
YELLOW='033円[1;33m'
NC='033円[0m' # No Color
if [ "$(id -u)" -ne 0 ]; then
echo -e "${YELLOW}Detected non-root user running, it's recommended to run as root user.${NC}\n"
fi
}
_init_params() {
if [ "$OS" != "" ]; then
return 0
fi
if [ -f /etc/os-release ]; then
OS=$(grep 'PRETTY_NAME' /etc/os-release | awk -F '=' '{print 2ドル}' | tr -d '"' | head -n 1)
elif [ -f /etc/redhat-release ]; then
OS=$(cat /etc/redhat-release)
elif [ -f /etc/alpine-release ]; then
OS="alpine"
else
_err "Unsupported operating system"
exit 1
fi
# NGINX_BIN=nginx
$NGINX_BIN -V > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "no nginx in PATH, find the nginx"
pid=$(ps -e | grep nginx | grep -v 'grep' | head -n 1 | awk '{print 1ドル}')
if [ -n "$pid" ]; then
NGINX_BIN=$(readlink -f /proc/"$pid"/exe)
# echo "NGINX_BIN=$NGINX_BIN"
# again to verify
$NGINX_BIN -V > /dev/null 2>&1
if [ $? -ne 0 ]; then
_no_nginx_here
else
echo "Nginx executable path: $NGINX_BIN"
fi
else
_no_nginx_here
fi
fi
NGINX_VERSION=$($NGINX_BIN -v 2>&1 | awk -F ': ' '{print 2ドル}' | head -n 1 | head -c 20)
# user can setting
if [ -z "$NGINX_CONFIG" ]; then
# Use a running nginx first
NGINX_CONFIG=$(ps -eo pid,cmd | grep nginx | grep master | grep '\-c' | awk -F '-c' '{print 2ドル}' | sed 's/ //g')
fi
# fix the NGINX_CONFIG equals nginx.conf bug
if [ -z "$NGINX_CONFIG" ] || [ "$NGINX_CONFIG" = "nginx.conf" ]; then
NGINX_CONFIG=$($NGINX_BIN -t 2>&1 | grep 'configuration' | head -n 1 | awk -F 'file' '{print 2ドル}' | awk '{print 1ドル}' )
fi
if [ -z "$NGINX_CONFIG_HOME" ]; then
NGINX_CONFIG_HOME=$(dirname "$NGINX_CONFIG")
fi
_init_httpsok_params
_info "os-name: $OS"
_info "version: $NGINX_VERSION"
_info "nginx-config: $NGINX_CONFIG"
_info "nginx-config-home: $NGINX_CONFIG_HOME"
_info "nginx-bin: $NGINX_BIN"
_info "httpsok-uuid: $HTTPSOK_UUID"
if [ "$NGINX_CONFIG_HOME" = "." ]; then
echo ""
echo ""
echo -e "0円33[31m获取nginx配置文件失败, 请您根据实际情况,手动设置0円33[0m"
echo ""
echo -e "0円33[1;36m修改文件 $PROJECT_ENTRY_BIN0円33[0m"
echo ""
echo "################################################"
echo "# 配置示例 "
echo "NGINX_CONFIG=/etc/nginx/nginx.conf"
echo "NGINX_CONFIG_HOME=/etc/nginx"
echo "##################################################"
echo ""
exit 0
fi
showWelcome
}
_init_httpsok_params() {
if [ "$HTTPSOK_UUID" != "" ]; then
return 0
fi
if [ -f "$HTTPSOK_UUID_FILE" ]; then
HTTPSOK_UUID=$(cat "$HTTPSOK_UUID_FILE")
fi
if [ "$HTTPSOK_UUID" != "" ]; then
# _info "load HTTPSOK_UUID from $HTTPSOK_UUID_FILE: $HTTPSOK_UUID"
return 0
fi
_initpath
if [ -f "/sys/class/dmi/id/product_uuid" ]; then
HTTPSOK_UUID=$(cat /sys/class/dmi/id/product_uuid)
if [ "$HTTPSOK_UUID" != "" ]; then
echo "$HTTPSOK_UUID" > "$HTTPSOK_UUID_FILE"
# _info "save HTTPSOK_UUID from product_uuid to $HTTPSOK_UUID_FILE: $HTTPSOK_UUID"
return 0
fi
fi
HTTPSOK_UUID=$(_random_md5)
echo "$HTTPSOK_UUID" > "$HTTPSOK_UUID_FILE"
# _info "save HTTPSOK_UUID to $HTTPSOK_UUID_FILE: $HTTPSOK_UUID"
}
_inithttp() {
_init_httpsok_params
_H0="Content-Type: text/plain"
_H1="httpsok-token: $HTTPSOK_TOKEN"
_H2="httpsok-version: $VER"
_H3="os-name: $OS"
_H4="nginx-version: $NGINX_VERSION"
_H5="nginx-config-home: $NGINX_CONFIG_HOME"
_H6="nginx-config: $NGINX_CONFIG"
_H7="trace-id: $TRACE_ID"
_H8="mode: $MODE"
_H9="httpsok-uuid: $HTTPSOK_UUID"
}
_post() {
_inithttp
url="${BASE_API_URL}1ドル"
body="2ドル"
curl -s -X POST -H "$_H0" -H "$_H1" -H "$_H2" -H "$_H3" -H "$_H4" -H "$_H5" -H "$_H6" -H "$_H7" -H "$_H8" -H "$_H9" --data-binary "$body" "$url"
}
_post2() {
_inithttp
url="${BASE_API_URL}1ドル"
fiename="2ドル"
curl -s -X POST -H "$_H0" -H "$_H1" -H "$_H2" -H "$_H3" -H "$_H4" -H "$_H5" -H "$_H6" -H "$_H7" -H "$_H8" -H "$_H9" --data-binary "@$fiename" "$url"
}
_get() {
_inithttp
url="${BASE_API_URL}1ドル"
curl -s -H "$_H0" -H "$_H1" -H "$_H2" -H "$_H3" -H "$_H4" -H "$_H5" -H "$_H6" -H "$_H7" -H "$_H8" -H "$_H9" "$url"
}
_upload() {
_inithttp
url="${BASE_API_URL}/upload?code=1ドル"
_F1="cert=@\"2ドル\""
_F2="certKey=@\"3ドル\""
curl -s -X POST -H "Content-Type: multipart/form-data" -H "$_H1" -H "$_H2" -H "$_H3" -H "$_H4" -H "$_H5" -H "$_H6" -H "$_H7" -H "$_H8" -H "$_H9" -F $_F1 -F $_F2 "$url" 2>&1
}
_put() {
_inithttp
url="${BASE_API_URL}1ドル"
body="2ドル"
curl -s -X PUT -H "$_H0" -H "$_H1" -H "$_H2" -H "$_H3" -H "$_H4" -H "$_H5" -H "$_H6" -H "$_H7" -H "$_H8" -H "$_H9" --data-binary "$body" "$url"
}
_remote_log() {
type="1ドル"
code="2ドル"
msg="3ドル"
_put "/log/$type?code=$code" "$msg"
}
_done() {
_t=$(_time)
_get "/done?t=$_t"
}
_remote_uninstall(){
_load_token
_t=$(_time)
_get "/uninstall?t=$_t"
}
_create_file() {
local _code="1ドル"
local file_path="2ドル"
if [ ! -e "$file_path" ]; then
dir_path=$(dirname "$file_path")
mkdir -p "$dir_path"
touch "$file_path"
_suc "$_code" "File created: $file_path"
else
# backup the files
if [ -f "$file_path" ]; then
_filename=${file_path##*/}
_date=$(date +"%Y%m%d%H%M%S")
backup_file_path="$PROJECT_BACKUPS/$_filename.$_date"
if [ -f "$backup_file_path" ]; then
_err "$_code" "Backup file already exists: $backup_file_path"
else
mv "$file_path" "$backup_file_path"
_suc "$_code" "Backup the file $file_path to $backup_file_path"
fi
fi
fi
}
_check() {
depth=1ドル
code=2ドル
cert_file=3ドル
cert_key_file=4ドル
url="/check?code=$code"
if [ $depth -le 0 ]; then
_err "The maximum number of attempts exceeded"
else
resp=$(_get "$url")
status=$(echo "$resp" | head -n 1)
case $status in
"1")
# _info "$code $cert_file The new certificate has been updated"
md5_line=$(echo "$resp" | awk 'NR==2')
cert_file_md5=$(echo $md5_line | awk -F ',' '{print 1ドル}')
cert_key_file_md5=$(echo $md5_line | awk -F ',' '{print 2ドル}')
tmp_cert_file="/tmp/$code.cer"
tmp_cert_key_file="/tmp/$code.key"
_get "/cert/$code.cer" > "$tmp_cert_file" && _get "/cert/$code.key" > "$tmp_cert_key_file"
# md5 check
tmp_cert_md5=$(md5sum "$tmp_cert_file" | awk '{print 1ドル}')
tmp_cert_key_md5=$(md5sum "$tmp_cert_key_file" | awk '{print 1ドル}')
if [ "$cert_file_md5" = "$tmp_cert_md5" ] && [ "$cert_key_file_md5" = "$tmp_cert_key_md5" ]; then
# if local_cert_file not here. need to create the file
_create_file "$code" "$cert_file" && _create_file "$code" "$cert_key_file"
mv "$tmp_cert_file" "$cert_file" && mv "$tmp_cert_key_file" "$cert_key_file"
_suc "$code$cert_file New cert updated(证书更新成功)"
_remote_log "cert-updated-success" "$code" "New cert updated(证书更新成功)"
echo "latest_code $code"
else
_err "$code$cert_file New cert update failed (md5 not match)"
_remote_log "cert-updated-failed" "$code" "New cert update failed (md5 not match): cert_file_md5=$cert_file_md5,tmp_cert_md5=$tmp_cert_md5,cert_key_file_md5=$cert_key_file_md5,tmp_cert_key_md5=$tmp_cert_key_md5"
fi
;;
"2")
_info "$code$cert_file Processing, please just wait(正在处理中,请稍等)..."
sleep 10
_check $((depth - 1)) "$code" "$cert_file" "$cert_key_file"
;;
"3")
_info "$code$cert_file Cert valid(证书有效)"
;;
"12")
_err "$code$cert_file DNS CNAME invalid(DNS检测不通过)"
;;
"13")
_err "$code$cert_file code invalid(非法请求)"
;;
*)
_err "$code$cert_file$resp"
;;
esac
fi
}
_save_token() {
_token="1ドル"
_check_token "$_token"
_initpath
if [ ! "$_token" = "" ]; then
echo "$_token" > "$PROJECT_TOKEN_FILE"
_suc "save token $_token to $PROJECT_TOKEN_FILE"
fi
}
_load_token() {
if [ "$HTTPSOK_TOKEN" = "" ]; then
HTTPSOK_TOKEN=$(cat "$PROJECT_TOKEN_FILE")
fi
}
_show_token() {
_load_token
echo -e "Your token is: 0円33[1;36m$HTTPSOK_TOKEN0円33[0m"
}
_check_token() {
_token="1ドル"
if [ ! "$_token" = "" ]; then
HTTPSOK_TOKEN="$_token"
fi
if [ "$HTTPSOK_TOKEN" = "" ]; then
_err "httpsok's token can not empty"
exit 4
fi
_init_params
status=$(_get "/status")
# _info "status >> $status"
if [ "$status" != "ok" ]; then
# echo -e "033円[1;36mTraceID: $TRACE_ID033円[0m"
_err "Invalid token: 0円33[1;36m$HTTPSOK_TOKEN0円33[0m"
_info "Please copy your token from '$HTTPSOK_HOME_URL'"
echo
_err "$status"
exit 4
fi
return 0
}
# Limit the maximum nesting level
_include_max_calls=20
_include_global_count=0
__process_include() {
# echo "-_include_global_count: $_include_global_count --------------------------------------------------"
# echo Recursive call, degree incremented by one
((_include_global_count++))
if [ $_include_global_count -gt $_include_max_calls ]; then
echo "#######################################################"
echo "##### warning: Maximum recursion limit reached."
echo "#######################################################"
cat /dev/stdin
return 0
fi
tmp=$(cat /dev/stdin | awk -v NGINX_CONFIG=">$NGINX_CONFIG:" -v NGINX_CONFIG_HOME="$NGINX_CONFIG_HOME" '{
original = 0ドル
# Remove leading and trailing whitespace characters from each line
gsub(/^[[:space:]]+|[[:space:]]+$/, "")
sub(/^[\t ]*|[\t ]*$/,"")
# Ignore the lines at the beginning of the file
if (0ドル ~ /^>/) {
print original
next
}
# Determines if it starts with #, and if it does, ignores it
if (0ドル ~ /^#/) {
# Replace the include in the comment
# gsub("include", "import")
print original
next
}
# Determine whether include is included
if (0ドル ~ /^include /) {
# Ignore mime.types
if(0ドル ~ /mime\.types;/){
print "#import " original
next
}
# print "#import " 2ドル
print "#import " original
# system("cat " 2ドル)
# print ">> "
# ls /etc/nginx/conf.d/*.conf | xargs -I {} sed "s|^|{}:|" {}
# system("ls " 2ドル " | xargs -I {} sed \"s|^|{}:|\" {}")
# /etc/nginx/conf.d/*.conf;
# Replace ;
gsub(/;/, "")
# /etc/nginx/conf.d/*.conf
# Resolved to an include file
# print 2ドル
# Deal with relative path issues
if (substr(2,ドル 1, 1) != "/") {
2ドル = NGINX_CONFIG_HOME "/" 2ドル
}
# print "# " original
# The second way
# find . -maxdepth 1 -print0 | xargs -0 command
# system("find " 2ドル " -maxdepth 1 -print0 | xargs -0 -I {} sed \"s|^|>{}:|\" {}")
# just backup
# system("ls -1 " 2ドル " | xargs -I {} sed \"s|^|>{}:|\" {}")
# If the last line of the file is not newline, the file will not be parsed correctly
# system("ls -1 " 2ドル " 2>/dev/null | xargs -I {} cat {} ")
# Using sh has security implications deprecated
# system("ls -1 " 2ドル " 2>/dev/null | xargs -I {} sh -c \"cat {} && echo\" ")
#
# system("ls -1 " 2ドル " 2>/dev/null | xargs -I {} sed -n \"$p\" {} ")
# xargs -I {} awk -v FP="{}" "BEGIN{ print \"# include \" FP } {print} END{print ""} " {}
#system("ls -1 " 2ドル " 2>/dev/null | xargs -I {} awk \" {print} END {print \"\" } \" {} ")
#
# cmd = "ls -1 " 2ドル " 2>/dev/null | xargs -I {} awk \" {print} END {print \"\\\"\"\n\"\\\"\" } \" {} "
# cmd = "ls -1 " 2ドル " 2>/dev/null | xargs -I {} awk \"BEGIN {print \"\"{}\"\" } {print} END {print \n } \" {} "
# OK Add a newline character to the end of the file
# cmd = "ls -1 " 2ドル " 2>/dev/null | xargs -I {} awk \" {print} END {print \"\\n\" } \" {} "
# OK Add a newline character to the end of the file
# cmd = "ls -1 " 2ドル " 2>/dev/null | xargs -I {} awk '\'' {print} '\'' {} "
# OK add config file path
#cmd = "ls -1 " 2ドル " 2>/dev/null | xargs -I GG awk '\'' BEGIN {print \"#included GG;\" } {print} '\'' GG "
#cmd = "ls -1 " 2ドル " 2>/dev/null | xargs -I {} awk '\'' BEGIN {print \"#included {};\" } {print} '\'' {} "
cmd = "ls -1 " 2ドル " 2>/dev/null | xargs -I {} awk '\'' BEGIN {print \"#included-begin {};\" } {print} END{ print \"#included-end {};\" } '\'' {} "
# print cmd
system(cmd)
print ""
next
}
print original
}'
)
if echo "$tmp" | grep -v '#' | grep -q "include"; then
# Perform a recursive call
echo "$tmp" | __process_include
else
# End the recursive call
echo "$tmp"
fi
}
_preparse() {
_init_params
config_text=$($NGINX_BIN -T)
if [ "$?" != "0" ]; then
config_text=$(cat $NGINX_CONFIG | __process_include )
fi
tmp_name="/tmp/2nLN3ZspTMGifYtO.tmp"
echo "$config_text" > $tmp_name
preparse=$(_post2 "/preparse" "$tmp_name")
rm -rf "$tmp_name" > /dev/null 2>&1
if [ "$preparse" = "" ]; then
return 4
fi
return 0
}
_upload_certs() {
while read row
do
if [ "$row" = "" ]; then
continue
fi
code=$(echo $row | awk -F ',' '{print 1ドル}')
cert_file=$(echo $row | awk -F ',' '{print 2ドル}')
cert_key_file=$(echo $row | awk -F ',' '{print 3ドル}')
up_status=$(_upload "$code" "$cert_file" "$cert_key_file")
if [ "$up_status" != "ok" ]; then
continue
fi
done <<EOF
$preparse
EOF
}
_check_certs() {
while read row
do
if [ "$row" = "" ]; then
continue
fi
code=$(echo $row | awk -F ',' '{print 1ドル}')
cert_file=$(echo $row | awk -F ',' '{print 2ドル}')
cert_key_file=$(echo $row | awk -F ',' '{print 3ドル}')
check_reposne=$(_check 60 "$code" "$cert_file" "$cert_key_file")
_code=$(echo "$check_reposne" | grep 'latest_code' | awk '{print 2ドル}')
if [ -n "$_code" ]; then
latest_code="$_code"
fi
done <<EOF
$preparse
EOF
}
_check_dns() {
codes=$(echo "$preparse" | awk -F ',' '{print 1ドル}' | tr '\n' ',' )
url="/checkDns"
resp=$(_get "$url")
status=$(echo "$resp" | head -n 1)
case $status in
"3")
_suc "DNS check pass(DNS检查通过)"
;;
"13")
_err "code invalid"
;;
*)
_err "$resp"
;;
esac
}
_reload_nginx() {
if [ "$latest_code" = "" ]; then
echo
_info "Nginx reload needless(无需重载)."
return 0
fi
(
# fixbug: signal process started
cd $NGINX_CONFIG_HOME
msg=$($NGINX_BIN -t 2>&1)
if [ $? != 0 ]; then
_remote_log "nginx-test-failed" "$latest_code" "$msg"
echo
_err "Nginx test failed(测试失败). \n\n$msg"
else
msg=$($NGINX_BIN -s reload 2>&1)
if [ $? -eq 0 ]; then
_remote_log "nginx-reload-success" "$latest_code" "Nginx reload success(重载成功)."
echo
_suc "Nginx reload success(重载成功)."
else
# Check if nginx is running
show_msg=$msg
pid=$(ps -e | grep nginx | grep -v 'grep' | head -n 1 | awk '{print 1ドル}')
if [ -z "$pid" ]; then
msg="Nginx is not started(服务未启动). \n\n$msg"
show_msg="0円33[33mNginx is not started. You can run \"service nginx start\" to start the Nginx(请重启服务). 0円33[31m\n\n$show_msg"
fi
_remote_log "nginx-reload-failed" "$latest_code" "$msg"
echo
_err "Nginx reload failed(重载失败). \n\n$show_msg"
fi
fi
)
}
version() {
echo "$PROJECT_ENTRY v$VER"
}
# Detect profile file if not specified as environment variable
_detect_profile() {
if [ -n "$PROFILE" -a -f "$PROFILE" ]; then
echo "$PROFILE"
return
fi
DETECTED_PROFILE=''
SHELLTYPE="$(basename "/$SHELL")"
if [ "$SHELLTYPE" = "bash" ]; then
if [ -f "$HOME/.bashrc" ]; then
DETECTED_PROFILE="$HOME/.bashrc"
elif [ -f "$HOME/.bash_profile" ]; then
DETECTED_PROFILE="$HOME/.bash_profile"
fi
elif [ "$SHELLTYPE" = "zsh" ]; then
DETECTED_PROFILE="$HOME/.zshrc"
fi
if [ -z "$DETECTED_PROFILE" ]; then
if [ -f "$HOME/.profile" ]; then
DETECTED_PROFILE="$HOME/.profile"
elif [ -f "$HOME/.bashrc" ]; then
DETECTED_PROFILE="$HOME/.bashrc"
elif [ -f "$HOME/.bash_profile" ]; then
DETECTED_PROFILE="$HOME/.bash_profile"
elif [ -f "$HOME/.zshrc" ]; then
DETECTED_PROFILE="$HOME/.zshrc"
fi
fi
if [ -z "$DETECTED_PROFILE" ]; then
if [ -f "/etc/profile" ]; then
DETECTED_PROFILE="/etc/profile"
fi
fi
echo "$DETECTED_PROFILE"
}
_tail_c() {
tail -c "1ドル" 2>/dev/null || tail -"1ドル"c
}
_setopt() {
__conf="1ドル"
__opt="2ドル"
__sep="3ドル"
__val="4ドル"
__end="5ドル"
if [ -z "$__opt" ]; then
_usage usage: _setopt '"file" "opt" "=" "value" [";"]'
return
fi
if [ ! -f "$__conf" ]; then
touch "$__conf"
fi
if [ -n "$(_tail_c 1 <"$__conf")" ]; then
echo >>"$__conf"
fi
if grep -n "^$__opt$__sep" "$__conf" >/dev/null; then
if _contains "$__val" "&"; then
__val="$(echo "$__val" | sed 's/&/\\&/g')"
fi
if _contains "$__val" "|"; then
__val="$(echo "$__val" | sed 's/|/\\|/g')"
fi
text="$(cat "$__conf")"
printf -- "%s\n" "$text" | sed "s|^$__opt$__sep.*$|$__opt$__sep$__val$__end|" >"$__conf"
elif grep -n "^#$__opt$__sep" "$__conf" >/dev/null; then
if _contains "$__val" "&"; then
__val="$(echo "$__val" | sed 's/&/\\&/g')"
fi
if _contains "$__val" "|"; then
__val="$(echo "$__val" | sed 's/|/\\|/g')"
fi
text="$(cat "$__conf")"
printf -- "%s\n" "$text" | sed "s|^#$__opt$__sep.*$|$__opt$__sep$__val$__end|" >"$__conf"
else
echo "$__opt$__sep$__val$__end" >>"$__conf"
fi
}
_install() {
_info "Installing $PROJECT_NAME."
_initpath
curl -s "$SCRIPT_URL" > "$PROJECT_ENTRY_BIN" && chmod +x "$PROJECT_ENTRY_BIN"
if [ -x "$PROJECT_ENTRY_BIN" ] ; then
_suc "Install $PROJECT_NAME complete."
else
_err "Install $PROJECT_NAME failed."
exit 4
fi
installcronjob
installAlais
}
installcronjob() {
_CRONTAB="crontab"
_t=$(_time)
random_minute=$(_math $_t % 60)
random_hour=$(_math $_t % 9 + 9 ) # 9 ~ 17
if ! _exists "$_CRONTAB" ; then
_err "$_CRONTAB not exits\ncrontab定时任务不存在,请安装。参考文档:https://httpsok.com/doc/faq/crontab.html \n"
return 4
fi
if ! $_CRONTAB -l | grep "$PROJECT_ENTRY" > /dev/null; then
_info "Installing cron job."
if _exists uname && uname -a | grep SunOS >/dev/null; then
_CRONTAB_STDIN="$_CRONTAB --"
else
_CRONTAB_STDIN="$_CRONTAB -"
fi
$_CRONTAB -l | {
cat
echo "$random_minute$random_hour * * * '$PROJECT_ENTRY_BIN' -m -r >> '$PROJECT_LOG_FILE' 2>&1"
} | $_CRONTAB_STDIN
_suc "Install cron job complete."
fi
if [ "$?" != "0" ]; then
_err "Install cron job failed. You can add cronjob by yourself."
_err "Or you can add cronjob by yourself:"
_err "$random_minute$random_hour * * * '$PROJECT_ENTRY_BIN' -m -r >> '$PROJECT_LOG_FILE' 2>&1"
return 1
fi
}
installAlais() {
_envfile="$PROJECT_ENTRY_BIN.env"
echo "alias $PROJECT_ENTRY=\"$PROJECT_ENTRY_BIN\"" > "$_envfile"
_info "Installing alias"
_profile="$(_detect_profile)"
if [ "$_profile" ]; then
_info "Found profile: $_profile"
_info "Installing alias to '$_profile'"
_setopt "$_profile" ". \"$_envfile\""
_suc "OK, Close and reopen your terminal to start using $PROJECT_NAME"
else
_err "No profile is found, you will need to go into $PROJECT_HOME to use $PROJECT_NAME"
fi
}
_uninstall() {
_info "Uninstalling httpsok."
_remote_uninstall
uninstallcronjob
_uninstallalias
if [ -d "$PROJECT_HOME" ]; then
_info "Removing directory $PROJECT_HOME"
rm -rf "$PROJECT_HOME"
fi
_suc "Uninstall httpsok complete."
showWelcome
echo "If your need install httpsok agian. Please see $HTTPSOK_HOME_URL .
curl -s $SCRIPT_URL | bash -s 'your token'
"
}
_uninstallalias() {
_envfile="$PROJECT_ENTRY_BIN.env"
_profile="$(_detect_profile)"
if [ "$_profile" ]; then
_info "Uninstalling alias from: '$_profile'"
text="$(cat "$_profile")"
echo "$text" | sed "s|^.*\"$_envfile\"$||" >"$_profile"
fi
}
uninstallcronjob() {
_CRONTAB="crontab"
if ! _exists "$_CRONTAB" ; then
_err "$_CRONTAB not exits"
return 4
fi
cr="$($_CRONTAB -l | grep "$PROJECT_ENTRY")"
if [ "$cr" ]; then
_info "Removing cron job"
if _exists uname && uname -a | grep SunOS >/dev/null; then
$_CRONTAB -l | sed "/$PROJECT_ENTRY/d" | $_CRONTAB --
else
$_CRONTAB -l | sed "/$PROJECT_ENTRY/d" | $_CRONTAB -
fi
_suc "Remove cron job complete."
fi
}
_run() {
_load_token
_check_token
if ! _preparse ; then
_err "No SSL certificate was detected(未检测到SSL证书).\n "
_info "Please refer to resolve the issue(查看文档,解决此问题). https://httpsok.com/doc/faq/nossl.html "
echo ""
return 4
fi
_info "Checking SSL certificate, please wait a moment(证书检测中请稍等...)."
echo
_upload_certs
_check_dns
_check_certs
_reload_nginx
_done
echo ""
}
_process() {
while [ ${#} -gt 0 ]; do
case "${1}" in
--help | -h)
show_help
return
;;
--version | -v)
version
return
;;
--run | -r)
_run
;;
--setup | -s)
_save_token "2ドル"
_install
_run
return
;;
--token | -t)
if [ "2ドル" ]; then
_save_token "2ドル"
else
_show_token
fi
return
;;
--mode | -m)
MODE="crontab"
;;
--install | -i)
_install
return
;;
--uninstall | -u)
_uninstall
return
;;
*)
echo "Unknown parameter : 1ドル2ドル"
return 1
;;
esac
shift 1
done
}
show_help() {
echo "Usage: $PROJECT_ENTRY <command> ... [parameters ...]
Commands:
-h, --help Show this help message.
-v, --version Show version info.
-r, --run Run the $PROJECT_NAME
-s, --setup Install and run (Recommend first time use it).
-t, --token Set or show the token.
-m, --mode Mode of normal or crontab.
-i, --install Install $PROJECT_NAME to your system.
-u, --uninstall Uninstall $PROJECT_NAME in your system.
"
showWelcome
}
main() {
[ -z "1ドル" ] && show_help && return
if _startswith "1ドル" '-'; then _process "$@"; else _process --setup "$@"; fi
}
main "$@"
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

🔥🔥🔥 一行命令,轻松搞定SSL证书自动续期。 SSL泛域名证书,SSL证书管理,SSL证书自动续期,SSL证书自动更新,七牛云、阿里云、腾讯云、CDN、OSS、https证书管理,https证书管理,免费证书,TLS证书自动续签,nginx证书自动续期工具,nginx证书管理。从此告别Let's Encrypt
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Shell
1
https://gitee.com/herun_admin/httpsok.git
git@gitee.com:herun_admin/httpsok.git
herun_admin
httpsok
httpsok
main
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /