This commit is contained in:
2024-12-30 23:56:13 +01:00
commit d7841b32be
8 changed files with 169 additions and 0 deletions

37
cmd/root.go Normal file
View File

@ -0,0 +1,37 @@
package cmd
import (
"os"
"github.com/spf13/cobra"
)
// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "rtmpauth",
Short: "A brief description of your application",
// Uncomment the following line if your bare application
// has an action associated with it:
// Run: func(cmd *cobra.Command, args []string) { },
}
// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
err := rootCmd.Execute()
if err != nil {
os.Exit(1)
}
}
func init() {
// Here you will define your flags and configuration settings.
// Cobra supports persistent flags, which, if defined here,
// will be global for your application.
// rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.rtmpauth.yaml)")
// Cobra also supports local flags, which will only run
// when this action is called directly.
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}

47
cmd/simple.go Normal file
View File

@ -0,0 +1,47 @@
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")
}