最近刚部署完 CactiEZ+weathermap+nagios+npc的整合,发现一个问题,weathermap下的editor.php文件是任何人都能访问的,并能修改气象图,如下图。


095332422.png

通过google的搜索相关的信息,从Weathermap的网站看到,editor.php是没有做验证的,任何人都可以修改你的气象图配置文件的。但其网站也提供了一个解决方法,如下


weathermap官网说明:http://www.network-weathermap.com/manual/latest/pages/install-cacti-editor.html


<Directory /var/www/html/plugins/weathermap>
   <Files editor.php>
            Order Deny,Allow
            Deny from all
            Allow from127.0.0.1
        </Files>
</Directory>

apache的配置文件末尾加上上面的代码,这样就可以解决问题了。但是不久后你就会发现,自己想要修改气象图的时候,却没有权限访问的,如下图


095405444.png




呵呵,是不是很郁闷呢,还得修改apache的配置文件?其实不用,如果我们用.htaccess的验证方法,就可以完全避免这个问题的发生了。

首先我们在/var/www/html/plugins/weathermap下创建一个验证文件


htpasswd -cb /var/www/html/plugins/weathermap/.htpasswd cacti catiuser

其中cacti是用户名,cactiuser是密码

创建好验证文件后,在apache的配置文件末尾加上如下的代码


<Directory/var/www/html/plugins/weathermap>
 <Files editor.php>
 AuthType Basic
 AuthName "Please input your username and password."
 AuthUserFile /var/www/html/plugins/weathermap/.htpasswd
 require valid-user     
 </Files>
</Directory>

这里大概说明一下上面的字段的意思。

AuthType指令选择了对用户实施认证的方法,最常用的是由mod_auth提供的Basic。很重要的必须认识到的一点是,Basic认证方法并不加密来自用户浏览器的密码,因此,不应该用于高度敏感的数据。Apache在最近的版本中还有另一种更安全的认证方法,即由mod_auth_digest提供的AuthType Digest
AuthName指令设置了使用认证的领域,它起两个作用,首先,此领域说明会出现在显示给用户的密码提问对话框中,其次,也帮助客户端程序确定应该输入哪个密码。

AuthUserFile指令设置了密码文件,也就是刚才我们已经用htpasswd建立的。

require valid-user表示针对/var/www/html/plugins/weathermap/.htpasswd设置的所有用户生效。如果只想对.htpasswd里面设置的一个用户生效,可以使用requier user Username1


好了,设置完上面内容,重新启动一下apache

再访问http://xxxx.com/plugins/weathermap/editor.php的时候,就会提示你输入用户名和密码了。如下图


095430765.png