Monday, October 17, 2011

Tiny Ad-Hoc CMS

index.php

<?php
$time_start = microtime(true);
error_reporting(E_ALL);
$pagetitle="hello world";
$needDB=1;
isset($needDB) ? include("db.inc.php") : $linkReport="\n>!--- no database connection used ---<\n" ;
include("inc/lists.txt");
foreach($anatomyA as $part) {include(${part});}
print $linkReport;
showSource();
$base=explode("/",$_SERVER['PHP_SELF']);
$num=count($base);
$base2=explode(".",$base[$num-1]);
$content=$docRoot."/inc/".$base2[0].".txt";
include($content);
foreach($anatomyB as $part) {include(${part});}
die();
?>

db.inc.php

<?php
if (isset($needDB)) {
${server}="localhost";
${username}="someuser";
${password}="somepassword";
${database}="somedatabase";
$link=mysql_connect(${server},${username},${password});
@mysql_select_db($database);
}
else {
$to = "example@example.com";
$subject = "alert db.inc.php";
$body = "a direct access to db.inc.db was just attempted.";
mail($to, $subject, $body);
die();
}
$link ? $linkReport="\n<!---mysql_connect was successfull-->\n" : $linkReport="\n<!---mysql_connect was not successful-->\n";
?>

inc/lists.txt

<?php
putenv("TZ=America/Los_Angeles");
$homepage="/index.php";
${docRoot}=getenv('DOCUMENT_ROOT');
${anatomyA}=array(
      "${docRoot}/inc/header.txt",
      "${docRoot}/inc/showsource.txt",
      "${docRoot}/inc/BANNERS.genPublic.txt"
      );
${anatomyB}=array(
      "${docRoot}/inc/footer.txt"
      );
?>

inc/header.txt

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns:fb="http://www.facebook.com/2008/fbml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="" />
<?php isset($linkReport) ? print $linkReport : print "\n>!--- no \$linkReport ---<\n"; ?>
<title>
<?php
print ${pagetitle};
?>
</title>


<?php
// grabs google api key for javascript
if (${needMaps}) {include("inc/googleMapsKey.js.txt");}
?>


<script type="text/javascript"> 
/*
http://code.google.com/apis/ajaxsearch/signup.html
http://code.google.com/apis/ajaxlibs/documentation/
*/
  // google.load("jquery", "1");
  // google.load("jqueryui", "1");
  // google.load("prototype", "1");
  // google.load("scriptaculous", "1");
  // google.load("mootools", "1"); TURNED OFF
  // google.load("dojo", "1");    TURNED OFF
  
</script>  

<link type="text/css" rel="stylesheet" href="/css/dos.css">
  </link>

<script type="text/javascript" src="/js/getElementsByClassName.js">
  </script>

<script type="text/javascript" src="/js/main.js">
  </script>

</head>
<body>
<table id="debugtable" style="display:none">
<tr>
<td class="boxstyle1" id="debugbox">debug output</td> 
<td class="spanstyle1">>></td>
<td>
<textarea id="debug" cols="80" rows="15" wrap="soft">
Welcome to the debug output textarea!
Vital info for the debug textarea :
1) the ID for this output field is: debug
2) is loaded into every page
3) defaults to style.display=none
4) area is shown by setting style.display=block
5) area is shown by javascript command debug() 
6) area is shown by debug=y query string at end of any URL
</textarea>
</td>
</tr>
</table>
<form name="formMain" id="formMain" method="POST">

inc/showsource.txt

<?php
// never include this in php files that show passwords
function showSource() {
if (isset($_GET['source'])) { highlight_file($_SERVER["SCRIPT_FILENAME"]); phpinfo(); }
}
function hilite($me) { print "\n<h3>${me}</h3>\n"; highlight_file(${me});}
?>

/inc/BANNERS.genPublic.txt

<div id="banner" style="border: solid 1px #000000">
<center>
<h1>Hello World</h1>
</center>
</div>

inc/footer.txt

</form>
<hr width="50%" />
<div id="footer">
<center>
</body>
</html>
<?php 
${time_end} = microtime(true);
isset(${time_start}) ? ${processTime} = $time_end - $time_start : ${processTime}=0 ;
print "\n<p><center>server process time: ".${processTime}."</center></p>\n";
include("${docRoot}/inc/insertAccesslogs.txt");
?>
</center>
</div>
</body>
</html>
<?php
die();
?>

inc/insertAccesslogs.txt

<?php
$page=getenv("SCRIPT_NAME"); 
$query=getenv("QUERY_STRING");
$referer=getenv("HTTP_REFERER"); 
$ip=getenv("REMOTE_ADDR");
isset(${processTime}) ? ${processTime}=${processTime} : ${processTime}=0 ; 
$query = "INSERT INTO `mydatabase`.`accesslogs` (`id`, `page`, `query`, `time`, `referer`, `ip`, `processTime`) 
          VALUES (NULL, '${page}', '${query}', NOW(), '${referer}', '${ip}', '${processTime}');";
print "\$sql = ".${query};
mysql_query(${query}) or trigger_error(mysql_error(),E_USER_ERROR);
?>

inc/accesslogs.sql.txt

--
-- Table structure for table `accesslogs`
--

CREATE TABLE IF NOT EXISTS `accesslogs` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `page` varchar(64) DEFAULT NULL,
  `query` varchar(64) DEFAULT NULL,
  `time` date NOT NULL,
  `referer` varchar(64) DEFAULT NULL,
  `ip` varchar(64) DEFAULT NULL,
  `processTime` varchar(64) DEFAULT NULL,
  UNIQUE KEY `id` (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 ;

css/main.css

body {
background-color:black;
color:gray;
font-family:Megazeux, monospace;
font-size:28px;
line-height:28px;
}

pre {
font-family:Megazeux, monospace;
}

a:link
{
text-decoration:none;
color:gray;
}

a:visited
{
text-decoration:none;
color:gray;
}

a:hover, a:active
{
text-decoration:none;
color:gray;
}

.blinker {
text-decoration:blink;
}

#footer {
font-size:75%;
}

Saturday, October 15, 2011

Unix Command Line Prompts


PS1="\n#--[\[\e[1;36m\]\u@\h\[\e[m\]]-[\[\e[1;34m\]\w\[\e[m\]]-[\$(date)]-->\n#>"