Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1840 Upgrade to 1.8.4 fails with SQLite #1895

Merged
merged 3 commits into from Mar 20, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions admin/index.php
Expand Up @@ -213,9 +213,9 @@
$admin_session['data'] = array();

// Only reset the loginattempts when we're really logged in and the user doesn't need to enter a 2fa code
$query = $db->simple_select("adminoptions", "2fasecret", "uid='{$mybb->user['uid']}'");
$query = $db->simple_select("adminoptions", "authsecret", "uid='{$mybb->user['uid']}'");
$admin_options = $db->fetch_array($query);
if(empty($admin_options['2fasecret']))
if(empty($admin_options['authsecret']))
{
$db->update_query("adminoptions", array("loginattempts" => 0, "loginlockoutexpiry" => 0), "uid='{$mybb->user['uid']}'");
}
Expand Down Expand Up @@ -531,7 +531,7 @@
require_once MYBB_ROOT."inc/3rdparty/2fa/GoogleAuthenticator.php";
$auth = new PHPGangsta_GoogleAuthenticator;

$test = $auth->verifyCode($admin_options['2fasecret'], $mybb->get_input('code'));
$test = $auth->verifyCode($admin_options['authsecret'], $mybb->get_input('code'));

// Either the code was okay or it was a recovery code
if($test === true || $recovery === true)
Expand Down Expand Up @@ -597,7 +597,7 @@
}

// Show our 2FA page
if(!empty($admin_options['2fasecret']) && $admin_session['authenticated'] != 1)
if(!empty($admin_options['authsecret']) && $admin_session['authenticated'] != 1)
{
$page->show_2fa();
}
Expand Down
16 changes: 8 additions & 8 deletions admin/modules/home/preferences.php
Expand Up @@ -51,10 +51,10 @@

if($mybb->request_method == "post")
{
$query = $db->simple_select("adminoptions", "permissions, defaultviews, 2fasecret, recovery_codes", "uid='{$mybb->user['uid']}'");
$query = $db->simple_select("adminoptions", "permissions, defaultviews, authsecret, recovery_codes", "uid='{$mybb->user['uid']}'");
$adminopts = $db->fetch_array($query);

$secret = $adminopts['2fasecret'];
$secret = $adminopts['authsecret'];
// Was the option changed? empty = disabled so ==
if($mybb->input['2fa'] == empty($secret))
{
Expand Down Expand Up @@ -83,7 +83,7 @@
"defaultviews" => $db->escape_string($adminopts['defaultviews']),
"uid" => $mybb->user['uid'],
"codepress" => $mybb->get_input('codepress', MyBB::INPUT_INT), // It's actually CodeMirror but for compatibility purposes lets leave it codepress
"2fasecret" => $db->escape_string($secret),
"authsecret" => $db->escape_string($secret),
"recovery_codes" => $db->escape_string($adminopts['recovery_codes']),
);

Expand All @@ -105,7 +105,7 @@

$page->output_nav_tabs($sub_tabs, 'preferences');

$query = $db->simple_select("adminoptions", "notes, cpstyle, cplanguage, codepress, 2fasecret", "uid='".$mybb->user['uid']."'", array('limit' => 1));
$query = $db->simple_select("adminoptions", "notes, cpstyle, cplanguage, codepress, authsecret", "uid='".$mybb->user['uid']."'", array('limit' => 1));
$admin_options = $db->fetch_array($query);

$form = new Form("index.php?module=home-preferences", "post");
Expand Down Expand Up @@ -139,17 +139,17 @@
$table->construct_row();

// If 2FA is enabled we need to display a link to the recovery codes page
if(!empty($admin_options['2fasecret']))
if(!empty($admin_options['authsecret']))
{
$lang->use_2fa_desc .= "<br />".$lang->recovery_codes_desc." ".$lang->recovery_codes_warning;
}

$table->construct_cell("<strong>{$lang->my2fa}</strong><br /><small>{$lang->use_2fa_desc}</small><br /><br />".$form->generate_on_off_radio('2fa', (int)!empty($admin_options['2fasecret'])));
$table->construct_cell("<strong>{$lang->my2fa}</strong><br /><small>{$lang->use_2fa_desc}</small><br /><br />".$form->generate_on_off_radio('2fa', (int)!empty($admin_options['authsecret'])));
$table->construct_row();

if(!empty($admin_options['2fasecret']))
if(!empty($admin_options['authsecret']))
{
$qr = $auth->getQRCodeGoogleUrl($mybb->user['username']."@".str_replace(" ", "", $mybb->settings['bbname']), $admin_options['2fasecret']);
$qr = $auth->getQRCodeGoogleUrl($mybb->user['username']."@".str_replace(" ", "", $mybb->settings['bbname']), $admin_options['authsecret']);
$table->construct_cell("<strong>{$lang->my2fa_qr}</strong><br /><img src=\"{$qr}\"");
$table->construct_row();
}
Expand Down
2 changes: 1 addition & 1 deletion install/resources/mysql_db_tables.php
Expand Up @@ -29,7 +29,7 @@
defaultviews text NOT NULL,
loginattempts smallint unsigned NOT NULL default '0',
loginlockoutexpiry int unsigned NOT NULL default '0',
2fasecret varchar(16) NOT NULL default '',
authsecret varchar(16) NOT NULL default '',
recovery_codes varchar(177) NOT NULL default '',
PRIMARY KEY (uid)
) ENGINE=MyISAM;";
Expand Down
2 changes: 1 addition & 1 deletion install/resources/pgsql_db_tables.php
Expand Up @@ -33,7 +33,7 @@
defaultviews text NOT NULL,
loginattempts smallint NOT NULL default '0',
loginlockoutexpiry int NOT NULL default '0',
2fasecret varchar(16) NOT NULL default '',
authsecret varchar(16) NOT NULL default '',
recovery_codes varchar(177) NOT NULL default '',
UNIQUE (uid)
);";
Expand Down
6 changes: 3 additions & 3 deletions install/resources/sqlite_db_tables.php
Expand Up @@ -26,9 +26,9 @@
permissions TEXT NOT NULL,
defaultviews TEXT NOT NULL,
loginattempts smallint unsigned NOT NULL default '0',
loginlockoutexpiry int unsigned NOT NULL default '0'
2fasecret varchar(16) NOT NULL default '',
recovery_codes varchar(177) NOT NULL default '',
loginlockoutexpiry int unsigned NOT NULL default '0',
authsecret varchar(16) NOT NULL default '',
recovery_codes varchar(177) NOT NULL default ''
);";

