'data.gchange.fr' ]; private $msgLimit = 15; private $pubsecDir = __DIR__ .'/../cache/pubsec/'; private $userPubsecPath; public function __construct ($userPubkey, $mode = 'local') { $this->userPubsecPath = $this->pubsecDir . $userPubkey .'.dunikey'; if ($this->mode != 'local') { $this->fred = new Fred(); } } public function getMessages () { if ($this->mode = 'local') { try { $msg_in = $this->getInboundMessages(); $msg_out = $this->getOutboundMessages(); } catch (Exception $errMsg) { throw new Exception($errMsg); } return [$msg_in, $msg_out]; } else { $this->fred->donneMoiSesPutainDeMessagesGchange($_SESSION['salt'], $_SESSION['pepper'], 'coucou'); } } public function getInboundMessages () { $cmd = $this->jaklisPath; $cmd .= ' --key '. $this->userPubsecPath; $cmd .= ' --node https://'. $this->nodes['gchange']; $cmd .= ' read'; $cmd .= ' --number ' . $this->msgLimit; $cmd .= ' --json'; $output=null; $result_code=null; exec($cmd, $output, $result_code); if (empty($output)) { throw new Exception('Jaklis marche pô pour les messages entrants.'); } $json = implode("\n", $output); // echo '

' . $cmd . '

'; // echo '
'; var_dump($json); echo '
'; $result = json_decode($json); // echo '
'; var_dump($result); echo '
'; return $result; } public function getOutboundMessages () { $cmd = $this->jaklisPath; $cmd .= ' --key '. $this->userPubsecPath; $cmd .= ' --node http://'. $this->nodes['gchange']; $cmd .= ' read'; $cmd .= ' --number ' . $this->msgLimit; $cmd .= ' --json'; $cmd .= ' --outbox'; $output=null; $result_code=null; exec($cmd, $output, $result_code); if (empty($output)) { throw new Exception('Jaklis marche pô pour les messages sortants.'); } $json = implode("\n", $output); // echo '

' . $cmd . '

'; // echo '
'; var_dump($json); echo '
'; $result = json_decode($json); // echo '
'; var_dump($result); echo '
'; return $result; } private function jescape ($str) { return str_replace('"', '\"', $str); } public function sendMessage ($msg, $toPubkey, $title, $fromPubkey) { $cmd = $this->jaklisPath; $cmd .= ' --key '. $this->userPubsecPath; $cmd .= ' --node http://'. $this->nodes['gchange']; $cmd .= ' send'; $cmd .= ' --destinataire "' . $this->jescape($toPubkey) . '"'; $cmd .= ' --titre "' . $this->jescape($title) . '"'; $cmd .= ' --message "' . $this->jescape($msg) . '"'; // echo '
'. $cmd . '
'; $output=null; $result_code=null; exec($cmd, $output, $result_code); // echo '
'; var_dump($result_code); echo '
'; // echo '
'; var_dump($output); echo '
'; // list($jaklisResult, $id) = $output; // echo '

'. $jaklisResult .'

'; } }