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"]); } }
public static function addNotification($userId, $item) { $col = \App\DB\Get::Collection(); $col->users->update(array("userid" => $userId), array('$inc' => array('counter_notify' => 1))); $item["owner"] = $userId; $item["time"] = new \MongoDate(); $col->notifications->insert($item); $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))); clog("ADD NOTIGF SENT3"); }
public static function checkX509($object, $pkey) { //echo 'JSON JS EXPORTED: {"test":"esr"} vs '.json_encode($object["object"]). "<br><br> SIGNATURE VALUE:". $object["signature"]["hashvalue"]."<br><br>"; //echo "signature is".($object["signature"]["hashvalue"]); // $json = ' {"object":{"test":"esr"},"signature":{"keyRevision":2,"hashvalue":"3af9b3a1aa867ccc4f99e8b00d4de6943eab4ad7d484087f94f3b66b3704b264f6817d4751bd3b443b69438048ccc10f62ef7f9b73472276773b73398794669bd4fd5c47dda07a6ca8a1ea7cdb69261abb45f1258c8f089197047768786945c32e9ac29a89b5d69c6115e3444565d0ecca9d7b886836bf0ef8662bf4fc97759ca7cc70dc7e4abbce14090ff0d4a2a2fc5062d2f637b8de71200d535d3c4b6bda1abf6cdcc99e3bf55d891e17711c35653d4fa2f86418a8cd6be6144a4fea608f661d8a8927a0e8870bc4e682bcf2112153b87500e551132bab112a27f05daf0e173af62334165523b45b11300784e80f056fd04a51715509885ff781d56d450d"}}'; clog("sign is: " . hex2bin($object["signature"]["hashvalue"])); clog("object is:" . json_encode($object["object"])); // JSON_UNESCAPED_SLASHES is important, as it does not match with the javascript function JSON.stringify otherwise (an will crash signature verification). $ok = openssl_verify(json_encode($object["object"], JSON_UNESCAPED_SLASHES), hex2bin($object["signature"]["hashvalue"]), openssl_pkey_get_public($pkey), "sha1WithRSAEncryption"); if ($ok == 1) { return true; } elseif ($ok == 0) { return false; } else { return -1; } }
function send($debug = false, $priority = 1, $tries = 0) { //clog("SEND PLAYLOAD IS"); clog2($this->payload); $dest = explode('@', $this->destination); $server = $dest[1]; $url = $server . "/charme/req.php"; $data_string = json_encode($this->payload); //clog("DATA STRING IS"); //clog($data_string); $fields = array('d' => urlencode($data_string), 'receiver' => urlencode($dest[0]), 'sender' => urlencode($this->source)); $fields_string = ""; foreach ($fields as $key => $value) { $fields_string .= $key . '=' . $value . '&'; } rtrim($fields_string, '&'); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, count($fields)); curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string); curl_setopt($ch, CURLOPT_TIMEOUT, 2); // 2 seconds timeout, servers have to respond fast! // Return result and not status code for curl_exec. This is very important curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); $result = curl_exec($ch); if (curl_errno($ch)) { $cha = 0; if (isset($ch)) { $cha = $ch; } $this->givePostman($priority, $cha, intval($tries) + 1); } curl_close($ch); if ($debug) { // Use $plain=true for debugging echo str_replace('$', '\\$', $result); } clog($result); // Only decode if no local request!!! return json_decode($result, true); }
function clog2($ar, $prefix = "") { clog($prefix . " " . print_r($ar, true)); }
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; }
break; case "collection_delete": $col = \App\DB\Get::Collection(); $realCollectionID = $item["signature"]["object"]["collectionId"]; if ($col->collections->count(array("owner" => $_SESSION["charme_userid"], "_id" => new MongoId($realCollectionID))) > 0) { $col->collections->remove(array("owner" => $_SESSION["charme_userid"], "_id" => new MongoId($realCollectionID))); $col->follower->remove(array("collectionId" => new MongoId($realCollectionID))); $col->following->remove(array("collectionId" => new MongoId($realCollectionID))); //$col->posts->remove(array("collectionId" => new MongoId($item["collectionId"]))); // MAKE DELETE POST FUNCTION!!!!! // TODO: Notify other servers! $dbReturn2 = $col->posts->find(array("collectionId" => $realCollectionID)); foreach ($dbReturn2 as $item_post) { $postId = $item_post["_id"]; // Type is MongoId here clog($postId . " is a postId"); // Delete postkeys $col->postkeys->remove(array("postId" => $item_post["_id"]->__toString(), "postOwner" => $_SESSION["charme_userid"])); // Delete post local first } $dbReturn2 = $col->followers->find(array("collectionId" => new MongoId($realCollectionID))); foreach ($dbReturn2 as $m_item) { // Now we notifiy the followers server $data = array("requests" => array(array("id" => "collection_delete_receive", "signature" => $item["signature"], "userId" => $_SESSION["charme_userid"]))); $req21 = new \App\Requests\JSON($m_item["follower"], $_SESSION["charme_userid"], $data); $arr = $req21->givePostman(2); // Queue the message. Call Distribute::start() to send it out! } \App\Hydra\Distribute::start(); $returnArray[$action] = array("STATUS" => "OK"); } else {
function ok($logfile) { clog('Form successfully sent', $logfile); response(200, 'danke'); }
<?php $doctor_id = $_SESSION["user_id"]; $q_get_pacients = "SELECT * FROM patient,doctor,queue WHERE patient.patient_id = queue.patient_id AND doctor.id = queue.doctor_id AND queue.doctor_id = {$doctor_id} ORDER BY queue.wait_idx;"; $res = mysqli_query($dbc, $q_get_pacients); clog(mysqli_error($dbc)); ?> <div class="sider_label"> <h4>Waiting patients</h1> <button type="button"class="btn btn-success">Next patient</button> </div> <ul class="list-group" id="patient_order"> <?php while ($row = mysqli_fetch_assoc($res)) { ?> <li class="ui-state-default active" id="<?php echo $row['patient_id']; ?> "> <a href="#" class="onlist_patient list-group-item"> <h4 class="list-group-item-heading"> <span class="wait_name"></span> <span class="wait_surname"></span> </h4> <p class="list-group-item-text"> <span class="wait_age"></span> <span class="wait_gender"></span> <span class="wait_born"></span>