Made xmlstarlet finding code hopefully more POSIX

http://mywiki.wooledge.org/BashFAQ/081
This commit is contained in:
Kai Hendry
2012-06-27 12:06:39 +02:00
parent bccb4abc99
commit f3bdc2aac0
3 changed files with 21 additions and 18 deletions

View File

@@ -6,6 +6,7 @@ Cache-Control: no-cache
Content-Type: text/html
END
badinput() {
echo "<h1>Bad input, parameter id $@</h1>"
exit
@@ -64,8 +65,7 @@ else
exit
fi
echo Need to create u/$id
mkdir u/$id
mkdir -p u/$id
fi

View File

@@ -10,12 +10,10 @@ then
exit 1
fi
# xmlstarlet is often just xml
if which xmlstarlet >> /dev/null; then
XMLSTARLET=xmlstarled
elif which xml >> /dev/null; then
XMLSTARLET=xml
else
command -v xmlstarlet >/dev/null && XMLSTARLET=xmlstarlet
command -v xml >/dev/null && XMLSTARLET=xml
if ! test $XMLSTARLET
then
echo "xmlstarlet not found :("
exit 1
fi
@@ -101,7 +99,7 @@ do
set -- $(echo $rest)
finUrl=$2
domain=$(echo $finUrl | cut -d'/' -f3)
if [ "$shortDomains" = *$domain* ]
if echo $shortDomains | grep -q $domain # TODO might match greedily, e.g. with t.co
then
finUrl=$(curl "$finUrl" -s -L -I -o /dev/null -w '%{url_effective}')
fi

View File

@@ -1,10 +1,15 @@
<?php
header('Content-type: application/json');
if (empty($_GET['q'])) { die(); }
// Is this the correct way to sanitise args to shell from PHP?
$QUERY=urldecode(escapeshellarg(urlencode($_GET['q'])));
// Debug Logging
//$fp = fopen('debug.log', 'a');
//fwrite($fp, $_GET['q'] . " : " . $QUERY . "\n");
//fclose($fp);
exec("grep -hi $QUERY *.txt", $array);
$data = json_encode($array);
echo $_GET['jsoncallback'] . '(' . $data . ');';