Ejemplo n.º 1
0
 /**
  * API to get versions of the source, filesystem and database
  *
  * @return string Standard JSON envelope
  */
 public function version()
 {
     getAuthentication()->requireAuthentication();
     $apiVersion = Request::getLatestApiVersion();
     $systemVersion = getConfig()->get('site')->lastCodeVersion;
     $databaseVersion = getDb()->version();
     $databaseType = getDb()->identity();
     $filesystemVersion = '0.0.0';
     $filesystemType = getFs()->identity();
     return $this->success('System versions', array('api' => $apiVersion, 'system' => $systemVersion, 'database' => $databaseVersion, 'databaseType' => $databaseType, 'filesystem' => $filesystemVersion, 'filesystemType' => $filesystemType));
 }
Ejemplo n.º 2
0
 public function __construct()
 {
     $this->api = getApi();
     $this->config = getConfig()->get();
     $this->logger = getLogger();
     $this->route = getRoute();
     $this->session = getSession();
     $this->cache = getCache();
     // really just for setup when the systems don't yet exist
     if (isset($this->config->systems)) {
         $this->db = getDb();
         $this->fs = getFs();
     }
 }
Ejemplo n.º 3
0
 public function home()
 {
     $db = getDb();
     $fs = getFs();
     $params = array();
     $params['systems'] = array('FileSystem' => $this->config->systems->fileSystem);
     $params['aws'] = array('bucket' => $this->config->aws->s3BucketName);
     $params['email'] = $this->config->user->email;
     //$params['diagnostics'] = array('db' => $db->diagnostics(), 'fs' => $fs->diagnostics());
     $params['navigation'] = $this->manageController->getNavigation('account');
     $bodyTemplate = sprintf('%s/account.php', $this->config->paths->templates);
     $body = $this->template->get($bodyTemplate, $params);
     $this->theme->display('template.php', array('body' => $body, 'page' => 'account'));
 }
            nonce_check();
            exit(doSaveEdit($subject, $path));
        case 'copy':
            nonce_check();
            exit(doCopy($subject, $path));
        case 'move':
            nonce_check();
            exit(doMove($subject, $path));
        case 'moveList':
            exit(moveList($subject, $path));
        case 'installCodeMirror':
            exit(installCodeMirror());
        case 'fileExists':
            exit(file_exists($path . '/' . $subject));
        case 'getfs':
            exit(getFs($path . '/' . $subject));
        case 'remoteCopy':
            nonce_check();
            exit(doRemoteCopy($path));
    }
}
/**
 * no action; list current directory
 */
getDirContents($path);
/**
 * helper functions
 */
/**
 * @return bool returns true if any empty values are passed
 */
