Exemple #1
0
 public static function deleteOnRemote($postId)
 {
     $col = \App\DB\Get::Collection();
     $col->streamitems->remove(array("postId" => $postId));
     $col->streamcomments->remove(array("commentData.object.postId" => $postId));
     return true;
 }
Exemple #2
0
 public static function CreateFilterWithList($owner, $context, $name, $lists, $hint = "")
 {
     $col = \App\DB\Get::Collection();
     $data = array("name" => $name, "owner" => $owner, "context" => array($context), "lists" => $lists);
     if ($hint != "") {
         $data["hint"] = $hint;
     }
     $data = array("owner" => $owner, "data" => $data, "createdAt" => new \MongoDate(), "class" => "filter");
     $ret = $col->simpleStorage->insert($data);
     /*
     [_id] => 566b21667f8b9ab70e8b4567
       [owner] => hryCrLzuoTytNiZaXfLY@charme.local
       [data] => Array
           (
               [name] => offer all
               [context] => Array
                   (
                       [0] => offer
                   )
     
               [constraints] => Array
                   (
                   )
     
           )
     
       [createdAt] => MongoDate Object
           (
               [sec] => 1449861478
               [usec] => 398000
           )
     
       [class] => filter
     */
 }
Exemple #3
0
 function givePostman($priority, $errorcode = 0, $tries = 0)
 {
     //clog("POSTMAN PLAYLOAD IS"); clog2($this->payload);
     $message = array("destination" => $this->destination, "source" => $this->source, "payload" => $this->payload);
     // Payload contains request array
     $col = \App\DB\Get::Collection();
     $col->outbox->insert(array("message" => $message, "priority" => $priority, "errorcode" => $errorcode, "tries" => $tries));
 }
Exemple #4
0
 public static function CreateList($listName, $ownerId)
 {
     $col = \App\DB\Get::Collection();
     $content = array("name" => $listName, "owner" => $ownerId);
     if ($listName != "") {
         $ins = $col->lists->insert($content);
         return $content["_id"]->__toString();
     }
     return false;
 }
Exemple #5
0
 public static function Insert($owner, $name, $description)
 {
     $col = \App\DB\Get::Collection();
     $content = array("owner" => $owner, "name" => $name, "description" => $description, "currentlist" => 0);
     $col->collections->insert($content);
     $content3 = array("owner" => $owner, "collectionOwner" => $owner, "collectionId" => new \MongoId($content["_id"]));
     $col->following->insert($content3);
     $content2 = array("follower" => $owner, "collectionId" => new \MongoId($content["_id"]));
     $col->followers->insert($content2);
     return true;
 }
Exemple #6
0
function hunt_postman_fn($job)
{
    clog("gearman Received hunt_postman command");
    // Send items out
    $col = \App\DB\Get::Collection();
    $res2 = $col->outbox->find();
    // TODO: order by priority
    foreach ($res2 as $resItem) {
        $req21 = new \App\Requests\JSON($resItem["message"]["destination"], $resItem["message"]["source"], $resItem["message"]["payload"]);
        // Remove from collection
        $col->outbox->remove(array("_id" => $resItem["_id"]));
        $req21->send(true, $resItem["priority"], $resItem["tries"]);
    }
}
Exemple #7
0
 public static function inc($userId, $counterId)
 {
     $blockIncrement = false;
     if ($counterId == "stream") {
         // Live updates for new stream items!!
         $context = new \ZMQContext();
         // Notifiy events.php which send the notification via web sockets to the client.
         // Send notfication to events.php for push notification to user device.
         $socket = $context->getSocket(\ZMQ::SOCKET_PUSH, 'my pusher');
         $socket->connect("tcp://localhost:5555");
         $socket->send(json_encode(array("type" => "newNotifications", "owner" => $userId)));
         $message = $socket->recv();
         clog2($message);
     }
     if (!$blockIncrement) {
         $col = \App\DB\Get::Collection();
         $col->users->update(array("userid" => $userId), array('$inc' => array('counter_' . $counterId => 1)));
     }
 }
Exemple #8
0
 public static function tryToGet($userId, $revision)
 {
     $col = \App\DB\Get::Collection();
     // Check if public key already exists in your servers key directory
     $result = $col->serverKeyDirectory->count(array("userId" => $userId, "revision" => $revision));
     if ($result < 1) {
         clog("KEY NOT FOUND");
         // If not found -> Send request to $userIds server to get the users public key
         $data = array("requests" => array(array("id" => "key_get", "pem" => true, "revision" => $revision, "profileId" => $userId)));
         $jsonRequest = new \App\Requests\JSON($userId, $userId, $data);
         $reqData = $jsonRequest->send();
         if ($reqData["key_get"]["revision"] == $revision) {
             $col->serverKeyDirectory->insert(array("userId" => $userId, "pemkey" => $reqData["key_get"]["pemkey"], "revision" => $revision));
         }
     }
     $result = $col->serverKeyDirectory->findOne(array("userId" => $userId, "revision" => $revision));
     if ($result != null) {
         return $result["pemkey"];
     } else {
         return false;
     }
 }
