Hits: 16172

List

Try: ca/tecreations/ViewFile.php -- Online


<?php
    global $SELF, $self;
    $self = $SELF = $_SERVER['PHP_SELF'];

    require_once "Debug.php";
    require_once "Cache_Revalidate.php";
    global $MANAGE_SESSIONS;
    global $PROTOCOL, $IS_WEB, $DOCROOT, $DOC_ROOT, $HOST, $HOSTNAME, $HOST_NAME, $METHOD;
    
    // maybe at some point, the site gets prefixed, thinking about waybackmachine.org here, they should be able to set $DOCROOT
    if ($DOCROOT == "") $DOCROOT = $_SERVER['DOCUMENT_ROOT'] . "/"; // IF document root is not empty, we are on the web
                                                                    // Prep for manipulation by appending FILE_SEPARATOR.
                                                                    // User can always get server.docroot raw, if they want.
    if ($DOCROOT == "/") {
        $IS_WEB = false;
        $DOCROOT = "/var/www/tecreations.ca/html/";
    } else {
        $IS_WEB = true;
        // keep $DOCROOT
    }
    if ($_SERVER['HTTPS'] == 'on') $PROTOCOL = "https://";
    else $PROTOCOL = "http://";

    // make it flexible
    $DOC_ROOT = $DOCROOT;
    $HOST           = "tecreations.ca";
    $HOSTNAME       = "tecreations.ca";
    $HOST_NAME      = "tecreations.ca";
    $METHOD         = "GET"; // change this if you want, you should specify in pages that need POST

    global $CLIENT_IP, $HOME_IP, $TIMS_PHONE_IP;
    $HOME_IP = "162.248.156.38";
    $TIMS_PHONE_IP = "207.34.93.1";
    if(isset($_SERVER['HTTP_X_FORWARDED_FOR']) && $_SERVER['HTTP_X_FORWARDED_FOR'] != '') {
       $CLIENT_IP = $_SERVER['HTTP_X_FORWARDED_FOR'];
    } else {
       $CLIENT_IP = $_SERVER['REMOTE_ADDR'];
    }

    function isTecNet() {
        global $CLIENT_IP, $HOME_IP;
        return $CLIENT_IP == $HOME_IP;
    }

    function isTim() {
        global $CLIENT_IP, $TIMS_PHONE_IP;
        return $CLIENT_IP == $TIMS_PHONE_IP;
    }

    global $ADMIN_EMAIL, $ADMIN_LEVEL, $TEC_PREFIX_DIR, $UPLOAD_DIR;
    $ADMIN_EMAIL    = "tim@tecreations.ca"; // set your email here
    $ADMIN_LEVEL    = 9; // choose an admin level for PHP use
    $TEC_PREFIX_DIR = "ca/tecreations/"; // prefix your site's access in java-package-style-naming
    $UPLOAD_DIR     = $DOCROOT . "$TEC_PREFIX_DIR/uploads/"; // you may only upload on this server here, we check if it's okay or not
    // I may make a mod-Class, but probs not, I expect people will only do what is good?!!!

    ini_set("include_path",ini_get("include_path") . ":" . $DOCROOT . ":" . $DOCROOT . $TEC_PREFIX_DIR);

    require_once $DOCROOT . "../private_db.php";
    require_once $DOCROOT . $TEC_PREFIX_DIR . "MySQL.php";
    require_once $DOCROOT . $TEC_PREFIX_DIR . "MySQLSessionHandler.php";
    require_once $DOCROOT . $TEC_PREFIX_DIR . "AES256.php";
    require_once $DOCROOT . $TEC_PREFIX_DIR . "AES256SessionHandler.php";
    require_once $DOCROOT . $TEC_PREFIX_DIR . "HardenedAES256SessionHandler.php";
    require_once $DOCROOT . $TEC_PREFIX_DIR . "User.php";
    require_once $DOCROOT . $TEC_PREFIX_DIR . "QA.php";
    require_once $DOCROOT . $TEC_PREFIX_DIR . "SiteDB.php";
    $oldDEBUG = $DEBUG;
    $DEBUG = false; // only debug these when we need to
    require_once $DOCROOT . $TEC_PREFIX_DIR . "FunctionsPHP.php";
    require_once $DOCROOT . $TEC_PREFIX_DIR . "Color.php";
    require_once $DOCROOT . $TEC_PREFIX_DIR . "Time.php"; 
    require_once $DOCROOT . $TEC_PREFIX_DIR . "Files.php";
    $DEBUG = $oldDEBUG;

    global $db, $DB, $mysql, $MYSQL, $SITE_DB;
    $db = $DB = $mysql = $MYSQL = $SITE_DB = $site_db;

    global $ENCRYPT_SESSIONS, $HARDEN_SESSIONS, $SECRET_KEY, $SESSION_HANDLER;
    $ENCRYPT_SESSIONS = false;
    $HARDEN_SESSIONS = false;
    if ($MANAGE_SESSIONS == "true") {
        if ($HARDEN_SESSIONS) {
            $SESSION_HANDLER = new HardenedAES256SessionHandler($SECRET_KEY);
        } else if ($ENCRYPT_SESSIONS) {
            $SESSION_HANDLER = new AES256SessionHandler($SECRET_KEY);
        } else {
            $SESSION_HANDLER = new MySQLSessionHandler();
        }
        session_set_save_handler($SESSION_HANDLER, true);
        session_start();
    }
    if ($SESSION_HANDLER != null) {
        if (isset($_SESSION['level']) && $_SESSION['level'] == $ADMIN_LEVEL) $SESSION_HANDLER->setDebug(true);
        else $SESSION_HANDLER->setDebug(false);
    }
 

    $php_self = $_SERVER['PHP_SELF'];
    if (!$db->hasTable("hits")) {
        $db->issue("CREATE TABLE IF NOT EXISTS hits (" .
                   "    id INT AUTO_INCREMENT PRIMARY KEY," .
                   "    path VARCHAR(16536) NOT NULL," .
                   "    hit_count INT(11) NOT NULL DEFAULT 0" .
                   ")"
        );
    }
    $count = $db->getVal("SELECT COUNT(*) FROM hits WHERE path='$php_self'","COUNT(*)");
    if ($count == 0) {
        $db->issue("INSERT INTO hits (path) VALUES ('$php_self')");
    }
    $id = $db->getVal("SELECT id FROM hits WHERE path='$php_self'","id");
    $path = substring_from($php_self,strlen($DOC_ROOT) - 1);
    $newHitNum = $db->incrementAndGet("hits",$id,"hit_count");
    print("Hits: $newHitNum<br />");