Ejemplo n.º 5
0
 /**
  * Posts the setup values from step 3 of the form, checks them, and saves in session
  *
  * @return void HTTP redirect (home)
  */
 public function setup3Post()
 {
     getSession()->set('isEditMode', isset($_GET['edit']));
     $isEditMode = getSession()->get('isEditMode');
     extract($this->getDefaultConfigParams());
     $step = 3;
     $secret = $this->getSecret();
     $database = getSession()->get('database');
     $filesystem = getSession()->get('filesystem');
     $appId = getSession()->get('appId');
     $usesAws = getSession()->get('database') == 'SimpleDb' || stristr(getSession()->get('fileSystem'), 'S3') !== false ? true : false;
     $usesMySql = getSession()->get('database') == 'MySql' ? true : false;
     $usesSimpleDb = getSession()->get('database') == 'SimpleDb' ? true : false;
     $usesLocalFs = stristr(getSession()->get('fileSystem'), 'Local') !== false ? true : false;
     $usesS3 = stristr(getSession()->get('fileSystem'), 'S3') !== false ? true : false;
     $usesDropbox = stristr(getSession()->get('fileSystem'), 'Dropbox') !== false ? true : false;
     $awsErrors = false;
     $mySqlErrors = false;
     $localFsErrors = false;
     $fsErrors = false;
     $dbErrors = false;
     $writeErrors = false;
     if ($usesAws) {
         $awsKey = $_POST['awsKey'];
         $awsSecret = $_POST['awsSecret'];
         $input = array(array('Amazon Access Key ID', $awsKey, 'required'), array('Amazon Secret Access Key', $awsSecret, 'required'));
         if ($usesS3) {
             $s3Bucket = $_POST['s3Bucket'];
             $input[] = array('Amazon S3 Bucket Name', $s3Bucket, 'required');
         }
         if ($usesSimpleDb) {
             $simpleDbDomain = $_POST['simpleDbDomain'];
             $input[] = array('Amazon SimpleDb Domain', $simpleDbDomain, 'required');
         }
         $awsErrors = getForm()->hasErrors($input);
     }
     if ($usesMySql) {
         $mySqlHost = $_POST['mySqlHost'];
         $mySqlUser = $_POST['mySqlUser'];
         $mySqlPassword = $_POST['mySqlPassword'];
         $mySqlDb = $_POST['mySqlDb'];
         $mySqlTablePrefix = $_POST['mySqlTablePrefix'];
         $input = array(array('MySQL Host', $mySqlHost, 'required'), array('MySQL Username', $mySqlUser, 'required'), array('MySQL Password', $mySqlPassword, 'required'), array('MySQL Database', $mySqlDb, 'required'));
         $mySqlErrors = getForm()->hasErrors($input);
     }
     if ($usesLocalFs) {
         $fsRoot = $_POST['fsRoot'];
         $fsHost = $_POST['fsHost'];
         $input = array(array('File System Root', $fsRoot, 'required'), array('File System Host', $fsHost, 'required'));
         $localFsErrors = getForm()->hasErrors($input);
     }
     if ($usesDropbox) {
         $dropboxKey = $_POST['dropboxKey'];
         $dropboxSecret = $_POST['dropboxSecret'];
         $dropboxToken = $_POST['dropboxToken'];
         $dropboxTokenSecret = $_POST['dropboxTokenSecret'];
         $dropboxFolder = $_POST['dropboxFolder'];
     }
     if ($awsErrors === false && $mySqlErrors === false && $localFsErrors === false) {
         $credentials = new stdClass();
         if ($usesAws) {
             getSession()->set('awsKey', $this->utility->encrypt($awsKey, $secret));
             getSession()->set('awsSecret', $this->utility->encrypt($awsSecret, $secret));
             $credentials->awsKey = $this->utility->encrypt($awsKey, $secret);
             $credentials->awsSecret = $this->utility->encrypt($awsSecret, $secret);
             $aws = new stdClass();
             if ($usesS3) {
                 getSession()->set('s3BucketName', $s3Bucket);
                 $aws->s3BucketName = $s3Bucket;
                 $aws->s3Host = "{$s3Bucket}.s3.amazonaws.com";
             }
             if ($usesSimpleDb) {
                 getSession()->set('simpleDbDomain', $simpleDbDomain);
                 $aws->simpleDbDomain = $simpleDbDomain;
             }
         }
         if ($usesMySql) {
             getSession()->set('mySqlHost', $mySqlHost);
             getSession()->set('mySqlUser', $mySqlUser);
             getSession()->set('mySqlPassword', $this->utility->encrypt($mySqlPassword, $secret));
             getSession()->set('mySqlDb', $mySqlDb);
             getSession()->set('mySqlTablePrefix', $mySqlTablePrefix);
             $mysql = new stdClass();
             $mysql->mySqlHost = $mySqlHost;
             $mysql->mySqlUser = $mySqlUser;
             $mysql->mySqlPassword = $this->utility->encrypt($mySqlPassword, $secret);
             $mysql->mySqlDb = $mySqlDb;
             $mysql->mySqlTablePrefix = $mySqlTablePrefix;
         }
         if ($usesLocalFs) {
             getSession()->set('fsRoot', $fsRoot);
             getSession()->set('fsHost', $fsHost);
             $fs = new stdClass();
             $fs->fsRoot = $fsRoot;
             $fs->fsHost = $fsHost;
         }
         if ($usesDropbox) {
             getSession()->set('dropboxKey', $this->utility->encrypt($dropboxKey, $secret));
             getSession()->set('dropboxSecret', $this->utility->encrypt($dropboxSecret, $secret));
             getSession()->set('dropboxToken', $this->utility->encrypt($dropboxToken, $secret));
             getSession()->set('dropboxTokenSecret', $this->utility->encrypt($dropboxTokenSecret, $secret));
             getSession()->set('dropboxFolder', $dropboxFolder);
             $credentials->dropboxKey = $this->utility->encrypt($dropboxKey, $secret);
             $credentials->dropboxSecret = $this->utility->encrypt($dropboxSecret, $secret);
             $credentials->dropboxToken = $this->utility->encrypt($dropboxToken, $secret);
             $credentials->dropboxTokenSecret = $this->utility->encrypt($dropboxTokenSecret, $secret);
             $dropbox = new stdClass();
             $dropbox->dropboxFolder = $dropboxFolder;
         }
         $systems = new stdClass();
         $systems->database = getSession()->get('database');
         $systems->fileSystem = getSession()->get('fileSystem');
         $secrets = new stdClass();
         $secrets->secret = $this->getSecret();
         $user = new stdClass();
         $user->email = getSession()->get('ownerEmail');
         // save the config info
         getConfig()->set('credentials', $credentials);
         if ($usesAws) {
             getConfig()->set('aws', $aws);
         }
         if ($usesMySql) {
             getConfig()->set('mysql', $mysql);
         }
         if ($usesLocalFs) {
             getConfig()->set('localfs', $fs);
         }
         if ($usesDropbox) {
             getConfig()->set('dropbox', $dropbox);
         }
         getConfig()->set('systems', $systems);
         getConfig()->set('secrets', $secrets);
         getConfig()->set('user', $user);
         $fsObj = getFs();
         $dbObj = getDb();
         $serverUser = exec("whoami");
         if (!$fsObj->initialize($isEditMode)) {
             if ($usesAws) {
                 $fsErrors[] = 'We were unable to initialize your S3 bucket.<ul><li>Make sure you\'re <a href="http://aws.amazon.com/s3/">signed up for AWS S3</a>.</li><li>Double check your AWS credentials.</li><li>S3 bucket names are globally unique, make sure yours isn\'t already in use by someone else.</li><li>S3 bucket names can\'t have certain special characters. Try using just alpha-numeric characters and periods.</li></ul>';
             } else {
                 if ($usesLocalFs) {
                     $fsErrors[] = "We were unable to set up your local file system using <em>{$fsObj->getRoot()}</em>. Make sure that the following user has proper permissions ({$serverUser}).";
                 } else {
                     $fsErrors[] = 'An unknown error occurred while setting up your file system. Check your error logs to see if there\'s more information about the error.';
                 }
             }
         }
         if (!$dbObj->initialize($isEditMode)) {
             if ($usesAws) {
                 $dbErrors[] = 'We were unable to initialize your SimpleDb domains.<ul><li>Make sure you\'re <a href="http://aws.amazon.com/simpledb/">signed up for AWS SimpleDb</a>.</li><li>Double check your AWS credentials.</li><li>SimpleDb domains cannot contain special characters such as periods.</li><li>Sometimes the SimpleDb create domain API is unstable. Try again later or check the error log if you have access to it.</li></ul>';
             } else {
                 if ($usesMySql) {
                     $dbErrors[] = 'We were unable to initialize your account in MySql. <ul><li>Please verify that the host, username and password are correct and have proper permissions to create a database.</li><li>Make sure your email address is not already in use.</li></ul>';
                 } else {
                     $dbErrors[] = 'An unknown error occurred while setting up your database. Check your error logsto see if there\'s more information about the error.';
                 }
             }
             $dbErrors = array_merge($dbErrors, $dbObj->errors());
         }
         if ($fsErrors === false && $dbErrors === false) {
             $writeError = $this->writeConfigFile();
             if ($writeErrors === false) {
                 if (isset($_GET['edit'])) {
                     $this->route->redirect('/?m=welcome');
                 } else {
                     // setting up a new site, we should log them in and redirect them to the upload form (Gh-290)
                     $this->user->setEmail($user->email);
                     $this->route->redirect('/photos/upload?m=welcome');
                 }
             } else {
                 $writeErrors[] = "We were unable to save your settings file. Please make sure that the following user has proper permissions to write to src/configs ({$user}).";
             }
         }
     }
     // combine all errors if they exist
     $errors = array();
     if (is_array($awsErrors)) {
         $errors = array_merge($errors, $awsErrors);
     }
     if (is_array($mySqlErrors)) {
         $errors = array_merge($errors, $mySqlErrors);
     }
     if (is_array($localFsErrors)) {
         $errors = array_merge($errors, $localFsErrors);
     }
     if (is_array($fsErrors)) {
         $errors = array_merge($errors, $fsErrors);
     }
     if (is_array($dbErrors)) {
         $errors = array_merge($errors, $dbErrors);
     }
     if (is_array($writeErrors)) {
         $errors = array_merge($errors, $writeErrors);
     }
     $qs = '';
     if (isset($_GET['edit'])) {
         $qs = '?edit';
     }
     $template = sprintf('%s/setup.php', getConfig()->get('paths')->templates);
     // copied to/from setup3()
     $body = $this->template->get($template, array('step' => $step, 'themes' => $themes, 'usesAws' => $usesAws, 'usesMySql' => $usesMySql, 'database' => $database, 'filesystem' => $filesystem, 'usesLocalFs' => $usesLocalFs, 'usesS3' => $usesS3, 'usesSimpleDb' => $usesSimpleDb, 'awsKey' => $awsKey, 'awsSecret' => $awsSecret, 's3Bucket' => $s3Bucket, 'simpleDbDomain' => $simpleDbDomain, 'mySqlHost' => $mySqlHost, 'mySqlUser' => $mySqlUser, 'mySqlDb' => $mySqlDb, 'mySqlPassword' => $mySqlPassword, 'mySqlTablePrefix' => $mySqlTablePrefix, 'fsRoot' => $fsRoot, 'fsHost' => $fsHost, 'usesDropbox' => $usesDropbox, 'dropboxKey' => $dropboxKey, 'dropboxSecret' => $dropboxSecret, 'dropboxToken' => $dropboxToken, 'dropboxTokenSecret' => $dropboxTokenSecret, 'dropboxFolder' => $dropboxFolder, 'qs' => $qs, 'appId' => $appId, 'errors' => $errors));
     $this->theme->display('template.php', array('body' => $body, 'page' => 'setup'));
 }
