Browse Source

Some modifications to optimize menu...
Now, it's possible to create new domaine by passing option -c|create|-n|new

HucSte 2 years ago
parent
commit
eb6d85ed90
3 changed files with 74 additions and 52 deletions
  1. 25 11
      config/vars
  2. 32 24
      launcher
  3. 17 17
      scripts/mng_menu

+ 25 - 11
config/vars

@@ -85,8 +85,13 @@ log_error="error.log"
 log_fpm_access="${domain}.access.log"
 log_fpm_slow="${domain}.slow.log"
 
+MENU_ARG=""
+MENU_CHOICE=""
+MENU_OPTION=""
+MENU_OTHER=""
+
 declare -A MENU_MAIN
-MENU_MAIN['default']='Création'
+MENU_MAIN['create']='Création'
 MENU_MAIN['delete']='Suppression'
 MENU_MAIN['help']='Aide'
 MENU_MAIN['restart']='Redémarrage'
@@ -150,13 +155,22 @@ ossl=$(which openssl)
 NB_PARAMS=$#
 PARAMS=("$@");
 
-case "${PARAMS[0]}" in
-    -d|del) PARAMS[0]="delete" ;;
-    -h|-H|-\?) PARAMS[0]="help" ;;
-    -r) PARAMS[0]="restart" ;;
-    -s) PARAMS[0]="ssl" ;;
-    -t) PARAMS[0]="test" ;;
-    -v) PARAMS[0]="view" ;;
-esac
-
-[ ${PARAMS[0]} ] && MENU_DESC="${MENU_MAIN[${PARAMS[0]}]}" || MENU_DESC="${MENU_MAIN['default']}"
+if [ -z "${PARAMS[0]}" ]; then MENU_CHOICE="create"
+else
+    case "${PARAMS[0]}" in
+    -c|create|-n|new) MENU_CHOICE="create" ;;
+    -d|del) MENU_CHOICE="delete" ;;
+    -h|-H|-\?) MENU_CHOICE="help" ;;
+    -r) MENU_CHOICE="restart" ;;
+    -s) MENU_CHOICE="ssl" ;;
+    -t) MENU_CHOICE="test" ;;
+    -v) MENU_CHOICE="view" ;;
+    esac
+
+    [ -n "${PARAMS[1]}" ] && MENU_OPTION="${PARAMS[1]}"
+    [ -n "${PARAMS[2]}" ] && MENU_ARG="${PARAMS[2]}"
+    [ -n "${PARAMS[3]}" ] && MENU_OTHER="${PARAMS[3]}"
+fi
+unset PARAMS
+
+[ "${MENU_CHOICE}" ] && MENU_DESC="${MENU_MAIN[${MENU_CHOICE}]}"

+ 32 - 24
launcher

@@ -58,18 +58,26 @@ function launcher() {
 
     detect_pwd
 
-    if [[ ${NB_PARAMS} -eq 0 ]]; then
+    #if [[ ${NB_PARAMS} -eq 0 ]]; then
 
-        launch_menu
-        . "${pwd}/scripts/create_vhosts"
-        . "${pwd}/scripts/mng_ssl"
-        . "${pwd}/scripts/mng_ssh"
-        . "${pwd}/scripts/mng_headers"
-        create_vhost
+        #launch_menu
+        #. "${pwd}/scripts/create_vhosts"
+        #. "${pwd}/scripts/mng_ssl"
+        #. "${pwd}/scripts/mng_ssh"
+        #. "${pwd}/scripts/mng_headers"
+        #create_vhost
 
-    else
+    #else
 
-        case "${PARAMS[0]}" in
+        case "${MENU_CHOICE}" in
+            create)
+                launch_menu
+                . "${pwd}/scripts/create_vhosts"
+                . "${pwd}/scripts/mng_ssl"
+                . "${pwd}/scripts/mng_ssh"
+                . "${pwd}/scripts/mng_headers"
+                create_vhost
+            ;;
             delete)
                 . "${pwd}/scripts/delete_vhosts"
                 launch_menu
@@ -79,10 +87,10 @@ function launcher() {
                 display_help
             ;;
             restart)
-                case "${PARAMS[1]}" in
+                case "${MENU_OPTION}" in
                     "php"|"web")
                         detect_uid
-                        restart_server "${PARAMS[1]}"
+                        restart_server "${MENU_OPTION}"
                     ;;
                     *)
                         display_bad_launcher
@@ -94,13 +102,13 @@ function launcher() {
                 detect_uid
                 . "${pwd}/scripts/mng_menu"
                 . "${pwd}/scripts/mng_ssl"
-                case "${PARAMS[1]}" in
+                case "${MENU_OPTION}" in
                     "create"|"new")
                         main_menu
                         use_ssl
                     ;;
                     "cron")
-                        # menu "${PARAMS[2]}"
+                        # menu "${MENU_ARG}"
                         main_menu
                         ssl_cron
                     ;;
@@ -120,11 +128,11 @@ function launcher() {
             ;;
             test)
                 # ajouter test zone
