diff --git a/cmd/root.go b/cmd/root.go index 6671b15..fbc3082 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -47,6 +47,7 @@ var rootCmd = &cobra.Command{ XtreamBaseURL: viper.GetString("xtream-base-url"), User: viper.GetString("user"), Password: viper.GetString("password"), + HTTPS: viper.GetBool("https"), } if e := routes.Serve(conf); e != nil { @@ -74,6 +75,7 @@ func init() { rootCmd.Flags().String("m3u-url", "http://example.com/iptv.m3u", "iptv m3u file") rootCmd.Flags().Int64("port", 8080, "Port to expose the IPTVs endpoints") rootCmd.Flags().String("hostname", "", "Hostname or IP to expose the IPTVs endpoints") + rootCmd.Flags().BoolP("https", "", false, "Activate https for urls proxy") rootCmd.Flags().String("user", "usertest", "user UNSAFE(temp auth to access proxy)") rootCmd.Flags().String("password", "passwordtest", "password UNSAFE(auth to access m3u proxy and xtream proxy)") rootCmd.Flags().String("xtream-user", "xtream_user", "Xtream-code user login") diff --git a/pkg/config/config.go b/pkg/config/config.go index c74fdda..dd3d6a0 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -20,6 +20,7 @@ type ProxyConfig struct { XtreamPassword string XtreamBaseURL string RemoteURL *url.URL + HTTPS bool //XXX Very unsafe User, Password string } diff --git a/pkg/m3u/m3u.go b/pkg/m3u/m3u.go index ba9dc4d..b0ad62a 100644 --- a/pkg/m3u/m3u.go +++ b/pkg/m3u/m3u.go @@ -28,7 +28,7 @@ func Marshall(p *m3u.Playlist) (string, error) { } // ReplaceURL replace original playlist url by proxy url -func ReplaceURL(playlist *m3u.Playlist, user, password string, hostConfig *config.HostConfiguration) (*m3u.Playlist, error) { +func ReplaceURL(playlist *m3u.Playlist, user, password string, hostConfig *config.HostConfiguration, https bool) (*m3u.Playlist, error) { result := make([]m3u.Track, 0, len(playlist.Tracks)) for _, track := range playlist.Tracks { oriURL, err := url.Parse(track.URI) @@ -36,8 +36,14 @@ func ReplaceURL(playlist *m3u.Playlist, user, password string, hostConfig *confi return nil, err } + protocol := "http" + if https { + protocol = "https" + } + uri := fmt.Sprintf( - "http://%s:%d%s?username=%s&password=%s", + "%s://%s:%d%s?username=%s&password=%s", + protocol, hostConfig.Hostname, hostConfig.Port, oriURL.Path, diff --git a/pkg/routes/routes.go b/pkg/routes/routes.go index 7ba0b79..e3d5fbe 100644 --- a/pkg/routes/routes.go +++ b/pkg/routes/routes.go @@ -158,7 +158,7 @@ func (p *proxy) appAuthenticate(c *gin.Context) { } func initm3u(p *config.ProxyConfig) ([]byte, error) { - playlist, err := proxyM3U.ReplaceURL(p.Playlist, p.User, p.Password, p.HostConfig) + playlist, err := proxyM3U.ReplaceURL(p.Playlist, p.User, p.Password, p.HostConfig, p.HTTPS) if err != nil { return nil, err } diff --git a/pkg/routes/xtream.go b/pkg/routes/xtream.go index ce53297..b1c555b 100644 --- a/pkg/routes/xtream.go +++ b/pkg/routes/xtream.go @@ -40,7 +40,7 @@ func (p *proxy) xtreamGet(c *gin.Context) { return } - newM3U, err := proxyM3U.ReplaceURL(&playlist, p.User, p.Password, p.HostConfig) + newM3U, err := proxyM3U.ReplaceURL(&playlist, p.User, p.Password, p.HostConfig, p.HTTPS) if err != nil { c.AbortWithError(http.StatusInternalServerError, err) return @@ -82,6 +82,11 @@ func (p *proxy) xtreamPlayerAPI(c *gin.Context, q url.Values) { action = q["action"][0] } + protocol := "http" + if p.HTTPS { + protocol = "https" + } + client, err := xtreamapi.New(p.XtreamUser, p.XtreamPassword, p.XtreamBaseURL) if err != nil { c.AbortWithError(http.StatusInternalServerError, err) @@ -116,7 +121,7 @@ func (p *proxy) xtreamPlayerAPI(c *gin.Context, q url.Values) { } respBody, err = client.GetSeriesInfo(q["series_id"][0]) default: - respBody, err = client.Login(p.User, p.Password, "http://"+p.HostConfig.Hostname, int(p.HostConfig.Port)) + respBody, err = client.Login(p.User, p.Password, protocol+"://"+p.HostConfig.Hostname, int(p.HostConfig.Port), protocol) } log.Printf("[iptv-proxy] %v | %s |Action\t%s\n", time.Now().Format("2006/01/02 - 15:04:05"), c.ClientIP(), action) diff --git a/pkg/xtream-proxy/xtream-proxy.go b/pkg/xtream-proxy/xtream-proxy.go index b66313f..5914080 100644 --- a/pkg/xtream-proxy/xtream-proxy.go +++ b/pkg/xtream-proxy/xtream-proxy.go @@ -33,7 +33,7 @@ type Login struct { ServerInfo xtream.ServerInfo `json:"server_info"` } -func (c *Client) Login(proxyUser, proxyPassword, proxyURL string, proxyPort int) (Login, error) { +func (c *Client) Login(proxyUser, proxyPassword, proxyURL string, proxyPort int, protocol string) (Login, error) { req := Login{ UserInfo: xtream.UserInfo{ Username: proxyUser, @@ -52,7 +52,7 @@ func (c *Client) Login(proxyUser, proxyPassword, proxyURL string, proxyPort int) URL: proxyURL, Port: proxyPort, HTTPSPort: proxyPort, - Protocol: c.ServerInfo.Protocol, + Protocol: protocol, RTMPPort: proxyPort, Timezone: c.ServerInfo.Timezone, TimestampNow: c.ServerInfo.TimestampNow,