List

Try: ca/tecreations/ViewFile.php


<?php

global $DEBUG, $VERBOSE;

//die("FunctionsPHP::TOP: " . "debug: $DEBUG -- verbose: $VERBOSE\")<br />");


if ($DEBUG && $VERBOSE) {
    print("EndsWith('tec8.jar','8.jar'): " . endsWith("tec8.jar","8.jar") . "<br />");
    print("StartsWith('tec8.jar','tec8'): " . startsWith("tec8.jar","tec8") . "<br />");
    print("<br />");
    print("EndsWith('tec8.Jar','8.jar'): " . endsWith("tec8.Jar","8.jar") . "<br />");
    print("StartsWith('Tec8.jar','TeC8'): " . startsWith("Tec8.jar","TeC8") . "<br />");
    print("<br />");
    print("Extension: (tec8.jar): " . getFileExtension("tec8.jar") . "<br />");
    print("Filename: (tec8.jar): " . getFileName("tec8.jar") . "<br />");
}

if ($DEBUG && $VERBOSE) {
    // test
    print("isNumber(123a45) : '" . isNumber("123a45")   . "'<br />\n");
    print("isNumber(12345)  : '" . isNumber("12345")    . "'<br />\n");

    print("Is Hex: '12345'  : '" . isHex("12345")        . "'<br />\n");
    print("Is Hex: '123a45' : '" . isHex("123a45")       . "'<br />\n");
    print("Is Hex: '123f45' : '" . isHex("123f45")       . "'<br />\n");
    print("Is Hex: '123F45' : '" . isHex("123F45")       . "'<br />\n");
    print("Is Hex: '123g45' : '" . isHex("123g45")       . "'<br />\n");

    print("Is Hex: '123u45' : '" . isHex("123u45")       . "'<br />\n");
    print("Is Hex: '123a45z': '" . isHex("123a45z")      . "'<br />\n");
    print("Is Hex: '123a45d': '" . isHex("123a45d")      . "'<br />\n");
    print("Is Hex: '123A45d': '" . isHex("123A45d")      . "'<br />\n");
    print("Is Hex: '123a45D': '" . isHex("123a45D")      . "'<br />\n");
    print("Is Hex: '123A45D': '" . isHex("123A45D")      . "'<br />\n");
    print("Is Hex: 'FFFFFFFFFFFFFFFFFFFFFFFFF': '" . isHex("FFFFFFFFFFFFFFFFFFFFFFFFF")      . "'<br />\n");
    print("Is Hex: 'FFFFFFFFFFFFFFFFFFFFFFFFFt': '" . isHex("FFFFFFFFFFFFFFFFFFFFFFFFFt")      . "'<br />\n");
print("Ok, hang on...<br />\n");
    print("Is Hex: 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF': '" . isHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF")      . "'<br />\n");
    print("Is Hex: 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFt': '" . isHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFt")      . "'<br />\n");

    print("<br />And Just to be sure...<br />");
    print("Is Hex: 'FFFFFFFFFFF12345FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF'  : '" . isHex("FFFFFFFFFFF12345FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF")      . "'<br />\n");
    print("Is Hex: 'FFFFFFaBcDFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF': '" . isHex("FFFFFFaBcDFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF")      . "'<br />\n");
    print("Is Hex: 'FFFFFFFFFFFFFFFFFFFFFFFF2FFFFFFFFFF91FFFFFFFFFFFFFFFFfedFFFFFFFFFFFFFfffffF'  : '" . isHex("FFFFFFFFFFFFFFFFFFFFFFFF2FFFFFFFFFF91FFFFFFFFFFFFFFFFfedFFFFFFFFFFFFFfffffF")      . "'<br />\n");
    print("Is Hex: 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFgFFFFFFFFFFFFFFFFFFFFF'  : '" . isHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFgFFFFFFFFFFFFFFFFFFFFF")      . "'<br />\n");
print("Ok, hang on...<br />\n");
    print("Is Hex: 'FFFFFFFFFFFFFFFFFFFFFFFF2FFFFFFFFFF91FFFFFFFFFFFFFFFFfediFFFFFFFFFFFFFfffffF'  : '" . isHex("FFFFFFFFFFFFFFFFFFFFFFFF2FFFFFFFFFF91FFFFFFFFFFFFFFFFfediFFFFFFFFFFFFFfffffF")      . "'<br />\n");
    print("Is Hex: 'FFFFFFFFFFFFFFFFFFFFFFFF2FFFFFFFFFF91FFFFFFFFFFFFFFFFfedFiFFFFFFFFFFFFfffffF'  : '" . isHex("FFFFFFFFFFFFFFFFFFFFFFFF2FFFFFFFFFF91FFFFFFFFFFFFFFFFfedFiFFFFFFFFFFFFfffffF")      . "'<br />\n");
}

function containsCode($string = "") {
    $containsCode = false;
    $parts = str_split($string);
    foreach ($parts as $char) {
        if ($char == '\'' ||
            $char == '\"' ||
            $char == '\\' ||
            $char == '\n' ||
            $char == '\r' ||
            $char == '\t' ||
            $char == '[' ||
            $char == ']' ||
            $char == '{' ||
            $char == '}' ||
            $char == '`' ||
            $char == '!' ||
            $char == '#' ||
            $char == '%' ||
            $char == '^' ||
            $char == '&' ||
            $char == '*' ||
            $char == '(' ||
            $char == ')' ||
            $char == '=' ||
            $char =='|' ||
            $char == ',' ||
            $char == '<' ||
            $char == '>' ||
            $char == '/' ||
            $char == '?' ||
            $char == ';' ||
            $char == ':') $containsCode = true;
        } 
        return $containsCode;
    }

    function endsWith($src = "", $ending = "") {
        global $DEBUG, $VERBOSE;
        if ($src == "") die("Programming error: FunctionsPHP.php::endsWith($" . "src is empty)");
        if ($ending == "") return true;
        $srcParts = str_split($src);
        $endingParts = str_split($ending);
        for($i = 1; $i <= count($endingParts); $i++) {
//            $srcPart = substr($src, count($srcParts) - $i, 1);
//            $endingPart = substr($ending, count($endingParts) - $i, 1);
            $srcPart = $srcParts[count($srcParts) - $i];
            $endingPart = $endingParts[count($endingParts) - $i];
            if ($DEBUG && $VERBOSE) print("endsWith(): $src: $ending: $i, $srcPart, $endingPart<br />");
            if (!($srcPart === $endingPart)) return false;
        }
        return true;
    }

    function getExtension($name = "") {
        $extension = "";
        if (hasDot($name)) {
            for($i = strlen($name); $i >= 0; $i--) {
                $char = substr($name, $i,1);
                if ($char == ".") return $extension;
                else $extension = $char . $extension;
            }
        } 
        return "";
    }


    function getFileExtension($name = "") {
        return getExtension($name);
    }

    function getFileName($name = "") {
        if ($name == "") die("Programming error: FunctionsPHP.php::getFileName($name is empty)");
        $filename = "";
        if (hasDot($name)) { // if not hasDot, return the full $name, like 'keystore'
            for($i = 0; $i <= strlen($name); $i++) {
                $char = substr($name, $i,1);
                if (hasDot($char)) break(1); // found the dot, so exit the loop
                else $filename = $filename . $char; // not a dot -- add to $filename
            }
        } else {
            return $name;
        }
        return $filename;
    }

    function getFileText($path = "") {
        global $TEC_PREFIX_DIR, $SITE_PREFIX_DIR;
        $PREFIX_DIR = ($SITE_PREFIX_DIR == "") ? $TEC_PREFIX_DIR : $SITE_PREFIX_DIR;
        if (empty($path)) {
            die("$PREFIX_DIR\FunctionsPHP.getFileText() : Path cannot be set to empty."); // programming error
        }
        $text = file_get_contents($path);
        return $text;
    }        

    function getMinimalMimeType($fname) {
        $fh=fopen($fname,'rb');
        if ($fh) { 
            $bytes6=fread($fh,6);
//print $bytes6;
            fclose($fh); 
            if ($bytes6===false) return false;
            if (substr($bytes6,0,3)=="\xff\xd8\xff") return 'image/jpeg';
            if ($bytes6=="\x89PNG\x0d\x0a") return 'image/png';
            if ($bytes6=="GIF87a" || $bytes6=="GIF89a") return 'image/gif';
            return 'application/octet-stream'; // something binary
        }
        return false;
    }


    function getRandom256($count) { // 0 to 256;
        $random = "";
        $chars = "";
        for($i = 0; $i < 256; $i++) {
            $chars = chr($i);
        }
        for($i = 0; $i < $count;$i++) {
            $random .= $chars[rand(0,strlen($chars))];
        }
        return $random;
    }

    function getRandomAlphanumeric($count = 0) {
        if ($count == 0) return "";
        $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
        $str = "";
        for($i = 0; $i < $count;$i++) {
           $str .= $characters[rand(0, strlen($characters) - 1)];
        }
        return $str;
    }

    function getRandomHexLower($count = 0) {
        if ($count == 0) return "";
        $characters = '0123456789abcdef';
        $str = "";
        for($i = 0; $i < $count;$i++) {
           $str .= $characters[rand(0, strlen($characters) - 1)];
        }
        return $str;
    }

    function getRandomHexMixed($count = 0) {
        if ($count == 0) return "";
        $characters = '0123456789abcdefABCDEF';
        $str = "";
        for($i = 0; $i < $count;$i++) {
           $str .= $characters[rand(0, strlen($characters) - 1)];
        }
        return $str;
    }

    function getRandomHexUpper($count = 0) {
        if ($count == 0) return "";
        $characters = '0123456789ABCDEF';
        $str = "";
        for($i = 0; $i < $count;$i++) {
           $str .= $characters[rand(0, strlen($characters) - 1)];
        }
        return $str;
    }

    function hasDot($str = "") {
       for($i = 0; $i < strlen($str);$i++) {
//print(substr($str,$i,1));
           if (substr($str,$i,1) == ".") return true;
       }
       return false;
    }
 
    function isAdmin() {
        global $ADMIN_LEVEL;
        if (isset($_SESSION['level']) && $_SESSION['level'] == $ADMIN_LEVEL) return true;
    }

    function isAToF($char = "") {
        if ($char == "") die("Programming Error: FunctionsPHP.php::isAToF($" . "char is empty)");
        if ($char == 'A' | $char === 'a') return true;
        if ($char == 'B' | $char === 'b') return true;
        if ($char == 'C' | $char === 'c') return true;
        if ($char == 'D' | $char === 'd') return true;
        if ($char == 'E' | $char === 'e') return true;
        if ($char == 'F' | $char === 'f') return true;
        return false;
    }

    function isDot($str = "") {
        return ($str == ".");
    }

    function isDotDot($str = "") {
         return ($str == "..");
    }

    function isHex($string = "") {
        if ($string == "") die("$TEC_PREFIX_DIR\Functions.php::isHex() : Programming error. Missing target string.");
        $parts = str_split($string);
        foreach ($parts as $part) {
            $goodSoFar = false;
            if (isNumber($part) || isAToF($part)) { // must be one of either
                $goodSoFar = true;
            }
            if (!$goodSoFar) return false; 
        }
        return true;
    }

    function isImage($path = "") {
        $minimime = getMinimalMimeType($path);
        if ($minimime == "image/jpeg") return true;
        if ($minimime == "image/png") return true;
        if ($minimime == "image/gif") return true;
    }

    function isLoggedIn() { 
        if (!(isset($_SESSION['uid']) && isset($_SESSION['level']) &&
            !empty($_SESSION['uid']) && !empty($_SESSION['level']))) {
            return false;
        }
        return true;
    }

    function isLower($string = "") {
        $non_numeric = false;
        $parts = str_split($string);
        foreach ($parts as $char) {
            $forRun = false;
            if (
              (
                $char == 'a' |
                $char == 'b' |
                $char == 'c' |
                $char == 'd' |
                $char == 'e' |
                $char == 'f' |
                $char == 'g' |
                $char == 'h' |
                $char == 'i' |
                $char == 'j' |
                $char == 'k' |
                $char == 'l' |
                $char == 'm' |
                $char == 'n' |
                $char == 'o' |
                $char == 'p' |
                $char == 'q' |
                $char == 'r' |
                $char == 's' |
                $char == 't' |
                $char == 'u' |
                $char == 'v' |
                $char == 'w' |
                $char == 'x' |
                $char == 'y' |
                $char == 'z'
              )
            ) {
                $forRun = true;
            } else {
                $forRun =  false; // short circuit if not a lowercase letter
            }
            if (!$forRun) return false; // IF SHORT CIRCUITED, return false, NOT LOWERCASE.
        }
        return true; // all parts are lowercase
    }

    function isNumber($string = "") {
        $non_numeric = false;
        $parts = str_split($string);
        foreach ($parts as $char) {
            $forRun = false;
            if (
              (// like, all as one? Numbers, hex, binary, etc.
                $char == '0' |
                $char == '1' |
                $char == '2' |
                $char == '3' |
                $char == '4' |
                $char == '5' |
                $char == '6' |
                $char == '7' |
                $char == '8' |
                $char == '9'
              )
            ) {
                $forRun = true;
            } else {
                $forRun =  false; // short circuit if not a number
            }
            if (!$forRun) return false; // IF SHORT CIRCUITED, return false, NOT A NUMBER.
        }
        return true; // all parts are digits
    }

    function isPHP($name = "") {
        $extension = getExtension($name);
        if ($extension == "php") return true;
        if ($extension == "phP") return true;
        if ($extension == "pHp") return true;
        if ($extension == "pHP") return true;
        if ($extension == "Php") return true;
        if ($extension == "PhP") return true;
        if ($extension == "PHp") return true;
        if ($extension == "PHP") return true;
        return false;
    }

    function isTextFile($name = "") {
        $extension = getExtension($name);
        if ($extension == "c") return true;
        if ($extension == "cpp") return true;
        if ($extension == "h") return true;
        if ($extension == "html") return true;
        if ($extension == "htmx") return true;
        if ($extension == "java") return true;
        if ($extension == "md") return true;
        if ($extension == "MF") return true;
        if ($extension == "php") return true;
        if ($extension == "pl") return true;
        if ($extension == "properties") return true;
        if ($extension == "py") return true;
        if ($extension == "sgml") return true;
        if ($extension == "sh") return true;
        if ($extension == "txt") return true;
        if ($extension == "uml") return true;
        if ($extension == "vrml") return true;
        if ($extension == "xml") return true;
        return false;
    }

    function isUpper($string = "") {
        $non_numeric = false;
        $parts = str_split($string);
        foreach ($parts as $char) {
            $forRun = false;
            if (
              (
                $char == 'A' |
                $char == 'B' |
                $char == 'C' |
                $char == 'D' |
                $char == 'E' |
                $char == 'F' |
                $char == 'G' |
                $char == 'H' |
                $char == 'I' |
                $char == 'J' |
                $char == 'K' |
                $char == 'L' |
                $char == 'M' |
                $char == 'N' |
                $char == 'O' |
                $char == 'P' |
                $char == 'Q' |
                $char == 'R' |
                $char == 'S' |
                $char == 'T' |
                $char == 'U' |
                $char == 'V' |
                $char == 'W' |
                $char == 'X' |
                $char == 'Y' |
                $char == 'Z'
              )
            ) {
                $forRun = true;
            } else {
                $forRun =  false; // short circuit if not an uppercase letter
            }
            if (!$forRun) return false; // IF SHORT CIRCUITED, return false, NOT UPPERCASE.
        }
        return true; // all parts are uppercase
    }

    function startsWith($src = "", $prefix = "") {
        global $DEBUG, $VERBOSE;
        if ($src == "") die("Programming error: FunctionsPHP.php:::startsWith($" . "src is empty)");
        if ($prefix == "") return true;
        $srcParts = str_split($src);
        $prefixParts = str_split($prefix);
        for($i = 0; $i <count($prefixParts); $i++) {
            // we confirmed it works in endsWith(), so do the lesser volume of code
            //$srcPart = substr($src, $i, 1);
            //$prefixPart = substr($prefix, $i, 1);
            $srcPart = $srcParts[$i];
            $prefixPart = $prefixParts[$i];
            if ($DEBUG && $VERBOSE) print("startsWith(): $src: $prefix: $i, $srcPart, $prefixPart<br />");
            if (!($srcPart === $prefixPart)) return false;
        }
        return true;
    }

    function Unauthorized() {
        global $TEC_PREFIX_DIR;
        header("Location: /$TEC_PREFIX_DIRApps/Unauthorized.php?query=" . urlencode($_SERVER['QUERY_STRING']) . "&uri=" . $_SERVER['PHP_SELF']);
    }


//////////////////////////////////////////////////////////////////////
// Paste Below This Comment Block And Then Reduce And Move Entities //
//////////////////////////////////////////////////////////////////////