$tables[] = "CREATE TABLE mybb_adminsessions (
Expand Down
10 changes: 5 additions & 5 deletions install/resources/upgrade32.php
Expand Up @@ -39,9 +39,9 @@ function upgrade32_dbchanges()
$db->drop_column("usergroups", "candeletereputations");
}

if($db->field_exists('2fasecret', 'adminoptions'))
if($db->field_exists('authsecret', 'adminoptions'))
{
$db->drop_column("adminoptions", "2fasecret");
$db->drop_column("adminoptions", "authsecret");
}

if($db->field_exists('recovery_codes', 'adminoptions'))
Expand All @@ -58,19 +58,19 @@ function upgrade32_dbchanges()
{
case "pgsql":
$db->add_column("usergroups", "candeletereputations", "smallint NOT NULL default '0' AFTER cangivereputations");
$db->add_column("adminoptions", "2fasecret", "varchar(16) NOT NULL default ''");
$db->add_column("adminoptions", "authsecret", "varchar(16) NOT NULL default ''");
$db->add_column("adminoptions", "recovery_codes", "varchar(177) NOT NULL default ''");
$db->add_column("adminsessions", "authenticated", "smallint NOT NULL default '0'");
break;
case "sqlite":
$db->add_column("usergroups", "candeletereputations", "tinyint(1) NOT NULL default '0'");
$db->add_column("adminoptions", "2fasecret", "varchar(16) NOT NULL default ''");
$db->add_column("adminoptions", "authsecret", "varchar(16) NOT NULL default ''");
$db->add_column("adminoptions", "recovery_codes", "varchar(177) NOT NULL default ''");
$db->add_column("adminsessions", "authenticated", "tinyint(1) NOT NULL default '0'");
break;
default:
$db->add_column("usergroups", "candeletereputations", "tinyint(1) NOT NULL default '0' AFTER cangivereputations");
$db->add_column("adminoptions", "2fasecret", "varchar(16) NOT NULL default ''");
$db->add_column("adminoptions", "authsecret", "varchar(16) NOT NULL default ''");
$db->add_column("adminoptions", "recovery_codes", "varchar(177) NOT NULL default ''");
$db->add_column("adminsessions", "authenticated", "tinyint(1) NOT NULL default '0'");
break;
Expand Down
34 changes: 34 additions & 0 deletions install/resources/upgrade33.php
@@ -0,0 +1,34 @@
<?php
/**
* MyBB 1.8
* Copyright 2014 MyBB Group, All Rights Reserved
*
* Website: http://www.mybb.com
* License: http://www.mybb.com/about/license
*
*/

/**
* Upgrade Script: 1.8.4
*/

$upgrade_detail = array(
"revert_all_templates" => 0,
"revert_all_themes" => 0,
"revert_all_settings" => 0
);

@set_time_limit(0);

function upgrade33_dbchanges()
{
global $db, $output;

if($db->field_exists('2fasecret', 'adminoptions'))
{
$db->rename_column('adminoptions', '2fasecret', 'authsecret', "varchar(16) NOT NULL default ''");
}

$output->print_contents("<p>Click next to continue with the upgrade process.</p>");
$output->print_footer("33_done");
}