예제 #1
0
/**
 * Fifth installation step.
 *
 * @return tempcode		Progress report / UI
 */
function step_5()
{
    if (count($_POST) == 0) {
        exit(do_lang('INST_POST_ERROR'));
    }
    if (function_exists('set_time_limit')) {
        @set_time_limit(180);
    }
    $url = 'install.php?step=6';
    $use_msn = post_param_integer('use_msn', 0);
    if ($use_msn == 0) {
        $use_msn = post_param_integer('use_multi_db', 0);
    }
    if ($use_msn == 0) {
        $_POST['db_forums'] = $_POST['db_site'];
        $_POST['db_forums_host'] = $_POST['db_site_host'];
        $_POST['db_forums_user'] = $_POST['db_site_user'];
        $_POST['db_forums_password'] = $_POST['db_site_password'];
        $_POST['ocf_table_prefix'] = array_key_exists('table_prefix', $_POST) ? $_POST['table_prefix'] : 'ocp_';
    }
    // Check cookie settings. IF THIS CODE IS CHANGED ALSO CHANGE COPY&PASTED CODE IN CONFIG_EDITOR.PHP
    $cookie_path = post_param('cookie_path');
    $cookie_domain = trim(post_param('cookie_domain'));
    $base_url = post_param('base_url');
    if (substr($base_url, -1) == '/') {
        $base_url = substr($base_url, 0, strlen($base_url) - 1);
    }
    $url_parts = parse_url($base_url);
    if (!array_key_exists('host', $url_parts)) {
        $url_parts['host'] = 'localhost';
    }
    if (!array_key_exists('path', $url_parts)) {
        $url_parts['path'] = '';
    }
    if (substr($url_parts['path'], -1) != '/') {
        $url_parts['path'] .= '/';
    }
    if (substr($cookie_path, -1) == '/') {
        $cookie_path = substr($cookie_path, 0, strlen($cookie_path) - 1);
    }
    if ($cookie_path != '' && substr($url_parts['path'], 0, strlen($cookie_path) + 1) != $cookie_path . '/') {
        warn_exit(do_lang_tempcode('COOKIE_PATH_MUST_MATCH', escape_html($url_parts['path'])));
    }
    if ($cookie_domain != '') {
        if (strpos($url_parts['host'], '.') === false) {
            warn_exit(do_lang_tempcode('COOKIE_DOMAIN_CANT_USE'));
        }
        if (substr($cookie_domain, 0, 1) != '.') {
            warn_exit(do_lang_tempcode('COOKIE_DOMAIN_MUST_START_DOT'));
        } elseif (substr($url_parts['host'], 1 - strlen($cookie_domain)) != substr($cookie_domain, 1)) {
            warn_exit(do_lang_tempcode('COOKIE_DOMAIN_MUST_MATCH', escape_html($url_parts['host'])));
        }
    }
    $table_prefix = post_param('table_prefix');
    if ($table_prefix == '') {
        warn_exit(do_lang_tempcode('NO_BLANK_TABLE_PREFIX'));
    }
    // Give warning if database contains data
    global $SITE_INFO;
    foreach ($_POST as $key => $val) {
        if ($key == 'ftp_password' || $key == 'ftp_password_confirm' || $key == 'admin_password_confirm' || $key == 'ocf_admin_password' || $key == 'ocf_admin_password_confirm') {
            continue;
        }
        if (get_magic_quotes_gpc()) {
            $val = stripslashes($val);
        }
        if ($key == 'admin_password') {
            $val = '!' . md5($val . 'ocp');
        }
        $SITE_INFO[$key] = trim($val);
    }
    require_code('database');
    if (post_param_integer('confirm', 0) == 0) {
        $tmp = new database_driver(trim(post_param('db_site')), trim(post_param('db_site_host')), trim(post_param('db_site_user')), trim(post_param('db_site_password')), $table_prefix);
        $test = $tmp->query_value_null_ok('config', 'the_type', array('the_name' => 'is_on_gd'), '', true);
        unset($tmp);
        if (!is_null($test)) {
            global $LANG;
            $sections = build_keep_post_fields(array('forum_type', 'db_type', 'board_path', 'default_lang'));
            $sections->attach(form_input_hidden('confirm', '1'));
            return do_template('INSTALLER_STEP_4', array('_GUID' => 'aaf0386966dd4b75c8027a6b1f7454c6', 'MESSAGE' => do_lang_tempcode('WARNING_DB_OVERWRITE'), 'LANG' => $LANG, 'DB_TYPE' => post_param('db_type'), 'FORUM_TYPE' => post_param('forum_type'), 'BOARD_PATH' => post_param('board_path'), 'SECTIONS' => $sections));
        }
    }
    if ($_POST['db_forums'] != $_POST['db_site'] && get_forum_type() == 'ocf') {
        $tmp = new database_driver(trim(post_param('db_forums')), trim(post_param('db_forums_host')), trim(post_param('db_forums_user')), trim(post_param('db_forums_password')), $table_prefix);
        if (is_null($tmp->query_value_null_ok('db_meta', 'COUNT(*)', NULL, '', true))) {
            warn_exit(do_lang_tempcode('MSN_FORUM_DB_NOT_OCF_ALREADY'));
        }
    }
    global $FILE_ARRAY;
    $still_ftp = false;
    $log = new ocp_tempcode();
    if (@is_array($FILE_ARRAY)) {
        $ftp_status = step_5_ftp();
        $log->attach($ftp_status[0]);
        if ($ftp_status[1] != -1) {
            $url = 'install.php?step=5&start_from=' . strval($ftp_status[1]);
            $still_ftp = true;
        }
    }
    if (!$still_ftp) {
        require_code('zones');
        require_code('comcode');
        require_code('themes');
        $log->attach(step_5_checks());
        $log->attach(step_5_write_config());
        $log->attach(step_5_uninstall());
        $log->attach(step_5_core());
        include_ocf();
        $log->attach(step_5_core_2());
    }
    return do_template('INSTALLER_STEP_LOG', array('_GUID' => '83ed0405bc32fdf2cc499662bfa51bc9', 'PREVIOUS_STEP' => '4', 'URL' => $url, 'LOG' => $log, 'HIDDEN' => build_keep_post_fields()));
}
예제 #2
0
 /**
  * Synchronizes events and loads them.
  *
  * @see database_driver::load_events()
  */
 public function load_events($start, $end, $query = null, $cal_ids = null, $virtual = 1, $modifiedsince = null, $force = false)
 {
     foreach ($this->sync_clients as $cal_id => $cal_sync) {
         if ($this->calendars[$cal_id]['active']) {
             if ($force || !$this->_is_synced($cal_id)) {
                 $this->_sync_calendar($cal_id);
             }
         }
     }
     if ($force) {
         return true;
     } else {
         $events = parent::load_events($start, $end, $query, $cal_ids, $virtual, $modifiedsince);
         $return = array();
         foreach ($events as $idx => $event) {
             $return[$idx] = $event;
             $return[$idx]['readonly'] = $this->readonly;
         }
         return $return;
     }
 }
