Пример #1
0
 /**
  * Get the singleton dictionary
  * @param bool $dbname Database name.
  * @return db/bool
  */
 public static function getguid()
 {
     if (!self::$m_pInstance) {
         self::$m_pInstance = new GUID();
     }
     return self::$m_pInstance;
 }
Пример #2
0
 /**
  * Helper function in order to upload an image
  * in the future it will use imagine library for resizing
  * @param  [laravel file] $file [the request file]
  * @return [array]  status=>ok|error, fileName=>$name
  */
 protected function uploadImageFile($file)
 {
     $extensions = ['png', 'jpeg', 'jpg', 'gif'];
     $maxSize = 1024 * 2000;
     // 200kb supposedly
     $path = public_path() . "/uploads/avatars";
     $status = null;
     $fileName = null;
     $status = null;
     $ext = $file->guessClientExtension();
     $size = $file->getClientSize();
     $name = GUID::generate() . ".{$ext}";
     if (in_array($ext, $extensions) and $size < $maxSize) {
         if ($file->move($path, $name)) {
             $status = 'ok';
         } else {
             $status = 'error';
         }
     } else {
         $status = 'error';
     }
     return ['status' => $status, 'fileName' => $name];
 }
Пример #3
0
print "Base16 encoded in UTF-8: " . $b16enc . "<br/>";
print "Base16 decoded in UTF-8: " . $b16dec . "<br/><br/>\n";
/**
* Test Base64 encoding.
*/
$b64enc = Base64::encode($input);
$b64dec = Base64::decode($b64enc);
//
print "Base64 encoded in UTF-8: " . $b64enc . "<br/>";
print "Base64 decoded in UTF-8: " . $b64dec . "<br/><br/>\n";
/**
* Test creating GUID's.
*/
print "Created GUID 1: " . GUID::create() . "<br/>";
print "Created GUID 2: " . GUID::create() . "<br/>";
print "Created GUID 3: " . GUID::create() . "<br/><br/>\n";
/**
* Test ROT13 encoding.
*/
$rot13enc = ROT13::encode($input);
$rot13dec = ROT13::decode($rot13enc);
//
print "ROT13 encoded in UTF-8: " . $rot13enc . "<br/>\n";
print "ROT13 decoded in UTF-8: " . $rot13dec . "<br/><br/>\n";
/**
* Test MD5 with one official test vector and custom input.
* Vectors from: http://www.febooti.com/products/filetweak/members/hash-and-crc/test-vectors/
*/
$md5 = MD5::compute($input);
$md5tv = MD5::compute("");
$md5hmac = MD5::computeHMAC("1234567890123456", $input);
Пример #4
0
 public function execute(Request $request)
 {
     if (LOGGING) {
         Log::log(LoggingConstants::DEBUG, "commandmessage " . $this->operation . " operation");
     }
     /*Object*/
     $returnValue = null;
     if ($this->operation == "0") {
         /*IDestination*/
         $destObj = ORBConfig::getInstance()->getDataServices()->getDestinationManager()->getDestination($this->destination);
         /*Hashtable*/
         $headers = array();
         if ($destObj != null) {
             /*String*/
             $selectorName = $this->headers["DSSelector"];
             /*String*/
             $subtopic = $this->headers["DSSubtopic"];
             /*String*/
             $dsId = $this->headers["DSId"];
             /*Subscriber*/
             $subscriber = new Subscriber($selectorName, $destObj);
             $subscriber->setDSId($dsId);
             $subscriber->setSubtopic($subtopic);
             $guid = new GUID();
             $subscriber->setClientId($guid->toString());
             SubscriptionsManager::getInstance()->addSubscriber($dsId, $subscriber);
             $destObj->getServiceHandler()->handleSubscribe($subscriber);
         } else {
             /*String*/
             $error = "Unknown destination " . $this->destination . ". Cannot handle subscription request";
             if (LOGGING) {
                 Log::log(LoggingConstants::ERROR, $error);
             }
             return new ErrMessage($this->messageId, new Exception($error));
         }
         return new AckMessage($this->messageId, $clientId, null, $headers);
     } else {
         if ($this->operation == "1") {
             /*String*/
             $dsId = $this->headers["DSId"];
             /*Subscriber*/
             $subscriber = SubscriptionsManager::getInstance()->getSubscriber($dsId);
             if ($subscriber == null) {
                 return new ErrMessage($this->messageId, new Exception("Unable to unsubscribe - unknown client"));
             }
             /*IDestination*/
             $destination = $subscriber->getDestination();
             $destination->getServiceHandler()->handleUnsubscribe($subscriber);
             SubscriptionsManager::getInstance()->removeSubscriber($dsId);
         } else {
             if ($this->operation == "2") {
                 /*String*/
                 $dsId = $this->headers["DSId"];
                 /*Subscriber*/
                 $subscriber = SubscriptionsManager::getInstance()->getSubscriber($dsId);
                 if ($subscriber == null) {
                     /*String*/
                     $error = "Invalid client id " . $dsId;
                     if (LOGGING) {
                         Log::log(LoggingConstants::ERROR, $error);
                     }
                     return new ErrMessage($this->messageId, new Exception($error));
                 }
                 /*IDestination*/
                 $destination = $subscriber->getDestination();
                 //Log::log( LoggingConstants::INFO, "Getting messages from " . $destination->getServiceHandler() );
                 /*ArrayList*/
                 $messages = $destination->getServiceHandler()->getMessages($subscriber);
                 $subscriber->setLastRequestTime(microtime(true));
                 if (count($messages) == 0) {
                     return new AckMessage(null, null, null, array());
                 }
                 return $this->createCmdMessage("4", $messages);
             } else {
                 if ($this->operation == "5") {
                     /*Hashtable*/
                     $headers = array();
                     $guid = new GUID();
                     $headers["DSId"] = $guid->toString();
                     return new AckMessage($this->messageId, $this->clientId, null, $headers);
                 } else {
                     if ($this->operation == "9") {
                         ThreadContext::setCallerCredentials(null);
                     } else {
                         if ($this->operation == "8") {
                             $arr = $this->body->getBody();
                             $adaptingType = $arr[0];
                             $authData = split(":", base64_decode($adaptingType->defaultAdapt()));
                             $credentials = new Credentials($authData[0], $authData[1]);
                             $authHandler = ORBSecurity::getAuthenticationHandler(ThreadContext::getORBConfig());
                             if (LOGGING) {
                                 Log::log(LoggingConstants::DEBUG, "got auth handler " . get_class($authHandler));
                             }
                             if ($authHandler == null) {
                                 $errorMessage = new ErrMessage($this->messageId, new ServiceException("Missing authentication handler"));
                                 $errorMessage->faultCode = "Client.Authentication";
                                 return $errorMessage;
                             }
                             try {
                                 $authHandler->checkCredentials($credentials->getUserId(), $credentials->getPassword(), $request);
                                 if (LOGGING) {
                                     Log::log(LoggingConstants::DEBUG, "credentials are valid ");
                                 }
                                 ThreadContext::setCallerCredentials($credentials);
                             } catch (Exception $e) {
                                 if (LOGGING) {
                                     Log::log(LoggingConstants::EXCEPTION, "authentication exception" . $e);
                                 }
                                 $errorMessage = new ErrMessage($this->messageId, $e);
                                 $errorMessage->faultCode = "Client.Authentication";
                                 return $errorMessage;
                             }
                             return new AckMessage($this->messageId, $this->clientId, null);
                         }
                     }
                 }
             }
         }
     }
     //echo $this->operation; exit;
     return new AckMessage($this->messageId, $this->clientId, $returnValue, array());
 }
