Example #1
0
 public function query($verbose = false)
 {
     $query = $this->site;
     if ($query == 'localhost' or $query == '127.0.0.1') {
         return 'LOL';
     } else {
         $curl = curl_init();
         // Configurable options (via config file)
         $agent = DaGdConfig::get('general.useragent');
         curl_setopt($curl, CURLOPT_URL, $query);
         $timeout = DaGdConfig::get('isitup.timeout');
         curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);
         $max_redirects = DaGdConfig::get('isitup.max_redirects');
         curl_setopt($curl, CURLOPT_MAXREDIRS, $max_redirects);
         curl_setopt($curl, CURLOPT_USERAGENT, $agent);
         curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
         curl_setopt($curl, CURLOPT_HEADER, true);
         curl_setopt($curl, CURLOPT_NOBODY, true);
         curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
         curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
         $this->response = curl_exec($curl);
         $http_response = curl_getinfo($curl, CURLINFO_HTTP_CODE);
         curl_close($curl);
         if ($verbose) {
             if ($http_response == 0) {
                 return 'The server appears to be offline.';
             } else {
                 return 'The server responded with HTTP status code ' . $http_response . '.';
             }
         }
         return $http_response;
     }
 }
Example #2
0
function debug($title, $text = null)
{
    $debug = DaGdConfig::get('general.debug');
    if ($debug) {
        echo '<h5>' . $title . '</h5>';
        if ($text) {
            echo '<div style="color: red;"><pre>' . $text . '</pre></div><br />';
        }
    }
}
Example #3
0
 public function render()
 {
     $environment = DaGdConfig::get('general.environment');
     if ($environment != 'development') {
         error400('This page is disabled in the production environment.');
         return false;
     } else {
         throw new Exception('This is a test exception.');
     }
 }
Example #4
0
File: help.php Project: relrod/dagd
 public function render()
 {
     $routes = DaGdConfig::get('general.routemap');
     $return = '';
     $controllers_visited = array();
     foreach ($routes as $path => $controller) {
         if (in_array($controller, $controllers_visited)) {
             continue;
         }
         $return .= help($controller);
         $controllers_visited[] = $controller;
     }
     return $return;
 }
Example #5
0
            break;
        }
    }
}
$debug = DaGdConfig::get('general.debug');
if (!$route_matches) {
    error404();
    if (!$debug) {
        die;
    }
}
debug('REQUEST variables', print_r($_REQUEST, true));
debug('Route matches', print_r($route_matches, true));
debug('Controller', $controller_match);
debug('Pass-off', 'Passing off to controller.');
// Extra headers
$headers = DaGdConfig::get('general.extra_headers');
foreach ($headers as $header) {
    header($header);
}
$git_dir = escapeshellarg(dirname($_SERVER['SCRIPT_FILENAME']) . '/../../.git/');
$git_latest_commit = shell_exec('git --git-dir=' . $git_dir . ' log -1 --pretty=format:%h');
header('X-Git-Commit: ' . $git_latest_commit);
$instance = new ReflectionClass($controller_match);
$instance = $instance->newInstance();
$instance->setRouteMatches($route_matches);
debug('Response from Controller', '');
echo $instance->finalize();
if (!isset($_REQUEST['strip'])) {
    echo "\n";
}
Example #6
0
 private function generate_link()
 {
     $link = DaGdConfig::get('general.baseurl') . '/p/' . $this->paste_id;
     return '<a href="' . $link . '">' . $link . '</a>';
 }
Example #7
0
 public function fetchWhoisServer()
 {
     $hardcoded_tld_map = DaGdConfig::get('whois.hardcode_map');
     if (array_key_exists($this->tld(), $hardcoded_tld_map)) {
         $custom_tld = $hardcoded_tld_map[$this->tld()];
         // We can have a custom query without having a custom server...
         if (array_key_exists('query', $custom_tld)) {
             $this->query = $custom_tld['query'] . ' ';
         }
         // But if we specify our own server, there's no point in looking for
         // a different one.
         if (array_key_exists('server', $custom_tld)) {
             $this->whois_server = $custom_tld['server'];
             return true;
         }
     }
     $transient_sock = null;
     if (filter_var($this->domain, FILTER_VALIDATE_IP)) {
         $default = DaGdConfig::get('whois.transient_server');
         $default_server = $default['server'];
         $default_port = 43;
         if (strpos($default_server, ':') !== false) {
             list($default_server, $default_port) = explode(':', $default_server, 2);
         }
         $transient_sock = fsockopen($default_server, $default_port);
         if (!$transient_sock) {
             return false;
         }
         fwrite($transient_sock, $default['query'] . ' ' . $this->domain . "\r\n");
     } else {
         $transient_sock = fsockopen($this->tld() . '.whois-servers.net', 43);
         if (!$transient_sock) {
             return false;
         }
         fwrite($transient_sock, 'domain ' . $this->domain . "\r\n");
     }
     $whois_server = null;
     $whois_info = '';
     while (!feof($transient_sock)) {
         $line = fgets($transient_sock);
         $referral = preg_match('#(?:Whois Server|ReferralServer): (.*)#i', $line, $whois_server);
         // This can't be easy because there's an edge case where the referral
         // server doesn't exist, so after parsing we get a simple "\r" back.
         $referral_server_name = null;
         if (!empty($whois_server) && count($whois_server) > 0) {
             $referral_server_name = trim($whois_server[1]);
         }
         if (!empty($referral) && !empty($whois_server) && !empty($referral_server_name)) {
             break;
         }
         $whois_info .= $line;
     }
     fclose($transient_sock);
     if ($whois_server && !empty($referral_server_name)) {
         $whois_server = $whois_server[1];
         $whois_server = preg_replace('#r?whois://#', '', $whois_server);
         if (strpos($whois_server, ':') !== false) {
             $exp = explode(':', $whois_server, 2);
             $this->whois_server = trim($exp[0]);
             $this->whois_port = trim($exp[1]);
         } else {
             $this->whois_server = trim($whois_server);
         }
         $blacklisted_referrals = DaGdConfig::get('whois.referral_blacklist');
         if (!in_array($this->whois_server, $blacklisted_referrals)) {
             return true;
         }
     }
     $this->skip_detail = true;
     return $whois_info;
 }
