Ejemplo n.º 1
0
function upgrade_step($index, $conn)
{
    global $path_to_root, $installers;
    $inst = $installers[$index];
    $pref = $conn['tbpref'];
    $ret = true;
    $force = get_post('force_' . $index);
    if ($force || get_post('install_' . $index)) {
        $state = $inst->installed($pref);
        if (!$state || $force) {
            if (!$inst->pre_check($pref, $force)) {
                return false;
            }
            $sql = $inst->sql;
            error_log(sprintf(_("Database upgrade for company '%s' (%s:%s*) started..."), $conn['name'], $conn['dbname'], $conn['tbpref']));
            if ($sql != '') {
                $ret &= db_import($path_to_root . '/sql/' . $sql, $conn, $force);
            }
            $ret &= $inst->install($pref, $force);
            error_log(_("Database upgrade finished."));
        } else {
            if ($state !== true) {
                display_error(_("Upgrade cannot be done because database has been already partially upgraded. Please downgrade database to clean previous version or try forced upgrade."));
                $ret = false;
            }
        }
    }
    return $ret;
}
Ejemplo n.º 2
0
echo "<br>";
if (isset($_POST["submit"])) {
    if (!isset($_FILES['uploadfile']['tmp_name']) || !is_uploaded_file($_FILES['uploadfile']['tmp_name'])) {
        display_error("You must select an SQL script for update");
    } else {
        include_once $path_to_root . "/config_db.php";
        if (!isset($_POST['user']) || !isset($_POST['passwd']) || $_POST['user'] == "") {
            display_error("You must select a user name and an optional password");
        } else {
            foreach ($db_connections as $id => $conn) {
                $conn['dbuser'] = $_POST['user'];
                $conn['dbpassword'] = $_POST['passwd'];
                if (!($db = db_open($conn))) {
                    display_error("Wrong user name or password - " . mysql_error());
                } else {
                    if (!db_import($_FILES['uploadfile']['tmp_name'], $conn)) {
                        display_error("Bad SQL file or you have already updated the company: " . $id . " " . $conn['name'] . " - " . mysql_error());
                    } else {
                        display_notification("Database has been updated for company: " . $id . " " . $conn['name']);
                    }
                }
            }
        }
    }
}
if (!isset($_POST['passwd'])) {
    $_POST['passwd'] = "";
}
echo "<form enctype='multipart/form-data' method='post' action='" . $_SERVER['PHP_SELF'] . "'>\n";
echo "<table align='center' width='50%' cellpadding=3 border=1 bordercolor='#cccccc' style='border-collapse: collapse'>\n";
text_row_ex("Database User", "user", 20);
Ejemplo n.º 3
0
function handle_submit()
{
    global $db_connections, $def_coy, $tb_pref_counter, $db, $comp_subdirs, $path_to_root, $selected_id;
    $error = false;
    if (!check_data()) {
        return false;
    }
    if ($selected_id == -1) {
        $selected_id = count($db_connections);
    }
    $new = !isset($db_connections[$selected_id]);
    if ((bool) $_POST['def'] == true) {
        $def_coy = $selected_id;
    }
    $db_connections[$selected_id]['name'] = $_POST['name'];
    if ($new) {
        $db_connections[$selected_id]['host'] = $_POST['host'];
        $db_connections[$selected_id]['dbuser'] = $_POST['dbuser'];
        $db_connections[$selected_id]['dbpassword'] = $_POST['dbpassword'];
        $db_connections[$selected_id]['dbname'] = $_POST['dbname'];
        if (is_numeric($_POST['tbpref'])) {
            $db_connections[$selected_id]['tbpref'] = $_POST['tbpref'] == 1 ? $tb_pref_counter . "_" : '';
        } else {
            if ($_POST['tbpref'] != "") {
                $db_connections[$selected_id]['tbpref'] = $_POST['tbpref'];
            } else {
                $db_connections[$selected_id]['tbpref'] = "";
            }
        }
        $conn = $db_connections[$selected_id];
        if (($db = db_create_db($conn)) == 0) {
            display_error(_("Error creating Database: ") . $conn['dbname'] . _(", Please create it manually"));
            $error = true;
        } else {
            if (!db_import($path_to_root . '/sql/' . get_post('coa'), $conn, $selected_id)) {
                display_error(_('Cannot create new company due to bugs in sql file.'));
                $error = true;
            } else {
                if (!isset($_POST['admpassword']) || $_POST['admpassword'] == "") {
                    $_POST['admpassword'] = "******";
                }
                update_admin_password($conn, md5($_POST['admpassword']));
            }
        }
        set_global_connection();
        if ($error) {
            remove_connection($selected_id);
            return false;
        }
    }
    $error = write_config_db($new);
    if ($error == -1) {
        display_error(_("Cannot open the configuration file - ") . $path_to_root . "/config_db.php");
    } else {
        if ($error == -2) {
            display_error(_("Cannot write to the configuration file - ") . $path_to_root . "/config_db.php");
        } else {
            if ($error == -3) {
                display_error(_("The configuration file ") . $path_to_root . "/config_db.php" . _(" is not writable. Change its permissions so it is, then re-run the operation."));
            }
        }
    }
    if ($error != 0) {
        return false;
    }
    if ($new) {
        create_comp_dirs(company_path($selected_id), $comp_subdirs);
    }
    $exts = get_company_extensions();
    write_extensions($exts, $selected_id);
    display_notification($new ? _('New company has been created.') : _('Company has been updated.'));
    return true;
}
Ejemplo n.º 4
0
function do_install()
{
    global $path_to_root, $db_connections, $def_coy, $installed_extensions, $tb_pref_counter, $dflt_lang, $installed_languages;
    $coa = $_SESSION['inst_set']['coa'];
    if (install_connect_db() && db_import($path_to_root . '/sql/' . $coa, $_SESSION['inst_set'])) {
        $con = $_SESSION['inst_set'];
        $table_prefix = $con['tbpref'];
        $def_coy = 0;
        $tb_pref_counter = 0;
        $db_connections = array(0 => array('name' => $con['name'], 'host' => $con['host'], 'dbuser' => $con['dbuser'], 'dbpassword' => $con['dbpassword'], 'dbname' => $con['dbname'], 'tbpref' => $table_prefix));
        $_SESSION['wa_current_user']->cur_con = 0;
        update_company_prefs(array('coy_name' => $con['name']));
        $admin = get_user_by_login('admin');
        update_user_prefs($admin['id'], array('language' => $con['lang'], 'password' => md5($con['pass']), 'user_id' => $con['admin']));
        if (!copy($path_to_root . "/config.default.php", $path_to_root . "/config.php")) {
            display_error(_("Cannot save system configuration file 'config.php'."));
            return false;
        }
        $err = write_config_db($table_prefix != "");
        if ($err == -1) {
            display_error(_("Cannot open 'config_db.php' configuration file."));
            return false;
        } else {
            if ($err == -2) {
                display_error(_("Cannot write to the 'config_db.php' configuration file."));
                return false;
            } else {
                if ($err == -3) {
                    display_error(_("Configuration file 'config_db.php' is not writable. Change its permissions so it is, then re-run installation step."));
                    return false;
                }
            }
        }
        // update default language
        if (file_exists($path_to_root . "/lang/installed_languages.inc")) {
            include_once $path_to_root . "/lang/installed_languages.inc";
        }
        $dflt_lang = $_POST['lang'];
        write_lang();
        return true;
    }
    return false;
}
Ejemplo n.º 5
0
Archivo: db.php Proyecto: refirio/levis
/**
 * Output a import page for database.
 *
 */
