Add https option for proxy urls

Signed-off-by: Pierre-Emmanuel Jacquier <pierre-emmanuel.jacquier@exoscale.ch>
This commit is contained in:
Pierre-Emmanuel Jacquier
2019-09-12 10:38:04 +00:00
parent 3f6bc7d648
commit 99378efdb8
6 changed files with 21 additions and 7 deletions

View File

@@ -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")

View File

@@ -20,6 +20,7 @@ type ProxyConfig struct {
XtreamPassword string
XtreamBaseURL string
RemoteURL *url.URL
HTTPS bool
//XXX Very unsafe
User, Password string
}

View File

@@ -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,

View File

@@ -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
}

View File

@@ -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)

View File

@@ -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,