48 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
		
		
			
		
	
	
			48 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
|  | package cmd
 | ||
|  | 
 | ||
|  | import (
 | ||
|  | 	"fmt"
 | ||
|  | 	"net/http"
 | ||
|  | 	"os"
 | ||
|  | 
 | ||
|  | 	"github.com/dchest/uniuri"
 | ||
|  | 	"github.com/spf13/cobra"
 | ||
|  | )
 | ||
|  | 
 | ||
|  | var port = "31337"
 | ||
|  | 
 | ||
|  | // simpleCmd represents the simple command
 | ||
|  | var simpleCmd = &cobra.Command{
 | ||
|  | 	Use:   "simple",
 | ||
|  | 	Short: "simple password comparison",
 | ||
|  | 	RunE: func(cmd *cobra.Command, args []string) error {
 | ||
|  | 		var pass = os.Getenv("RTMPAUTH_PASS")
 | ||
|  | 		if pass == "" {
 | ||
|  | 			pass = uniuri.New()
 | ||
|  | 		}
 | ||
|  | 		fmt.Println("Stream password:", pass)
 | ||
|  | 		return http.ListenAndServe(fmt.Sprintf("127.0.0.1:%s", port), http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
 | ||
|  | 			if r.FormValue("name") == pass {
 | ||
|  | 				w.WriteHeader(http.StatusOK)
 | ||
|  | 			} else {
 | ||
|  | 				w.WriteHeader(http.StatusForbidden)
 | ||
|  | 			}
 | ||
|  | 		}))
 | ||
|  | 	},
 | ||
|  | }
 | ||
|  | 
 | ||
|  | func init() {
 | ||
|  | 	rootCmd.AddCommand(simpleCmd)
 | ||
|  | 
 | ||
|  | 	// Here you will define your flags and configuration settings.
 | ||
|  | 
 | ||
|  | 	// Cobra supports Persistent Flags which will work for this command
 | ||
|  | 	// and all subcommands, e.g.:
 | ||
|  | 	// simpleCmd.PersistentFlags().String("foo", "", "A help for foo")
 | ||
|  | 
 | ||
|  | 	// Cobra supports local flags which will only run when this command
 | ||
|  | 	// is called directly, e.g.:
 | ||
|  | 	// simpleCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
 | ||
|  | 	simpleCmd.Flags().StringVarP(&port, "port", "p", "31337", "Port to listen on")
 | ||
|  | }
 |