File: //opt/hc_php/unversioned/EventPublisher.php
<?php
namespace HcEventPublisher;
include_once('JsonRPC/Client.php');
use JsonRPC;
const USER_MDS_SOCKET = '/var/run/hc_mds/user_mds.socket';
const ROOT_MDS_SOCKET = '/var/run/hc_mds/root_mds.socket';
const METHOD = 'event';
const DEBUG = false;
const BASE_PATH = '/var/cpanel/userdata';
const TOKEN_FILE = 'hc_mds.token';
class EventPublisher extends JsonRPC\Client {
public function __construct()
{
$processUser = posix_getpwuid(posix_geteuid());
$this->user = $processUser['name'];
if ($this->user == 'root') {
parent::__construct(ROOT_MDS_SOCKET);
} else {
parent::__construct(USER_MDS_SOCKET);
}
$this->debug = DEBUG;
}
public function send($params=array()) {
// Add token to the request if user is not root.
if ($this->user != 'root') {
$full_token_path = sprintf('%s/%s/%s', BASE_PATH, $this->user, TOKEN_FILE);
if (file_exists($full_token_path)) {
$params['metadata']['token'] = trim(file_get_contents($full_token_path));
}
}
return $this->execute(METHOD, $params);
}
}
?>