Skip to content

Commit

Permalink
Fixed OpenID logins and moved around a permissions change in the data…
Browse files Browse the repository at this point in the history
…base configuration script, though adding an OpenID is still broken for some reason.
  • Loading branch information
Chris Vandevelde committed Nov 16, 2010
1 parent 10ac798 commit 0c18a3c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 24 deletions.
46 changes: 23 additions & 23 deletions bin/gbrowse_metadb_config.pl
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@
use List::Util;

# First, collect all the flags - or output the correct usage, if none listed.
my ($dsn, $admin, $pprompt, $which_db, $force);
my ($dsn, $admin, $pprompt, $which_db);
GetOptions('dsn=s' => \$dsn,
'admin|owner=s' => \$admin,
'p' => \$pprompt,
'db=s' => \$which_db,
'f' => \$force) or die <<EOF;
'db=s' => \$which_db) or die <<EOF;
Usage: $0 [options] <optional path to GBrowse.conf>
Initializes an empty GBrowse user accounts database. Options:
Expand All @@ -23,7 +22,6 @@
-owner [SQLite only] Username and primary group for the Web user in the format "user:group"
-p Prompt for password
-db Specify which database ("users," "uploads" or "both")
-f Force the creation of a new database, regardless of pre-existing database.
Currently mysql and SQLite databases are supported. When creating a
mysql database you must provide the -admin option to specify a user
Expand Down Expand Up @@ -66,17 +64,16 @@
my $globals = Bio::Graphics::Browser2->open_globals;
my $users_credentials = $globals->user_account_db or die "No users database credentials specified in GBrowse.conf.";
my $userdb = DBI->connect($users_credentials) or die "Error: Could not open users database, please check your credentials.\n" . DBI->errstr;
my $uploads_credentials = $globals->uploads_db or die "No uploads database credentials specified in GBrowse.conf.";

# Check the users DB, if requested.
my $checked = 0;
if ($which_db =~ /(user|both|all)/) {
if ($which_db =~ /(user|both|all)/i) {
# Database schema. To change the schema, update/add the fields here, and run this script.
my $users_columns = {
userid => "varchar(32) not null UNIQUE key",
userid => "varchar(32) not null PRIMARY key",
uploadsid => "varchar(32)",
username => "varchar(32) not null PRIMARY key",
email => "varchar(64) not null UNIQUE key",
username => "varchar(32) not null UNIQUE",
email => "varchar(64) not null UNIQUE",
pass => "varchar(32) not null",
remember => "boolean not null",
openid_only => "boolean not null",
Expand All @@ -99,7 +96,8 @@
}

# Check the uploads DB, if requested.
if ($which_db =~ /(file|upload|both|all)/) {
if ($which_db =~ /(file|upload|both|all)/i) {
my $uploads_credentials = $globals->uploads_db or die "No uploads database credentials specified in GBrowse.conf.";
my $uploadsdb = DBI->connect($uploads_credentials) or die "Could not open uploads database, please check your credentials.\n" . DBI->errstr;

# Database schema. To change the schema, update/add the fields here, and run this script.
Expand All @@ -122,6 +120,7 @@
check_all_files($userdb, $uploadsdb);
$checked = 1;
$uploadsdb->disconnect;
print STDERR "Please make sure your Gbrowse.conf file includes the following line:\n";
}
$userdb->disconnect;

Expand All @@ -136,8 +135,8 @@ sub check_table {
my $data_source = shift or die "No database connection found, please check the gbrowse_metadb_config.pl script.\n";
my $name = shift or die "No database name given, please check the gbrowse_metadb_config.pl script.\n";
my $columns = shift or die "No database schema given, please check the gbrowse_metadb_config.pl script.\n";
my $type = $data_source->get_info(17); # Returns the database type.
my $dsn = $data_source->{Driver}->{Name};
my $type = $data_source->{Driver}->{Name};
my $dsn ||= $;

# If the database doesn't exist, create it.
unless ($data_source->do("SELECT * FROM $name LIMIT 1")) {
Expand All @@ -146,11 +145,20 @@ sub check_table {
my $creation_sql = "CREATE TABLE $name (" . (join ", ", @column_descriptors) . ")" . (($type =~ /mysql/i)? " ENGINE=InnoDB;" : ";");
$data_source->do($creation_sql) or die "Could not create $name database.\n";

if ($type =~ /mysql/) {
my $db_user = $dsn =~ /user=([^;]+)/;
my $db_pass = $dsn =~ /password=([^;]+)/;
if ($type =~ /mysql/i) {
my $db_user = $dsn =~ /user=([^;]+)/i;
my $db_pass = $dsn =~ /password=([^;]+)/i;
$data_source->do("GRANT ALL PRIVILEGES on $name.* TO '$db_user'\@'%' IDENTIFIED BY '$db_pass' WITH GRANT OPTION") or die DBI->errstr;
}
if ($type =~ /sqlite/i) {
my $path = $dsn =~ /dbname=([^;]+)/i;
$path ||= $dsn =~ /DBI:SQLite:([^;]+)/i;
print STDERR "Using sudo to set ownership to $admin_user:$admin_pass. You may be prompted for your login password now.\n";
die "Couldn't figure out location of database index from $dsn" unless $path;
system "sudo chown $admin_user $path";
system "sudo chgrp $admin_pass $path";
print STDERR "Done.\n";
}
}

# If a required column doesn't exist, add it.
Expand All @@ -159,8 +167,6 @@ sub check_table {
if (@{$sth->{NAME_lc}} != keys %$columns) {
my @columns_to_create;
my $run = 0;
my $path = $dsn =~ /dbname=([^;]+)/;
$path ||= $dsn =~ /DBI:SQLite:([^;]+)/;

# SQLite doesn't support altering to add multiple columns or ENUMS, so it gets special treatment.
if ($type =~ /sqlite/i) {
Expand All @@ -173,12 +179,6 @@ sub check_table {
my $alter_sql = "ALTER TABLE $name ADD COLUMN $_ " . $$columns{$_} . ";";
$data_source->do($alter_sql);
}

print STDERR "Using sudo to set ownership to $admin_user:$admin_pass. You may be prompted for your login password now.\n";
die "Couldn't figure out location of database index from $dsn" unless $path;
system "sudo chown $admin_user $path";
system "sudo chgrp $admin_pass $path";
print STDERR "Done.\n";
}
} else {
# If we don't find a specific column, add its SQL to the columns_to_create array.
Expand Down
7 changes: 6 additions & 1 deletion htdocs/js/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -955,14 +955,19 @@ function check_openid(openid) {
function process_openid() {
var i, element;
var hash = new Array();
var args = String(String(document.location).split('#')[0]).split('&');

// For some reason the delimiter has changed, just double-check on the old one.
var colon_args = String(String(document.location.href).split('#')[0]).split(';');
var ampersand_args = args = String(String(document.location.href).split('#')[0]).split('&');
var args = (colon_args.length > ampersand_args.length)? colon_args : ampersand_args;

for(i=1; i<args.length; i++) {
element = String(args[i]).split('=');
hash[2*(i-1)] = element[0]; //element
hash[(2*i)-1] = unescape(element[1]); //value
}

console.log(hash);
return hash;
}

Expand Down

0 comments on commit 0c18a3c

Please sign in to comment.