是否有可能使用Apache,Javascript或CSS(或Plone中的某些内容)使<div>
仅对一组IP地址可见?
以下是我希望某些IP地址可用的代码:
<div id="user">
<ul>
<li><a href="#" title="Login">Login</a></li>
</ul>
</div>
理想情况下,我希望这只能从3组IP地址中看到。我有一个单独的站点运行以下限制(当然,IP地址已更改)以控制访问,但是对整个站点而不仅仅是div。
Order allow,deny
Allow from 000.0.00
Allow from 000.0.01
# Order deny,allow
# Deny from all
这样做的目的是将弹出式登录(或登录页面)限制为不在特定位置访问该站点的任何人。即使我可以隐藏“用户”div(未登录时是登录按钮)给没有从IP地址范围访问的人,也没关系。非常感谢任何帮助,谢谢!
答案 0 :(得分:2)
您可以使用Products.AutoRole自动为来自某些IP范围的访问者分配一个组,然后调整您的Plone模板,以便您的div以该组为条件。 (并且对于您的最终问题,我们应该提交一个功能请求,“可以登录”应该绑定到权限,默认情况下将授予匿名权。)
FWIW,在工作中,我们还在apache配置中限制/login|/login_form
。
答案 1 :(得分:1)
你需要一些css:
#user {
display: none;
}
还有一些js:
<script type="application/javascript">
function getip(json){
if(json.ip === "127.0.0.1") {
document.getElementById('user').style.display = 'block';
}
}
</script>
<script type="application/javascript" src="http://jsonip.appspot.com/?callback=getip"></script>
我从这里得到了这个:https://stackoverflow.com/a/810461/3132718
现在,默认情况下,div不会在页面上显示,但仍可通过查看源代码看到。
答案 2 :(得分:0)
import numpy as np
#This will create a 2-d array of zeroes of dimensions 3x4
x = np.zeros((3,4))
print(x)
[[ 0. 0. 0. 0.]
[ 0. 0. 0. 0.]
[ 0. 0. 0. 0.]]
#This will print the First Row of the 2-d array
x[0]
array([ 0., 0., 0., 0.])
#This will Give the Length of 1st row
x[0].shape
(4,)
#This will Give the Length of 2nd row, verified that length of row is showing same
x[1].shape
(4,)
#This will give the dimension of 2-d Array
x.shape
(3, 4)
# This will give the number of rows is 2-d array
x.shape[0]
3
# This will give the number of columns is 2-d array
x.shape[1]
3
# This will give the number of columns is 2-d array
x.shape[1]
4
# This will give an error as we have a 2-d array and we are asking value for an index
out of range
x.shape[2]
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-20-4b202d084bc7> in <module>()
----> 1 x.shape[2]
IndexError: tuple index out of range
*multiple class hiding*
<script type="application/javascript">
function getip(json){
if(json.query == "87.1.1.5") {
var elems = document.getElementsByClassName('price');
for (i = 0; i < elems.length; i++) {
elems[i].style.display = 'block';
}
}
}