I've been working on fun, simple little PHP-based APIs that do useful things for the company.
I've got a whois API and a website screenshot API going. Not bad.
whois:
<?php
error_reporting(0);
foreach ($argv as $arg) {
$e = explode("=", $arg);
if(count($e) == 2) {
$_GET[$e[0]] = $e[1];
} else {
$_GET[] = $e[0];
}
}
if (!isset($_GET["domain"]) || is_null($_GET["domain"]) || $_GET["domain"] == "") {
die("{}");
}
$whois = array();
exec("whois '".escapeshellcmd($_GET["domain"])."' | grep Registrant", $whois);
$count = count($whois);
for ($i = 0; $i < $count; $i++) {
$arr = explode(":", $whois[$i]);
$before = trim($arr[0]);
$after = trim($arr[1]);
$whois[$before] = $after;
unset($whois[$i]);
}
echo(json_encode((object) $whois));
?>
screenshot:
<?php
error_reporting(0);
foreach ($argv as $arg) {
$e = explode("=", $arg);
if(count($e) == 2) {
$_GET[$e[0]] = $e[1];
} else {
$_GET[] = $e[0];
}
}
if (!isset($_GET["url"]) || is_null($_GET["url"]) || $_GET["url"] == "") {
die();
}
$hostname = null;
$hostname = $_SERVER['HTTP_HOST'];
if (is_null($hostname) || $hostname == "") {
$hostname = $_SERVER['SERVER_NAME'];
}
$file = preg_replace("([^\w\s\d\-_~,;:\[\]\(\).])", '', $_GET["url"]);
$file = preg_replace("([\.]{2,})", '', $file);
$mobile = false;
if (isset($_GET["mobile"]) && $_GET["mobile"] == "true") {
$mobile = true;
}
if (!$mobile) {
unlink(dirname(__FILE__)."/webshots/".$file.".jpg");
exec("wkhtmltoimage "
." --load-error-handling ignore"
." --quality 100"
." -q"
." --width 1920"
." --custom-header \"User-Agent\" \"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2227.0 Safari/537.36\""
." --custom-header-propagation"
." '".escapeshellcmd($_GET["url"])."'"
." /var/www/html/webshots/".$file.".jpg"
);
echo("http".(isset($_SERVER['HTTPS']) ? "s": "")."://".$hostname."/webshots/".$file.".jpg");
} else {
unlink(dirname(__FILE__)."/webshots/".$file."-mobile.jpg");
exec("wkhtmltoimage "
." --load-error-handling ignore"
." --quality 100"
." -q"
." --width 360"
." --custom-header \"User-Agent\" \"Mozilla/5.0 (Linux; U; Android 4.0.3; ko-kr; LG-L160L Build/IML74K) AppleWebkit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30\""
." --custom-header-propagation"
." '".escapeshellcmd($_GET["url"])."'"
." /var/www/html/webshots/".$file."-mobile.jpg"
);
echo("http".(isset($_SERVER['HTTPS']) ? "s": "")."://".$hostname."/webshots/".$file."-mobile.jpg");
}
?>
I feel really dirty about making exec calls, but at least it works.
Programming stuffs (tutorials and extras)
PM me (instead of MintPaw) if you're confuzzled.
thank Skaren for the sig :P