Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add advertised port (useful to put iptv-proxy behind a reverse proxy) #77

Merged
merged 1 commit into from
Mar 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ var rootCmd = &cobra.Command{
conf := &config.ProxyConfig{
HostConfig: &config.HostConfiguration{
Hostname: viper.GetString("hostname"),
Port: viper.GetInt64("port"),
Port: viper.GetInt("port"),
},
RemoteURL: remoteHostURL,
XtreamUser: config.CredentialString(xtreamUser),
Expand All @@ -80,11 +80,16 @@ var rootCmd = &cobra.Command{
M3UCacheExpiration: viper.GetInt("m3u-cache-expiration"),
User: config.CredentialString(viper.GetString("user")),
Password: config.CredentialString(viper.GetString("password")),
AdvertisedPort: viper.GetInt("advertised-port"),
HTTPS: viper.GetBool("https"),
M3UFileName: viper.GetString("m3u-file-name"),
CustomEndpoint: viper.GetString("custom-endpoint"),
}

if conf.AdvertisedPort == 0 {
conf.AdvertisedPort = conf.HostConfig.Port
}

server, err := server.NewServer(conf)
if err != nil {
log.Fatal(err)
Expand All @@ -111,15 +116,16 @@ 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, "iptv-proxy-config", "C", "config file (default is $HOME/.iptv-proxy.yaml)")
rootCmd.Flags().StringP("m3u-url", "u", "", `iptv m3u file or url e.g: "http://example.com/iptv.m3u"`)
rootCmd.Flags().StringP("m3u-file-name", "", "iptv.m3u", `name of the new proxified m3u file e.g "http://poxy.com/iptv.m3u"`)
rootCmd.Flags().StringP("custom-endpoint", "", "", `custom endpoint "http://poxy.com/<custom-endpoint>/iptv.m3u"`)
rootCmd.Flags().Int64("port", 8080, "Port to expose the IPTVs endpoints")
rootCmd.PersistentFlags().StringVar(&cfgFile, "iptv-proxy-config", "C", "Config file (default is $HOME/.iptv-proxy.yaml)")
rootCmd.Flags().StringP("m3u-url", "u", "", `Iptv m3u file or url e.g: "http://example.com/iptv.m3u"`)
rootCmd.Flags().StringP("m3u-file-name", "", "iptv.m3u", `Name of the new proxified m3u file e.g "http://poxy.com/iptv.m3u"`)
rootCmd.Flags().StringP("custom-endpoint", "", "", `Custom endpoint "http://poxy.com/<custom-endpoint>/iptv.m3u"`)
rootCmd.Flags().Int("port", 8080, "Iptv-proxy listening port")
rootCmd.Flags().Int("advertised-port", 0, "Port to expose the IPTV file and xtream (by default, it's taking value from port) useful to put behind a reverse proxy")
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("user", "usertest", "User auth to access proxy (m3u/xtream)")
rootCmd.Flags().String("password", "passwordtest", "Password auth to access proxy (m3u/xtream)")
rootCmd.Flags().String("xtream-user", "", "Xtream-code user login")
rootCmd.Flags().String("xtream-password", "", "Xtream-code password login")
rootCmd.Flags().String("xtream-base-url", "", "Xtream-code base url e.g(http://expample.tv:8080)")
Expand Down
3 changes: 2 additions & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (c CredentialString) String() string {
// HostConfiguration containt host infos
type HostConfiguration struct {
Hostname string
Port int64
Port int
}

// ProxyConfig Contain original m3u playlist and HostConfiguration
Expand All @@ -51,6 +51,7 @@ type ProxyConfig struct {
M3UFileName string
CustomEndpoint string
RemoteURL *url.URL
AdvertisedPort int
HTTPS bool
User, Password CredentialString
}
2 changes: 1 addition & 1 deletion pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func (c *Config) replaceURL(uri string, trackIndex int, xtream bool) (string, er
protocol,
basicAuth,
c.HostConfig.Hostname,
c.HostConfig.Port,
c.AdvertisedPort,
customEnd,
uriPath,
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/xtream-proxy/xtream-proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (c *Client) Action(config *config.ProxyConfig, action string, q url.Values)
}
respBody, err = c.GetEPG(q["stream_id"][0])
default:
respBody, err = c.login(config.User.String(), config.Password.String(), protocol+"://"+config.HostConfig.Hostname, int(config.HostConfig.Port), protocol)
respBody, err = c.login(config.User.String(), config.Password.String(), protocol+"://"+config.HostConfig.Hostname, config.AdvertisedPort, protocol)
}

return
Expand Down