예제 #1
0
파일: model.php 프로젝트: stoyan/whomsy
 function getData($conf, $domain = '')
 {
     // is this a request for a static page?
     if (!empty($conf['static']) && empty($domain)) {
         return file_get_contents("includes/content/" . $conf['static']);
     }
     // input
     if (!$domain) {
         return WhomsyModel::bye('I need a domain name', true);
     }
     // try the best to make sense of any input
     $parts = @parse_url($domain);
     $host = empty($parts['host']) ? $parts['path'] : $parts['host'];
     $host = explode('/', $host);
     $host = $host[0];
     $host = explode('.', $host);
     $count = count($host);
     if ($count < 2) {
         return WhomsyModel::bye('I need a valid domain name - like "example.org"', true);
     }
     $d = $host[$count - 2] . '.' . $host[$count - 1];
     // execute command
     $cmd = 'whois ' . escapeshellarg($d);
     exec($cmd, $output, $result);
     if ($result === 1) {
         return WhomsyModel::bye('Error executing whois command', true);
     }
     $output = implode("\n", $output);
     return WhomsyModel::bye($output);
 }
예제 #2
0
파일: index.php 프로젝트: stoyan/whomsy
$conf = array('domain' => array(), 'api' => array('nohtml' => 'true'), 'tools' => array('static' => 'tools.html', 'title' => 'Tools'), 'faq' => array('static' => 'faq.html', 'title' => 'FAQ'), 'apidoc' => array('static' => 'apidoc.html', 'title' => 'API Docs'), 'home' => array('static' => 'home.html', 'title' => 'Whomsy'));
// make sense of the request
$url = parse_url($_SERVER['REQUEST_URI']);
if (empty($_REQUEST) && !empty($url['query'])) {
    // dreamhost quirk with phpcgi
    parse_str($url['query'], $_REQUEST);
}
$url = $url['path'];
$self = dirname($_SERVER['PHP_SELF']);
if ($self !== '/') {
    // app not in the server root
    $url = str_replace($self, '', $url);
    $self = $self . '/';
}
$url = ltrim($url, '/');
$request = explode('/', $url);
if (!in_array($request[0], array_keys($conf))) {
    $request[0] = 'home';
}
// define useful constants
define('HOME', $self);
define('PAGEID', $request[0]);
// the requested page
define('DOMAIN', !empty($_REQUEST['domain']) ? $_REQUEST['domain'] : @$request[1]);
// domain, if any
$conf = $conf[PAGEID];
// config for the requested page
// the "business" logic
$data = WhomsyModel::getData($conf, DOMAIN);
// render the view
WhomsyView::render($data, $conf);