function _configBaseInit() { global $argv; _configBaseSet("originalargs", $argv); _configBaseSet("targetdir", $argv[1]); _configBaseSet("scriptdir", __DIR__); _configBaseQuery("loaded", false); }
function _logBaseWrite($msg, $key = 'DEBUG') { if (is_array($msg)) { $msg = "ARRAYSTART\n" . print_r($msg, true); } $msg = _configBaseQuery("spid") . "-" . _configBaseQuery("pid") . ",,,{$key},,," . $msg; file_put_contents("/tmp/" . _configBaseQuery("basename") . ".log", "{$msg}\n", FILE_APPEND | LOCK_EX); }
function _modeCommandHandle() { if (_keyboardBaseHandleLoad()) { _configBaseQuery("_screenBaseViewDirty", true); return; } if (_keyboardBaseHandleMovement()) { return; } }
function _configBaseInit() { global $argv; _configBaseQuery("pid", getmypid()); _configBaseQuery("originalargs", $argv); _configBaseQuery("targetdir", $argv[1]); _configBaseQuery("hostname", $argv[2]); _configBaseQuery("timestamp", $argv[3]); _configBaseQuery("spid", $argv[4]); _configBaseQuery("scriptdir", __DIR__); _configBaseQuery("basename", basename(__DIR__)); _configBaseQuery("cachedir", _configBaseQuery("scriptdir") . "/_cache_"); if (!file_exists(_configBaseQuery("cachedir"))) { mkdir(_configBaseQuery("cachedir")); chmod(_configBaseQuery("cachedir"), 0777); } }
function _keyboardBaseHandleLoad() { // if( _appBaseGetMode( ) == "edit" ) return( false ) ; $byte = _keyboardBasePullInput(); if (chr($byte) == 'p') { if (!_configBaseQuery("loaded")) { $t = _cursorBaseGridLine(); if ($t != "") { $ph = hash('sha256', "~_1ZAF_2WOZ_3ERE_+" . $t); _configBaseQuery("loadedHash", $ph); _configBaseQuery("loaded", true); _appBaseLoadSession(); _logBaseWrite("LOADED!!"); } } return true; } _keyboardBasePushInput($byte); return false; }
function _appBaseDecrypt($data) { $key = substr(_configBaseQuery("loadedHash"), 0, \Sodium\CRYPTO_SECRETBOX_KEYBYTES); $decoded = $data; $nonce = mb_substr($decoded, 0, \Sodium\CRYPTO_SECRETBOX_NONCEBYTES, '8bit'); $ciphertext = mb_substr($decoded, \Sodium\CRYPTO_SECRETBOX_NONCEBYTES, null, '8bit'); $decrypted = \Sodium\crypto_secretbox_open($ciphertext, $nonce, $key); if ($decrypted === false) { _logBaseWrite("_appBaseDecryptERR!"); _screenBaseCleanUp(); exit; } return $decrypted; }
function _cursorBaseGridLine() { $cy = _configBaseQuery("cursory"); $gy = _configBaseQuery("gridy"); $y = $gy + $cy - 1; $cx = _configBaseQuery("cursorx"); $gx = _configBaseQuery("gridx"); $x = $gx + $cx - 1; $res = array("x" => $x, "y" => $y); $line = ""; for ($i = 0; $i < $x; $i++) { $z = _gridBaseQuery($i, $y); if ($z == -1) { break; } $line .= chr($z & 255); } //_logBaseWrite($line); return $line; }
function _gridBaseLoad($fn) { if (!_configBaseQuery("loaded")) { _gridBaseInit(); _logBaseWrite("_gridBaseLoad NOT LOADED"); return; } $afp = _configBaseGet("targetdir") . "/" . $fn; if (file_exists($afp)) { system("cp {$afp} {$afp}." . time()); $t1 = file_get_contents(_configBaseGet("targetdir") . "/" . $fn); $t1 = _appBaseDecrypt($t1); $t2 = base64_decode($t1); $t3 = gzdecode($t2); $t4 = json_decode($t3, true); $data = $t4; _configBaseSet("grid", $data['grid']); $config = $data['config']; _configBaseQuery("config", $config); } else { _gridBaseInit(); } }