Exemple #9
0
//
include_once "config.php";
header('Access-Control-Allow-Origin: ' . $CHARME_SETTINGS["ACCEPTED_CLIENT_URL"]);
header('Access-Control-Allow-Methods: POST, GET, OPTIONS');
// if POST, GET, OPTIONS then $_POST will be empty.
header('Access-Control-Max-Age: 1000');
header('Access-Control-Allow-Headers: Content-Type');
header('Content-type: application/json');
header('Access-Control-Allow-Credentials: true');
session_start();
require_once 'lib/App/ClassLoader/UniversalClassLoader.php';
use Symfony\Component\ClassLoader\UniversalClassLoader;
$loader = new UniversalClassLoader();
$loader->registerNamespaces(array('App' => __DIR__ . '/lib'));
$loader->register();
$col = \App\DB\Get::Collection();
$sel = array("owner" => $_SESSION["charme_userid"], 'key.obj.username' => new MongoRegex('/' . $_GET["q"] . '/i'));
// q is the search query for the autocomplete.
$ar = iterator_to_array($col->keydirectory->find($sel), true);
$keys = array();
$jsonArr = array();
// Filter out duplicates
foreach ($ar as $key => $value) {
    if (!in_array($value["userId"], $keys)) {
        $userId = $value["key"]["obj"]["publicKeyUserId"];
        if ($userId != $_SESSION["charme_userid"]) {
            $keys[] = $userId;
            $jsonArr[] = array("name" => $value["key"]["obj"]["username"], "id" => $userId);
        }
    }
}
 function execute()
 {
     global $CHARME_SETTINGS;
     // Access Attributes over $_GET[formname]
     $data = $this->data;
     /*$m = new Mongo();
     		$db = $m->charme;
     		$collection = $db->users;
     
     
     		$collection->insert($obj);
     		*/
     $arr = array("test" => true);
     $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
     $randomString = '';
     for ($i = 0; $i < 32; $i++) {
         $randomString .= $characters[rand(0, strlen($characters) - 1)];
     }
     /**
      *		Error codes, see jsclient/templates/signup.html:
      *
      *		<div id='error1'>Invalid Registration Code</div>
      *		<div  id='error2'>Invalid characters in username</div>
      *		<div  id='error3'>Username lenght must be between 2 and 30 characters</div>
      *
      *		<div id='error4'>Password lenght must be between 10 and 30 characters</div>
      *		<div id='error5'>Password contains illegal characters</div>
      *		<div id='error6'>Please create a certificate</div>
      *
      *		<div id='error7'>Invalid mail address</div>
      *
      *		<div id='error8'>Invalid server</div>
      *
      *		<div  id='error9'>Name must have between 2 and 30 characters and should not contain special characters</div>
      *
      *		<div  id='error10'>Please accept the terms.</div>
      *		<div  id='error11'>Outdated Charme Client Version. Please update your client software.</div>
      *		error 12: password do not match
      */
     /**
      * Validation part:
      */
     if (strlen($data["username"]) < 2 || strlen($data["username"]) > 30) {
         $arr["error"] = 3;
     } else {
         if ($data["rsa"] == "" || !isset($data["rsa"])) {
             $arr["error"] = 6;
         }
     }
     if ($data["pubkey"] == "") {
         // Has to be tested AFTER rsa key test.
         $arr["error"] = 13;
     } else {
         // Insert user into database...
         $arr["success"] = 1;
         // Registration was successful!
         $obj = array("username" => $data["username"], "password" => $data["hashpass"], "userid" => $data["username"] . "@" . $data["server"], "email" => $data["email"], "firstname" => $data["firstname"], "signedData" => $data["signedData"], "lastname" => $data["lastname"], "name" => $data["firstname"] . " " . $data["lastname"], "salt" => $randomString, "publickey" => json_decode($data["pubkey"], true), "keyring" => $data["rsa"]);
         $col = \App\DB\Get::Collection();
         $col->users->insert($obj);
         $col->localkeydirectory->insert(array("userid" => $data["username"] . "@" . $data["server"], "publicKey" => json_decode($data["pubkey"], true), "revision" => 1, "pemkey" => $data["pemkey"]));
         // Set session Id
         $_SESSION["charme_userid"] = $data["username"] . "@" . $data["server"];
         // Create some default lists
         $friendListId = \App\CRUD\Lists::CreateList("Friends", $_SESSION["charme_userid"]);
         clog("frid list" . $friendListId);
         $colleagues = \App\CRUD\Lists::CreateList("Colleagues", $_SESSION["charme_userid"]);
         $fellow = \App\CRUD\Lists::CreateList("Fellow students", $_SESSION["charme_userid"]);
         \App\CRUD\Filter::CreateFilterWithList($_SESSION["charme_userid"], "offer", "Local Shop", array($friendListId, $colleagues, $fellow), "This filter shows things your friends and colleagues give away. You can create your own filters by clicking on the plus symbol. ");
         \App\CRUD\Filter::CreateFilterWithList($_SESSION["charme_userid"], "activities", "Activities", array($friendListId), "This filter shows your friends activities. You can create your own filters by clicking on the plus symbol. ");
         \App\CRUD\Collections::Insert($_SESSION["charme_userid"], "Things about me (Public)", "Selfies, Stories and mor of me");
         \App\CRUD\Collections::Insert($_SESSION["charme_userid"], "Music and Videos I like (Public)", "Stuff I like so far...");
     }
     return $arr;
 }
Exemple #11
0
 public static function getNotifications($userId)
 {
     $col = \App\DB\Get::Collection();
     return iterator_to_array($col->notifications->find(array("owner" => $userId))->sort(array("time" => -1))->limit(10), false);
 }