Пример #5
0
define('ACTION_DEFAULT', 'view');
$actions = array(ACTION_DEFAULT, 'upload', 'delete', 'detail');
$action = isset($_REQUEST['action']) && in_array($_REQUEST['action'], $actions) ? $_REQUEST['action'] : ACTION_DEFAULT;
switch ($action) {
    case 'upload':
        ob_start();
        $_JSON = array();
        if ($_FILES && isset($_FILES['file']['name'])) {
            foreach ($_FILES['file']['name'] as $key => $fileName) {
                try {
                    $extsAllow = array('png', 'jpeg', 'jpg', 'gif');
                    $fileExt = mb_convert_case(pathinfo($fileName, PATHINFO_EXTENSION), MB_CASE_LOWER);
                    if (!in_array($fileExt, $extsAllow)) {
                        throw new \Exception(sprintf('Разрешены только файлы с расширениями %s.', '<b>' . implode($extsAllow, '</b>, <b>') . '</b>'));
                    }
                    $fileGuid = GUID::generate();
                    $fileNameNew = trim($fileGuid, '{}') . '.' . $fileExt;
                    $fileSize = $_FILES['file']['size'][$key];
                    list($fileImageWidth, $fileImageHeight) = getimagesize($_FILES['file']['tmp_name'][$key]);
                    // insert main data
                    $stmt = DB::getConnection()->prepare("INSERT INTO `file` (file_guid, file_name, file_ext, file_original_name, file_size, file_image_width, file_image_height) VALUES (:file_guid, :file_name, :file_ext, :file_original_name, :file_size, :file_image_width, :file_image_height)");
                    $stmt->bindParam(':file_guid', $fileGuid);
                    $stmt->bindParam(':file_name', $fileNameNew);
                    $stmt->bindParam(':file_ext', $fileExt);
                    $stmt->bindParam(':file_original_name', $fileName);
                    $stmt->bindParam(':file_size', $fileSize);
                    $stmt->bindParam(':file_image_width', $fileImageWidth);
                    $stmt->bindParam(':file_image_height', $fileImageHeight);
                    $stmt->execute();
                    $fileId = DB::getConnection()->lastInsertId();
                    // insert file content
 public function postCreate()
 {
     $platformVersion = new ToolVersion(array('platform_version_uuid' => GUID::create(), 'platform_uuid' => Input::get('platform_uuid'), 'version_string' => Input::get('version_string'), 'release_date' => Input::get('release_date'), 'retire_date' => Input::get('retire_date'), 'notes' => Input::get('notes'), 'platform_path' => Input::get('platform_path'), 'deployment_cmd' => Input::get('deployment_cmd')));
     $platformVersion->save();
     return $platformVersion;
 }
Пример #7
0
function guid()
{
    $GUID = GUID::getguid();
    $id = $GUID->create_guid();
    return $id;
}