plugins/SpecialAdmin.php
changeset 261 5f1cd51bf1be
parent 259 112debff64bd
child 270 a48b72312f6d
equal deleted inserted replaced
259:112debff64bd 261:5f1cd51bf1be
  2163   {
  2163   {
  2164     echo '<h3>Error: Not authenticated</h3><p>It looks like your administration session is invalid or you are not authorized to access this administration page. Please <a href="' . makeUrlNS('Special', 'Login/' . $paths->nslist['Special'] . 'Administration', 'level=' . USER_LEVEL_ADMIN, true) . '">re-authenticate</a> to continue.</p>';
  2164     echo '<h3>Error: Not authenticated</h3><p>It looks like your administration session is invalid or you are not authorized to access this administration page. Please <a href="' . makeUrlNS('Special', 'Login/' . $paths->nslist['Special'] . 'Administration', 'level=' . USER_LEVEL_ADMIN, true) . '">re-authenticate</a> to continue.</p>';
  2165     return;
  2165     return;
  2166   }
  2166   }
  2167   
  2167   
       
  2168   if ( ENANO_DBLAYER != 'MYSQL' )
       
  2169     die('<h3>Not supported</h3>
       
  2170           <p>This function is only supported under the MySQL database driver.</p>');
       
  2171   
  2168   if(isset($_GET['submitting']) && $_GET['submitting'] == 'yes' && defined('ENANO_DEMO_MODE') )
  2172   if(isset($_GET['submitting']) && $_GET['submitting'] == 'yes' && defined('ENANO_DEMO_MODE') )
  2169   {
  2173   {
  2170     redirect(makeUrlComplete('Special', 'Administration'), 'Access denied', 'You\'ve got to be kidding me. Forget it, kid.', 4 );
  2174     redirect(makeUrlComplete('Special', 'Administration'), 'Access denied', 'You\'ve got to be kidding me. Forget it, kid.', 4 );
  2171   }
  2175   }
  2172   
  2176   
  2174   if(isset($_GET['submitting']) && $_GET['submitting'] == 'yes')
  2178   if(isset($_GET['submitting']) && $_GET['submitting'] == 'yes')
  2175   {
  2179   {
  2176     
  2180     
  2177     if(defined('SQL_BACKUP_CRYPT'))
  2181     if(defined('SQL_BACKUP_CRYPT'))
  2178       // Try to increase our time limit
  2182       // Try to increase our time limit
  2179       @set_time_limit(300); // five minutes
  2183       @set_time_limit(0);
  2180     // Do the actual export
  2184     // Do the actual export
  2181     $aesext = ( defined('SQL_BACKUP_CRYPT') ) ? '.tea' : '';
  2185     $aesext = ( defined('SQL_BACKUP_CRYPT') ) ? '.tea' : '';
  2182     $filename = 'enano_backup_' . date('ymd') . '.sql' . $aesext;
  2186     $filename = 'enano_backup_' . date('ymd') . '.sql' . $aesext;
  2183     ob_start();
  2187     ob_start();
  2184     header('Content-disposition: attachment, filename="'.$filename.'";');
       
  2185     header('Content-type: application/transact-sql');
       
  2186     // Spew some headers
  2188     // Spew some headers
  2187     $headdate = date('F d, Y \a\t h:i a');
  2189     $headdate = date('F d, Y \a\t h:i a');
  2188     echo <<<HEADER
  2190     echo <<<HEADER
  2189 -- Enano CMS SQL backup
  2191 -- Enano CMS SQL backup
  2190 -- Generated on {$headdate} by {$session->username}
  2192 -- Generated on {$headdate} by {$session->username}
  2210     foreach($tables as $t)
  2212     foreach($tables as $t)
  2211     {
  2213     {
  2212       // THE FOLLOWING COMMENT DOES NOT APPLY AS OF 1.0.
  2214       // THE FOLLOWING COMMENT DOES NOT APPLY AS OF 1.0.
  2213       // Sorry folks - this script CAN'T backup enano_files and enano_search_index due to the sheer size of the tables.
  2215       // Sorry folks - this script CAN'T backup enano_files and enano_search_index due to the sheer size of the tables.
  2214       // If encryption is enabled the log data will be excluded too.
  2216       // If encryption is enabled the log data will be excluded too.
  2215       echo export_table(
  2217       $result = export_table(
  2216         $t,
  2218         $t,
  2217         isset($_POST['do_struct']),
  2219         isset($_POST['do_struct']),
  2218         ( isset($_POST['do_data']) ),
  2220         ( isset($_POST['do_data']) ),
  2219         false
  2221         false
  2220         ) . "\n";
  2222         ) . "\n";
       
  2223       if ( !$result )
       
  2224       {
       
  2225         $db->_die();
       
  2226       }
       
  2227       echo $result;
  2221     }
  2228     }
  2222     $data = ob_get_contents();
  2229     $data = ob_get_contents();
  2223     ob_end_clean();
  2230     ob_end_clean();
  2224     if(defined('SQL_BACKUP_CRYPT'))
  2231     if(defined('SQL_BACKUP_CRYPT'))
  2225     {
  2232     {
  2227       $db->close();
  2234       $db->close();
  2228       unset($paths, $db, $template, $plugins);
  2235       unset($paths, $db, $template, $plugins);
  2229       $tea = new TEACrypt();
  2236       $tea = new TEACrypt();
  2230       $data = $tea->encrypt($data, $session->private_key);
  2237       $data = $tea->encrypt($data, $session->private_key);
  2231     }
  2238     }
       
  2239     header('Content-disposition: attachment, filename="'.$filename.'";');
       
  2240     header('Content-type: application/transact-sql');
  2232     header('Content-length: '.strlen($data));
  2241     header('Content-length: '.strlen($data));
  2233     echo $data;
  2242     echo $data;
  2234     exit;
  2243     exit;
  2235   }
  2244   }
  2236   else
  2245   else
  2241     <p>This page allows you to back up your Enano database should something go miserably wrong.</p>
  2250     <p>This page allows you to back up your Enano database should something go miserably wrong.</p>
  2242     <p><label><input type="checkbox" name="do_system_tables" checked="checked" />  Export tables that are part of the Enano core</label><p>
  2251     <p><label><input type="checkbox" name="do_system_tables" checked="checked" />  Export tables that are part of the Enano core</label><p>
  2243     <p>Additional tables to export:</p>
  2252     <p>Additional tables to export:</p>
  2244     <p><select name="additional_tables[]" multiple="multiple">
  2253     <p><select name="additional_tables[]" multiple="multiple">
  2245        <?php
  2254        <?php
  2246          $q = $db->sql_query('SHOW TABLES;') or $db->_die('Somehow we were denied the request to get the list of tables.');
  2255          if ( ENANO_DBLAYER == 'MYSQL' )
       
  2256          {
       
  2257            $q = $db->sql_query('SHOW TABLES;') or $db->_die('Somehow we were denied the request to get the list of tables.');
       
  2258          }
       
  2259          else if ( ENANO_DBLAYER == 'PGSQL' )
       
  2260          {
       
  2261            $q = $db->sql_query('SELECT relname FROM pg_stat_user_tables ORDER BY relname;') or $db->_die('Somehow we were denied the request to get the list of tables.');
       
  2262          }
  2247          while($row = $db->fetchrow_num())
  2263          while($row = $db->fetchrow_num())
  2248          {
  2264          {
  2249            if(!in_array($row[0], $system_table_list)) echo '<option value="'.$row[0].'">'.$row[0].'</option>';
  2265            if(!in_array($row[0], $system_table_list)) echo '<option value="'.$row[0].'">'.$row[0].'</option>';
  2250          }
  2266          }
  2251        ?>
  2267        ?>