initial commit

This commit is contained in:
Ben Ramey
2017-03-02 21:32:16 -06:00
commit 194e0ca89e
399 changed files with 16444 additions and 0 deletions

1
production/php/.htaccess Normal file
View File

@@ -0,0 +1 @@
Options -indexes

View File

@@ -0,0 +1,312 @@
<?php
//
// PHP module for easy utilization of the free captchas.net CAPTCHA service
//
// For documentation look at http://captchas.net/sample/php/
//
// Written by
// Sebastian Wilhelmi <seppi@seppi.de> and
// Felix Holderied <felix@holderied.de>
// This file is in the public domain.
//
// ChangeLog:
//
// 2006-08-16: New optional features integrated
//
// 2006-03-01: Only delete the random string from the repository in
// case of a successful verification.
//
// 2006-02-14: Add new image() method returning an HTML/JavaScript
// snippet providing a fault tolerant service.
//
// 2005-06-02: Initial version.
//
class CaptchasDotNet
{
function CaptchasDotNet ($client, $secret,
$random_repository = '/tmp/captchasnet-random-strings',
$cleanup_time = 3600,
$alphabet = 'abcdefghijklmnopqrstuvwxyz',
$letters = 6,
$width = 240,
$height = 80
)
{
$this->__client = $client;
$this->__secret = $secret;
$this->__random_repository = $random_repository;
$this->__cleanup_time = $cleanup_time;
$this->__time_stamp_file = $random_repository . '/__time_stamp__';
$this->__alphabet = $alphabet;
$this->__letters = $letters;
$this->__width = $width;
$this->__height = $height;
}
function __random_string ()
{
// The random string shall consist of small letters, big letters
// and digits.
$letters = "abcdefghijklmnopqrstuvwxyz";
$letters .= strtoupper ($letters) + "0123456789";
// The random starts out empty, then 40 random possible characters
// are appended.
$random_string = '';
for ($i = 0; $i < 40; $i++)
{
$random_string .= $letters{rand (0, strlen ($letters) - 1)};
}
// Return the random string.
return $random_string;
}
// Create a new random string and register it.
function random ()
{
// If the repository directory is does not yet exist, create it.
if (!is_dir ($this->__random_repository))
{
mkdir ($this->__random_repository);
}
// If the time stamp file does not yet exist, create it.
if (!is_file ($this->__time_stamp_file))
{
touch ($this->__time_stamp_file);
}
// Get the current time.
$now = time ();
// Determine the time, before which to remove random strings.
$cleanup_time = $now - $this->__cleanup_time;
// If the last cleanup is older than specified, cleanup the
// directory.
if (filemtime ($this->__time_stamp_file) < $cleanup_time)
{
$handle = opendir ($this->__random_repository);
while (true)
{
$filename = readdir ($handle);
if (!$filename)
{
break;
}
if ($filename != '.' && $filename != '..')
{
$filename = $this->__random_repository . '/' . $filename;
if (filemtime ($filename) < $cleanup_time)
{
unlink ($filename);
}
}
}
closedir ($handle);
touch ($this->__time_stamp_file);
}
// loop until a valid random string has been found and registered,
// but at most 20 times. If no valid random has been found during
// that time, there is something really wrong. Also show the error
// in the last run.
for ($remaining = 20; $remaining > 0; $remaining--)
{
// generate a new random string.
$random = $this->__random_string ();
// open a file with the corresponding name in the repository
// directory in such a way, that the creation fails, when the
// file already exists. That should be near to impossible with
// good seeding of the random number generator, but it's better
// to play safe. If this is the last run, show the possible
// error message.
$filename = $this->__random_repository . '/' . $random;
if ($remaining == 1)
{
$file = fopen ($filename, 'x');
}
else
{
$file = @fopen ($filename, 'x');
}
if ($file)
{
fclose ($file);
break;
}
// if the file already existed, rerun the loop to try the next
// string.
}
// return the successfully registered random string.
$this->__random = $random;
return $random;
}
//
// Generates image-URL Parameters are only atached if different from default
//
function image_url ($random = False, $base = 'http://image.captchas.net/')
{
if (!$random)
{
$random = $this->__random;
}
$image_url = $base;
$image_url .= '?client=' . $this->__client;
$image_url .= '&random=' . $random;
if ($this->__alphabet!='abcdefghijklmnopqrstuvwxyz') {$image_url .= '&alphabet=' . $this->__alphabet;};
if ($this->__letters!=6) {$image_url .= '&letters=' . $this->__letters;};
if ($this->__width!=240) {$image_url .= '&width=' . $this->__width;};
if ($this->__height!=80) {$image_url .= '&height=' . $this->__height;};
return $image_url;
}
//
// Same as image_url but without width and height
//
function audio_url ($random = False, $base = 'http://audio.captchas.net/')
{
if (!$random)
{
$random = $this->__random;
}
$audio_url = $base;
$audio_url .= '?client=' . $this->__client;
$audio_url .= '&random=' . $random;
if ($this->__alphabet!='abcdefghijklmnopqrstuvwxyz') {$audio_url .= '&alphabet=' . $this->__alphabet;};
if ($this->__letters!=6) {$audio_url .= '&letters=' . $this->__letters;};
return $audio_url;
}
//
// Generates complete html-sample with javascript to reload image from
// backup server
//
function image ($random = False, $id = 'captchas.net')
{
$image = <<<EOT
<a href="http://captchas.net"><img
style="border: none; vertical-align: bottom"
id="@ID@" src="@URL@" width="@WIDTH@" height="@HEIGHT@"
alt="The Captcha image" /></a>
<script type="text/javascript">
<!--
function captchas_image_error (image)
{
if (!image.timeout) return true;
image.src = image.src.replace (/^http:\/\/image\.captchas\.net/,
'http://image.backup.captchas.net');
return captchas_image_loaded (image);
}
function captchas_image_loaded (image)
{
if (!image.timeout) return true;
window.clearTimeout (image.timeout);
image.timeout = false;
return true;
}
var image = document.getElementById ('@ID@');
image.onerror = function() {return captchas_image_error (image);};
image.onload = function() {return captchas_image_loaded (image);};
image.timeout
= window.setTimeout(
"captchas_image_error (document.getElementById ('@ID@'))",
10000);
image.src = image.src;
//-->
</script>
EOT;
$image = str_replace ('@HEIGHT@', $this->__height, $image);
$image = str_replace ('@WIDTH@', $this->__width, $image);
$image = str_replace ('@ID@', $id, $image);
$image = str_replace ('@URL@', $this->image_url (), $image);
return $image;
}
function validate ($random)
{
$this->__random = $random;
$file_name = $this->__random_repository . '/' . $random;
// Find out, whether the file exists
$result = is_file ($file_name);
// if the file exists, remember it.
if ($result)
{
$this->__random_file = $file_name;
}
// the random string was valid, if and only if the corresponding
// file existed.
return $result;
}
function verify ($input, $random = False)
{
if (!$random)
{
$random = $this->__random;
}
$password_letters = $this->__alphabet;
$password_length = $this->__letters;
// If the user input has the wrong lenght, it can't be correct.
if (strlen ($input) != $password_length)
{
return False;
}
// Calculate the MD5 digest of the concatenation of secret key and
// random string. The digest is a hex string.
$encryption_base = $this->__secret . $random;
// This extension is needed for secure use of optional parameters
// In case of standard use we do not append the values, to be
// compatible to existing implementations
if(($password_letters != 'abcdefghijklmnopqrstuvwxyz') || ($password_length != '6'))
{
$encryption_base = $encryption_base . ':' . $password_letters . ':' . $password_length;
}
$digest = md5 ($encryption_base);
// Check the password according to the rules from the first
// positions of the digest.
for ($pos = 0; $pos < $password_length; $pos++)
{
$letter_num
= hexdec (substr ($digest, 2 * $pos, 2)) % strlen ($password_letters);
// If the letter at the current position is wrong, the user
// input isn't correct.
if ($input[$pos] != $password_letters[$letter_num])
{
return False;
}
}
// if the file exists, remove it.
if ($this->__random_file)
{
unlink ($this->__random_file);
unset ($this->__random_file);
}
// The user input was correct.
return True;
}
}
?>

