-
Notifications
You must be signed in to change notification settings - Fork 0
/
submit_news.pl
executable file
·46 lines (38 loc) · 1.29 KB
/
submit_news.pl
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
36
37
38
39
40
41
42
43
44
45
46
#!/usr/local/bin/perl
use strict;
use DBI;
use CGI;
my $config = "/var/aethyra/config";
#### read in config ####
open (CONFIG,$config);
my @config = <CONFIG>;
my @line = split(":",$config[0]);
my $online_file = $line[1];
chomp($online_file);
@line = split(":",$config[1]);
my $credential_file = $line[1];
chomp($credential_file);
close(CONFIG);
#### END CONFIG ####
#### database credentials ####
open(CRED,$credential_file);
my @creds = <CRED>;
@line = split(":", $creds[0]);
my $database = $line[1];
chomp($database);
@line = split(":",$creds[1]);
my $username = $line[1];
chomp($username);
@line = split(":",$creds[2]);
my $password = $line[1];
chomp($password);
close(CRED);
#### END CREDENTIALS #####
my $q = CGI->new();
my $the_news = $q->param('the_news');
my $dbh = DBI->connect("dbi:Pg:dbname=$database",$username,$password) or die "Database connection failed in submit_news.pl";
my $query = "insert into news (news) values ('$the_news')";
my $sth = $dbh->prepare($query) or die "couldn't prepare query";
$sth->execute or die "couldn't execute statement";
print "Content-type: text/html\n\n";
print "All good champ. If not talk to bels, he was slacking when he wrote this in the first place. Click <a href=\"http://www.aethyraproject.org\">here</a> to go back to the main site and look at the shinies";