コード例 #1
0
 /**
  * Check whether a given URL is excluded
  *
  * @param   peer.URL url
  * @return  bool
  */
 public function isExcluded(URL $url)
 {
     foreach ($this->excludes as $pattern) {
         if (stristr($url->getHost(), $pattern)) {
             return TRUE;
         }
     }
     return FALSE;
 }
コード例 #2
0
 /**
  * Setup the class instance. A dsn string must be given with the relevant information
  * about the server and script:
  *
  * Eg: nagios://nagios.xp_framework.net:5667/service_to_monitor
  *
  * @param   string dsn
  */
 public function setup($dsn)
 {
     $url = new URL($dsn);
     $this->server = $url->getHost();
     $this->port = $url->getPort(5667);
     $this->version = $url->getParam('version', NSCA_VERSION_2);
     $this->service = trim($url->getPath(), '/');
     $this->host = $url->getParam('hostname', System::getProperty('host.name'));
     if (FALSE !== $url->getParam('domain', FALSE)) {
         $this->host .= '.' . ltrim($url->getParam('domain'), '.');
     }
 }
コード例 #3
0
 /**
  * Creates a new request object
  *
  * @param   string method
  * @param   peer.URL url
  * @return  scriptlet.HttpScriptletRequest
  */
 protected function newRequest($method, URL $url)
 {
     $q = $url->getQuery('');
     $req = new HttpScriptletRequest();
     $req->method = $method;
     $req->env['SERVER_PROTOCOL'] = 'HTTP/1.1';
     $req->env['REQUEST_URI'] = $url->getPath('/') . ($q ? '?' . $q : '');
     $req->env['QUERY_STRING'] = $q;
     $req->env['HTTP_HOST'] = $url->getHost();
     if ('https' === $url->getScheme()) {
         $req->env['HTTPS'] = 'on';
     }
     $req->setHeaders(array());
     $req->setParams($url->getParams());
     return $req;
 }
コード例 #4
0
ファイル: proj_email.php プロジェクト: nterray/tuleap
function send_new_project_email($group_id)
{
    global $Language;
    $res_grp = db_query("SELECT * FROM groups WHERE group_id='" . db_ei($group_id) . "'");
    if (db_numrows($res_grp) < 1) {
        echo $Language->getText('include_proj_email', 'g_not_exist', $group_id);
    }
    $row_grp = db_fetch_array($res_grp);
    $res_admins = db_query("SELECT user.user_name,user.email FROM user,user_group WHERE " . "user.user_id=user_group.user_id AND user_group.group_id='" . db_ei($group_id) . "' AND " . "user_group.admin_flags='A'");
    $nb_recipients = db_numrows($res_admins);
    if ($nb_recipients < 1) {
        echo $Language->getText('include_proj_email', 'no_admin', $group_id);
    }
    // send one email per admin
    $nb_mail_failed = 0;
    $pm = ProjectManager::instance();
    while ($row_admins = db_fetch_array($res_admins)) {
        $server = get_server_url();
        $p = $pm->getProject($group_id);
        $host = $GLOBALS['sys_default_domain'];
        if ($p && $p->usesService('svn')) {
            $sf = new ServerFactory();
            if ($s =& $sf->getServerById($p->services['svn']->getServerId())) {
                $host = URL::getHost($s->getUrl(session_issecure()));
            }
        }
        if ($GLOBALS['sys_force_ssl']) {
            $svn_url = 'https://' . $host;
        } else {
            $svn_url = 'http://svn.' . $row_grp['unix_group_name'] . '.' . $host;
        }
        $svn_url .= '/svnroot/' . $row_grp['unix_group_name'];
        // $message is defined in the content file
        include $Language->getContent('include/new_project_email');
        // LJ Uncomment to test
        //echo $message; return
        $mail = new Mail();
        $mail->setTo($row_admins['email']);
        $mail->setSubject($GLOBALS['sys_name'] . ' ' . $Language->getText('include_proj_email', 'proj_approve', $row_grp['unix_group_name']));
        $mail->setBody($message);
        $mail->setFrom($GLOBALS['sys_email_admin']);
        if (!$mail->send()) {
            $nb_mail_failed++;
        }
    }
    return $nb_mail_failed < $nb_recipients;
}
コード例 #5
0
 /**
  * Acquire a handler instance
  *
  * @param   string key
  * @return  remote.protocol.ProtocolHandler
  * @throws  remote.protocol.UnknownProtocolException
  */
 public function acquire($key, $initialize = FALSE)
 {
     $url = new URL($key);
     $key = new URL($url->getScheme() . '://' . $url->getHost());
     if ($this->pool->containsKey($key)) {
         $instance = $this->pool->get($key);
     } else {
         sscanf($url->getScheme(), '%[^+]+%s', $type, $option);
         $class = HandlerFactory::handlerFor($type);
         $instance = $this->pool($key, $class->newInstance($option));
     }
     // Add logger
     if (NULL !== ($cat = $url->getParam('log'))) {
         $instance->setTrace(Logger::getInstance()->getCategory($cat));
     }
     // Set timeout, defaults to 60 seconds
     $instance->setTimeout($url->getParam('timeout', 60));
     $initialize && $instance->initialize($url);
     return $instance;
 }