Example #8
0
File: sql.php Project: relrod/dagd
<?php

// For better or worse, right now this is our gateway to the world of SQL.
if (!function_exists('mysqli_connect')) {
    throw new Exception('da.gd heavily depends on mysqli, and this library was not found. Please ' . 'ensure that mysqli is installed, then restart your httpd and try again.');
}
$__db_handler = new mysqli(DaGdConfig::get('mysql.host'), DaGdConfig::get('mysql.user'), DaGdConfig::get('mysql.password'), DaGdConfig::get('mysql.database'));
Example #9
0
 public function render()
 {
     $max_width = DaGdConfig::get('image.max_width');
     $max_height = DaGdConfig::get('image.max_height');
     $default_filetype = DaGdConfig::get('image.default_filetype');
     $imagetypes = DaGdConfig::get('image.imagetypes');
     $fontpath = DaGdConfig::get('image.fontpath');
     $bg_color_rgb = DaGdConfig::get('image.default_bg_rgb');
     $text_color_rgb = DaGdConfig::get('image.default_text_rgb');
     $split = preg_split('@(?:x|\\*)@', $this->route_matches[1]);
     if (count($split) !== 2) {
         error400('You must separate width and height with either * or x');
         return false;
     } else {
         $this->width = $split[0];
         $this->height = $split[1];
     }
     if ($this->width > $max_width || $this->height > $max_height) {
         error400('The generated image should be less than ' . $max_width . 'x' . $max_height . '.');
         return false;
     }
     if (count($this->route_matches) === 3) {
         if (in_array($this->route_matches[2], array_keys($imagetypes))) {
             $this->filetype = $this->route_matches[2];
         } else {
             error400('The image type you specified is not supported.');
             return false;
         }
     } else {
         $this->filetype = $default_filetype;
     }
     $r = $bg_color_rgb[0];
     $g = $bg_color_rgb[1];
     $b = $bg_color_rgb[2];
     if ($bgcolor = request_or_default('bgcolor')) {
         if (strlen($bgcolor) == 6) {
             $r = $bgcolor[0] . $bgcolor[1];
             $g = $bgcolor[2] . $bgcolor[3];
             $b = $bgcolor[4] . $bgcolor[5];
         } elseif (strlen($bgcolor) == 3) {
             $r = $bgcolor[0] . $bgcolor[0];
             $g = $bgcolor[1] . $bgcolor[1];
             $b = $bgcolor[2] . $bgcolor[2];
         }
     }
     $this->bgcolor = array(hexdec($r), hexdec($g), hexdec($b));
     $this->escape = false;
     $this->wrap_pre = false;
     $this->text_html_strip = false;
     $this->text_content_type = false;
     // Generate the image.
     header('Content-Type: ' . $imagetypes[$this->filetype]['contenttype']);
     $image = imagecreate($this->width, $this->height);
     imagecolorallocate($image, $this->bgcolor[0], $this->bgcolor[1], $this->bgcolor[2]);
     $text = request_or_default('text', $this->width . 'x' . $this->height);
     if ($text == 'off') {
         $text = '';
     }
     $positions = imagettfbbox(30, 0, $fontpath, $text);
     $center_x = ceil(($this->width - $positions[2]) / 2);
     $center_y = ceil(($this->height - $positions[5]) / 2);
     $color = imagecolorallocate($image, $text_color_rgb[0], $text_color_rgb[1], $text_color_rgb[2]);
     imagettftext($image, 30, 0, $center_x, $center_y, $color, $fontpath, $text);
     call_user_func($imagetypes[$this->filetype]['phpfunction'], $image);
     imagedestroy($image);
 }
Example #10
0
    public function render()
    {
        if (array_key_exists('url', $_REQUEST)) {
            if ($this->set_longurl_or_400() && $this->set_shorturl_or_400()) {
                if ($this->store_shorturl()) {
                    header('X-Short-URL: ' . $this->short_url);
                    $this->escape = false;
                    $new_link = DaGdConfig::get('general.baseurl') . '/' . $this->short_url;
                    return '<a href="' . $new_link . '">' . $new_link . '</a>';
                }
            }
            return;
        }
        // No 'url' was passed, so we are not creating a new short-url.
        if ($this->route_matches[1]) {
            // Attempt to access a stored URL
            $this->redirect_from_shorturl();
            return;
        } else {
            // We are not attempting to access a stored URL, but we also don't have
            // a 'url' - Show the form so that we can create a new short-url.
            if (!is_html_useragent()) {
                // No use in showing a form for text UAs. Rather, show help text.
                return help('DaGdShortenController');
            }
            // Not a text useragent because we didn't return above.
            // Bring in the form. // TODO: html in strings = bad.
            $this->escape = false;
            $content = '<h2>da.gd</h2><form method="POST" action="/">
Long URL: <input type="text" name="url" id="url" size="35" autofocus /><br />
Custom short URL (leave blank for random): <input type="text" name="shorturl" size="20" maxlength="10" /><br />
<input type="submit" value="Shorten URL" />
</form>
[help](/help) | [open source](http://github.com/codeblock/dagd)';
            $markup = new DaGdMarkup($content);
            $markup = $markup->render();
            $markup .= '<script>window.onload = function() {document.getElementById("url").focus();}</script>';
            return $markup;
        }
    }