Esempio n. 1
0
/*----------------------------------------------------------------------------------------
 * Purpose: Display the address for the client listener
 * Input: commandArgument - A linked list that provides all the parameters the users typed 
 * 		in. This list is in the same order as they were typed.
 * 	clientThreadArguments - A struct providing the basic address information for the 
 * 		current connection.
 * 	commandNode - A pointer to the current node in the command tree structure.
 * Output:  0 for success or 1 for failure
 * Note:        
 * Kevin Burnett @ November 3, 2008
 * -------------------------------------------------------------------------------------*/
int cmdShowClients(commandArgument * ca, clientThreadArguments * client, commandNode * cn) {
	long* clientIDs = NULL;
	long clientID = 0;
	int clientCount = 0, i = 0;
	int clientPort = 0;
	char * clientAddress = NULL;

	clientCount = getActiveClientsIDs(&clientIDs, CLIENT_LISTENER_UPDATA);

	// display all clients
	if(clientCount>0) { 
		sendMessage(client->socket, "ID\taddress\t\tport\n");
		for(i = 0; i<clientCount; i++) {
			clientID = clientIDs[i];

			clientPort = getClientPort(clientID, CLIENT_LISTENER_UPDATA);
			clientAddress = getClientAddress(clientID, CLIENT_LISTENER_UPDATA);

			sendMessage(client->socket, "%d\t%s\t%d\n", clientID, clientAddress, clientPort);

			free(clientAddress);
		}
	}
	else {
		sendMessage(client->socket, "No active clients.\n");
	}

	free(clientIDs);
	return 0;
}
Esempio n. 2
0
void WEnvironment::init(const WebRequest& request)
{
  Configuration& conf = session_->controller()->configuration();

  queryString_ = request.queryString();
  parameters_ = request.getParameterMap();

  urlScheme_       = request.urlScheme();
  referer_         = request.headerValue("Referer");
  accept_          = request.headerValue("Accept");
  serverSignature_ = request.envValue("SERVER_SIGNATURE");
  serverSoftware_  = request.envValue("SERVER_SOFTWARE");
  serverAdmin_     = request.envValue("SERVER_ADMIN");
  pathInfo_        = request.pathInfo();
#ifndef WT_TARGET_JAVA
  sslInfo_         = request.sslInfo();
#endif

  setUserAgent(request.headerValue("User-Agent"));

  LOG_INFO("UserAgent: " << userAgent_);

  /*
   * Determine server host name
   */
  if (conf.behindReverseProxy()) {
    /*
     * Take the last entry in X-Forwarded-Host, assuming that we are only
     * behind 1 proxy
     */
    std::string forwardedHost = request.headerValue("X-Forwarded-Host");

    if (!forwardedHost.empty()) {
      std::string::size_type i = forwardedHost.rfind(',');
      if (i == std::string::npos)
	host_ = forwardedHost;
      else
	host_ = forwardedHost.substr(i+1);
    } else
      host_ = request.headerValue("Host");
  } else
    host_ = request.headerValue("Host");

  if (host_.empty()) {
    /*
     * HTTP 1.0 doesn't require it: guess from config
     */
    host_ = request.serverName();
    if (!request.serverPort().empty())
      host_ += ":" + request.serverPort();
  }

  clientAddress_ = getClientAddress(request, conf);

  std::string cookie = request.headerValue("Cookie");
  doesCookies_ = !cookie.empty();

  if (doesCookies_)
    parseCookies(cookie, cookies_);

  locale_ = request.parseLocale();
}
Esempio n. 3
0
void WEnvironment::updateUrlScheme(const WebRequest& request) 
{
  urlScheme_       = str(request.urlScheme());

  Configuration& conf = session_->controller()->configuration();
#ifndef WT_TARGET_JAVA
  if (conf.behindReverseProxy() || server()->dedicatedSessionProcess()) {
#else
  if (conf.behindReverseProxy()){
#endif
  std::string forwardedProto = str(request.headerValue("X-Forwarded-Proto"));
  if (!forwardedProto.empty()) {
	std::string::size_type i = forwardedProto.rfind(',');
	if (i == std::string::npos)
	  urlScheme_ = forwardedProto;
	else
	  urlScheme_ = forwardedProto.substr(i+1);
  }
  }
}


void WEnvironment::init(const WebRequest& request)
{
  Configuration& conf = session_->controller()->configuration();

  queryString_ = request.queryString();
  parameters_ = request.getParameterMap();
  host_            = str(request.headerValue("Host"));
  referer_         = str(request.headerValue("Referer"));
  accept_          = str(request.headerValue("Accept"));
  serverSignature_ = str(request.envValue("SERVER_SIGNATURE"));
  serverSoftware_  = str(request.envValue("SERVER_SOFTWARE"));
  serverAdmin_     = str(request.envValue("SERVER_ADMIN"));
  pathInfo_        = request.pathInfo();

#ifndef WT_TARGET_JAVA
  if(!str(request.headerValue("Redirect-Secret")).empty())
	session_->controller()->redirectSecret_ = str(request.headerValue("Redirect-Secret"));

  sslInfo_         = request.sslInfo();
  if(!sslInfo_ && !str(request.headerValue("SSL-Client-Certificates")).empty()) {
	parseSSLInfo(str(request.headerValue("SSL-Client-Certificates")));
  }
#endif

  setUserAgent(str(request.headerValue("User-Agent")));
  updateUrlScheme(request);

  LOG_INFO("UserAgent: " << userAgent_);

  /*
   * If behind a reverse proxy, use external host, schema as communicated using 'X-Forwarded'
   * headers.
   */
#ifndef WT_TARGET_JAVA
  if (conf.behindReverseProxy() || server()->dedicatedSessionProcess()) {
#else
	if (conf.behindReverseProxy()){
#endif
    std::string forwardedHost = str(request.headerValue("X-Forwarded-Host"));

    if (!forwardedHost.empty()) {
      std::string::size_type i = forwardedHost.rfind(',');
      if (i == std::string::npos)
	host_ = forwardedHost;
      else
	host_ = forwardedHost.substr(i+1);
    }
  }



  if (host_.empty()) {
    /*
     * HTTP 1.0 doesn't require it: guess from config
     */
    host_ = request.serverName();
    if (!request.serverPort().empty())
      host_ += ":" + request.serverPort();
  }

  clientAddress_ = getClientAddress(request, conf);

  const char *cookie = request.headerValue("Cookie");
  doesCookies_ = cookie;

  if (cookie)
    parseCookies(cookie, cookies_);

  locale_ = request.parseLocale();
}

#ifndef WT_TARGET_JAVA
void WEnvironment::parseSSLInfo(const std::string& json) {
#ifdef WT_WITH_SSL
	Wt::Json::Object obj;
	Wt::Json::ParseError error;
	if(!Wt::Json::parse(Wt::Utils::base64Decode(json), obj, error)) {
	  LOG_ERROR("error while parsing client certificates");
	  return;
	}

	std::string clientCertificatePem = obj["client-certificate"];
  
	X509* cert = Wt::Ssl::readFromPem(clientCertificatePem);

	if(cert) {
	  Wt::WSslCertificate clientCert = Wt::Ssl::x509ToWSslCertificate(cert);
	  X509_free(cert);

	  Wt::Json::Array arr = obj["client-pem-certification-chain"];

	  std::vector<Wt::WSslCertificate> clientCertChain;

	  for(unsigned int i = 0; i < arr.size(); ++i ) {
		clientCertChain.push_back(Wt::Ssl::x509ToWSslCertificate(Wt::Ssl::readFromPem(arr[i])));
	  }

	  Wt::WValidator::State state = static_cast<Wt::WValidator::State>((int)obj["client-verification-result-state"]);
	  Wt::WString message = obj["client-verification-result-message"];

	  sslInfo_ = new Wt::WSslInfo(clientCert, clientCertChain, Wt::WValidator::Result(state, message));
	}
#endif // WT_WITH_SSL
}