コード例 #6
0
 public function doCreate()
 {
     $req = $this->newRequest('GET', new URL('http://localhost/'));
     $res = new HttpScriptletResponse();
     $s = newinstance('scriptlet.xml.XMLScriptlet', array(), '{
     public function needsSession($request) { return TRUE; }
   }');
     $s->service($req, $res);
     $this->assertEquals(HttpConstants::STATUS_FOUND, $res->statusCode);
     // Check URL from Location: header contains the session ID
     with($redirect = new URL(substr($res->headers[0], strlen('Location: '))));
     $this->assertEquals('http', $redirect->getScheme());
     $this->assertEquals('localhost', $redirect->getHost());
     $this->assertEquals(sprintf('/xml/psessionid=%s/static', session_id()), $redirect->getPath());
     $this->assertEquals(array(), $redirect->getParams(), $redirect->getURL());
 }
コード例 #7
0
 /**
  * Creates a socket
  *
  * @param   peer.URL url
  * @param   string arg
  * @return  peer.Socket
  */
 protected function newSocket(URL $url, $arg)
 {
     return new Socket($url->getHost(), $url->getPort(80));
 }
コード例 #8
0
 /**
  * Creates a socket - overridden from parent class
  *
  * @param   peer.URL url
  * @param   string arg
  * @return  peer.Socket
  */
 protected function newSocket(URL $url, $arg)
 {
     sscanf($arg, 'v%d', $version);
     return new SSLSocket($url->getHost(), $url->getPort(443), NULL, $version);
 }
コード例 #9
0
 public function handleSessionInitializationError()
 {
     $req = $this->newRequest('GET', new URL('http://localhost/?psessionid=MALFORMED'));
     $res = new HttpScriptletResponse();
     $s = newinstance('scriptlet.HttpScriptlet', array(), '{
     public function needsSession($request) { return TRUE; }
     public function handleSessionInitialization($request) {
       if (!preg_match("/^a-f0-9$/", $request->getSessionId())) { 
         throw new IllegalArgumentException("Invalid characters in session id");
       }
       parent::handleSessionInitialization($request);
     }
     public function handleSessionInitializationError($request, $response) {
       $request->getURL()->addParam("relogin", 1);
       return $request->session->initialize(NULL);
     } 
   }');
     $s->service($req, $res);
     $this->assertEquals(HttpConstants::STATUS_FOUND, $res->statusCode);
     // Check URL from Location: header contains the session ID
     with($redirect = new URL(substr($res->headers[0], strlen('Location: '))));
     $this->assertEquals('http', $redirect->getScheme());
     $this->assertEquals('localhost', $redirect->getHost());
     $this->assertEquals('/', $redirect->getPath());
     $this->assertEquals(session_id(), $redirect->getParam('psessionid'));
     $this->assertEquals('1', $redirect->getParam('relogin'));
 }
コード例 #10
0
 /**
  * Get the IP address of our host. An empty host field or a DNS failure
  * will result in a null return.
  *
  * @param u a URL object
  * @return InetAddress an <code>InetAddress</code> representing the host
  * IP address.
  * @since 1.3
  */
 public function getHostAddress(URL $u)
 {
     if ($u->hostAddress != null) {
         return $u->hostAddress;
     }
     $host = $u->getHost();
     if ($host == null || $host->equals("")) {
         return null;
     } else {
         try {
             $u->hostAddress = InetAddress::getByName($host);
             //            } catch (UnknownHostException $ex) {
             //                return null;
             //            } catch (SecurityException $se) {
             //                return null;
         } catch (\blaze\lang\Exception $e) {
             return null;
         }
     }
     return $u->hostAddress;
 }
