【发布时间】:2012-06-09 23:46:19
【问题描述】:
一些背景
我有一个 tumblog。
我还有一个疯子的前女友。
该人一直痴迷于访问我的帖子,考虑到我们关系的性质(或缺乏关系),我觉得这相当令人不安。我的目标是阻止访问她或任何可能成为她/她的朋友/家人的人,而无需更改我已建立的 URL。
进攻计划
由于我没有在第三方主机上托管我的博客,因此我几乎无法使用有助于阻止她访问的工具。但是,如果有需要的解决方案,我会自己托管。我不是专家,据我所知,JavaScript 是唯一能让她相信她无法访问我的页面的方法,至少可以欺骗她。
我已经编写了一个脚本,希望真的得到一些指导。使用 jQuery 和 jQuery Cookie 插件,我想出了一些代码来展示我的目标。 让我们开始吧。
var ips = "{text:Ips}"; // String generated by tumblr: IP addresses separated by a space
var towns = "{text:Towns}"; // Same but with towns
var iparray = ips.split(" ");
var townarray = towns.split(" ");
$.getJSON("http://www.geoplugin.net/json.gp?jsoncallback=?",
function(data){ // JSON request that returns geolocation data
for(i = 0; i < townarray.length; i++){
if (data['geoplugin_city'] == townarray[i]) // Test to see if user is accessing from a blacklisted town
{
if ($.cookie('banned_ip_tumblr')) // Looks for evidence of tracking cookie, if found: we stop loading, hide any content that was rendered, and send the user back up to 3 pages.
{
window.stop();
$('#all').hide(); // Div that wraps all content in body
history.go(-3);
history.go(-2);
history.go(-1);
}
else // Sets a cookie destined to be stale. Really stale. Then proceed with hiding posts
{
$.cookie('banned_ip_tumblr', 'true', { expires: 365, path: '/' });
$('#all').hide();
history.go(-3);
history.go(-2);
history.go(-1);
window.stop();
}
}
}
for(i = 0; i < iparray.length; i++){
if (data['geoplugin_request'] == iparray[i]) // Same as above, IP style.
{
if ($.cookie('banned_ip_tumblr'))
{
window.stop();
$('#all').hide();
history.go(-3);
history.go(-2);
history.go(-1);
}
else
{
$.cookie('banned_ip_tumblr', 'true', { expires: 365, path: '/' });
window.stop();
$('#all').hide();
history.go(-3);
history.go(-2);
history.go(-1);
}
}
}
}
);
if ($.cookie('banned_ip_tumblr')) // If the user has been caught but is now connecting from a new host, there is a chance this will catch them
{
window.stop();
$('#all').hide();
history.go(-3);
history.go(-2);
history.go(-1);
}
已知故障点
- 如果用户禁用了 JS,或者正在使用插件过滤 JS,这将失败。
- 如果用户使用的是移动设备(使用 iPod touch 测试),这将 失败。
- 如果用户使用的是 Internet Explorer,这将失败。
- 如果用户使用网络代理,这将失败。
结束思考
这不是我基于 IP / 地理位置阻止访问的理想方法,但是,这是我目前所知的最好的方法。我所处的情况让我感到不安,但我也认为这是一个机会,可以探索一些不太常见的方法来阻止用户访问。我很高兴听到任何没有 JS 的解决方案以及那些可能的解决方案。
请指出我的错误(我相信有很多),因为它们体现在我的代码和/或概念中。我想养成写代码的习惯。
这是我在 Stack 的第一篇文章,尽管我在整理项目时多次使用这个社区。感谢您花一些时间阅读并考虑我的问题,我期待得到一些意见。
【问题讨论】:
-
您有一个 Tumbler 帐户,他们允许您将 javascript 发布到您的页面?或者这是你自己托管的一些微博?作为一个低技术的解决方案,为什么不停止发布?
-
Tumblr 允许在主题中完全自定义客户端语言
-
我会将他们重定向回他们的仪表板而不是
window.location = "http://tumblr.com/dashboard" -
If the user has JS disabled, or is using a plug-in to filter JS, this will fail.OP 回答了他自己的问题.. JS 不是一种有效的方法。 -
@ThinkingSites '如果她发现我上周末的所作所为,这并不是世界末日,但我非常想让她为难。
标签: javascript jquery ip-address tumblr privacy