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

Plugin helper to get country information from an IP #5195

Open
JohnXLivingston opened this issue Aug 14, 2022 · 2 comments
Open

Plugin helper to get country information from an IP #5195

JohnXLivingston opened this issue Aug 14, 2022 · 2 comments
Labels
Component: PeerTube Plugin 📦 Features that can be developed in a plugin, but require PeerTube plugin API development Type: Feature Request ✨

Comments

@JohnXLivingston
Copy link
Contributor

Describe the problem to be solved

Some time ago, I created the plugin georegister. With this plugin, you can configure a set of countries allowes to create account, or disallowed to create account.
I then use the IP provided to the hook filter:api.user.signup.allowed.result to check the country.
I didn't want to download and maintain a geoip list at the time I wrote this plugin. So I use the whois command, and check the country in the whois result.

Describe the solution you would like

Now that Peertube has an (optional) geoip database (used for viewing stats), it would be nice to provide the IP's country as parameter here:

async getServerConfig (ip?: string): Promise<ServerConfig> {
const { allowed } = await Hooks.wrapPromiseFun(
isSignupAllowed,
{
ip
},
'filter:api.user.signup.allowed.result'
)

Of course, only if the geoip database is configured. If not, just don't pass any country attribute.

@Chocobozzz Chocobozzz changed the title Feature Request: additional parameter 'country' for plugin hook filter:api.user.signup.allowed.result Aug 16, 2022
@Chocobozzz Chocobozzz added Type: Feature Request ✨ Component: PeerTube Plugin 📦 Features that can be developed in a plugin, but require PeerTube plugin API development labels Aug 16, 2022
@EricGuic
Copy link
Contributor

EricGuic commented Dec 9, 2022

Hi, for the Peertube instance of my public company in educational sector, we have to limit the access of some videos to our country (for legal reasons). Those videos could be in various visibility state.

The need :
To be able to block some countries from accessing peertube.mydomain.com and also any website where our videos could have been embed, and also every other peertube instance federated (maybe the most difficult part ?).
This geoblocking should be possible at the video or channel level (and for other user, maybe for the whole instance but there other solution like reverse proxy could do the job I guess).

Regarding my needs, I've discussed with John the idea of a plugin based on the geoIP database and allowing us to specify some basic rule (for example "block entire world") then some specific rules (eg "allow FR" and "allow UK").
Then, in a new tab of the video edit page, the owner can specify which rule will be applied to his video (for example by checking the box "block entire world" and the box "allow FR").

For this specific use case, John suggest that this functionnality could be implemented in his own georegister plugin, or in a new plugin (maybe cleaner), but that it could be relevant to discuss it here.
For example, he's wondering if a "helper" could be more usefull than a hook (or in addition to). I'm not a developper so I let you discuss the Pro and Cons.

Thanks for your thoughs about it.

@JohnXLivingston
Copy link
Contributor Author

Thanks @EricGuic for the summary.
Indeed, I think that a helper method, taking res as parameter, and returning the country code could be really usefull. And if geoip is not enabled on Peertube, just don't provide this helper.

So we could write something like:

const country = peertubeHelpers.getRequestCountry ? peertubeHelpers.getRequestCountry(res) : null

And to respond to my first need, ensure I can get res in the filter:api.user.signup.allowed.result filter (see this discussion: some hooks/filters don't get res as parameter).

@Chocobozzz Chocobozzz changed the title Additional parameter 'country' for plugin hook filter:api.user.signup.allowed.result Dec 12, 2022
@Chocobozzz Chocobozzz changed the title Plugin helper to get contry information from an IP Mar 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: PeerTube Plugin 📦 Features that can be developed in a plugin, but require PeerTube plugin API development Type: Feature Request ✨
3 participants