コード例 #11
0
 public function sqliteUrl()
 {
     $u = new URL('sqlite:///path/to/file.db');
     $this->assertEquals(NULL, $u->getHost());
     $this->assertEquals('/path/to/file.db', $u->getPath());
 }
コード例 #12
0
 /**
  * Navigate to a given URL
  *
  * @param   string target
  * @param   string params
  * @param   string method
  * @throws  unittest.AssertionFailedError  
  */
 public function navigateTo($target, $params = NULL, $method = HttpConstants::GET)
 {
     if (strstr($target, '://')) {
         $url = new URL($target);
         $this->conn = $this->getConnection(sprintf('%s://%s%s/', $url->getScheme(), $url->getHost(), -1 === $url->getPort(-1) ? '' : ':' . $url->getPort()));
         $params ? $url->setParams($params) : '';
         $this->beginAt($url->getPath(), $url->getParams(), $method);
     } else {
         if ('' !== $target && '/' === $target[0]) {
             $this->beginAt($target, $params, $method);
         } else {
             $base = $this->getBase();
             $this->beginAt(substr($base, 0, strrpos($base, '/')) . '/' . $target, $params, $method);
         }
     }
 }
コード例 #13
0
 /**
  * Parse DSN
  *
  * @param   string dsn
  * @return  bool success
  */
 protected function _parsedsn($dsn)
 {
     if (NULL === $dsn) {
         return TRUE;
     }
     $u = new URL($dsn);
     if (!$u->getHost()) {
         throw new IllegalArgumentException('DSN parsing failed ["' . $dsn . '"]');
     }
     // Scheme
     switch (strtoupper($u->getScheme())) {
         case 'ESMTP':
             $this->ext = TRUE;
             break;
         case 'SMTP':
             $this->ext = FALSE;
             break;
         default:
             throw new IllegalArgumentException('Scheme "' . $u->getScheme() . '" not supported');
     }
     // Copy host and port
     $this->host = $u->getHost();
     $this->port = $u->getPort() ? $u->getPort() : 25;
     // User & password
     if ($u->getUser()) {
         $this->auth = $u->getParam('auth', SMTP_AUTH_PLAIN);
         $this->user = $u->getUser();
         $this->pass = $u->getPassword();
     }
 }
コード例 #14
0
ファイル: svn_intro.php プロジェクト: nterray/tuleap
// Table for summary info
print '<TABLE width="100%"><TR valign="top"><TD width="65%">' . "\n";
// Get group properties
$res_grp = db_query("SELECT * FROM groups WHERE group_id=" . db_ei($group_id));
$row_grp = db_fetch_array($res_grp);
$pm = ProjectManager::instance();
$p = $pm->getProject($group_id);
// Show CVS access information
if ($row_grp['svn_preamble'] != '') {
    echo $hp->purify(util_unconvert_htmlspecialchars($row_grp['svn_preamble']), CODENDI_PURIFIER_FULL);
} else {
    $host = $GLOBALS['sys_default_domain'];
    if ($p && $p->usesService('svn')) {
        $sf = new ServerFactory();
        if ($server =& $sf->getServerById($p->services['svn']->getServerId())) {
            $host = URL::getHost($server->getUrl(session_issecure()));
        }
    }
    if ($GLOBALS['sys_force_ssl']) {
        $svn_url = 'https://' . $host;
    } else {
        if (isset($GLOBALS['sys_disable_subdomains']) && $GLOBALS['sys_disable_subdomains']) {
            $svn_url = 'http://' . $host;
        } else {
            $svn_url = 'http://svn.' . $row_grp['unix_group_name'] . '.' . $host;
        }
    }
    // Domain name must be lowercase (issue with some SVN clients)
    $svn_url = strtolower($svn_url);
    $svn_url .= '/svnroot/' . $row_grp['unix_group_name'];
    // Hook to replace the default information about subversion