简体   繁体   English

如何使用`http.server`实现一个简单的强制门户?

[英]How do I implement a simple Captive Portal with `http.server`?

I would like to serve a Captive Portal - page that would prompt the user to agree to certain terms before starting browsing the web from my wireless network (through WiFi) using http.server on my Raspberry Pi that runs the newest version of Raspbian. 我想提供一个Captive Portal - 这个页面会提示用户在开始使用运行最新版本Raspbian的Raspberry Pi上的http.server从我的无线网络(通过WiFi)浏览网页之前同意某些条款。

I have http.server (comes with Python3) up an running and have a webpage portal.html locally on the Pi. 我有一个运行的http.server (随Python3一起),并在Pi上本地有一个网页portal.html This is the page that I want users to be redirected to when they connect to my Pi. 这是我希望用户在连接到我的Pi时重定向到的页面。 Lets say that the local IP of that page is 192.168.1.5:80/portal.html 让我们说该页面的本地IP是192.168.1.5:80/portal.html

My thought is that I would then somehow allow their connection when they have connected and accepted the terms and conditions. 我的想法是,当他们连接并接受条款和条件时,我会以某种方式允许他们的连接。

How would I go about that? 我该怎么办呢?

You need to work out the document in question, with all the necessary terms and conditions that will link the acceptance of the conditions to a specific user. 您需要制定相关文档,其中包含将条件接受与特定用户联系起来的所有必要条款和条件。 You can implement a simple login, and link a String (Name - ID) to a Boolean for example, "accepted = true". 您可以实现简单的登录,并将String(Name - ID)链接到布尔值,例如“accepted = true”。 If you don't need to store the user data, just redirect yo your document and when checked "agree", then you allow the user connection. 如果您不需要存储用户数据,只需重定向您的文档,当选中“同意”时,您就允许用户连接。

So 'old-style' captive portals (i believe) would just hijack an unencrypted HTTP GET request and force the browser to be redirected to the portal page. 因此,'旧式'强制门户网站(我相信)只会劫持未加密的HTTP GET请求,并强制将浏览器重定向到门户网站页面。 While easy, it also demonstrates how crazy insecure HTTP can be. 虽然简单,但它也证明了不安全的HTTP是多么疯狂。

Now there more secure mechanisms implemented by OS's regarding captive portals. 现在,操作系统实施了更多关于强制门户网站的安全机制。 RFC 7710 details the exact mechanism. RFC 7710详细说明了确切的机制。 There are also OS specific requirements, like OS X requires that http://captive.apple.com/hotspotdetect.html is reachable. 还有操作系统特定的要求,例如OS X要求可以访问http://captive.apple.com/hotspotdetect.html You will need to implement all of these to redirect to your page. 您需要实现所有这些以重定向到您的页面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM