header('Message Manager: Installer'); $t->paragraph("First we need to set up the SQL configuration, ". "then we will set up the first user."); $t->openTag('form', array('method'=>'post','action'=>$uri)); $t->tag('input', array('type'=>'hidden', 'name'=>'try', 'value'=>'t')); $try = isset($_POST['try']); $mysql = false; if ($try) { @$mysql = mysql_connect($_POST['db_host'], $_POST['db_user'], $_POST['db_password']); } //////////////////////////////////////////////////////////////////////// $t->openFieldset("MySQL Authentication", $mysql); $t->inputText('db_host', 'Hostname', '', mm_getParam('db_host','localhost'), $mysql); $t->inputText('db_user', 'Username', '', mm_getParam('db_user'), $mysql); $t->inputPassword('db_password', 'Password', '', mm_getParam('db_password'), $mysql); if ($try && !$mysql) { $t->inputP("Could not authenticate: ".mysql_error(), true); } $t->closeFieldset(); //////////////////////////////////////////////////////////////////////// $charset = false; if ($mysql) { $charset = mysql_set_charset($_POST['db_charset'], $mysql); if (!$charset) { $charset_error = mysql_error($mysql); } } $db = false; $db_message = ''; if ($charset) { $t->setRet(true); $db = mm_mysql_create_db($mysql, $_POST['db_name'], $db_message); $t->setRet(false); } $db_prefix = $_POST['db_prefix']; $table = false; if ($db) { $table_auth = mm_mysql_create_table($mysql,$db_prefix.'auth', array('uid INT UNSIGNED '. 'AUTO_INCREMENT PRIMARY KEY', 'name VARCHAR(255)', 'hash CHAR(60)', 'status INT')); $table_users = mm_mysql_create_table($mysql,$db_prefix.'users', array('uid INT UNSIGNED', 'k VARCHAR(255)', 'v TEXT')); $table_conf = mm_mysql_create_table($mysql,$db_prefix.'conf', array('k VARCHAR(255)', 'v VARCHAR(255)')); $table_plugins = mm_mysql_create_table($mysql,$db_prefix.'plugins', array('plugin VARCHAR(255)', 'k VARCHAR(255)', 'v VARCHAR(255)')); $tables_ok=(!is_string($table_auth)) && (!is_string($table_users)) && (!is_string($table_conf)) && (!is_string($table_plugins)); } //////////////////////////////////////////////////////////////////////// $t->openFieldset("MySQL Settings", $tables_ok); $t->inputText('db_charset', 'Charset', "I've heard that you may need to change this if ". "you use an old version of MySQL. 'utf8' is ". "generally a good option, though.", mm_getParam('db_charset','utf8'), $tables_ok); if ($mysql) { $str = $_POST['db_charset']; if ($charset) { $t->inputP("Set charset to $str."); } else { $t->inputP("Could not set charset to ". "$str: ".$charset_error, true); } } $t->inputText('db_name', 'Database name', '', mm_getParam('db_name', 'messagemanager'), $tables_ok); echo $db_message; $t->inputText('db_prefix', 'Table prefix', 'Just use simple characters, like [A-Za-z0-9_], '. 'and keep it short.', mm_getParam('db_prefix','mm_'), $tables_ok); if ($db) { $tables = array($db_prefix.'auth'=>$table_auth, $db_prefix.'users'=>$table_users, $db_prefix.'conf'=>$table_conf, $db_prefix.'plugins'=>$table_plugins); foreach ($tables as $name => $table) { $htmlname = ''.htmlentities($name).''; if (is_string($table)) { $msg = "Could not create table $htmlname: ". $table; } else { switch ($table) { case 0: $msg = "Table $htmlname already exists."; break; case 1: $msg = "Created table $htmlname."; break; } } $t->inputP($msg, is_string($table)); } } $t->closeFieldset(); //////////////////////////////////////////////////////////////////////// $fh = false; if ($tables_ok) { $fh = fopen($conf_file, 'w'); if ($fh === false) { $msg="Could not open file conf.php for writing."; $t->paragraph($msg, array('class'=>'error')); } else { fwrite($fh, 'closeTag('form'); $t->openTag('form', array('action'=>$uri)); $t->tag('input', array('type'=>'submit', 'value'=>'Cool beans, go to step 2!')); } else { $t->tag('input', array('type'=>'submit', 'value'=>'Submit')); } $t->closeTag('form'); $t->footer(); //////////////////////////////////////////////////////////////////////// } else { require_once('MessageManager.class.php'); $mm = new MessageManager($conf_file); $t = $mm->template(); $db = $mm->database(); $t->header('Message Manager: Installer'); $user_count = $db->countUsers(); if ($user_count<1) { $t->openTag('form', array('method'=>'post', 'action'=>$uri)); $t->tag('input', array('type'=>'hidden', 'id'=>'try', 'name'=>'try', 'value'=>'t')); $try = isset($_POST['try']); $pw = false; if ($try) { $pw = ( $_POST['mm_password'] === $_POST['mm_password_verify'] ); } $admin = false; if ($pw) { $user = $_POST['mm_user']; $password = $_POST['mm_password']; $uid = $db->addUser($user, $password); $admin = $db->setStatus($uid, 2); if (!$admin) { $admin_error = $db->mysql_error(); } } //////////////////////////////////////////////////////////////// $t->openFieldset("First Account (administrator)",$admin); $t->inputText('mm_user', 'Username', "Must be <= 255 characters.", mm_getParam('mm_user','root'), $admin); $t->inputNewPassword('mm_password', 'Password', ($pw?mm_getParam('mm_password'):''), $admin); if ($try && !$pw) { $msg="Passwords don't match."; $template->inputP($msg, true); } if ($pw) { $user = "".$_POST['mm_user'].''; if ($admin) { $msg="Created user $user."; } else { $msg="Could not create user $user: ". $admin_error; } $t->inputP($msg, !$admin); } $t->closeFieldset(); //////////////////////////////////////////////////////////////// if (!$admin) { $t->tag('input', array('type'=>'submit', 'value'=>'Submit')); } $t->closeTag('form'); } else { $t->paragraph("File conf.php already exists, and there ". "is at least one user. Return to the ". "main page."); } $t->footer(); }