2021-02-21 16:37:27 +00:00
< ? php
require_once __DIR__ . '/../vendor/autoload.php' ;
require_once __DIR__ . '/../config.php' ;
/* Initialize Twig engine */
$loader = new \Twig\Loader\FilesystemLoader ( __DIR__ . '/../templates' );
$twig = new \Twig\Environment ( $loader , [
'cache' => __DIR__ . '/../cache' ,
'auto_reload' => true ,
]);
$utils = new App\Utils ;
$result = [];
$q = " " ;
2021-06-13 04:55:08 +00:00
$a = false ;
2021-09-13 17:21:23 +00:00
$all = false ;
2021-02-21 16:37:27 +00:00
if ( isset ( $query ) && strlen ( $query ) > 67 || isset ( $_POST [ " q " ]) && strlen ( $_POST [ " q " ]) > 67 ) {
$result [ " error " ] = " Request is too long, max length is 67 chars " ;
} else if ( isset ( $query ) && ! empty ( $query )) {
$q = htmlspecialchars ( $query );
} else if ( isset ( $_POST [ " q " ])) {
$q = htmlspecialchars ( $_POST [ " q " ]);
}
2022-08-26 17:29:19 +00:00
if ( isset ( $_POST [ " a " ]) || isset ( $_GET [ " a " ]))
2021-06-13 04:55:08 +00:00
$a = true ;
2021-09-13 17:21:23 +00:00
if ( isset ( $_POST [ " all " ]) || isset ( $_GET [ " all " ]))
$all = true ;
2021-06-13 04:55:08 +00:00
2021-02-21 16:37:27 +00:00
if ( ! empty ( $q )) {
$pdo = ( new App\DB ( $options )) -> pdo ;
2021-06-13 04:55:08 +00:00
if ( $a )
$STH = $pdo -> query ( " SELECT `host`, `base64`, `base32`, `last_seen` FROM `hosts` WHERE (`host` LIKE '% " . $q . " %' OR `base32` LIKE '% " . $q . " %') AND `disabled` = 0 LIMIT " . $options [ " tableitems " ]);
else
$STH = $pdo -> query ( " SELECT `host`, `base64`, `base32`, `last_seen` FROM `hosts` WHERE `host` LIKE '% " . $q . " %' OR `base32` LIKE '% " . $q . " %' LIMIT " . $options [ " tableitems " ]);
2021-02-21 16:37:27 +00:00
$STH -> setFetchMode ( PDO :: FETCH_ASSOC );
$row = $STH -> fetchAll ();
if ( empty ( $row ))
$result [ " error " ] = " Nothing was found " ;
else
$result = array_merge ( $result , $row );
}
$template = $twig -> load ( 'search.twig' );
2021-09-13 17:21:23 +00:00
echo $template -> render ([ 'query' => $q ? : 'removed request' , 'result' => $result , 'limit' => $options [ " tableitems " ], 'all' => $all ]);