252
production/php/classes/page.php Executable file
View File

@@ -0,0 +1,252 @@
<?php
class Page
{
################################################################################
# PRIVATE DATA
private $title,$pageName, $lang;
private $cssFiles = array(),$jsFiles = array();
private $header, $footer, $content;
private $display,$data;
private $absPath,$absURL,$site,$templates,$js,$css,$graphics;
private $messages = array(),$errors = array();
################################################################################
# PUBLIC FUNCTIONS
# constructor
public function __construct()
{
# set our paths
$this->absPath = preg_replace('/^(.*)\/\w+\.php$/','$1',$_SERVER['SCRIPT_FILENAME']).'/';
$this->absURL = preg_replace('/^(.*)\/\w+\.php$/','$1',$_SERVER['SCRIPT_NAME']).'/';
$this->site = 'site/';
$this->templates = $this->site;
$this->js = $this->site . 'javascript/';
$this->css = $this->site . 'css/';
$this->graphics = $this->site . 'graphics/';
# the page language is automatically pulled from a language
# cookie names 'lang'
if(isset($_GET['lang']))
{
$this->lang = $_GET['lang'];
setcookie('lang',$_GET['lang'],time() + 60*60*24*365);
# if the lang parameter is empty, we want to get rid of the cookie
if(empty($_GET['lang']))
unset($_COOKIE['lang']);
}
else if(isset($_COOKIE['lang']) && !empty($_COOKIE['lang']))
$this->lang = $_COOKIE['lang'];
else
$this->lang = 'en';
$this->templates .= $this->lang .'/';
$this->graphics .= $this->lang .'/';
# default values for title and pageName
$this->title = 'Welcome!';
$this->pageName = preg_replace('/^.*\/(\w+)\.php$/','$1',$_SERVER['SCRIPT_NAME']);
# elements of our page
$this->header = $this->templates . 'header.php';
$this->footer = $this->templates . 'footer.php';
$this->content = $this->templates . 'home.php';
# by default, the header, footer and content are all displayed
$this->display = array(
'header' => true,
'footer' => true,
'content' => true,
'menu' => true
);
# load default css and js files
array_push($this->cssFiles,$this->css . '/default.css');
array_push($this->jsFiles,$this->js . '/default.js');
}
# automatically load all css files from folder
public function autoloadCSS()
{
# find all CSS files in css folder
$this->cssFiles = preg_grep('/\.css$/',scandir($this->absPath . $this->css));
# make each path relative to absURL
foreach($this->cssFiles as $key => $value)
$this->cssFiles[$key] = $this->css . $value;
}
# automatically load all javascript files from folder
public function autoloadJS()
{
# find all js files in javascript folder
$this->jsFiles = preg_grep('/\.js$/',scandir($this->absPath . $this->js));
# make each path relative to absURL
foreach($this->jsFiles as $key => $value)
$this->jsFiles[$key] = $this->js . $value;
}
# processes all or part of the page
public function process($part = NULL)
{
# it is possible to process the header or footer by
# itself or just the content, or the entire page
if($part == 'header')
$this->_processHeader();
else if($part == 'footer')
$this->_processFooter();
else if($part == 'content')
$this->_processContent();
else
$this->_processPage();
}
# adds a js file to ones already pulled from standard
# folder
public function addJSFile($new_file)
{
# add file with relative path
array_push($this->jsFiles, $this->js . $new_file);
}
# replaces all other js files with this one
public function useJSFile($new_file)
{
$this->jsFiles = array($this->js . $new_file);
}
# adds a css file to ones already pulled from standard folder
public function addCSSFile($new_file)
{
# add file with relative path
array_push($this->cssFiles, $this->css . $new_file);
}
# replaces all other css files with this one
public function useCSSFile($new_file)
{
$this->cssFiles = array($this->css . $new_file);
}
# adds an error message to the array
public function addError($err)
{
array_push($this->errors,$err);
}
# adds non-error message to the array
public function addMessage($msg)
{
array_push($this->messages,$msg);
}
################################################################################
# SETTERS/GETTERS
# you can pass data to the template via this variable
public function data($key,&$value = NULL)
{
if(!is_null($value))
$this->data[$key] = $value;
else
return($this->data[$key]);
}
# you can turn off parts of the page by setting it's
# corresponding display element to false
public function display($page_element,$value = NULL)
{
if(!is_null($value))
$this->display[$page_element] = $value;
else
return($this->display[$page_element]);
}
# setter/getter for header file
public function header($new_header = NULL)
{
if(!is_null($new_header))
$this->header = $this->templates . $new_header;
else
return $this->header;
}
# setter/getter for footer file
public function footer($new_footer = NULL)
{
if(!is_null($new_footer))
$this->footer = $this->templates . $new_footer;
else
return $this->footer;
}
# setter/getter for content file
public function content($new_content = NULL)
{
if(!is_null($new_content))
$this->content = $this->templates . $new_content;
else
return $this->content;
}
# accessor/modifier for page attributes
public function attr($attr,$value = NULL)
{
# the case when we are setting an attribute
if(!is_null($value))
{
switch($attr)
{
case 'lang':
$this->lang = $value;
$this->templates = $this->site;
$this->templates .= $this->lang .'/';
$this->graphics .= $this->lang .'/';
$this->header = $this->templates . 'header.php';
$this->footer = $this->templates . 'footer.php';
$this->content = $this->templates . 'home.php';
break;
case 'title':
$this->title = $value;
break;
default:
break;
}
}
# the case when we are getting an attribute
else
{
switch($attr)
{
case 'lang':
return $this->lang;
break;
case 'title':
return $this->title;
break;
default:
break;
}
}
}
################################################################################
# PRIVATE FUNCTIONS
private function _processPage()
{
include $this->absPath . $this->site . 'layout/html.php';
}
private function _processHeader()
{
include $this->header;
}
private function _processFooter()
{
include $this->footer;
}
private function _processContent()
{
include $this->content;
}
}
?>

