Subversion Repositories VORC

Rev

Rev 63 | Rev 121 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 63 Rev 92
Line 10... Line 10...
10
  # Connect to MySQL server, using hardwired name and password
10
  # Connect to MySQL server, using hardwired name and password
11
  sub connect  {
11
  sub connect  {
12
    return connect_with_option_file() unless !(-f $ENV{HOME}.'/.my.cnf');
12
    return connect_with_option_file() unless !(-f $ENV{HOME}.'/.my.cnf');
Line 13... Line 13...
13
    
13
    
14
    warn "using hardcoded password (not $ENV{HOME}/.my.cnf)...";
14
    warn "using hardcoded password (not $ENV{HOME}/.my.cnf)...";
15
 	  return (DBI->connect ($dsn, "root", "********",
-
 
16
	  {PrintError => 0, RaiseError => 1}));
15
 	  return (DBI->connect ($dsn, "root", "********", {PrintError => 0, RaiseError => 0}) or db_error ($DBI::errstr));
Line 17... Line 16...
17
  }
16
  }
18
  
17
  
19
  # Connect to MySQL server, using name and password from the current
18
  # Connect to MySQL server, using name and password from the current
20
  # user's ~/.my.cnf option file. The mysql_read_default_file option,
19
  # user's ~/.my.cnf option file. The mysql_read_default_file option,
21
  # when added to the DSN, specifies which option file to read.
20
  # when added to the DSN, specifies which option file to read.
-
 
21
  sub connect_with_option_file  {
22
  sub connect_with_option_file  {
22
	  $dsn .= ";mysql_read_default_file=$ENV{HOME}/.my.cnf";
23
	  $dsn .= ";mysql_read_default_file=$ENV{HOME}/.my.cnf";
-
 
24
	  return (DBI->connect ($dsn, undef, undef,
23
	  
Line 25... Line 24...
25
	  {PrintError => 0, RaiseError => 1}));
24
	  return (DBI->connect ($dsn, undef, undef, {PrintError => 0, RaiseError => 0}) or db_error ($DBI::errstr));
26
  }
25
  }
27
  
26
  
Line 33... Line 32...
33
  	$str =~ s/^\s+//;
32
  	$str =~ s/^\s+//;
34
  	$str =~ s/\s+$//;
33
  	$str =~ s/\s+$//;
35
  	return ($str);
34
  	return ($str);
36
  }
35
  }
Line -... Line 36...
-
 
36
 
-
 
37
 
-
 
38
sub db_error {
-
 
39
  my $ERR = shift // "something bad happened";
-
 
40
  
-
 
41
  use Carp qw/cluck/;
-
 
42
  cluck $ERR;
-
 
43
  
-
 
44
  use HTML::Tiny;
-
 
45
  my $h = HTML::Tiny->new( mode => 'html' );
-
 
46
  $ERR = $ERR ? $h->p ( {class=>"hint"}, $ERR) : "";
-
 
47
  use CGI qw/header/;
-
 
48
  print header ();
-
 
49
  print $h->html ([ $h->head ( [ $h->title ( "vORC - Database Error" ), $h->link ( { rel=>"stylesheet", href=>"/style.css" }) ] ),
-
 
50
	  [ $h->div ({ class=>"sp0", style=>"max-width:700px" }, [
-
 
51
	                               $h->div ({ class=>"spLeft"  },  $h->a ({ href=>"/schedule/" }, $h->img ({ src=>"/logo.jpg", width=>"75", height=>"75" }))),
-
 
52
	                               $h->div ({ class=>"spRight" },  $h->h1 ("vORC Database Error"))
-
 
53
	                               ]),
-
 
54
	    $h->div ({ class=>"error" }, [ $h->br, $h->br, "If you're seeing this, there was an error connecting to the database:", $h->br, $ERR, "Apologies." ])
-
 
55
	  ]
-
 
56
	]);
-
 
57
	
-
 
58
  exit;
-
 
59
}
37
 
60