File: filter.pl

package info (click to toggle)
pronto 2.4.0-3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,112 kB
  • ctags: 488
  • sloc: perl: 22,159; makefile: 140; sh: 34; sql: 7
file content (35 lines) | stat: -rwxr-xr-x 1,195 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/perl
use DBI;

$user = $ENV{"USER"};
$home = $ENV{"HOME"};
if (open(CFG,"<$home/.cscmailrc")) {
 @cfg = <CFG>;
 close(CFG);
 foreach (@cfg) {
  /^#/ and next;
  /^Database Driver: (\S+)/ and $dbd = $1;
 }
} else { die "You don't have a ~/.cscmailrc, I would say you probably
 do not need to run this program."; }

$conn=DBI->connect("dbi:$dbd:dbname=$user", "", "", {AutoCommit => 1}) or
die "Cannot connect to $user\'s database. Make sure that your
administrator has installed and configured DBI drivers on this machine for
you.";

$sql = "drop table filters";
$conn->do($sql);
if ($dbd eq "Pg") {
 $sql = "create table filters (id int4 default nextval('filtid') PRIMARY KEY,
          sorder int4, type int4, boxid int4, regex text, addr text,
          name text UNIQUE)";
 $conn->do($sql) or die "Could not create table filters\n";
} elsif ($dbd eq "mysql") {
  $sql = "create table filters (id int4 AUTO_INCREMENT PRIMARY KEY,
          sorder int4, type int4, boxid int4, regex text, addr text,
          name varchar(100) NOT NULL, UNIQUE name (name))";
  $conn->do($sql) or die "Could not create table filters\n";
}
print "Database Succesfully updated.\n";
$conn->disconnect;