示例#1
0
 public function Check($Type = '', $Name = '')
 {
     if ($Type != '' && $Name != '') {
         $this->AddItem($Type, $Name);
     }
     if (count($this->_Items) > 0) {
         // TODO: Use garden update check url instead of this:
         $UpdateUrl = Url('/lussumo/update', TRUE, TRUE);
         $Host = Gdn_Url::Host();
         $Path = CombinePaths(array(Gdn_Url::WebRoot(), 'lussumo', 'update'), '/');
         $Port = 80;
         /*
         $UpdateUrl = Gdn::Config('Garden.UpdateCheckUrl', '');
         $UpdateUrl = parse_url($UpdateUrl);
         $Host = ArrayValue('host', $UpdateUrl, 'www.lussumo.com');
         $Path = ArrayValue('path', $UpdateUrl, '/');
         $Port = ArrayValue('port', $UpdateUrl, '80');
         */
         $Path .= '?Check=' . urlencode(Format::Serialize($this->_Items));
         $Locale = Gdn::Config('Garden.Locale', 'Undefined');
         $Referer = Gdn_Url::WebRoot(TRUE);
         if ($Referer === FALSE) {
             $Referer = 'Undefined';
         }
         $Timeout = 10;
         $Response = '';
         // Connect to the update server.
         $Pointer = @fsockopen($Host, '80', $ErrorNumber, $Error, $Timeout);
         if (!$Pointer) {
             throw new Exception(sprintf(Gdn::Translate('Encountered an error when attempting to connect to the update server (%1$s): [%2$s] %3$s'), $UpdateUrl, $ErrorNumber, $Error));
         } else {
             // send the necessary headers to get the file
             fputs($Pointer, "GET {$Path} HTTP/1.0\r\n" . "Host: {$Host}\r\n" . "User-Agent: Lussumo Garden/1.0\r\n" . "Accept: */*\r\n" . "Accept-Language: " . $Locale . "\r\n" . "Accept-Charset: utf-8;\r\n" . "Keep-Alive: 300\r\n" . "Connection: keep-alive\r\n" . "Referer: {$Referer}\r\n\r\n");
             // Retrieve the response from the remote server
             while ($Line = fread($Pointer, 4096)) {
                 $Response .= $Line;
             }
             fclose($Pointer);
             // Remove response headers
             $Response = substr($Response, strpos($Response, "\r\n\r\n") + 4);
         }
         $Result = Format::Unserialize($Response);
         // print_r($Result);
         if (is_array($Result)) {
             $this->_Items = $Result;
         } else {
             $Result = FALSE;
         }
         return $Result;
     }
 }
示例#2
0
 /**
  * Force the admin user into UserID 1.
  */
 public function SaveAdminUser($FormPostValues)
 {
     $UserID = 0;
     // Add & apply any extra validation rules:
     $Name = ArrayValue('Name', $FormPostValues, '');
     $FormPostValues['Email'] = ArrayValue('Email', $FormPostValues, strtolower($Name . '@' . Gdn_Url::Host()));
     $FormPostValues['ShowEmail'] = '0';
     $FormPostValues['TermsOfService'] = '1';
     $FormPostValues['DateOfBirth'] = '1975-09-16';
     $FormPostValues['DateLastActive'] = Gdn_Format::ToDateTime();
     $FormPostValues['DateUpdated'] = Gdn_Format::ToDateTime();
     $FormPostValues['Gender'] = 'm';
     $FormPostValues['Admin'] = '1';
     $this->AddInsertFields($FormPostValues);
     if ($this->Validate($FormPostValues, TRUE) === TRUE) {
         $UserID = 1;
         $Fields = $this->Validation->ValidationFields();
         // All fields on the form that need to be validated (including non-schema field rules defined above)
         $Username = ArrayValue('Name', $Fields);
         $Email = ArrayValue('Email', $Fields);
         $Fields = $this->Validation->SchemaValidationFields();
         // Only fields that are present in the schema
         $Fields['UserID'] = 1;
         $Fields['Password'] = array('md5' => $Fields['Password']);
         if ($this->Get($UserID) !== FALSE) {
             $this->SQL->Put($this->Name, $Fields);
         } else {
             // Insert the new user
             $UserID = $this->_Insert($Fields);
             AddActivity($UserID, 'Join', T('Welcome to Vanilla!'));
         }
         $this->SaveRoles($UserID, array(16), FALSE);
     }
     return $UserID;
 }
