-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.pl
executable file
·89 lines (74 loc) · 3.04 KB
/
index.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/local/bin/perl
use strict;
use Template;
use DBI;
my @styles = ("styles/styles.css");
my @javascripts = ();
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);
@line = split(":",$config[2]);
my $avatar_location = $line[1];
chomp($avatar_location);
close(CONFIG);
#### END CONFIG ####
#### get online players #####
open (ONLINE,$online_file);
my @array = <ONLINE>;
my $online = pop(@array);
chomp $online;
close(ONLINE);
#####################
#### 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 $dbh = DBI->connect("dbi:mysql:dbname=$database",$username,$password) or die "Database connection failed in index";
#my $query = "select * from news order by entered DESC limit 3";
my $query = "select phpbb_users.username, phpbb_users.user_avatar, phpbb_posts.post_subject, phpbb_posts.post_text, phpbb_posts.post_time FROM phpbb_posts INNER JOIN phpbb_users ON phpbb_posts.poster_id = phpbb_users.user_id where phpbb_posts.post_postcount = 1 and phpbb_posts.forum_id = 38 ORDER BY phpbb_posts.post_time DESC LIMIT 3";
my $sth = $dbh->prepare($query);
$sth->execute;
my $results = $sth->fetchall_arrayref;
#this should read in all the files in the directory specified in avatar location
opendir(DIR, $avatar_location);
my @avatars = readdir(DIR);
my $row = @$results[0];
my $news1 = @$row[3];
my $news1_date = scalar localtime(@$row[4]);
my $news1_subject = @$row[2];
my $news1_poster = @$row[0];
my $news1_image = "forum/download/file.php?avatar=@$row[1]";
$row = @$results[1];
my $news2 = @$row[3];
my $news2_date = scalar localtime(@$row[4]);
my $news2_subject = @$row[2];
my $news2_poster = @$row[0];
my $news2_image = "forum/download/file.php?avatar=@$row[1]";
$row = @$results[2];
my $news3 = @$row[3];
my $news3_date = scalar localtime(@$row[4]);
my $news3_subject = @$row[2];
my $news3_poster = @$row[0];
my $news3_image = "forum/download/file.php?avatar=@$row[1]";
my $vars = {'title' => 'Aethyra Project','styles' => \@styles,'javascripts' => \@javascripts,'online_players' => $online,'news1' => $news1,'news2' => $news2,'news2' => $news2,'news1_date' => $news1_date,'news2_date' => $news2_date,'news2_date' => $news2_date, 'news1_image' => $news1_image, 'news2_image' => $news2_image, 'news3_image' => $news3_image, 'news1_poster' => $news1_poster, 'news2_poster' => $news2_poster, 'news3_poster' => $news3_poster, 'news1_subject' => $news1_subject, 'news2_subject' => $news2_subject, 'news3_subject' => $news3_subject};
my $file = "index.tt";
print "Content-type: text/html\n\n";
my $template = Template->new();
$template->process($file,$vars) || die $template->error();