summaryrefslogtreecommitdiff
path: root/search.php
blob: 8d027a03d62be8c91c7ed16cf892afac11d41f13 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php

    $config = false;
try {
    if (!is_readable("config.ini")) {
        throw new Exception('File config.ini does not exist');
    }
    if (!$config = parse_ini_file("config.ini")) {
        throw new Exception('Could not parse ini file');
    }
    
    // hash the password
    $hash = hash("sha256", $config['password']);
    $curl = curl_init($config["url"]. "?format=json");
    curl_setopt($curl, CURLOPT_HTTPHEADER, array("Cookie: password=$hash"));
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    $output = json_decode(curl_exec($curl));
    curl_close($curl);

    
    $search = "abel";

    // Really slow search
    $results = [];
    foreach ($output as $upload) {
        if (strpos($upload->filename, $search) !== false) {
            $results[] = $config["url"] . "/" . $upload->filename;
        }
    }

    // Return results
    if (empty($results)) {
        echo "No results found\n";
    } else {
        var_dump($results);die();
    }

} catch (Exception $e) {
    var_dump($e->getMessage());die();
}