예제 #1
0
파일: session.php 프로젝트: uinerd/Code
 /**
  * Destroy current session
  */
 public static function delCurrent()
 {
     // Delete the global object
     if ($session = LigminchaGlobalSession::getCurrent()) {
         lgDebug('Session destroyed', $session);
         LigminchaGlobalDistributed::del(array('id' => $session->id));
     }
     // Delete the SSO cookie
     LigminchaGlobalSSO::delCookie();
 }
예제 #2
0
 /**
  * Called after the page has rendered but before it's been sent to the client
  */
 public function onAfterRender()
 {
     LigminchaGlobalSSO::appendTokenRequest();
     LigminchaGlobalSSO::toolbar();
     LigminchaGlobalDistributed::sendQueue();
 }
예제 #3
0
파일: distributed.php 프로젝트: uinerd/Code
 /**
  * Send all queued sync-objects
  */
 public static function sendQueue()
 {
     // Get all LG_SYNC items, bail if none
     if (!($queue = LigminchaGlobalSync::select())) {
         return false;
     }
     // Make data streams for each target from the sync objects
     $streams = array();
     $server = LigminchaGlobalServer::getCurrent()->id;
     $session = LigminchaGlobalSession::getCurrent() ? LigminchaGlobalSession::getCurrent()->id : 0;
     foreach ($queue as $sync) {
         $target = LigminchaGlobalServer::newFromId($sync->ref1)->id;
         if (array_key_exists($target, $streams)) {
             $streams[$target][] = $sync;
         } else {
             $streams[$target] = array(0, $server, $session, $sync);
         }
     }
     //print '<pre>'; print_r($streams); print '</pre>';
     // Encode and send each stream
     foreach ($streams as $target => $stream) {
         // Get the target domain from it's tag
         $url = LigminchaGlobalServer::newFromId($target)->tag;
         // Zip up the data in JSON format
         // TODO: encrypt using shared secret or public key
         $data = self::encodeData($stream);
         // If we're standalone or the master, ensure no data is routed to the master, mark it as successful so the sync objects are cleared
         if (LigminchaGlobalServer::getCurrent()->isMaster && $url == LigminchaGlobalServer::masterDomain()) {
             $result = LG_SUCCESS;
         } else {
             $result = self::post($url, array(self::$cmd => $data));
         }
         // If result is success, remove all sync objects destined for this target server
         if ($result == LG_SUCCESS) {
             LigminchaGlobalDistributed::del(array('type' => LG_SYNC, 'ref1' => $target), false, true);
         } else {
             die(lgDebug("Failed to post outgoing sync data to {$url} result({$result})"));
         }
     }
     return true;
 }
예제 #4
0
파일: sso.php 프로젝트: uinerd/Code
 /**
  * Make a current session and current user from an SSO session ID cookie (called when running on a master standalone site)
  */
 public static function makeSessionFromCookie()
 {
     if (array_key_exists(self::$cookie, $_COOKIE)) {
         if ($session = LigminchaGlobalSession::selectOne(array('id' => $_COOKIE[self::$cookie]))) {
             if ($user = LigminchaGlobalUser::newFromId($session->owner)) {
                 LigminchaGlobalSession::setCurrent($session);
                 LigminchaGlobalUser::setCurrent($user);
                 lgDebug('Session established from existing SSO cookie', $session);
             } else {
                 lgDebug('SSO session cookie found, but user is no longer logged in (' . substr($_COOKIE[self::$cookie], 0, 5) . ')');
             }
         } else {
             lgDebug('SSO session cookie found, but not in database (' . substr($_COOKIE[self::$cookie], 0, 5) . ')');
         }
         if (!$session || !$user) {
             if ($session) {
                 LigminchaGlobalDistributed::del(array('id' => $session->id));
             }
             self::delCookie();
         }
     } else {
         lgDebug('No SSO session cookie found ' . var_export($_COOKIE, true));
     }
 }
예제 #5
0
파일: object.php 프로젝트: uinerd/Code
 /**
  * Convert a DB row assoc array into a LigminchaGlobalObject or sub-class
  */
 public static function newFromFields($fields)
 {
     $class = 'LigminchaGlobalObject';
     if (array_key_exists($fields['type'], self::$classes)) {
         $c = 'LigminchaGlobal' . self::$classes[$fields['type']];
         if (class_exists($c)) {
             $class = $c;
         }
     }
     $obj = new $class();
     foreach ($fields as $field => $val) {
         $obj->{$field} = LigminchaGlobalDistributed::objField($field, $val);
     }
     $obj->data = LigminchaGlobalDistributed::decodeDataField($obj->data);
     return $obj;
 }