function restrict_access($levels)
{
    if (!user_access($levels)) {
        // Access forbidden
        $user_level = $_SESSION['permissions'];
        if ($user_level == 'X') {
            alert('You need to log in to do that.', -1);
            require_once PATH::root() . '/Account/Signin.php';
            die;
        } else {
            if ($user_level == 'E') {
                location('Account/Verify_Email');
            } else {
                if ($user_level == 'P') {
                    location('Account/Approve');
                } else {
                    if ($user_level == '+') {
                        location('Admin/Super_Admin');
                    } else {
                        if ($user_level == 'B') {
                            location('Account/Banned');
                        } else {
                            // Go home - e.g. if you're logged in and it's restrict_access('X') on Signin, you shouldn't be signing in again. It'll just bring you back home.
                            location('Home');
                        }
                    }
                }
            }
        }
    }
}
Beispiel #2
0
function write_log($txt)
{
    //Generate error text
    $logtext = ' DATE:' . date(DATE_RFC822) . ' IP:' . $_SERVER['REMOTE_ADDR'] . ' ' . $txt;
    //Log it in the proper file
    file_put_contents(PATH::errfile(), $logtext, FILE_APPEND);
}
 public function test_old_cache_is_cleared()
 {
     $this->assertFalse($this->size->is_site_size_cached());
     $this->size = new Site_Size('file');
     $this->size->recursive_filesize_scanner();
     $this->assertTrue($this->size->is_site_size_cached());
     // Set the filemtime to over a week ago
     touch(PATH::get_path() . '/.files', time() - WEEK_IN_SECONDS - 10);
     clearstatcache();
     $this->assertFalse($this->size->is_site_size_cached());
 }
 public function test_only_database_zipped_up()
 {
     $this->backup->set_type('database');
     Path::get_instance()->reset_path();
     file_put_contents(PATH::get_path() . '/foo.zip.SmuhtP', 'bar');
     file_put_contents(PATH::get_path() . '/zicBotXQ', 'baz');
     $this->backup->run();
     $this->assertFileExists($this->backup->get_backup_filepath());
     $this->assertArchiveContains($this->backup->get_backup_filepath(), array(basename($this->backup->get_database_backup_filepath())));
     $this->assertArchiveNotContains($this->backup->get_backup_filepath(), array('zicBotXQ', 'foo.zip.SmuhtP'));
     $this->assertArchiveFileCount($this->backup->get_backup_filepath(), 1);
 }
Beispiel #5
0
 public function get_cached_filesizes($max_age = WEEK_IN_SECONDS)
 {
     $cache = PATH::get_path() . '/.files';
     $files = false;
     if (file_exists($cache)) {
         // If the file is old then regenerate it
         if (time() - filemtime($cache) <= $max_age) {
             $files = json_decode(gzuncompress(file_get_contents($cache)), 'ARRAY_A');
         }
     }
     return $files;
 }
 /**
  * Normalise the exclude rules so they are ready to work with.
  *
  * @param array $excludes The array of exclude rules to normalise.
  *
  * @return array          The array of normalised rules.
  */
 public function normalize($excludes)
 {
     $excludes = array_map(function ($exclude) {
         // Convert absolute paths to relative.
         $exclude = str_replace(PATH::get_root(), '', wp_normalize_path($exclude));
         // Trim the slashes.
         $exclude = trim($exclude);
         $exclude = ltrim($exclude, '/');
         $exclude = untrailingslashit($exclude);
         return $exclude;
     }, $excludes);
     // Remove duplicate or empty rules.
     $excludes = array_unique($excludes);
     $excludes = array_filter($excludes);
     return $excludes;
 }
Beispiel #7
0
<?php

