Subversion Repositories VORC

Rev

Rev 92 | Rev 150 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
7 - 1
package WebDB;
2
  use strict;
3
  use DBI;
4
  my $host_name = "192.168.1.5";
47 - 5
  my $db_name = "rollerco_vorc";
7 - 6
  my $dsn = "DBI:mysql:host=$host_name;database=$db_name";
63 bgadell 7
  $ENV{HOME} = $ENV{SERVER_NAME} eq "volunteers.rollercon.com" ? "/home3/rollerco" : "/tmp";
8
#  $ENV{HOME} = "/tmp" unless $ENV{HOME};
7 - 9
 
10
  # Connect to MySQL server, using hardwired name and password
11
  sub connect  {
50 bgadell 12
    return connect_with_option_file() unless !(-f $ENV{HOME}.'/.my.cnf');
13
 
14
    warn "using hardcoded password (not $ENV{HOME}/.my.cnf)...";
92 bgadell 15
 	  return (DBI->connect ($dsn, "root", "********", {PrintError => 0, RaiseError => 0}) or db_error ($DBI::errstr));
7 - 16
  }
17
 
18
  # Connect to MySQL server, using name and password from the current
19
  # user's ~/.my.cnf option file. The mysql_read_default_file option,
20
  # when added to the DSN, specifies which option file to read.
21
  sub connect_with_option_file  {
22
	  $dsn .= ";mysql_read_default_file=$ENV{HOME}/.my.cnf";
92 bgadell 23
 
24
	  return (DBI->connect ($dsn, undef, undef, {PrintError => 0, RaiseError => 0}) or db_error ($DBI::errstr));
7 - 25
  }
26
 
50 bgadell 27
  # Quash any leading or trailing whitespace
7 - 28
  sub trim {
29
    my $str = shift;
30
 
31
  	return "" if !defined $str;
32
  	$str =~ s/^\s+//;
33
  	$str =~ s/\s+$//;
34
  	return ($str);
35
  }
50 bgadell 36
 
92 bgadell 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
}
60
 
50 bgadell 61
1; # return true