示例#3
0
 /**
  * Create an admin user account.
  *
  * @param array $FormPostValues
  */
 public function saveAdminUser($FormPostValues)
 {
     $UserID = 0;
     // Add & apply any extra validation rules:
     $Name = val('Name', $FormPostValues, '');
     $FormPostValues['Email'] = val('Email', $FormPostValues, strtolower($Name . '@' . Gdn_Url::Host()));
     $FormPostValues['ShowEmail'] = '0';
     $FormPostValues['TermsOfService'] = '1';
     $FormPostValues['DateOfBirth'] = '1975-09-16';
     $FormPostValues['DateLastActive'] = Gdn_Format::toDateTime();
     $FormPostValues['DateUpdated'] = Gdn_Format::toDateTime();
     $FormPostValues['Gender'] = 'u';
     $FormPostValues['Admin'] = '1';
     $this->addInsertFields($FormPostValues);
     if ($this->validate($FormPostValues, true) === true) {
         $Fields = $this->Validation->validationFields();
         // All fields on the form that need to be validated (including non-schema field rules defined above)
         $Username = val('Name', $Fields);
         $Email = val('Email', $Fields);
         $Fields = $this->Validation->schemaValidationFields();
         // Only fields that are present in the schema
         // Insert the new user
         $UserID = $this->_insert($Fields, array('NoConfirmEmail' => true, 'Setup' => true));
         if ($UserID) {
             $ActivityModel = new ActivityModel();
             $ActivityModel->save(array('ActivityUserID' => $UserID, 'ActivityType' => 'Registration', 'HeadlineFormat' => t('HeadlineFormat.Registration', '{ActivityUserID,You} joined.'), 'Story' => t('Welcome Aboard!')), false, array('GroupBy' => 'ActivityTypeID'));
         }
         $this->saveRoles($UserID, array(16), false);
     }
     return $UserID;
 }
