-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
blog.pl
221 lines (186 loc) · 6.3 KB
/
blog.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#!/usr/bin/perl
# Felipe Gonzalez Memo - Perl Blog
########################################################
#
# COPYRIGHT NOTICE
# Copyright 2004 Felipe A. Gonzalez
# All Rights Reserved.
#
# This script can be used\modified free of charge
# as long as you don't change this header, or the
# parts of this script that generates the script
# info. If you really need to remove these, go to
#
#
# By using this script you agree to indemnify me from
# any liability that might arise from its use.
#
# Redistributing\selling the code for this program
# without prior written consent is expressly
# forbidden.
#
########################################################
#
# By Computer Science Engineer: Felipe Alfonso Gonzalez
# EMail: (f.alfonso@res-ear.ch)
# Started : Jan 16, 2005
#
########################################################
#
# If this script doesn't work for you try
# adjusting the first line above to
# #!/usr/local/bin/perl
# DO NOT REMOVE THE # OR ! or add any spaces.
#
# IF YOU WANT TO USE IT FOR YOUR OWN DONT FORGET
# TO MAKE IT EXECTUABLE, (CHMOD +X *.pl) AND TO
# GIVE IT THE RIGHT PERMISSIONS, (CHMOD 755 *.pl).
# --
# INSTALLING DBI ON MAC
# -
# sudo cpan Bundle::DBI (USE SUDO)
########################################################
########################################################
my($database,$host,$data_source,$username,$password,$dbh,$usr_log,$usr_pwd);
########################################################
# DB Configuration
########################################################
$database = "felipe";
$host = "localhost";
$username = "root2";
# set the password here
$password = "root2";
#------------------------------------------------------
$data_source = "DBI:mysql:$database:$host";
########################################################
#libraries
use CGI;
use strict;
use warnings;
use DBI;
#to define the $cgi variable as a paremeter
my $cgi=new CGI; #read in parameters
#print $cgi->header(); #print a header
print "Content-type: text/html\n\n";
print "<title>PerlMemoPad - Perl Mini Weblog</title>";
print "<link href=\"./style.css\" rel=\"stylesheet\" type=\"text/css\" >";
print " <link rel=\"icon\" href=\"./favicon.ico\" type=\"image/ico\" > ";
print " <link rel=\"shortcut icon\" href=\"./favicon.ico\" type=\"image/ico\" > ";
#print "<script type=\"text/javascript\" language=\"javascript\" src=\"js.js\"></script>";
#print "<script language=\"JavaScript\">
#var username = prompt(\"Ingrese Nombre de Usuario\",\"\")
#var password = prompt(\"Ingrese Password\",\"\")
#if (username !=\"$usr_log\" || password !=\"$usr_pwd\")
#{ top.location=\"about:Bad Username and/or Password\" }
#else
#//{
#//top.location=\"./blog.pl\"
#//}
#//-->
#</script>";
my ($qs);
my $version = "1.0b";
#print $cgi->start_html("written at the fly and left behind by the world wide web - in version $version"); #generate html document
print "<pre>";
#print" -- - *.cgi-bin:,:/,,*.pl,,,,.. post it,. at any time\n";
print" a note: html, is a href=blahblahblah.html target=_blank\n";
print" do not use quotation marks.i\n";
print " <b> [ <a href=\"blog.pl\">refresh</a> ]</b><br>\n";
#generating a input box text for search paarameters
#print " <br><form method=\"post\" action=\"py.pl?$qs \">";
#print "<input type=text name=\"qs\">";
#print " <input type=\"submit\" value=\"Buscar Noticias\">";
#print "</center><br>";
#----- printing sys info
#my $sys = "system(\"uptime\");";
#print "<br>$sys<br>";
#system("uptime");
#print "<h3>";
#system("date");
#print "</h3>";
print "<hr size=1><br>";
#end
#print "Results string:<i><b> ", $cgi->param('qs'), "</b></i> .
#Results:<br>";
###
#delcaring the vars
my ($sth, $sth2, $sth3, $a, $b, $c, $d);
my ($c1, $c2 , $c3, $c4, $c5, $k, $sth55);
#conection to the db using the DBI library application
#my $dbh=DBI->connect('dbi:mysql:py', 'root2', 'root2') ||
#my $dbh=DBI->connect('DBI:mysql:database=py;host=localhost','root2','root2') ||
# die "Error opening database: $DBI::errstr\n";
$dbh = DBI->connect($data_source, $username, $password) or die "Imposible conectar con $data_source: " . $dbh->errstr . "\n";
#$dbh->disconnect || die "Failed to disconnect\n";
#in the following section the intention is to build an sql with post var
#$qs = $FORM{'s'};
#my($qs);
#if ($FORM{'qs'} eq "$qs") {
#my $qs = $cgi->param('qs');
#if (my $qs = $cgi->param('qs')) {
#}
#print "$sth\n";
$sth2=$dbh->prepare("select * from pmpad ORDER BY id DESC;") ||
die "Prepare failed: $DBI::errstr\n";
#print "$sth\n";
$sth2->execute() ||
die "Couldn't execute query: $DBI::errstr\n";
my($sth_com);
#my ($e);
#built a boocle to display the reached notices
#my("$a, $b, $c, $d");
#time
my($time);
$time=(localtime(time));
#print "$time";
while (($a, $b, $c, $d) = $sth2 ->fetchrow_array) {
#print "<pre>";
#print "<a href=\"?id=$a\">";
#print "<s><b><i>ID: $a </i></b></s>\n";
#print "</a>";
#print " date: $b\n";
#print " --<a href=\"?id=$a#show\"> $c </a>";
#print " --<a href=\"blog.pl?id=$a\"> $c </a>";
#print " --<a href=\"comment.pl?id=$a\"> $c </a>";
#print $c;
print $c;
$sth55=$dbh->prepare("SELECT COUNT(0) FROM pmpad_com where id_iddata ='$a'") ||
die "Prepare failed: $DBI::errstr\n";
$sth55->execute() ||
die "Couldn't execute query: $DBI::errstr\n";
while (($c1, $c2 , $c3, $c4, $c5) = $sth55 ->fetchrow_array) {
print " - <a href=\"./comment.pl?id=$a#show\">leer mas</a>";
print " - There're : ". $c1 ." comments " ;
}
#date
print " $b\n ";
#print " $time\n";
#print " </pre>";
}
#end comments
#variables
my ($sth5, $date, $subject, $FORM, $submit, $message, $post);
#my ($sth5, $date );
print "<hr size=1><br>";
print "<left>By Computer Science Engineer: Felipe Alfonso Gonzalez (f.alfonso\@res-ear.ch) - Powered by Perl / MySQL</left>";
print "</pre>\n";
#my($id, $sth3);
if (my $id = $cgi->param('id')) {
$sth3=$dbh->prepare("select * from pmpad where id like '%$id%' ;") ||
die "Prepare failed: $DBI::errstr\n";
#print "$sth\n";
$sth3->execute() ||
die "Couldn't execute query: $DBI::errstr\n";
my($k,$l, $z, $x, $v);
while (($k, $l , $z, $x, $c) = $sth3 ->fetchrow_array) {
print "<a name=\"show\">";
print "<pre>";
print ("$k\n");
print ("$l\n");
print ("$z\n");
print ("$x\n");
print ("$v\n");
print "</font></pre>";
}
}
print $cgi->end_html();