function db_admin_import()
{
    if ($_SERVER['REQUEST_METHOD'] === 'POST') {
        if ($_POST['means'] === 'upload') {
            if (is_uploaded_file($_FILES['target']['tmp_name'])) {
                $target = $_FILES['target']['tmp_name'];
            } else {
                error('db: Import file not found');
            }
        } else {
            $target = DATABASE_NAME . '.sql';
            if (!is_file($target)) {
                error('db: Import file not found');
            }
        }
        $count = db_import($target);
        $_view['message'] = $count . ' sql executed.';
    } else {
        $_view['message'] = '';
    }
    echo "<!DOCTYPE html>\n";
    echo "<html>\n";
    echo "<head>\n";
    echo "<meta charset=\"" . t(MAIN_CHARSET, true) . "\" />\n";
    echo "<title>DB</title>\n";
    style();
    echo "</head>\n";
    echo "<body>\n";
    echo "<h1><a href=\"" . t(MAIN_FILE, true) . "/?_mode=db_admin\">DB</a></h1>\n";
    echo "<h2>Menu</h2>\n";
    echo "<ul>\n";
    echo "<li><a href=\"" . t(MAIN_FILE, true) . "/?_mode=db_admin&amp;_work=sql\">SQL</a></li>\n";
    echo "<li>Import</li>\n";
    echo "<li><a href=\"" . t(MAIN_FILE, true) . "/?_mode=db_admin&amp;_work=export\">Export</a></li>\n";
    if (file_exists(DATABASE_BACKUP_PATH)) {
        echo "<li><a href=\"" . t(MAIN_FILE, true) . "/?_mode=db_admin&amp;_work=backup\">Backup</a></li>\n";
    }
    echo "</ul>\n";
    echo "<h2>Import</h2>\n";
    if ($_view['message']) {
        echo "<ul>\n";
        echo "<li>" . $_view['message'] . "</li>\n";
        echo "</ul>\n";
    } else {
        echo "<ul>\n";
        echo "<li>Import from SQL file.</li>\n";
        echo "</ul>\n";
    }
    echo "<form action=\"" . t(MAIN_FILE, true) . "/?_mode=db_admin&amp;_work=import\" method=\"post\" enctype=\"multipart/form-data\">\n";
    echo "<fieldset>\n";
    echo "<legend>import</legend>\n";
    echo "<dl>\n";
    echo "<dt><label><input type=\"radio\" name=\"means\" value=\"upload\" checked=\"checked\" /> upload</label></dt>\n";
    echo "<dd><input type=\"file\" name=\"target\" size=\"30\" /></dd>\n";
    echo "<dt><label><input type=\"radio\" name=\"means\" value=\"file\" /> read</label></dt>\n";
    echo "<dd>\n";
    echo "<code title=\"" . dirname($_SERVER['SCRIPT_FILENAME']) . '/' . DATABASE_NAME . ".sql\">" . DATABASE_NAME . ".sql</code>\n";
    if (!is_file(DATABASE_NAME . '.sql')) {
        echo "(Not found.)\n";
    }
    echo "</dd>\n";
    echo "</dl>\n";
    echo "<p><input type=\"submit\" value=\"import\" /></p>\n";
    echo "</fieldset>\n";
    echo "</form>\n";
    echo "</body>\n";
    echo "</html>\n";
    return;
}
Ejemplo n.º 6
0
    header('Content-Length: ' . filesize($filename));
    header('Content-Disposition: attachment; filename="' . $saveasname . '"');
    readfile($filename);
    return true;
}
$db_name = $_SESSION["wa_current_user"]->company;
$conn = $db_connections[$db_name];
$backup_name = clean_file_name(get_post('backups'));
$backup_path = BACKUP_PATH . $backup_name;
if (get_post('creat')) {
    generate_backup($conn, get_post('comp'), get_post('comments'));
    $Ajax->activate('backups');
}
if (get_post('restore')) {
    if ($backup_name) {
        if (db_import($backup_path, $conn)) {
            display_notification(_("Restore backup completed."));
        }
        refresh_sys_prefs();
        // re-read system setup
    } else {
        display_error(_("Select backup file first."));
    }
}
if (get_post('deldump')) {
    if ($backup_name) {
        if (unlink($backup_path)) {
            display_notification(_("File successfully deleted.") . " " . _("Filename") . ": " . $backup_name);
            $Ajax->activate('backups');
        } else {
            display_error(_("Can't delete backup file."));
Ejemplo n.º 7
0
function handle_submit()
{
    global $db_connections, $def_coy, $tb_pref_counter, $db, $comp_path, $comp_subdirs;
    $new = false;
    if (!check_data()) {
        return false;
    }
    $id = $_GET['id'];
    $db_connections[$id]['name'] = $_POST['name'];
    $db_connections[$id]['host'] = $_POST['host'];
    $db_connections[$id]['dbuser'] = $_POST['dbuser'];
    $db_connections[$id]['dbpassword'] = $_POST['dbpassword'];
    $db_connections[$id]['dbname'] = $_POST['dbname'];
    if ((bool) $_POST['def'] == true) {
        $def_coy = $id;
    }
    if (isset($_GET['ul']) && $_GET['ul'] == 1) {
        $conn = $db_connections[$id];
        if (($db = db_create_db($conn)) == 0) {
            display_error(tr("Error creating Database: ") . $conn['dbname'] . tr(", Please create it manually"));
            remove_connection($id);
            set_global_connection();
            return false;
        }
        $filename = $_FILES['uploadfile']['tmp_name'];
        if (is_uploaded_file($filename)) {
            db_import($filename, $conn, $id);
            if (isset($_POST['admpassword']) && $_POST['admpassword'] != "") {
                db_query("UPDATE users set password = '******'admpassword']) . "' WHERE user_id = 'admin'");
            }
        } else {
            display_error(tr("Error uploading Database Script, please upload it manually"));
            set_global_connection();
            return false;
        }
        set_global_connection();
    }
    $error = write_config_db($new);
    if ($error == -1) {
        display_error(tr("Cannot open the configuration file - ") . $path_to_root . "/config_db.php");
    } else {
        if ($error == -2) {
            display_error(tr("Cannot write to the configuration file - ") . $path_to_root . "/config_db.php");
        } else {
            if ($error == -3) {
                display_error(tr("The configuration file ") . $path_to_root . "/config_db.php" . tr(" is not writable. Change its permissions so it is, then re-run the operation."));
            }
        }
    }
    if ($error != 0) {
        return false;
    }
    $index = "<?php\nheader(\"Location: ../../index.php\");\n?>";
    if ($new) {
        $cdir = $comp_path . '/' . $id;
        @mkdir($cdir);
        save_to_file($cdir . '/' . 'index.php', 0, $index);
        foreach ($comp_subdirs as $dir) {
            @mkdir($cdir . '/' . $dir);
            save_to_file($cdir . '/' . $dir . '/' . 'index.php', 0, $index);
        }
    }
    return true;
}
Ejemplo n.º 8
0
function handle_submit()
{
    global $path_to_root, $installed_modules, $db_connections;
    if (!check_data()) {
        return false;
    }
    $id = $_GET['id'];
    $installed_modules[$id]['tab'] = $_POST['tab'];
    $installed_modules[$id]['name'] = $_POST['name'];
    $installed_modules[$id]['path'] = $_POST['path'];
    $directory = $path_to_root . "/modules/" . $_POST['path'];
    if (!file_exists($directory)) {
        mkdir($directory);
    }
    if (is_uploaded_file($_FILES['uploadfile']['tmp_name'])) {
        $installed_modules[$id]['filename'] = $_FILES['uploadfile']['name'];
        $file1 = $_FILES['uploadfile']['tmp_name'];
        $file2 = $directory . "/" . $_FILES['uploadfile']['name'];
        if (file_exists($file2)) {
            unlink($file2);
        }
        move_uploaded_file($file1, $file2);
    } else {
        $installed_modules[$id]['filename'] = $_POST['filename'];
    }
    if (is_uploaded_file($_FILES['uploadfile2']['tmp_name'])) {
        $file1 = $_FILES['uploadfile2']['tmp_name'];
        $file2 = $directory . "/" . $_FILES['uploadfile2']['name'];
        if (file_exists($file2)) {
            unlink($file2);
        }
        move_uploaded_file($file1, $file2);
        $db_name = $_SESSION["wa_current_user"]->company;
        db_import($file2, $db_connections[$db_name]);
    }
    if (!write_modules()) {
        return false;
    }
    return true;
}
Ejemplo n.º 9
0
        }
    }
}
// Try connecting to database
$db = mysql_connect($database_host, $database_username, $database_password);
if (!$db) {
    set_error('Database host name, username and/or password incorrect. MySQL Error:<br />' . mysql_error());
}
if ($install_tables == true) {
    if (!mysql_select_db($database_name, $db)) {
        // Try to create the database
        mysql_query('CREATE DATABASE ' . $database_name);
        mysql_select_db($database_name, $db);
    }
    // we use swiss german and don't overwrite non existing tables
    $import_filename = accounting_scheme();
    if (!db_import($import_filename, $db_connections[$id], 1)) {
        set_error("Import error, try to import {$import_filename} manually via phpMyAdmin");
    }
} else {
    mysql_select_db($database_name, $db);
}
$sql = "UPDATE users SET password = '******', email = " . db_escape($admin_email) . " WHERE user_id = 'admin'";
db_query($sql, "could not update admin account");
$sql = "UPDATE company SET coy_name = " . db_escape($company_name) . " WHERE coy_code = 1";
db_query($sql, "could not update company name. Do it manually later in Setup");
session_unset();
session_destroy();
$_SESSION = array();
header("Location: " . $path_to_root . "/index.php");
exit;
Ejemplo n.º 10
0
function restore_backup($filename, $conn)
{
    return db_import($filename, $conn);
}
Ejemplo n.º 11
0
 if ($calculated_checksum != $checksum) {
     forbidden();
 }
 // if
 $database_dir = $backup_dir . '/database';
 if (!db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME, true, DB_CHARSET)) {
     die('Could not connect to database. Check activeCollab database settings');
 }
 // if
 $database_file = $backup_dir . '/database.sql';
 if (!is_file($database_file)) {
     echo "<p>Could not restore backup. Database dump is missing</p>";
     die;
 }
 // if
 $restore_database = db_import($database_file);
 if (!$restore_database) {
     echo 'Cannot import database: Unknown Error';
     die;
 } else {
     if (is_error($restore_database)) {
         echo 'Cannot import database: ' . $restore_database->getMessage();
         die;
     }
 }
 // if
 // restore files
 $errors = array();
 special_copy_dir($backup_dir . '/upload', UPLOAD_PATH, false, $errors);
 special_copy_dir($backup_dir . '/projects_icons', ENVIRONMENT_PATH . '/' . PUBLIC_FOLDER_NAME . '/projects_icons', false, $errors);
 special_copy_dir($backup_dir . '/avatars', ENVIRONMENT_PATH . '/' . PUBLIC_FOLDER_NAME . '/avatars', false, $errors);