1<?php
2/**
3 * Date: 2015/3/11
4 * Time: 4:39
5 */
6if (!defined('DOKU_INC')) die();
7if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN', DOKU_INC . 'lib/plugins/');
8require_once (DOKU_PLUGIN . 'action.php');
9
10class  action_plugin_remoteinf extends DokuWiki_Action_Plugin{
11    function register(&$controller) {
12        $controller->register_hook('DOKUWIKI_STARTED', 'AFTER',  $this, 'set_data',array());
13    }
14
15    function set_data(){
16        $enkey= $this->getConf("authkey");
17        $timespan = $this->getConf("refreshtime");
18        if($_SERVER['REMOTE_USER']!=null){
19            $theuser=$_SERVER['REMOTE_USER'];
20            $entime=floor (time()/(60*$timespan));
21            $pat_str=$entime."~".$theuser."+".$enkey; // must be same with check_data
22            $enmd5=md5($pat_str);
23            $finalout= base64_encode( $theuser."|".$enmd5 );
24            //    setcookie(DOKU_COOKIE, '', time() - 600000, $cookieDir, '', ($conf['securecookie'] && is_ssl()), true);
25            setcookie("DWremoteinf",$finalout,time()+$timespan*60);
26        }else{
27            setcookie("DWremoteinf","",10);
28        }
29    }
30
31    function check_data($infcode){
32        $enkey= $this->getConf("authkey");    // this should be manual record in the other server which receive inf
33        $timespan = $this->getConf("refreshtime");  //time span should be manual set to the same in the other server
34        $entime=floor (time()/(60*$timespan));
35
36        $txtstr=base64_decode($infcode);
37        $argdata=explode("|",$txtstr,2);
38        if(count($argdata)!=2){
39            return false;
40        }
41        $theuser=$argdata[0];
42        $enmd5_remote=$argdata[1];
43
44        $pat_str=$entime."~".$theuser."+".$enkey;
45        $enmd5=md5($pat_str);
46
47        if($enmd5==$enmd5_remote){
48            return $theuser;
49        }else{
50            return false;
51        }
52
53    }
54
55}