예제 #3
0
/**
 * Get data from wordpress db
 *
 * @return array		Result array
 */
function get_wordpress_data()
{
    $host_name = post_param('wp_host');
    $db_name = post_param('wp_db');
    $db_user = post_param('wp_db_user');
    $db_passwrod = post_param('wp_db_password');
    $db_table_prefix = post_param('wp_table_prefix');
    // Create DB connection
    $db = new database_driver($db_name, $host_name, $db_user, $db_passwrod, $db_table_prefix);
    $row = $db->query('SELECT * FROM ' . db_escape_string($db_name) . '.' . db_escape_string($db_table_prefix) . '_users');
    $data = array();
    foreach ($row as $users) {
        $user_id = $users['ID'];
        $data[$user_id] = $users;
        // Fetch user posts
        $row1 = $db->query('SELECT * FROM ' . $db_table_prefix . '_posts WHERE post_author=' . strval($user_id) . ' AND (post_type=\'post\' OR post_type=\'page\')');
        foreach ($row1 as $posts) {
            $post_id = $posts['ID'];
            $data[$user_id]['POSTS'][$post_id] = $posts;
            // Get categories
            $row3 = $db->query('SELECT t1.slug,t1.name FROM ' . $db_table_prefix . '_terms t1,' . db_escape_string($db_name) . '.' . db_escape_string($db_table_prefix) . '_term_relationships t2 WHERE t1.term_id=t2.term_taxonomy_id AND t2.object_id=' . strval($post_id));
            foreach ($row3 as $categories) {
                $data[$user_id]['POSTS'][$post_id]['category'][$categories['slug']] = $categories['name'];
            }
            // Comments
            $row2 = $db->query('SELECT * FROM ' . $db_table_prefix . '_comments WHERE comment_post_ID=' . strval($post_id) . ' AND comment_approved=1');
            foreach ($row2 as $comments) {
                $comment_id = $comments['comment_ID'];
                $data[$user_id]['POSTS'][$post_id]['COMMENTS'][$comment_id] = $comments;
            }
        }
    }
    return $data;
}
예제 #4
0
 /**
  * Feedback after showing/sending an alarm notification
  *
  * @see calendar_driver::dismiss_alarm()
  */
 public function dismiss_alarm($event_id, $snooze = 0)
 {
     $success = parent::dismiss_alarm($event_id, $snooze);
     $success = false;
     $result = $this->rc->db->limitquery("SELECT calendar_id FROM " . $this->_get_table($this->db_events) . "\n            WHERE event_id = ?", 0, 1, $event_id);
     $result = $this->rc->db->fetch_assoc($result);
     if (is_array($result)) {
         $cal_id = $result['calendar_id'];
         $props = $this->_get_caldav_props($event_id, self::OBJ_TYPE_VEVENT);
         $sync_client = $this->sync_clients[$cal_id];
         if (is_array($props)) {
             if ($event = parent::get_master(array('id' => $event_id), false)) {
                 $event = $this->_save_preprocess($event);
                 $success = $sync_client->update_event($event, $props);
             } else {
                 $success = false;
             }
         } else {
             $success = false;
         }
     }
     return $success;
 }