Ejemplo n.º 6
0
 public function settingsPost()
 {
     getAuthentication()->requireAuthentication();
     getAuthentication()->requireCrumb();
     $configFile = $this->utility->getConfigFile(true);
     $configString = getConfig()->getString($configFile);
     $configArray = parse_ini_string($configString, true);
     // set defaults since checkbox values are not passed if unchecked
     $post = array_merge(array('enableBetaFeatures' => 0, 'allowDuplicate' => 0, 'downloadOriginal' => 0, 'hideFromSearchEngines' => 0, 'decreaseLocationPrecision' => 0), $_POST);
     foreach ($post as $key => $value) {
         switch ($key) {
             case 'admins':
                 $configArray['user']['admins'] = implode(',', (array) $value);
                 break;
             case 'enableBetaFeatures':
                 $configArray['site']['enableBetaFeatures'] = (string) intval($value);
                 break;
             case 'allowDuplicate':
                 $configArray['site']['allowDuplicate'] = (string) intval($value);
                 break;
             case 'downloadOriginal':
                 $configArray['site']['allowOriginalDownload'] = (string) intval($value);
                 break;
             case 'hideFromSearchEngines':
                 $configArray['site']['hideFromSearchEngines'] = (string) intval($value);
                 break;
             case 'decreaseLocationPrecision':
                 $configArray['site']['decreaseLocationPrecision'] = (string) intval($value);
                 break;
             case 'fileSystem':
                 // validate this is an existing file system
                 try {
                     $testFs = getFs($value, false);
                     $configArray['systems']['fileSystem'] = $value;
                 } catch (Exception $e) {
                     $this->logger->warn(sprintf('Unable to find the specified file system adapter (%s)', $value), $e);
                 }
                 break;
             case 'credentials':
             case 'box':
             case 'aws':
             case 'dropbox':
                 if (empty($value)) {
                     continue;
                 }
                 // if credentials we need to encrypt
                 if ($key === 'credentials') {
                     $tmpCredentials = json_decode($value, true);
                     foreach ($tmpCredentials as $k => $v) {
                         $tmpCredentials[$k] = $this->utility->encrypt($v);
                     }
                     $value = json_encode($tmpCredentials);
                 }
                 // we do a merge here since it's an array of values and we don't want to clobber values not passed in
                 if (isset($configArray[$key])) {
                     $configArray[$key] = array_merge($configArray[$key], json_decode($value, true));
                 } else {
                     $configArray[$key] = json_decode($value, true);
                 }
                 break;
         }
     }
     $res = getConfig()->write($configFile, $this->utility->generateIniString($configArray, true));
     if ($res) {
         return $this->success('Features successfully updated', true);
     } else {
         return $this->error('Could not update features', false);
     }
 }