-                case "${PARAMS[1]}" in
+                case "${MENU_OPTION}" in
                     "cfg")
-                        case "${PARAMS[2]}" in
+                        case "${MENU_ARG}" in
                             "php"|"web")
-                                test_cfg "${PARAMS[2]}"
+                                test_cfg "${MENU_ARG}"
                             ;;
                             *)
                                 display_bad_launcher
@@ -142,9 +150,9 @@ function launcher() {
                         test_conn_domain "${PARAMS[3]}"
                     ;;
                     "mem")
-                        case "${PARAMS[2]}" in
+                        case "${MENU_ARG}" in
                             "php"|"web")
-                                check_memory_usage "${PARAMS[2]}"
+                                check_memory_usage "${MENU_ARG}"
                             ;;
                             *)
                                 display_bad_launcher
@@ -166,12 +174,12 @@ function launcher() {
             ;;
             view)
                 . "${pwd}/scripts/mng_menu"
-                case "${PARAMS[1]}" in
+                case "${MENU_OPTION}" in
                     "cfg")
-                        case "${PARAMS[2]}" in
+                        case "${MENU_ARG}" in
                             "php"|"web")
                                 main_menu
-                                display_cfg "${PARAMS[2]}"
+                                display_cfg "${MENU_ARG}"
                             ;;
                             *)
                                 display_bad_launcher
@@ -180,10 +188,10 @@ function launcher() {
                         esac
                     ;;
                     "log")
-                        case "${PARAMS[2]}" in
+                        case "${MENU_ARG}" in
                             "php"|"web")
                                 main_menu
-                                view_log "${PARAMS[2]}"
+                                view_log "${MENU_ARG}"
                             ;;
                             *)
                                 display_bad_launcher
@@ -202,7 +210,7 @@ function launcher() {
             ;;
         esac
 
-    fi
+    #fi
 
     }
 

+ 17 - 17
scripts/mng_menu

@@ -13,24 +13,24 @@ function main_menu() {
 
     local bypass=0
 
-    if [[ "${PARAMS[1]}" ]]; then
+    if [[ "${MENU_OPTION}" ]]; then
 
-        case "${PARAMS[0]}" in
-            "delete")
-                domain="${PARAMS[1]}"
+        case "${MENU_CHOICE}" in
+            "create"|"delete")
+                domain="${MENU_OPTION}"
                 test_domain_exists
             ;;
             "ssl")
-                [[ "${PARAMS[1]}" == "cron" ]] && bypass=1
-                if [[ "${PARAMS[2]}" ]]; then
-                    domain="${PARAMS[2]}"
+                [[ "${MENU_OPTION}" == "cron" ]] && bypass=1
+                if [[ "${MENU_ARG}" ]]; then
+                    domain="${MENU_ARG}"
                     test_domain_exists
                 else
                     menu_actived_domains
                 fi
             ;;
             "test")
-                case "${PARAMS[1]}" in
+                case "${MENU_OPTION}" in
                     "child"|"domain"|"ocsp")
                         bypass=1
                         menu_actived_domains
@@ -38,8 +38,8 @@ function main_menu() {
                 esac
             ;;
             "view")
-                if [[ "${PARAMS[3]}" ]]; then
-                    domain="${PARAMS[3]}"
+                if [[ "${MENU_OTHER}" ]]; then
+                    domain="${MENU_OTHER}"
                     test_domain_exists
                 else
                     menu_actived_domains
@@ -47,10 +47,10 @@ function main_menu() {
                 bypass=1
             ;;
             *)
-                if [[ -d "${home}/${PARAMS[1]}" && -L "${dir_sites_enabled}/${PARAMS[1]}" ]]; then
-                    domain="${PARAMS[1]}"
+                if [[ -d "${home}/${MENU_OPTION}" && -L "${dir_sites_enabled}/${MENU_OPTION}" ]]; then
+                    domain="${MENU_OPTION}"
                 else
-                    display_mssg "KO" "nonexistent_domain" "${PARAMS[1]}"
+                    display_mssg "KO" "nonexistent_domain" "${MENU_OPTION}"
                     stop
                 fi
             ;;
@@ -90,9 +90,9 @@ function menu_actived_domains() {
     get_actived_domains
 
     # delete domain if not using ssl, for menu ssl
-    if [[ "${PARAMS[0]}" == "ssl" ]]; then
+    if [[ "${MENU_CHOICE}" == "ssl" ]]; then
 
-        case "${PARAMS[1]}" in
+        case "${MENU_OPTION}" in
             "create"|"new")
                 for index in "${!domains_actived[@]}"; do
                     name="${domains_actived[index]}"
@@ -114,9 +114,9 @@ function menu_actived_domains() {
     fi
 
     # delete domain if not using php for menu test
-    if [[ "${PARAMS[0]}" == "test" ]]; then
+    if [[ "${MENU_CHOICE}" == "test" ]]; then
 
-        if [[ "${PARAMS[1]}" == "child" ]]; then
+        if [[ "${MENU_OPTION}" == "child" ]]; then
 
             for index in "${!domains_actived[@]}"; do
                 name="${domains_actived[index]}"