Example #1
0
File: relay.php Project: pedra/limp
 function decMSG($msg)
 {
     if (!isset($msg->id)) {
         return false;
     }
     //get key
     $this->db->query('SELECT * FROM users WHERE ID = :id', [':id' => $msg->id]);
     $rs = $this->db->result();
     if ($rs === false) {
         return false;
     }
     $rs = $rs[0];
     Lib\Aes::size(256);
     $dec = Lib\Aes::dec($msg->msg, $rs->SKEY);
     if (!$dec) {
         return false;
     }
     $ret = json_decode($dec);
     $ret->name = $rs->NAME;
     $ret->userid = $rs->ID;
     return $ret;
 }
Example #2
0
 /** Decodifica entrada via Post
  *
  *
  */
 function _decodePostData()
 {
     if (!isset($_POST['data'])) {
         return false;
     }
     $rec = json_decode($_POST['data']);
     //Se não for JSON...
     if (!is_object($rec)) {
         return false;
     }
     if (isset($rec->enc)) {
         //$zumbi = new Model\Zumbi;
         $this->key = $this->model->getUserKey($rec->id);
         if ($this->key === false) {
             return false;
         }
         //Decriptando
         Lib\Aes::size(256);
         return ['data' => $rec, 'dec' => json_decode(Lib\Aes::dec($rec->enc, $this->key))];
     }
     return ['data' => $rec];
 }
Example #3
0
 private function saveFile($rec)
 {
     $key = $this->getKey($rec->tk);
     if ($key === false) {
         exit;
     }
     //se a KEY não existir, sai em silêncio
     //Decodifica
     Lib\Aes::size(256);
     $dec = Lib\Aes::dec($rec->file, $key);
     //Se a chave não for identica, sai.
     if (!$dec) {
         exit;
     }
     $dir = App::upload() . $rec->tk . '/';
     if (!is_dir($dir)) {
         mkdir($dir, 0777, true);
         chmod($dir, 0777);
     }
     $can = new Lib\Can();
     $name = str_shuffle($can->encode(microtime(true) * 100000 / 2) . $can->encode(microtime(true) * 100000 / 3));
     file_put_contents($dir . $name, base64_decode($dec));
     exit(json_encode(['name' => $name]));
 }