Skip to content
Snippets Groups Projects
Commit 303c0370 authored by Peter Rotich's avatar Peter Rotich
Browse files

Add mysqli support to installer and minor improvements

parent 577e2c46
No related branches found
No related tags found
No related merge requests found
......@@ -22,22 +22,24 @@ function db_connect($host, $user, $passwd, $options) {
global $__db;
//Assert
if(!strlen($user) || !strlen($passwd) || !strlen($host))
if(!strlen($user) || !strlen($host))
return NULL;
if (!($__db = mysqli_init()))
return NULL;
// Setup SSL if enabled
if (isset($options['certs']))
$__db->set_ssl(
$options['certs']['key'],
$options['certs']['cert'],
$options['certs']['ca'],
if (isset($options['ssl']))
$__db->ssl_set(
$options['ssl']['key'],
$options['ssl']['cert'],
$options['ssl']['ca'],
null, null);
elseif(!$passwd)
return NULL;
//Connectr
if(!$__db->real_connect($host, $user, $passwd))
if(!@$__db->real_connect($host, $user, $passwd))
return NULL;
//Select the database, if any.
......@@ -214,6 +216,11 @@ function db_input($var, $quote=true) {
return db_real_escape($var, $quote);
}
function db_connect_error() {
global $__db;
return $__db->connect_error;
}
function db_error() {
global $__db;
return $__db->error;
......
......@@ -195,12 +195,13 @@
$ferror=null;
$options = array();
if (defined('DBSSLCA'))
$options['certs'] = array(
$options['ssl'] = array(
'ca' => DBSSLCA,
'cert' => DBSSLCERT,
'key' => DBSSLKEY
);
if (!db_connect(DBHOST,DBUSER,DBPASS, $options)
if (!db_connect(DBHOST, DBUSER, DBPASS, $options)
|| !db_select_database(DBNAME)) {
$ferror='Unable to connect to the database';
} elseif(!($ost=osTicket::start(1)) || !($cfg = $ost->getConfig())) {
......
......@@ -44,7 +44,7 @@ class Installer extends SetupWizard {
function install($vars) {
$this->errors=$f=array();
$f['name'] = array('type'=>'string', 'required'=>1, 'error'=>'Name required');
$f['email'] = array('type'=>'email', 'required'=>1, 'error'=>'Valid email required');
$f['fname'] = array('type'=>'string', 'required'=>1, 'error'=>'First name required');
......@@ -58,7 +58,7 @@ class Installer extends SetupWizard {
$f['dbname'] = array('type'=>'string', 'required'=>1, 'error'=>'Database name required');
$f['dbuser'] = array('type'=>'string', 'required'=>1, 'error'=>'Username required');
$f['dbpass'] = array('type'=>'string', 'required'=>1, 'error'=>'password required');
if(!Validator::process($f,$vars,$this->errors) && !$this->errors['err'])
$this->errors['err']='Missing or invalid data - correct the errors and try again.';
......@@ -67,14 +67,14 @@ class Installer extends SetupWizard {
//Staff's email can't be same as system emails.
if($vars['admin_email'] && $vars['email'] && !strcasecmp($vars['admin_email'],$vars['email']))
$this->errors['admin_email']='Conflicts with system email above';
//Admin's pass confirmation.
//Admin's pass confirmation.
if(!$this->errors && strcasecmp($vars['passwd'],$vars['passwd2']))
$this->errors['passwd2']='passwords to not match!';
//Check table prefix underscore required at the end!
if($vars['prefix'] && substr($vars['prefix'], -1)!='_')
$this->errors['prefix']='Bad prefix. Must have underscore (_) at the end. e.g \'ost_\'';
//Make sure admin username is not very predictable. XXX: feels dirty but necessary
//Make sure admin username is not very predictable. XXX: feels dirty but necessary
if(!$this->errors['username'] && in_array(strtolower($vars['username']),array('admin','admins','username','osticket')))
$this->errors['username']='Bad username';
......@@ -123,7 +123,7 @@ class Installer extends SetupWizard {
$this->errors['err']='Unable to open config file for writing. Permission denied! (#3)';
elseif(!$this->load_sql_file($schemaFile,$vars['prefix'], true, $debug))
$this->errors['err']='Error parsing SQL schema! Get help from developers (#4)';
if(!$this->errors) {
//Create admin user.
$sql='INSERT INTO '.PREFIX.'staff SET created=NOW() '
......@@ -178,7 +178,7 @@ class Installer extends SetupWizard {
.",(2,1,'osTicket Alerts','alerts@$domain',NOW(),NOW())"
.",(3,1,'','noreply@$domain',NOW(),NOW())";
@mysql_query($sql);
//Create a ticket to make the system warm and happy.
$sql='INSERT INTO '.PREFIX.'ticket SET created=NOW(), status="open", source="Web" '
.' ,priority_id=2, dept_id=1, topic_id=1 '
......@@ -189,7 +189,7 @@ class Installer extends SetupWizard {
if(mysql_query($sql) && ($tid=mysql_insert_id())) {
if(!($msg=file_get_contents(INC_DIR.'msg/installed.txt')))
$msg='Congratulations and Thank you for choosing osTicket!';
$sql='INSERT INTO '.PREFIX.'ticket_thread SET created=NOW()'
.', source="Web" '
.', thread_type="M" '
......@@ -199,7 +199,7 @@ class Installer extends SetupWizard {
@mysql_query($sql);
}
//TODO: create another personalized ticket and assign to admin??
//Log a message.
$msg="Congratulations osTicket basic installation completed!\n\nThank you for choosing osTicket!";
$sql='INSERT INTO '.PREFIX.'syslog SET created=NOW(), updated=NOW(), log_type="Debug" '
......
......@@ -66,5 +66,10 @@ require_once(INCLUDE_DIR.'class.validator.php');
require_once(INCLUDE_DIR.'class.passwd.php');
require_once(INCLUDE_DIR.'class.format.php');
require_once(INCLUDE_DIR.'class.misc.php');
require_once(INCLUDE_DIR.'mysql.php');
if (extension_loaded('mysqli'))
require_once INCLUDE_DIR.'mysqli.php';
else
require(INCLUDE_DIR.'mysql.php');
?>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment