]> lifelog.hopto.org Git - LifeLog.git/commitdiff
Initial commit of htdocs
authorwbudic <redacted>
Tue, 21 Aug 2018 06:10:58 +0000 (16:10 +1000)
committerwbudic <redacted>
Tue, 21 Aug 2018 06:10:58 +0000 (16:10 +1000)
README.md [new file with mode: 0644]
htdocs/cgi-bin/.main.cgi.swo [new file with mode: 0644]
htdocs/cgi-bin/.main.cgi.swp [new file with mode: 0644]
htdocs/cgi-bin/hello.cgi [new file with mode: 0755]
htdocs/cgi-bin/main.cgi [new file with mode: 0755]
htdocs/cgi-bin/perl_env.cgi [new file with mode: 0755]
htdocs/cgi-bin/wsrc/main.css [new file with mode: 0644]
htdocs/cgi-bin/wsrc/main.js [new file with mode: 0644]
htdocs/data [new symlink]
htdocs/test.html [new file with mode: 0644]

diff --git a/README.md b/README.md
new file mode 100644 (file)
index 0000000..610f07c
--- /dev/null
+++ b/README.md
@@ -0,0 +1 @@
+# LifeLog
diff --git a/htdocs/cgi-bin/.main.cgi.swo b/htdocs/cgi-bin/.main.cgi.swo
new file mode 100644 (file)
index 0000000..2dcb35b
Binary files /dev/null and b/htdocs/cgi-bin/.main.cgi.swo differ
diff --git a/htdocs/cgi-bin/.main.cgi.swp b/htdocs/cgi-bin/.main.cgi.swp
new file mode 100644 (file)
index 0000000..f15b2e0
Binary files /dev/null and b/htdocs/cgi-bin/.main.cgi.swp differ
diff --git a/htdocs/cgi-bin/hello.cgi b/htdocs/cgi-bin/hello.cgi
new file mode 100755 (executable)
index 0000000..805abba
--- /dev/null
@@ -0,0 +1,10 @@
+#!/usr/bin/env python
+print "Content-Type: text/html"     # HTML is following
+print                               # blank line, end of headers
+print "<TITLE>CGI script output</TITLE>"
+print "<H1>This is my first CGI script</H1>"
+print "Hello, world! <br/>"
+for i in range(10):
+    print i, '<br/>'
+print 'Just to show that some stuff is "dynamically" generated server side<br/>'
+
diff --git a/htdocs/cgi-bin/main.cgi b/htdocs/cgi-bin/main.cgi
new file mode 100755 (executable)
index 0000000..4588661
--- /dev/null
@@ -0,0 +1,179 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use CGI;
+use DBI;
+
+use DateTime;
+use DateTime::Format::SQLite;
+
+my $q = CGI->new;
+
+my $driver   = "SQLite"; 
+my $database = "../../dbLifeLog/data_log.db";
+my $dsn = "DBI:$driver:dbname=$database";
+my $userid = "";
+my $password = "";
+my $dbh = DBI->connect($dsn, $userid, $password, { RaiseError => 1 }) 
+   or die "<p>Error->"& $DBI::errstri &"</p>";
+
+
+
+print $q->header(-expires=>"+6os");    
+
+print $q->start_html(-title => "Personal Log", 
+                            -script=>{-type => 'text/javascript', -src => 'wsrc/main.js'},
+                    -style =>{-type => 'text/css', -src => 'wsrc/main.css'}
+
+                       );        
+
+
+my $rv;
+my $today = DateTime->now;
+$today->set_time_zone( 'Australia/Sydney' );
+
+my $sth = $dbh->prepare("SELECT name FROM sqlite_master WHERE type='table' AND name='LOG';");
+$sth->execute();
+
+if(!$sth->fetchrow_array()) {
+                       my $stmt = qq(
+
+                       CREATE TABLE LOG (
+                         ID INT PRIMARY KEY NOT NULL,
+                         ID_CAT TINY,
+                         DATE DATETIME  NOT NULL,
+                         LOG VCHAR(60)
+                                       );
+                                                  
+                       );
+
+                       $rv = $dbh->do($stmt);
+
+                       if($rv < 0) {
+                                     print "<p>Error->"& $DBI::errstri &"</p>";
+                       } 
+
+                       $sth = $dbh->prepare('INSERT INTO LOG VALUES (?,?,?,?)');
+
+       $sth->execute(1, 3, $today, "DB Created!");
+
+                       
+                        $stmt = qq(
+
+                       CREATE TABLE CAT(
+                         ID INT PRIMARY KEY NOT NULL,
+                         NAME VCHAR(16)
+                       );
+                                                  
+                       );
+
+                       $rv = $dbh->do($stmt);
+
+                       if($rv < 0) {
+                                     print "<p>Error->"& $DBI::errstri &"</p>";
+                       } 
+
+                       $sth = $dbh->prepare('INSERT INTO CAT VALUES (?,?)');
+
+       $sth->execute(1,"Unspecified");
+       $sth->execute(3,"File System");
+       $sth->execute(6,"System Log");
+       $sth->execute(9,"Event");
+       $sth->execute(28,"Personal");
+       $sth->execute(32, "Expense");
+}
+my $stmtCat = "SELECT * FROM CAT;";
+my $stmt = "SELECT * from LOG;";
+
+
+$sth = $dbh->prepare( $stmtCat );
+$rv = $sth->execute() or die or die "<p>Error->"& $DBI::errstri &"</p>";
+
+my $cats = '<select name="cat">\n';
+my %hshCats;
+
+ while(my @row = $sth->fetchrow_array()) {
+       $cats = $cats. '<option value="'.@row[0].'">'.@row[1].'</option>\n';
+       $hshCats{@row[0]} = @row[1];
+ }
+
+$cats = $cats.'</select>';
+
+
+my $tbl = '<table border="1px" width="480px"><tr><th>Date</th><th>Time</th><th>Log</th><th>Category</th></tr>';
+my $tbl_rc = 0;
+
+##################################
+&processSubmit($q, %hshCats);
+##################################
+
+#Fetch entries!
+#
+$sth = $dbh->prepare( $stmt );
+$rv = $sth->execute() or die or die "<p>Error->"& $DBI::errstri &"</p>";
+if($rv < 0) {
+            print "<p>Error->"& $DBI::errstri &"</p>";
+}
+
+
+
+ while(my @row = $sth->fetchrow_array()) {
+
+        my $ct = $hshCats{@row[1]};
+        my $dt = DateTime::Format::SQLite->parse_datetime( $row[2] );
+
+                $tbl = $tbl . "<tr><td>". $dt->ymd . "</td>" . 
+                         "<td>" . $dt->hms . "</td>" . "<td>" . $row[3] . "</td>".
+                         "<td>" . $ct ."</td></tr>\n";
+       $tbl_rc +=1;    
+ }
+
+ if($tbl_rc==1){
+        $tbl = $tbl . "<tr><td colspan=\"4\"><b>Table is Empty!</b></td></tr>\n";
+ }
+ $tbl = $tbl . "</table>";
+
+my  $frm = qq(
+ <form name="frm_log" action="main.cgi" onSubmit="return formValidation();">
+        <table><tr>
+                <td>Date</td><td><input type="text" name="date" value=") .$today->ymd . qq("></td>
+                </tr>
+                <tr><td>Log:</td> <td><textarea name="log" rows="2" cols="40"></textarea></td>
+                <td>).$cats.qq(</td></tr>
+                <tr><td></td><td></td><td><input type="submit" value="Submit"></td>
+       </tr></table>
+</form>
+ );
+
+
+
+print "<div id=\"tbl\">\n" . $tbl ."</div>";
+print "<div id=\"frm\">\n" . $frm ."</div>";
+
+print $q->end_html;
+
+$dbh->disconnect();
+
+sub processSubmit { 
+
+
+       my $date = $q->param('date');
+       my $log = $q->param('log');
+       my $cat = $q->param('cat');
+
+
+       if($log){
+               print "<h2>Received!". $log. "</h2>";
+
+       }
+       if($date){
+               print "<h2>Received!". $date. "</h2>";
+
+       }
+       if($cat){
+               print "<h2>Received!". $hshCats{$cat}. "</h2>";
+
+       }
+}
diff --git a/htdocs/cgi-bin/perl_env.cgi b/htdocs/cgi-bin/perl_env.cgi
new file mode 100755 (executable)
index 0000000..b61d708
--- /dev/null
@@ -0,0 +1,10 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use CGI;
+my $q = CGI->new;
+print $q->header;
+print "Hello World!";
diff --git a/htdocs/cgi-bin/wsrc/main.css b/htdocs/cgi-bin/wsrc/main.css
new file mode 100644 (file)
index 0000000..3f97381
--- /dev/null
@@ -0,0 +1,11 @@
+[type="submit"] {
+       clear: left;
+       margin: 10px 0 0 30px;
+       font-size:12px
+}
+
+p {
+       margin-left: 70px;
+       font-weight: bold;
+}
+
diff --git a/htdocs/cgi-bin/wsrc/main.js b/htdocs/cgi-bin/wsrc/main.js
new file mode 100644 (file)
index 0000000..2d8460b
--- /dev/null
@@ -0,0 +1,25 @@
+function formValidation(){
+  
+var date = document.frm_log.date;
+var log  = document.frm_log.log;
+
+return validDate(date.value) && validLog(log.value);
+
+}
+
+function validDate(dt){
+       if(!Date.parse(dt)){
+               alert("Date -> '" + dt +"' is Invalid can't submit!");
+               return false;
+       }
+return true;
+}
+
+function validLog(log){
+       if(log==""){
+
+               alert("Log -> entry can't be empty, can't submit!");
+               return false;
+       }
+return true;
+}
diff --git a/htdocs/data b/htdocs/data
new file mode 120000 (symlink)
index 0000000..fa3d85b
--- /dev/null
@@ -0,0 +1 @@
+/usr/local/www/data
\ No newline at end of file
diff --git a/htdocs/test.html b/htdocs/test.html
new file mode 100644 (file)
index 0000000..eebbb0e
--- /dev/null
@@ -0,0 +1 @@
+<h1>Hello thttpd</h1>