IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    ELK中kibana3 php授权方案的设计

    istrone发表于 2016-07-07 13:01:47
    love 0

    kibana3 本身就是纯html,基于require.js 然后 结合 angular.js 实现的一个单页面应用。
    所以,修改起来相对简单。

    1. 部署本地的php环境,
    2. 把index.html 修改成 index.php 在开头直接嵌入相关权限判断的php代码
    3. 接口权限的判断,修改权限的本质是对公网屏蔽ES存储的细节。考虑到kibana的前端代码有一个url集中配置,直接修改config.js
    中

    32 elasticsearch: “http://”+window.location.hostname+”/proxy.php?q=”,

    4. 编写proxy.php

    <?php
    
    function post($url, $data) {
        $ch = curl_init($url);
        $options = array(
            CURLOPT_CONNECTTIMEOUT => 30, 
            CURLOPT_TIMEOUT => 60, 
            CURLOPT_RETURNTRANSFER => 1,
            CURLOPT_FRESH_CONNECT => true,
            CURLOPT_CUSTOMREQUEST => 'POST',
            CURLOPT_POST => true,
            CURLOPT_POSTFIELDS => $data
        );  
        curl_setopt_array($ch, $options);
        $result = curl_exec($ch);
        curl_close($ch);
        return $result;
    }
    
    function put($url, $data) {
        $ch = curl_init($url);
        $options = array(
            CURLOPT_CONNECTTIMEOUT => 30, 
            CURLOPT_TIMEOUT => 60, 
            CURLOPT_RETURNTRANSFER => 1,
            CURLOPT_FRESH_CONNECT => true,
            CURLOPT_CUSTOMREQUEST => 'PUT',
            CURLOPT_POST => true,
            CURLOPT_POSTFIELDS => $data
        );  
        curl_setopt_array($ch, $options);
        $result = curl_exec($ch);
        curl_close($ch);
        return $result;
    }
    
    $url = $_GET['q'];
    $method = $_SERVER['REQUEST_METHOD'];
    $host = 'http://localhost:9200/';
    $get_url = $host . $url ;
    
    if("GET" == $method) {
    	$content = file_get_contents($get_url);
    	echo $content;
    } else if("POST" == $method){
    	$data = $GLOBALS['HTTP_RAW_POST_DATA'];
    	$content = post($get_url,$data);
    	echo $content;
    } else if("PUT" == $method) {
    	$data = file_get_contents('php://input');
    	$content = put($get_url,$data);
    	echo $content;
    }
    
    Maybe you like these:
    PHP改变当前工作路径
    用PHP写Shell
    PHP经典代码
    关于PHP扩展的几个函数
    PHP VLD安装使用
    无觅


沪ICP备19023445号-2号
友情链接