private function onCheckout(array $argv) { if (count($argv) < 3) { return $this->showRepoHelp('checkout'); } $type = strtolower($argv[0]); if (!Dog_Repo::isValidType($type)) { return $this->error('err_type'); } $url = $argv[1]; if (!GWF_Validator::isValidURL($url) || !GWF_HTTP::pageExists($url)) { // return $this->error('err_url'); } $name = $argv[2]; if (!Dog_Repo::isNameValid($name)) { return $this->error('err_name_invalid'); } if (Dog_Repo::repoExists($name, $url)) { return $this->error('err_dup'); } $user = NULL; $pass = NULL; if (isset($argv[3])) { $user = $argv[3]; $pass = isset($argv[4]) ? $argv[4] : ''; } $repo = new Dog_Repo(array('repo_id' => '0', 'repo_type' => $type, 'repo_name' => $name, 'repo_url' => $url, 'repo_user' => $user, 'repo_pass' => $pass, 'repo_options' => '0')); if (!$repo->insert()) { return $this->error('err_database'); } $this->rply('msg_checking_out', array($name)); $repo->checkout(); }
/** * Check if a page exists. * @param string $url * @return true|false */ public static function pageExists($url) { if (substr($url, 0, 1) === '/') { $url = 'http://' . GWF_DOMAIN . GWF_WEB_ROOT . substr($url, 1); } # Check URL // GWF_Debug::disableErrorHandler(); // $parts = @parse_url($url); // GWF_Debug::enableErrorHandler(); // if(!$parts) { // return false; /* the URL was seriously wrong */ // } if (!GWF_Validator::isValidURL($url)) { return false; } if (!($ch = curl_init($url))) { return false; } #curl_setopt($ch, CURLOPT_VERBOSE, true); curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS); # Set the user agent - might help, doesn't hurt curl_setopt($ch, CURLOPT_USERAGENT, self::USERAGENT); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); # Try to follow redirects curl_setopt($ch, CURLOPT_AUTOREFERER, true); curl_setopt($ch, CURLOPT_MAXREDIRS, 10); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); # Cookie stuff $cookiefile = tempnam(self::COOKIE_PATH, self::COOKIE_PREFIX); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile); # Timeout curl_setopt($ch, CURLOPT_TIMEOUT, self::$TIMEOUT); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, self::$TIMEOUT_CONNECT); /* don't download the page, just the header (much faster in this case) */ curl_setopt($ch, CURLOPT_NOBODY, true); curl_setopt($ch, CURLOPT_HEADER, true); # Handle HTTPS links if (isset($parts['scheme']) && $parts['scheme'] == 'https') { curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); # Should be 1! curl_setopt($ch, CURLOPT_SSLVERSION, 1); } $response = curl_exec($ch); curl_close($ch); # Get the status code from HTTP headers if (preg_match('/HTTP\\/1\\.\\d+\\s+(\\d+)/', $response, $matches)) { $code = intval($matches[1]); } else { return false; } # See if code indicates success return $code >= 200 && $code < 400 || $code === 403 || $code === 401; }
public static function validate_href(Module_Links $module, $arg, $check_dups) { $arg = trim($arg); $_POST['link_href'] = $arg; if (strlen($arg) > $module->cfgMaxUrlLen()) { return $module->lang('err_url_long', array($module->cfgMaxUrlLen())); } if (false === GWF_Validator::isValidURL($arg)) { return $module->lang('err_url'); } if (false === GWF_HTTP::pageExists($arg)) { return $module->lang('err_url_down'); } if ($check_dups === true) { if (false !== GWF_Links::getByHREF($arg)) { return $module->lang('err_url_dup'); } } return false; }
public function validate_url(Module_Guestbook $m, $arg) { $arg = $_POST['url'] = trim($arg); if ($arg === '') { return false; } if (!GWF_Validator::isValidURL($arg)) { return $m->lang('err_gbm_url'); } if (!GWF_HTTP::pageExists($arg)) { return $m->lang('err_gbm_url'); } return false; }