github.com/waltonchain/waltonchain_gwtc_src@v1.1.4-0.20201225072101-8a298c95a819/cmd/puppeth/wizard_nginx.go (about)

     1  // Copyright 2017 The go-ethereum Authors
     2  // This file is part of go-wtc.
     3  //
     4  // go-wtc is free software: you can redistribute it and/or modify
     5  // it under the terms of the GNU General Public License as published by
     6  // the Free Software Foundation, either version 3 of the License, or
     7  // (at your option) any later version.
     8  //
     9  // go-wtc is distributed in the hope that it will be useful,
    10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    12  // GNU General Public License for more details.
    13  //
    14  // You should have received a copy of the GNU General Public License
    15  // along with go-wtc. If not, see <http://www.gnu.org/licenses/>.
    16  
    17  package main
    18  
    19  import (
    20  	"fmt"
    21  
    22  	"github.com/wtc/go-wtc/log"
    23  )
    24  
    25  // ensureVirtualHost checks whether a reverse-proxy is running on the specified
    26  // host machine, and if yes requests a virtual host from the user to host a
    27  // specific web service on. If no proxy exists, the method will offer to deploy
    28  // one.
    29  //
    30  // If the user elects not to use a reverse proxy, an empty hostname is returned!
    31  func (w *wizard) ensureVirtualHost(client *sshClient, port int, def string) (string, error) {
    32  	if proxy, _ := checkNginx(client, w.network); proxy != nil {
    33  		// Reverse proxy is running, if ports match, we need a virtual host
    34  		if proxy.port == port {
    35  			fmt.Println()
    36  			fmt.Printf("Shared port, which domain to assign? (default = %s)\n", def)
    37  			return w.readDefaultString(def), nil
    38  		}
    39  	}
    40  	// Reverse proxy is not running, offer to deploy a new one
    41  	fmt.Println()
    42  	fmt.Println("Allow sharing the port with other services (y/n)? (default = yes)")
    43  	if w.readDefaultString("y") == "y" {
    44  		if out, err := deployNginx(client, w.network, port); err != nil {
    45  			log.Error("Failed to deploy reverse-proxy", "err", err)
    46  			if len(out) > 0 {
    47  				fmt.Printf("%s\n", out)
    48  			}
    49  			return "", err
    50  		}
    51  		// Reverse proxy deployed, ask again for the virtual-host
    52  		fmt.Println()
    53  		fmt.Printf("Proxy deployed, which domain to assign? (default = %s)\n", def)
    54  		return w.readDefaultString(def), nil
    55  	}
    56  	// Reverse proxy not requested, deploy as a standalone service
    57  	return "", nil
    58  }