forked from La_Bureautique/zeg1jeux
120 lines
2.5 KiB
PHP
120 lines
2.5 KiB
PHP
|
<?php
|
||
|
|
||
|
require_once('Fred.class.php');
|
||
|
|
||
|
class Jaklis {
|
||
|
|
||
|
private $mode = 'local';
|
||
|
|
||
|
private $jaklisPath = __DIR__ . '/../vendors/jaklis/jaklis';
|
||
|
|
||
|
private $nodes = [
|
||
|
|
||
|
'gchange' => 'data.gchange.fr'
|
||
|
];
|
||
|
|
||
|
private $msgLimit = 30;
|
||
|
|
||
|
private $userPubsecPath;
|
||
|
|
||
|
|
||
|
public function __construct ($userPubkey) {
|
||
|
|
||
|
$this->userPubsecPath = __DIR__ .'/../cache/pubsec/'. $userPubkey .'.dunikey';
|
||
|
}
|
||
|
|
||
|
public function getMessages () {
|
||
|
|
||
|
if ($mode = 'local') {
|
||
|
|
||
|
return [
|
||
|
|
||
|
$this->getInboundMessages(),
|
||
|
$this->getOutboundMessages()
|
||
|
];
|
||
|
|
||
|
} else {
|
||
|
|
||
|
$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);
|
||
|
|
||
|
$json = implode("\n", $output);
|
||
|
|
||
|
// echo '<p>' . $cmd . '</p>';
|
||
|
// echo '<pre>'; var_dump($json); echo '</pre>';
|
||
|
|
||
|
$result = json_decode($json);
|
||
|
|
||
|
// echo '<pre>'; var_dump($result); echo '</pre>';
|
||
|
|
||
|
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);
|
||
|
|
||
|
$json = implode("\n", $output);
|
||
|
|
||
|
// echo '<p>' . $cmd . '</p>';
|
||
|
// echo '<pre>'; var_dump($json); echo '</pre>';
|
||
|
|
||
|
$result = json_decode($json);
|
||
|
|
||
|
// echo '<pre>'; var_dump($result); echo '</pre>';
|
||
|
|
||
|
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 '<pre>'. $cmd . '</pre>';
|
||
|
|
||
|
$output=null;
|
||
|
$result_code=null;
|
||
|
exec($cmd, $output, $result_code);
|
||
|
|
||
|
// echo '<pre>'; var_dump($result_code); echo '</pre>';
|
||
|
// echo '<pre>'; var_dump($output); echo '</pre>';
|
||
|
// list($jaklisResult, $id) = $output;
|
||
|
// echo '<p>'. $jaklisResult .'</p>';
|
||
|
}
|
||
|
}
|
||
|
|