require_once PATH::lib() . '/meekrodb.2.3.class.php';
//Even better version of class.DB.php, with OO'd database management.
function db_error_handler($params)
{
    $out = 'DB ERROR: ';
    if (strpos($params['error'], 'Unable to connect to MySQL server!')) {
        $params['error'] .= " (Did you accidentally upload CONFIG.local.php?)";
    }
    if (isset($params['query'])) {
        $out .= "QUERY: " . $params['query'] . '<br />';
    }
    if (isset($params['error'])) {
        $out .= "ERROR: " . $params['error'] . '<br />';
    }
    trigger_error($out, E_USER_ERROR);
    die;
}
class DBExt
{
    //A few more features to add to MeekroDB.
    public static function parseWhereClause($where, $args)
    {
        //Better whereclause creation, to be used in placeholding %l. (may not necessarily be a whereclause)
        //Does not deal with replacement params.
        if (!is_array($args)) {
            $args = array();
        }
        if (is_object($where) && get_class($where) == 'WhereClause') {
            //Well, it's already a WhereClause.
 public function test_file_with_strange_characters()
 {
     file_put_contents(PATH::get_root() . '/Groß.jpg', '');
     $this->assertFileExists(PATH::get_root() . '/Groß.jpg');
     $this->backup->backup();
     $this->assertFileExists($this->backup->get_backup_filepath());
     $this->assertArchiveContains($this->backup->get_backup_filepath(), array('Groß.jpg'));
     unlink(PATH::get_root() . '/Groß.jpg');
 }
Beispiel #9
0
function send_email($bcc_list, $subject, $bb_body, $reply_to = NULL, $prefix = NULL, $footer = NULL, $headers = NULL)
{
    global $EMAIL_ADDRESS, $EMAIL_USERNAME, $EMAIL_PASSWORD, $SMTP_SERVER, $SMTP_SERVER_PORT, $SMTP_SERVER_PROTOCOL, $LMT_EMAIL;
    require_once PATH::lib() . "/swiftmailer/swift_required.php";
    //Instead of using parameter default values, so we can pass NULL. And it's more readable.
    if (count($bcc_list) == 0) {
        return true;
    }
    if (is_null($reply_to)) {
        $reply_to = array($EMAIL_ADDRESS => 'LHS Math Club Mailbot');
    }
    if (is_null($prefix)) {
        $prefix = '[LHS Math Club]';
    }
    if (is_null($footer)) {
        $footer = "LHS Math Club\n[url]" . get_site_url() . "[/url]\nTo stop receiving LHSMATH emails, contact [email]webmaster@lhsmath.org[/email].";
    }
    if (is_null($headers)) {
        $headers = array();
    }
    if (is_string($bcc_list)) {
        $bcc_list = array($bcc_list);
    }
    if (!is_array($bcc_list) || !is_string($subject) || !is_string($bb_body) || !is_array($reply_to) && !is_string($reply_to) || !is_string($prefix) || !is_string($footer) || !is_array($headers)) {
        return 'Invalid email parameters.';
    }
    if (($error_msg = val_email_msg($subject, $bb_body)) !== true) {
        return $error_msg;
    }
    if ($footer != "") {
        $bb_body .= "\n\n\n---\n{$footer}\n";
    }
    //Attach footer.
    $html = BBCode($bb_body);
    //BBCode it.
    $subject = preg_replace("/[^\\S ]/ui", '', strip_tags($prefix . ' ' . $subject));
    //"remove everything that's not [non-whitespace or space]"
    //preg_replace("/[^[:alnum][:space]]/ui", '', $string);?
    //Ok everything seems to be working, let's go ahead
    Swift_Preferences::getInstance()->setCacheType('array');
    //Prevents a ton of warnings about SwiftMail's DiskKeyCache, thus actually speeding things up considerably.
    //Connect to the SMTP server
    $transport = Swift_SmtpTransport::newInstance($SMTP_SERVER, $SMTP_SERVER_PORT, $SMTP_SERVER_PROTOCOL)->setUsername($EMAIL_USERNAME)->setPassword($EMAIL_PASSWORD);
    //Make a Mailer that will send through that transport (limiting to 50/send)
    $mailer = Swift_Mailer::newInstance($transport);
    //$mailer->registerPlugin(new Swift_Plugins_AntiFloodPlugin(50, 1));//Max 50 emails per send, 1 sec delay between sends
    try {
        //Mush all info into the Mailer
        $message = Swift_Message::newInstance($subject)->setFrom(array($EMAIL_ADDRESS => 'LHS Math Club Mailbot'))->setBcc($bcc_list)->setContentType("text/html")->setBody($html)->setReplyTo($reply_to);
        foreach ($headers as $field => $value) {
            //Add custom headers, such as listserv stuff.
            $message->getHeaders()->addTextHeader($field, $value);
        }
        //Send the message
        if (!$mailer->send($message)) {
            LOG::fatal('Error sending email');
        }
    } catch (Exception $e) {
        LOG::fatal('Email exception: ' . $e->getMessage());
    }
    return true;
}
Beispiel #10
0
</span> member files</li>
		  <li><span class="b"><?php 
echo $num_public_files;
?>
</span> public files</li>
		  <li><span class="b"><?php 
echo $num_admin_files;
?>
</span> admin files</li>
		</ul>
	  </td>		  
	  <td>
		<h4>Error Log</h4>
		<ul>
		  <li>Size of <span class="monospace"><?php 
echo PATH::errfile();
?>
</span>: <?php 
echo $errors_file_size;
?>
. <a href="?do_download_errors">[Download]</a> <a href="?do_clear_errors" onclick="window.location.reload()">[Download & clear]</a></li>
		  <li>Also check via FTP <span class="monospace">/home/logs/*</span>.</li>
		</ul>
	  </td>
	</tr>
  </table>
  
  <br><br>
  <h3>Some things to do regularly:</h3>
  <ul>
	<li>DB: <a href="Database">Optimize tables, check integrity, generate a backup, or download <span class="monospace">.content</span>.</a> (~1x/month)</li>
/**
 * Handles anything that needs to be
 * done when the plugin is updated
 */
function update()
{
    // Update from backUpWordPress 0.4.5
    if (get_option('bkpwp_max_backups')) {
        // Carry over the custom path
        if ($legacy_path = get_option('bkpwppath')) {
            update_option('hmbkp_path', $legacy_path);
        }
        // Options to remove
        $legacy_options = array('bkpwp_archive_types', 'bkpwp_automail_from', 'bkpwp_domain', 'bkpwp_domain_path', 'bkpwp_easy_mode', 'bkpwp_excludelists', 'bkpwp_install_user', 'bkpwp_listmax_backups', 'bkpwp_max_backups', 'bkpwp_presets', 'bkpwp_reccurrences', 'bkpwp_schedules', 'bkpwp_calculation', 'bkpwppath', 'bkpwp_status_config', 'bkpwp_status');
        foreach ($legacy_options as $option) {
            delete_option($option);
        }
        global $wp_roles;
        $wp_roles->remove_cap('administrator', 'manage_backups');
        $wp_roles->remove_cap('administrator', 'download_backups');
        wp_clear_scheduled_hook('bkpwp_schedule_bkpwp_hook');
    }
    // Version 1 to 2
    if (get_option('hmbkp_plugin_version') && version_compare('2.0', get_option('hmbkp_plugin_version'), '>')) {
        /**
         * Setup a backwards compatible schedule
         */
        $legacy_schedule = new Scheduled_Backup('backup');
        // Backup type
        if (defined('HMBKP_FILES_ONLY') && HMBKP_FILES_ONLY || get_option('hmbkp_files_only')) {
            $legacy_schedule->set_type('file');
        } elseif (defined('HMBKP_DATABASE_ONLY') && HMBKP_DATABASE_ONLY || get_option('hmbkp_database_only')) {
            $legacy_schedule->set_type('database');
        } else {
            $legacy_schedule->set_type('complete');
        }
        // Daily schedule time
        if (defined('HMBKP_DAILY_SCHEDULE_TIME') && HMBKP_DAILY_SCHEDULE_TIME) {
            $legacy_schedule->set_schedule_start_time(strtotime(HMBKP_DAILY_SCHEDULE_TIME));
        }
        // Backup schedule
        $legacy_schedule->set_reoccurrence(get_option('hmbkp_schedule_frequency', 'daily'));
        // Automatic backups disabled?
        if (defined('HMBKP_DISABLE_AUTOMATIC_BACKUP') && HMBKP_DISABLE_AUTOMATIC_BACKUP || get_option('hmbkp_disable_automatic_backup')) {
            $legacy_schedule->set_reoccurrence('manually');
        }
        // Max backups
        if (defined('HMBKP_MAX_BACKUPS') && is_numeric(HMBKP_MAX_BACKUPS)) {
            $legacy_schedule->set_max_backups((int) HMBKP_MAX_BACKUPS);
        } else {
            $legacy_schedule->set_max_backups((int) get_option('hmbkp_max_backups', 10));
        }
        // Excludes
        if (get_option('hmbkp_excludes')) {
            $legacy_schedule->set_excludes(get_option('hmbkp_excludes'));
        }
        // Backup email
        if (defined('HMBKP_EMAIL') && is_email(HMBKP_EMAIL)) {
            $legacy_schedule->set_service_options('HMBKP_Email_Service', array('email' => HMBKP_EMAIL));
        } elseif (is_email(get_option('hmbkp_email_address'))) {
            $legacy_schedule->set_service_options('HMBKP_Email_Service', array('email' => get_option('hmbkp_email_address')));
        }
        // Set the archive filename to what it used to be
        $legacy_schedule->backup_filename = implode('-', array(get_bloginfo('name'), 'backup', current_time('Y-m-d-H-i-s'))) . '.zip';
        $legacy_schedule->save();
        $legacy_path = get_option('hmbkp_path');
        if ($legacy_path) {
            // Prepend 'backup-' to the beginning of any legacy backups so they are picked up by the legacy schedule
            if ($handle = opendir($legacy_path)) {
                while (false !== ($file = readdir($handle))) {
                    if ('zip' === pathinfo($file, PATHINFO_EXTENSION)) {
                        rename(trailingslashit($legacy_path) . $file, trailingslashit($legacy_path) . 'backup-' . $file);
                    }
                }
                closedir($handle);
            }
            PATH::get_instance()->move_old_backups($legacy_path);
        }
        // Remove the legacy options
        foreach (array('hmbkp_database_only', 'hmbkp_files_only', 'hmbkp_max_backups', 'hmbkp_email_address', 'hmbkp_email', 'hmbkp_schedule_frequency', 'hmbkp_disable_automatic_backup') as $option_name) {
            delete_option($option_name);
        }
    }
    // Update from 2.x to 3.0
    if (get_option('hmbkp_plugin_version') && version_compare('2.0', get_option('hmbkp_plugin_version'), '>')) {
        // Remove the plugin data cache
        delete_transient('hmbkp_plugin_data');
    }
    // Update to 3.1
    if (get_option('hmbkp_plugin_version') && version_compare('3.0', get_option('hmbkp_plugin_version'), '>')) {
        // Remove the plugin data cache
        delete_option('hmbkp_path');
        delete_option('hmbkp_default_path');
    }
    // update to 3.1.4
    if (get_option('hmbkp_plugin_version') && version_compare('3.1.4', get_option('hmbkp_plugin_version'), '>')) {
        $old_option_names = array('HM\\BackUpWordPressDropbox\\Dropbox_Service' => 'dropbox', 'HMBKP_DX_Backup_Service' => 'dropbox', 'HM\\BackUpWordPressFTP\\FTP_Backup_Service' => 'ftp', 'HMBKP_FTP_Backup_Service' => 'ftp', 'HM\\BackUpWordPressGDrive\\Google_Drive_BackUp' => 'google-drive', 'HMBKP_GDV_Backup_Service' => 'google-drive', 'HM\\BackUpWordPressRackspace\\RackSpace_BackUp' => 'rackspace-cloud', 'HMBKP_RSC_Backup_Service' => 'rackspace-cloud', 'HM\\BackUpWordPressS3\\S3_Backup' => 's3', 'HMBKP_S3_Backup_Service' => 's3', 'HM\\BackUpWordPressWinAzure\\WinAzure_Backup' => 'azure', 'HMBKP_WAZ_Backup_Service' => 'azure', 'HM\\BackUpWordPress\\Email_Service' => 'email');
        global $wpdb;
        // Get all schedule options with a SELECT query and delete them.
        $schedules = $wpdb->get_col($wpdb->prepare("SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE %s", 'hmbkp_schedule_%'));
        if (0 < count($schedules)) {
            // Access each schedules settings to see if the addon settings names need to be be updated to the new naming convention which uses the service slug generated from the $name property.
            foreach ($schedules as $schedule_id) {
                // Load the settings for this schedule into an array
                // so we can loop through the different service settings
                $schedule_settings = get_option($schedule_id);
                // Iterate over each schedule setting for this schedule and check its name against our array.
                foreach ($schedule_settings as $key => $val) {
                    // Find the current element key in our control array and get its value. Set a new element in the settings array with the found value as its key. Aka rename the element key
                    if (array_key_exists($key, $old_option_names)) {
                        // move the value to our new key
                        $schedule_settings[$old_option_names[$key]] = $schedule_settings[$key];
                        unset($schedule_settings[$key]);
                    }
                }
                // Save back to the DB
                update_option($schedule_id, $schedule_settings);
            }
        }
    }
    // Update to 3.1.5
    if (get_option('hmbkp_plugin_version') && version_compare('3.1.5', get_option('hmbkp_plugin_version'), '>')) {
        // Delete all transients
        $transients = array('hmbkp_plugin_data', 'hmbkp_directory_filesizes', 'hmbkp_directory_filesizes_running', 'hmbkp_wp_cron_test_beacon', 'hm_backdrop');
        array_map('delete_transient', $transients);
        // Clear duplicate schedules on multisite
        if (is_multisite()) {
            // get current blogs from DB
            $blogs = wp_get_sites();
            foreach ($blogs as $blog) {
                switch_to_blog(get_current_blog_id());
                if (is_main_site(get_current_blog_id())) {
                    continue;
                }
                global $wpdb;
                // Get the schedule options
                $schedules = $wpdb->get_col($wpdb->prepare("SELECT option_name FROM {$wpdb->options} WHERE option_name LIKE %s", 'hmbkp_schedule_%'));
                // clear schedules
                foreach (array_map(function ($item) {
                    return ltrim($item, 'hmbkp_schedule_');
                }, $schedules) as $item) {
                    wp_clear_scheduled_hook('hmbkp_schedule_hook', array('id' => $item));
                }
                // delete options
                array_map('delete_option', $schedules);
                array_map('delete_option', array('hmbkp_enable_support', 'hmbkp_plugin_version', 'hmbkp_path', 'hmbkp_default_path', 'hmbkp_upsell'));
                // Delete all transients
                array_map('delete_transient', array('hmbkp_plugin_data', 'hmbkp_directory_filesizes', 'hmbkp_directory_filesize_running', 'timeout_hmbkp_wp_cron_test_beacon', 'hmbkp_wp_cron_test_beacon'));
            }
            restore_current_blog();
        }
    }
    // Update from 3.3.0
    if (get_option('hmbkp_plugin_version') && version_compare('3.3.0', get_option('hmbkp_plugin_version'), '>')) {
        $schedules = Schedules::get_instance();
        // Loop through all schedules and re-set the reccurrence to include hmbkp_
        foreach ($schedules->get_schedules() as $schedule) {
            $reoccurrence = $schedule->get_reoccurrence();
            if ('manually' !== $reoccurrence && strpos($reoccurrence, 'hmbkp_') === 0) {
                $schedule->set_reoccurrence(substr($reoccurrence, 6));
            }
            $schedule->save();
        }
    }
    // Update from 3.3.4
    if (get_option('hmbkp_plugin_version') && version_compare('3.4.0', get_option('hmbkp_plugin_version'), '>')) {
        delete_transient('hmbkp_directory_filesizes');
    }
    // Every update
    if (get_option('hmbkp_plugin_version') && version_compare(Plugin::PLUGIN_VERSION, get_option('hmbkp_plugin_version'), '>')) {
        require_once HMBKP_PLUGIN_PATH . 'classes/class-setup.php';
        \HMBKP_Setup::deactivate();
        Path::get_instance()->protect_path('reset');
    }
    // Update the stored version
    if (get_option('hmbkp_plugin_version') !== Plugin::PLUGIN_VERSION) {
        update_option('hmbkp_plugin_version', Plugin::PLUGIN_VERSION);
    }
}
Beispiel #12
0
 public function __construct($subpath = '')
 {
     parent::__construct(new \SYSTEM\PSYSTEM(), 'sql/', $subpath);
 }
 public function test_cleanup()
 {
     // Should be cleaned up
     file_put_contents(PATH::get_path() . '/foo.zip.SmuhtP', 'bar');
     file_put_contents(PATH::get_path() . '/foo.sql', 'bar');
     file_put_contents(PATH::get_path() . '/zicBotXQ', 'baz');
     // Existing backups shouldn't be cleaned up
     file_put_contents(PATH::get_path() . '/backup.zip', 'baz');
     Path::get_instance()->cleanup();
     $this->assertFileNotExists(PATH::get_path() . '/foo.zip.SmuhtP');
     $this->assertFileNotExists(PATH::get_path() . '/foo.sql');
     $this->assertFileNotExists(PATH::get_path() . '/zicBotXQ');
     $this->assertFileExists(PATH::get_path() . '/index.html');
     $this->assertFileExists(PATH::get_path() . '/backup.zip');
 }
 public static function pathToRootFromURLRoot()
 {
     return removeLeadingSlash(subtractURLsEnd(backslashToForward(dirname(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH))), subtractURLsStart(PATH::dir(), PATH::root())));
 }
Beispiel #15
0
/*
 * recaptcha_get_html_f()
 * A laziness function that puts in the $RECAPTCHA_PUBLIC_KEY for me.
 */
function recaptcha_get_html_f()
{
    global $RECAPTCHA_PUBLIC_KEY;
    return recaptcha_get_html($RECAPTCHA_PUBLIC_KEY);
}
// check IP ban list
if (in_array(strtolower($_SERVER['REMOTE_ADDR']), $BANNED_IPS)) {
    session_name('Session');
    session_start();
    session_destroy();
    $_SESSION['permissions'] = 'B';
    require_once PATH::root() . '/Account/Banned.php';
}
// hide .PHP extension (/Home.php -> /Home - this works because of a URL Rewrite in the .htaccess file)
@($url_pieces = parse_url($_SERVER['REQUEST_URI']));
if ($url_pieces != false && basename($url_pieces['path']) != basename($url_pieces['path'], '.php')) {
    $url = basename($url_pieces['path'], '.php');
    if (isset($url_pieces['query'])) {
        $url .= '?' . $url_pieces['query'];
    }
    header('Location: ' . $url);
}
// start a session
session_name('Session');
session_start();
// all sessions have an XSRF-protection token that should be
// submitted with all forms via invisible field.
Beispiel #16
0
function scoring_access()
{
    if (!scoring_is_enabled()) {
        require_once PATH::lmt() . '/Backstage/Scoring_Frozen.php';
    }
}