-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.php
47 lines (39 loc) · 891 Bytes
/
index.php
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
41
42
43
44
45
46
47
<?php
require('./jq.php');
header("Access-Control-Allow-Origin: *");
$contents = null;
if(isset($_GET['url']))
{
$url = $_GET['url'];
if (filter_var($url, FILTER_VALIDATE_URL) !== false)
{
$contents = file_get_contents($url);
if ($contents === false)
{
http_response_code(400);
header("Content-Type: plain/text");
die("Fetching URL failed: ".$url);
}
}
}
else if(is_null($contents))
{
// Read Input JSON off the request POST
$contents = file_get_contents('php://input');
}
if (empty($contents))
{
// We don't have a request body or a URL
// Send user to the wiki
header("Location: https://github.com/captn3m0/jqaas");
exit;
}
if (isset($_SERVER['HTTP_JQ_FILTER']))
{
$filter = $_SERVER['HTTP_JQ_FILTER'];
}
else
{
$filter = '.';
}
echo call_jq($contents, $filter);