예제 #5
0
/**
 * Script to handle XML DB/MySQL chain synching.
 */
function xml_dump_script()
{
    // Run checks and set up chain DB
    if (get_db_type() != 'xml') {
        warn_exit('It makes no sense to run this script if you are not running the XML database driver.');
    }
    global $SITE_INFO;
    if (array_key_exists('db_chain_type', $SITE_INFO)) {
        require_code('database/' . $SITE_INFO['db_chain_type']);
        $chain_db = new database_driver($SITE_INFO['db_chain'], $SITE_INFO['db_chain_host'], $SITE_INFO['db_chain_user'], $SITE_INFO['db_chain_password'], get_table_prefix(), false, object_factory('Database_Static_' . $SITE_INFO['db_chain_type']));
    } else {
        warn_exit('It makes no sense to run this script if you have not set up the following config options in info.php: db_chain_type, db_chain_host, db_chain_user, db_chain_password, db_chain');
    }
    $chain_connection =& $chain_db->connection_write;
    if (count($chain_connection) > 4) {
        $chain_connection = call_user_func_array(array($chain_db->static_ob, 'db_get_connection'), $chain_connection);
        _general_db_init();
    }
    if (function_exists('set_time_limit')) {
        @set_time_limit(0);
    }
    $GLOBALS['DEBUG_MODE'] = false;
    $GLOBALS['SEMI_DEBUG_MODE'] = false;
    @ini_set('ocproducts.xss_detect', '0');
    if (strtolower(ocp_srv('REQUEST_METHOD')) == 'get') {
        $from = get_param('from', NULL);
        $skip = get_param('skip', NULL);
        $only = get_param('only', NULL);
        echo '
		<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
		<html xmlns="http://www.w3.org/1999/xhtml">
		<head>
		<title>XML/MySQL DB syncher</title>
		</head>
		<body>
		';
        echo '<p>Select the tables to sync below. Tables have been auto-ticked based on what seems to need re-synching.</p>';
        $keep = symbol_tempcode('KEEP', array('1'));
        echo '<form title="Choose tables" method="post" action="' . escape_html(find_script('xml_db_import') . $keep->evaluate()) . '">';
        $tables = array_keys(find_all_tables($GLOBALS['SITE_DB']));
        $mysql_status = list_to_map('Name', $chain_db->query('SHOW TABLE STATUS'));
        $mysql_tables = array_keys($mysql_status);
        foreach ($tables as $table_name) {
            $default_selected = (!is_null($from) && $table_name >= $from || !is_null($only) && in_array($table_name, explode(',', $only))) && (!is_null($skip) || !in_array($table_name, explode(',', $skip)));
            $missing = !in_array(get_table_prefix() . $table_name, $mysql_tables);
            $count_mismatch = !$missing && $chain_db->query_value($table_name, 'COUNT(*)') != $GLOBALS['SITE_DB']->query_value($table_name, 'COUNT(*)');
            $date_mismatch = false;
            if (!$missing && !$count_mismatch) {
                $last_m_time = NULL;
                $path = get_custom_file_base() . '/uploads/website_specific/' . get_db_site() . '/' . get_table_prefix() . $table_name;
                $dh = @opendir($path);
                if ($dh !== false) {
                    while (($f = readdir($dh)) !== false) {
                        if (substr($f, -4) == '.dat' || substr($f, -4) == '.xml') {
                            $last_m_time = @max($last_m_time, filemtime($path . '/' . $f));
                        }
                        // @ because of the 255 read filepath limit on Windows
                    }
                    closedir($dh);
                }
                if (!is_null($last_m_time)) {
                    $mysql_time = strtotime($mysql_status[get_table_prefix() . $table_name]['Update_time']);
                    $date_mismatch = $mysql_time < $last_m_time;
                    // We can't do "!=" as last m-time for MySQL could well by the last sync time
                }
            }
            $needs_doing = $count_mismatch || $date_mismatch || $missing || $default_selected;
            echo '
				<div style="width: 500px">
					<span style="float: right; font-style: italic">
					' . ($missing ? '[table is missing]' : '') . '
					' . ($count_mismatch ? '[different record-counts]' : '') . '
					' . ($date_mismatch ? '[different last-modified-time]' : '') . '
					</span>

					<input ' . ($needs_doing ? 'checked="checked" ' : '') . 'type="checkbox" name="table_' . htmlentities($table_name) . '" id="table_' . htmlentities($table_name) . '" value="1" />
					<label for="table_' . htmlentities($table_name) . '">' . htmlentities($table_name) . '</label>
				</div>
			';
        }
        echo '<p><input type="submit" value="Sync" /> &nbsp;&nbsp;&nbsp;&nbsp; [<a href="#" onclick="var form=document.getElementsByTagName(\'form\')[0]; for (var i=0;i&lt;form.elements.length;i++) if (form.elements[i].checked) form.elements[i].checked=false; return false;">un-tick all</a>]</p>';
        echo '</form>';
        echo '
		</body>
		</html>
		';
        exit;
    }
    // Actualiser
    $from = NULL;
    $skip = NULL;
    $only = '';
    foreach (array_keys($_POST) as $key) {
        if (substr($key, 0, 6) == 'table_') {
            if ($only != '') {
                $only .= ',';
            }
            $only .= substr($key, 6);
        }
    }
    if ($only == '') {
        $only = NULL;
    }
    @header('Content-type: text/plain');
    @ob_end_clean();
    $sql = get_sql_dump(true, true, $from, is_null($skip) ? array() : explode(',', $skip), is_null($only) ? NULL : explode(',', $only));
    $cnt = count($sql);
    foreach ($sql as $i => $s) {
        print 'Executing query ' . strval($i + 1) . '/' . strval($cnt) . ' ... ' . $s . "\n\n";
        flush();
        $fail_ok = substr($s, 0, 5) == 'ALTER';
        $chain_db->static_ob->db_query($s, $chain_connection, NULL, NULL, $fail_ok, false);
    }
    print '!!Done!!';
}
 // Via addon_registry hooks (bundled ones)
 $files = array();
 $files = array_merge($files, get_directory_contents($path, '', false, false));
 if (file_exists(str_replace('/sources/', '/sources_custom/', $path))) {
     $files = array_merge($files, get_directory_contents(str_replace('/sources/', '/sources_custom/', $path), '', false, false));
 }
 foreach ($files as $file) {
     if (substr($file, -4) == '.php') {
         $auto_probe[] = basename($file, '.php');
     }
 }
 // Via addons table (non-bundled ones)
 global $SITE_INFO;
 $backup = $SITE_INFO;
 require_once $probe_dir . '/info.php';
 $linked_db = new database_driver(get_db_site(), get_db_site_host(), get_db_site_user(), get_db_site_password(), get_table_prefix());
 $auto_probe += collapse_1d_complexity('addon_name', $linked_db->query_select('addons', array('addon_name')));
 $SITE_INFO = $backup;
 // Via filesystem (non-bundled ones)
 foreach ($addons['non_bundled'] as $addon => $files) {
     foreach ($files as $file) {
         if (file_exists($probe_dir . '/' . $file)) {
             $auto_probe[] = $addon;
         }
     }
 }
 $auto_probe = array_unique($auto_probe);
 // Find oldest modified file that has been modified since
 $cutoff_days = 0;
 $files = get_directory_contents($probe_dir);
 foreach ($files as $file) {