(object)[], 'input'=>(object)[], 'access'=>(object)[], ]; # Put the info into the variables define( 'LEGALAI[env][d]', getenv( 'HTTP_HOST' ) ); define( 'LEGALAI[env][p]', getenv( 'SCRIPT_NAME' ) ); define( 'LEGALAI[env][q]', getenv( 'QUERY_STRING' ) ); define( 'LEGALAI[env][r]', getenv( 'HTTP_REFERER' ) ); define( 'LEGALAI[env][a]', getenv( 'HTTP_USER_AGENT' ) ); define( 'LEGALAI[env][i]', getenv( 'REMOTE_ADDR' ) ); define( 'LEGALAI[env][m]', strtolower( getenv( 'REQUEST_METHOD' ) ) ); define( 'LEGALAI[env][s]', ( getenv( 'HTTPS' ) == 'on' ? 'https' : 'http' ) ); # Make patameter array (state) $state->env->uri_parameters = $legalai_co->make_parameter_array( constant( 'LEGALAI[env][d]' ), constant( 'LEGALAI[env][p]' ), constant( 'LEGALAI[env][q]' ), constant( 'LEGALAI[env][m]' ), $_POST, $_FILES ); # Force https if ( constant( 'LEGALAI[env][s]' ) != constant( 'LEGALAI[init][http_protocol]' ) ){ $url = 'https://'. constant( 'LEGALAI[env][d]' ) . ( constant( 'LEGALAI[env][p]' ) == '/' ? '' : constant( 'LEGALAI[env][p]' ) ) . ( constant( 'LEGALAI[env][q]' ) == '' ? '' : '?'. constant( 'LEGALAI[env][q]' ) ); $url = preg_replace( '!index\.(html|php)$!', '', $url ); header( 'HTTP/1.1 301 Moved Permanently' ); header( 'location: '. $url ); $legalai_co->do_exit(); } else { // Set subdomain define( 'LEGALAI[init][subdomain]', preg_replace( '!\..*$!', '', constant( 'LEGALAI[env][d]' ) ) ); } # REDIRECT ( r.legalai.as ) if ( ( $state->env->uri_parameters['d'][0] ?? null ) == 'r' ){ if ( preg_match( '!^[0-9a-zA-Z]{8}$!', $state->env->uri_parameters['c'][0] ) ){ require_once( constant( 'LEGALAI[init][path]' ) .'/blocks/url-shortener.blk' ); } $legalai_co->do_exit(); # Path: w(\d+) } elseif ( isset( $state->env->uri_parameters['c'][0] ) and preg_match( '!^w(\d+)$!', $state->env->uri_parameters['c'][0], $match ) and !isset( $state->env->uri_parameters['c'][1] ) ){ $state->env->type = 'WEB-'. $match[1]; $state->env->timestamp = time(); $state->env->translations = $legalai_co->get_translations( constant( 'LEGALAI[init][path]' ) .'/translations.json', constant( 'LEGALAI[init][language]' ) ); $state->env->categories = $legalai_co->get_categories( constant( 'LEGALAI[init][path]' ) .'/categories.json', constant( 'LEGALAI[init][language]' ) ); if ( file_exists( constant( 'LEGALAI[init][path]' ) .'/blocks/w-'. $match[1] .'.blk' ) ){ require_once( constant( 'LEGALAI[init][path]' ) .'/blocks/w-'. $match[1] .'.blk' ); } $legalai_co->do_exit(); # CDN: pdf # } elseif ( isset( $state->env->uri_parameters['c'][0] ) and preg_match( '!^cdn$!', $state->env->uri_parameters['c'][0], $match ) and isset( $state->env->uri_parameters['c'][1] ) and preg_match( '!^[A-Za-z0-9]{'. constant( 'LEGALAI[access][caseid][length]' ) .'}$!', $state->env->uri_parameters['c'][1] ) and isset( $state->env->uri_parameters['c'][2] ) and preg_match( '!\.pdf$!', $state->env->uri_parameters['c'][2] ) ){ } elseif ( isset( $state->env->uri_parameters['c'][0] ) and preg_match( '!^cdn$!', $state->env->uri_parameters['c'][0], $match ) and isset( $state->env->uri_parameters['c'][1] ) and preg_match( '!\.pdf$!', $state->env->uri_parameters['c'][1] ) ){ usleep(100); $catid = preg_replace( '![^a-f0-9]!', '', $_COOKIE['catid'] ); // Get Mysql class require_once( constant( 'LEGALAI[init][path]' ) .'/classes/legalai_mysql.class' ); $db = new Mysql( constant( 'LEGALAI[db][database_name]' ), constant( 'LEGALAI[db][username]' ), constant( 'LEGALAI[db][password]' ) ); $sql = "select CASEID from CASEINFO where SHA2( concat( SHA2( CASEID, 512 ), CASE_ACCESS_TOKEN, CASE_EMAIL_TOKEN, INIT_TIMESTAMP, '". constant( 'LEGALAI[env][i]' ) ."' ), 512 )='". $catid ."' and STATUS='open' and STATE='active'"; if ( $db->query( $sql ) and $db->num_rows() == 1 and $row = current( $db->result() ) ){ $caseid = $row->CASEID; $filename = constant( 'LEGALAI[init][path]' ) .'/data/'. $caseid .'/documents/'. utf8_encode( basename( $state->env->uri_parameters['c'][1] ) ); if ( file_exists( $filename ) ){ header( 'content-type:application/pdf' ); echo file_get_contents( $filename ); } else { header( "HTTP/1.0 404 Not Found" ); } } else { header( "HTTP/1.0 404 Not Found" ); } $legalai_co->do_exit(); # CDN: mp3 } elseif ( isset( $state->env->uri_parameters['c'][0] ) and preg_match( '!^cdn$!', $state->env->uri_parameters['c'][0], $match ) and isset( $state->env->uri_parameters['c'][1] ) and preg_match( '!\.mp3$!', $state->env->uri_parameters['c'][1] ) ){ usleep(100); $filename = constant('LEGALAI[init][path]') . '/audio/' . utf8_encode( basename( $state->env->uri_parameters['c'][1] ) ); if ( file_exists( $filename ) ){ header('Content-Type: audio/mpeg'); header('Pragma: cache'); header('Cache-Control: max-age=86400, must-revalidate'); echo file_get_contents( $filename ); } else { header( "HTTP/1.0 404 Not Found" ); } $legalai_co->do_exit(); # CDN: mp4 } elseif ( isset( $state->env->uri_parameters['c'][0] ) and preg_match( '!^cdn$!', $state->env->uri_parameters['c'][0], $match ) and isset( $state->env->uri_parameters['c'][1] ) and preg_match( '!\.mp4$!', $state->env->uri_parameters['c'][1] ) ){ usleep(100); $catid = preg_replace( '![^a-f0-9]!', '', $_COOKIE['catid'] ); // Get Mysql class require_once( constant( 'LEGALAI[init][path]' ) .'/classes/legalai_mysql.class' ); $db = new Mysql( constant( 'LEGALAI[db][database_name]' ), constant( 'LEGALAI[db][username]' ), constant( 'LEGALAI[db][password]' ) ); $sql = "select CASEID from CASEINFO where SHA2( concat( SHA2( CASEID, 512 ), CASE_ACCESS_TOKEN, CASE_EMAIL_TOKEN, INIT_TIMESTAMP, '". constant( 'LEGALAI[env][i]' ) ."' ), 512 )='". $catid ."' and STATUS='open' and STATE='active'"; if ( $db->query( $sql ) and $db->num_rows() == 1 and $row = current( $db->result() ) ){ $caseid = $row->CASEID; $filename = constant( 'LEGALAI[init][path]' ) .'/data/'. $caseid .'/documents/'. utf8_encode( basename( $state->env->uri_parameters['c'][1] ) ); if ( file_exists( $filename ) ){ $filesize = filesize( $filename ); $start = 0; $end = $filesize - 1; if ( isset($_SERVER['HTTP_RANGE']) and preg_match('/bytes=(\d+)-(\d*)/', $_SERVER['HTTP_RANGE'], $matches) ){ $start = intval($matches[1]); if ( $matches[2] !== '' ){ $end = intval($matches[2]); } if ( $end >= $filesize ){ $end = $filesize - 1; } header("HTTP/1.1 206 Partial Content"); header("Content-Range: bytes $start-$end/$filesize"); } else { header("HTTP/1.1 200 OK"); } $length = $end - $start + 1; header("Accept-Ranges: bytes"); header("Content-Type: video/mp4"); header("Content-Length: $length"); $fp = fopen($filename, 'rb'); fseek($fp, $start); while ( !feof($fp) and ftell($fp) <= $end ){ echo fread($fp, 8192); flush(); } fclose($fp); } else { header( "HTTP/1.0 404 Not Found" ); } } else { header( "HTTP/1.0 404 Not Found" ); } $legalai_co->do_exit(); # Logout } elseif ( isset( $state->env->uri_parameters['c'][0] ) and $state->env->uri_parameters['c'][0] == 'utlogging' ){ header( 'HTTP/1.1 301 Moved Permanently' ); header( 'location: /w1#utlogging' ); $legalai_co->do_exit(); } else { header( 'HTTP/1.1 301 Moved Permanently' ); header( 'location: /w1' ); echo time(); $legalai_co->do_exit(); } ?>