コード例 #1
0
ファイル: setup.php プロジェクト: shannara/banshee
 public function create_database($username, $password)
 {
     $db = new MySQLi_connection(DB_HOSTNAME, "mysql", $username, $password);
     if ($db->connected == false) {
         $this->output->add_message("Error connecting to database.");
         return false;
     }
     $db->query("begin");
     /* Create database
      */
     $query = "create database if not exists %S character set utf8";
     if ($db->query($query, DB_DATABASE) == false) {
         $db->query("rollback");
         $this->output->add_message("Error creating database.");
         return false;
     }
     /* Create user
      */
     $query = "select count(*) as count from user where User=%s";
     if (($users = $db->execute($query, DB_USERNAME)) === false) {
         $db->query("rollback");
         $this->output->add_message("Error checking for user.");
         return false;
     }
     if ($users[0]["count"] == 0) {
         $query = "create user %s@%s identified by %s";
         if ($db->query($query, DB_USERNAME, DB_HOSTNAME, DB_PASSWORD) == false) {
             $db->query("rollback");
             $this->output->add_message("Error creating user.");
             return false;
         }
     } else {
         $login_test = new MySQLi_connection(DB_HOSTNAME, DB_DATABASE, DB_USERNAME, DB_PASSWORD);
         if ($login_test->connected == false) {
             $db->query("rollback");
             $this->output->add_message("Invalid credentials in settings/website.conf.");
             return false;
         }
     }
     /* Set access rights
      */
     $rights = array("select", "insert", "update", "delete", "create", "drop", "alter", "index", "lock tables", "create view", "show view");
     $query = "grant " . implode(", ", $rights) . " on %S.* to %s@%s";
     if ($db->query($query, DB_DATABASE, DB_USERNAME, DB_HOSTNAME) == false) {
         $db->query("rollback");
         $this->output->add_message("Error setting access rights.");
         return false;
     }
     /* Commit changes
      */
     $db->query("commit");
     $db->query("flush privileges");
     unset($db);
     return true;
 }
コード例 #2
0
ファイル: index.php プロジェクト: Wabuo/monitor
 * http://www.banshee-php.org/
 *
 * Don't change this file, unless you know what you are doing.
 */
ob_start();
require "../libraries/error.php";
require "../libraries/banshee.php";
require "../libraries/security.php";
/* Abort on dangerous PHP settings
 */
check_PHP_setting("allow_url_include", 0);
check_PHP_setting("magic_quotes_gpc", 0);
check_PHP_setting("register_globals", 0);
/* Create core objects
 */
$_database = new MySQLi_connection(DB_HOSTNAME, DB_DATABASE, DB_USERNAME, DB_PASSWORD);
$_settings = new settings($_database);
$_session = new session($_database, $_settings);
$_user = new user($_database, $_settings, $_session);
$_page = new page($_database, $_settings, $_user);
$_output = new output($_database, $_settings, $_page);
if (is_true(MULTILINGUAL)) {
    $_language = new language($_database, $_page, $_output);
}
/* Prevent Cross-Site Request Forgery
 */
prevent_csrf($_output, $_user);
/* User switch warning
 */
if (isset($_SESSION["user_switch"])) {
    $real_user = $_database->entry("users", $_SESSION["user_switch"]);