1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
   |  
<?php
include 'XML/RPC2/Server.php';
 
class OpenKeysGateway {
    /**
     * Update the status of the keys
     *
     * @param array $status Status of keys
     * @return integer 1 if ok, 0 else
     */
    public static function notify($status) {
        $logmsg = "";
        foreach ($status as $key_num_from_zero => $key_pres) {
            if (!is_numeric($key_pres) || intval($key_pres)!=$key_pres || $key_pres < 0 || $key_pres > 1) continue;
            if (!is_numeric($key_num_from_zero) || intval($key_num_from_zero)!=$key_num_from_zero 
                || $key_num_from_zero < 0 || $key_num_from_zero > 9) continue;
            $logmsg .= "".($key_num_from_zero+1).":".$key_pres.",";
        }
        file_put_contents('test.txt', "key notify :".$logmsg, FILE_APPEND );
        return 1;
    }
 
    /**
     * Check if user is able to release the key 'key_num'
     *
     * @param string $sessid PHPSESSID of a connected user
     * @param integer $key_num number of the key to release
     * @return integer 0:NOK, 1:OK
     */
    public static function checkCommand($sessid, $key_num) {
        /* sanitize input */
        if (!is_numeric($key_num) || intval($key_num)!=$key_num || $key_num < 1 || $key_num > 10) {
            return 0;
        }
 
        $weDontWant = 1;
 
        if ($weDontWant) {
            file_put_contents('test.txt', "$key_num has no associated airborne aircraft", FILE_APPEND );
            return 0;
        }
        else {
            file_put_contents('test.txt', "granted key: ".$key_num.":permission granted", FILE_APPEND );
            return 1;
        }
    }
}
 
$options = array(
    'autoDocument' => true,
);
 
// dirty hack to get things work !
$GLOBALS['HTTP_RAW_POST_DATA'] = file_get_contents('php://input');
 
$server = XML_RPC2_Server::create('OpenKeysGateway', $options);
$server->handleCall();
 
?> | 
Partager