Exemplo n.º 1
0
 /**
  * attempt to create an htaccess file
  * .htaccess creation only works for base_installations because of the $dirPrefix variable
  * 		This is for the rewrite_rule and TestResponse() which uses AbsoluteUrl()
  *
  * @access public
  * @static
  * @since 1.7
  *
  * @param string $destination The root path of the installation
  * @param array $config Current installation configuration
  */
 static function InstallHtaccess($destination, $config)
 {
     global $install_ftp_connection, $dirPrefix;
     includeFile('admin/admin_permalinks.php');
     //only proceed with save if we can test the results
     if (!gpRemoteGet::Test()) {
         return;
     }
     $GLOBALS['config']['homepath'] = false;
     //to prevent a warning from absoluteUrl()
     $file = $destination . '/.htaccess';
     $original_contents = false;
     if (file_exists($file)) {
         $original_contents = file_get_contents($file);
     }
     $contents = admin_permalinks::Rewrite_Rules(true, $dirPrefix, $original_contents);
     if (!isset($config['useftp'])) {
         //echo 'not using ftp';
         $fp = @fopen($file, 'wb');
         if (!$fp) {
             return;
         }
         @fwrite($fp, $contents);
         fclose($fp);
         @chmod($file, 0666);
         //return .htaccess to original state
         if (!admin_permalinks::TestResponse()) {
             if ($original_contents === false) {
                 unlink($file);
             } else {
                 $fp = @fopen($file, 'wb');
                 if ($fp) {
                     @fwrite($fp, $original_contents);
                     fclose($fp);
                 }
             }
         }
         return;
     }
     //using ftp
     $file = $config['ftp_root'] . '/.htaccess';
     $temp = tmpfile();
     if (!$temp) {
         return false;
     }
     fwrite($temp, $contents);
     fseek($temp, 0);
     //Skip back to the start of the file being written to
     @ftp_fput($install_ftp_connection, $file, $temp, FTP_ASCII);
     fclose($temp);
     //return .htaccess to original state
     if (!admin_permalinks::TestResponse()) {
         if ($original_contents === false) {
             @ftp_delete($install_ftp_connection, $file);
         } else {
             $temp = tmpfile();
             fwrite($temp, $original_contents);
             fseek($temp, 0);
             @ftp_fput($install_ftp_connection, $file, $temp, FTP_ASCII);
             fclose($temp);
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Save the htaccess rule to the server using $filesystem and test to make sure we aren't getting 500 errors
  *
  * @access public
  * @since 1.7
  *
  * @param string $path The path to the local .htaccess file
  * @param string $rules The rules to be added to the .htaccess file
  * @return boolean
  */
 function SaveRules($path, $rules)
 {
     global $gp_filesystem, $langmessage;
     //force a 500 error for testing
     //$rules .= "\n</IfModule>";
     //get current .htaccess
     $contents = '';
     $original_contents = false;
     if (file_exists($path)) {
         $original_contents = $contents = file_get_contents($path);
     }
     // new gpeasy rules
     admin_permalinks::StripRules($contents);
     $contents .= $rules;
     $filesystem_base = $gp_filesystem->get_base_dir();
     if ($filesystem_base === false) {
         return false;
     }
     $filesystem_path = $filesystem_base . '/.htaccess';
     if (!$gp_filesystem->put_contents($filesystem_path, $contents)) {
         return false;
     }
     //if TestResponse Fails, undo the changes
     //only need to test for hiding
     if ($this->changed_to_hide && !admin_permalinks::TestResponse()) {
         if ($original_contents === false) {
             $gp_filesystem->unlink($filesystem_path);
         } else {
             $gp_filesystem->put_contents($filesystem_path, $original_contents);
         }
         return false;
     }
     return true;
 }
Exemplo n.º 3
0
 /**
  * Save the htaccess rule to the server using $filesystem and test to make sure we aren't getting 500 errors
  *
  * @access public
  * @since 1.7
  *
  * @return boolean
  */
 function SaveRules()
 {
     global $gp_filesystem, $langmessage, $dirPrefix;
     //get current .htaccess
     $original_contents = false;
     if (file_exists($this->rule_file)) {
         $original_contents = file_get_contents($this->rule_file);
     }
     //add/remove gpEasy rules from $original_contents to get new $contents
     $contents = admin_permalinks::Rewrite_Rules($this->changed_to_hide, $dirPrefix, $original_contents);
     if ($contents === false) {
         return false;
     }
     $filesystem_base = $gp_filesystem->get_base_dir();
     if ($filesystem_base === false) {
         return false;
     }
     $filesystem_path = $filesystem_base . '/' . $this->rule_file_name;
     if (!$gp_filesystem->put_contents($filesystem_path, $contents)) {
         return false;
     }
     //if TestResponse Fails, undo the changes
     //only need to test for hiding
     if ($this->changed_to_hide && !admin_permalinks::TestResponse()) {
         if ($original_contents === false) {
             $gp_filesystem->unlink($filesystem_path);
         } else {
             $gp_filesystem->put_contents($filesystem_path, $original_contents);
         }
         return false;
     }
     return true;
 }
Exemplo n.º 4
0
 /**
  * Make sure the save hasn't broken the installation
  * if TestResponse Fails, undo the changes
  *
  */
 public function TestSave($filesystem_path)
 {
     //only need to test if we might needt to undo
     if (!$this->undo_if_failed) {
         return true;
     }
     if (!admin_permalinks::TestResponse($this->hide_index)) {
         if ($this->orig_rules === false) {
             $this->FileSystem->unlink($filesystem_path);
         } else {
             $this->FileSystem->put_contents($filesystem_path, $this->orig_rules);
         }
         return false;
     }
     return true;
 }