View File

@@ -0,0 +1,150 @@
<?php
#################################################################################
# #
# written by benjamin ramey #
# bsr@rameydesign.net #
# #
# This file contains: #
# Functions that perform various filesystem tasks such as removing #
# unwanted types of files/folders from an array of files and folders #
# in a folder #
# #
#################################################################################
############################################# FUNCTION: filesys_get_folder_tree #
# returns: html of folder tree
# parameters: path to root folder
function filesys_get_folder_tree($path)
{
global $_DOC_ROOT,$_SCRIPT_FOLDER;
# variable that will hold all the HTML for the folder
$folderhtml = '';
# get folder contents in alphabetical order
$folder_contents = scandir($path);
# the url is used so that people can download/look at these files through
# the browser, a doc_root path wouldn't work, of course
$url = str_replace($_DOC_ROOT,"$_SCRIPT_FOLDER",$path);
# one by one, set $element to a file or folder inside the passed folder
foreach($folder_contents as $element)
{
# ignore current and parent folders
if( ($element != '.') and ($element != '..') )
{
# make sure each is_dir call is not using cached information
# from last is_dir check
clearstatcache();
# if $element is a folder, call this function recursively and
# create HTML for this subfolder
if( is_dir("$path/$element") )
{
$folderhtml .= "
<div class='folder_name' id='${element}_name'
onclick='ExpandFolder(this)'
onmouseover='ChangeFolderNameBG(this,0)'
onmouseout='ChangeFolderNameBG(this,1)'>
+ $element
</div>
<div class='sub_folder' id='${element}_folder'>";
$folderhtml .= filesys_get_folder_tree("$path/$element");
$folderhtml .= "
</div>\n\n";
}
else
{
# get the size of this file in kilobytes
$file_size_kb = intval(filesize($path.'/'.$element) / 1024);
$folderhtml .= "
+ <a href='/$url/$element'>$element</a>
($file_size_kb Kb)<br />\n";
}
}
}
return $folderhtml;
}
################################################ FUNCTION: filesys_dirs_present #
# returns: true or false
# parameters: path to directory to inspect, pattern to match directory name
# against
function filesys_dirs_present($path,$pattern = "/.*/")
{
# make sure the path passed here is really a directory we can't
# check anything but a directory, since only directory will contain
# other directories, duh
$handle = is_dir($path) ? opendir($path) : NULL ;
if(empty($handle))
{ return(NULL); }
# set through each child in this directory and see if the child
# is directory but not the parent or current directory
# readdir returns FALSE when no children are left to inspect
while($child = readdir($handle) and $child !== false)
{
# make sure each is_dir call is not using cached information
# from last is_dir check
clearstatcache();
# check if this child is directory and whether it
# matches the user given pattern or not
if(is_dir($path.'/'.$child)
and ($child !== '..')
and ($child !== '.')
and (preg_match($pattern,$child)) )
{
# we can return true with the first matching folder we find
# this is an OR operation
return(true);
}
}
# if we get here, no matching folders were found, so none exist
# so we return false
return(false);
}
######################################### FUNCTION: filesys_get_wanted_children #
# returns: array of wanted dir children
# parameters: 1) path to directory; 2) command to remove [files,folders]
# 3) a pattern to match folder/file names against
function filesys_get_wanted_children($path,$cmd,$pattern = "/.*/")
{
# the cmd can be passed as either all cap or not, so conform it
# here to lower case
$cmd = strtolower($cmd);
# fill an array full of the directory children, but only, of course if
# the passed path is really to a directory
$children = is_dir($path) ? scandir($path) : NULL ;
if(empty($children))
{ return(NULL); }
# remove the current and parent directories
$children = preg_grep("/^\.{1,2}$/",$children,PREG_GREP_INVERT);
# get only the children that match the pattern
$children = preg_grep($pattern,$children);
# if files are to be removed, remove them
if($cmd == 'files')
{
foreach($children as $child)
{
if(!is_dir($path.'/'.$child))
{ array_splice($children,array_search($child,$children),1); }
}
}
# if folders are to be removed, remove them
else if($cmd == 'folders')
{
foreach($children as $child)
{
if(is_dir($path.'/'.$child))
{ array_splice($children,array_search($child,$children),1); }
}
}
# return the array of directory children, free of the bad little ones
return($children);
}
?>

View File

@@ -0,0 +1,50 @@
<?php
#################################################################################
# #
# written by benjamin ramey #
# bsr@rameydesign.net #
# #
# This file contains: #
# Functions that govern various images process, such at #
# grabbing a random one from a give folder, etc #
# #
#################################################################################
################################################### FUNCTION: images_get_random #
function images_get_random($folders,$num = 1,$patt = "/.(jpg)|(JPG)/")
{
$images = array();
$folder_info = array();
$num_folders = count($folders);
# get the pictures for each folder
foreach($folders as $key => $value)
{
$folder_info[$key]['name'] = $value;
$folder_info[$key]['pictures'] = filesys_get_wanted_children($value,'folders',$patt);
}
# get pictures until we have enough!
for($k = 0; $k < $num; $k++)
{
$folder = $folder_info[array_rand($folder_info)];
$image = $folder['pictures'][array_rand($folder['pictures'])];
array_push($images,$folder['name'].'/'.$image);
}
return($images);
}
################################################# FUNCTION: images_print_strip #
function images_print_strip($images,$absPath)
{
print "<div id='image-strip'>\n";
foreach($images as $image)
{
$image = str_replace($absPath,'',$image);
print "<img src='$image' />\n";
}
print "</div>";
}
?>