示例#4
0
 /**
  * Allows the configuration of basic setup information in Garden. This
  * should not be functional after the application has been set up.
  */
 public function Configure($RedirectUrl = '')
 {
     $Config = Gdn::Factory(Gdn::AliasConfig);
     $ConfigFile = PATH_CONF . DS . 'config.php';
     // Create a model to save configuration settings
     $Validation = new Gdn_Validation();
     $ConfigurationModel = new Gdn_ConfigurationModel('Configuration', $ConfigFile, $Validation);
     $ConfigurationModel->SetField(array('Garden.Locale', 'Garden.Title', 'Garden.RewriteUrls', 'Garden.WebRoot', 'Garden.Cookie.Salt', 'Garden.Cookie.Domain', 'Database.Name', 'Database.Host', 'Database.User', 'Database.Password'));
     // Set the models on the forms.
     $this->Form->SetModel($ConfigurationModel);
     // Load the locales for the locale dropdown
     // $Locale = Gdn::Locale();
     // $AvailableLocales = $Locale->GetAvailableLocaleSources();
     // $this->LocaleData = array_combine($AvailableLocales, $AvailableLocales);
     // If seeing the form for the first time...
     if (!$this->Form->IsPostback()) {
         // Force the webroot using our best guesstimates
         $ConfigurationModel->Data['Database.Host'] = 'localhost';
         $this->Form->SetData($ConfigurationModel->Data);
     } else {
         // Define some validation rules for the fields being saved
         $ConfigurationModel->Validation->AddRule('Connection', 'function:ValidateConnection');
         $ConfigurationModel->Validation->ApplyRule('Database.Name', 'Connection');
         $ConfigurationModel->Validation->ApplyRule('Garden.Title', 'Required');
         $ConfigurationFormValues = $this->Form->FormValues();
         if ($ConfigurationModel->Validate($ConfigurationFormValues) !== TRUE) {
             // Apply the validation results to the form(s)
             $this->Form->SetValidationResults($ConfigurationModel->ValidationResults());
         } else {
             $Host = Gdn_Url::Host();
             $Domain = Gdn_Url::Domain();
             // Set up cookies now so that the user can be signed in.
             $ConfigurationFormValues['Garden.Cookie.Salt'] = RandomString(10);
             $ConfigurationFormValues['Garden.Cookie.Domain'] = strpos($Host, '.') === FALSE ? '' : $Host;
             // Don't assign the domain if it is a non .com domain as that will break cookies.
             $ConfigurationModel->Save($ConfigurationFormValues);
             // If changing locale, redefine locale sources:
             $NewLocale = 'en-CA';
             // $this->Form->GetFormValue('Garden.Locale', FALSE);
             if ($NewLocale !== FALSE && Gdn::Config('Garden.Locale') != $NewLocale) {
                 $ApplicationManager = new Gdn_ApplicationManager();
                 $PluginManager = Gdn::Factory('PluginManager');
                 $Locale = Gdn::Locale();
                 $Locale->Set($NewLocale, $ApplicationManager->EnabledApplicationFolders(), $PluginManager->EnabledPluginFolders(), TRUE);
             }
             // Set the instantiated config object's db params and make the database use them (otherwise it will use the default values from conf/config-defaults.php).
             $Config->Set('Database.Host', $ConfigurationFormValues['Database.Host']);
             $Config->Set('Database.Name', $ConfigurationFormValues['Database.Name']);
             $Config->Set('Database.User', $ConfigurationFormValues['Database.User']);
             $Config->Set('Database.Password', $ConfigurationFormValues['Database.Password']);
             $Config->ClearSaveData();
             Gdn::FactoryInstall(Gdn::AliasDatabase, 'Gdn_Database', PATH_LIBRARY . DS . 'database' . DS . 'class.database.php', Gdn::FactorySingleton, array(Gdn::Config('Database')));
             // Install db structure & basic data.
             $Database = Gdn::Database();
             $Drop = FALSE;
             // Gdn::Config('Garden.Version') === FALSE ? TRUE : FALSE;
             $Explicit = FALSE;
             try {
                 include PATH_APPLICATIONS . DS . 'garden' . DS . 'settings' . DS . 'structure.php';
             } catch (Exception $ex) {
                 $this->Form->AddError(strip_tags($ex->getMessage()));
             }
             if ($this->Form->ErrorCount() > 0) {
                 return FALSE;
             }
             // Create the administrative user
             $UserModel = Gdn::UserModel();
             $UserModel->DefineSchema();
             $UserModel->Validation->ApplyRule('Name', 'Username', 'Admin username can only contain letters, numbers, and underscores.');
             $UserModel->Validation->ApplyRule('Password', 'Required');
             $UserModel->Validation->ApplyRule('Password', 'Match');
             if (!$UserModel->SaveAdminUser($ConfigurationFormValues)) {
                 $this->Form->SetValidationResults($UserModel->ValidationResults());
             } else {
                 // The user has been created successfully, so sign in now
                 $Authenticator = Gdn::Authenticator();
                 $AuthUserID = $Authenticator->Authenticate(array('Name' => $this->Form->GetValue('Name'), 'Password' => $this->Form->GetValue('Password'), 'RememberMe' => TRUE));
             }
             if ($this->Form->ErrorCount() > 0) {
                 return FALSE;
             }
             // Assign some extra settings to the configuration file if everything succeeded.
             $ApplicationInfo = array();
             include CombinePaths(array(PATH_APPLICATIONS . DS . 'garden' . DS . 'settings' . DS . 'about.php'));
             $Config->Load($ConfigFile, 'Save');
             $Config->Set('Garden.Version', ArrayValue('Version', ArrayValue('Garden', $ApplicationInfo, array()), 'Undefined'));
             $Config->Set('Garden.WebRoot', Gdn_Url::WebRoot());
             $Config->Set('Garden.RewriteUrls', function_exists('apache_get_modules') && in_array('mod_rewrite', apache_get_modules()) ? TRUE : FALSE);
             $Config->Set('Garden.Domain', $Domain);
             $Config->Set('Garden.CanProcessImages', function_exists('gd_info'));
             $Config->Set('Garden.Messages.Cache', 'arr:["Garden\\/Settings\\/Index"]');
             // Make sure that the "welcome" message is cached for viewing
             $Config->Set('EnabledPlugins.HTMLPurifier', 'HtmlPurifier');
             // Make sure html purifier is enabled so html has a default way of being safely parsed
             $Config->Save();
         }
     }
     return $this->Form->ErrorCount() == 0 ? TRUE : FALSE;
 }