Exemple #1
0
static String* create_json(String* content, Project* project, Message* message, List* elements, List* element_types)
{
    Iterator* it;
    String* base_url_a = string_new();
    base_url_a = get_base_url(base_url_a);
    string_appendf(content, "{project:{name: \"%s\"}, ticket:{id: %d, url: \"%s/%s/ticket/%d\",fields:[",
            string_rawstr(project->name),
            message->id,
            string_rawstr(base_url_a),
            g_project_code_4_url,
            message->id);
    string_free(base_url_a);
    foreach (it, element_types) {
        ElementType* et = it->element;
        String* field_a = string_new();
        String* name_a = string_new();
        String* value_a = string_new();
        string_append(name_a, string_rawstr(et->name));
        escape_quot(name_a);
        string_append(value_a, get_element_value(elements, et));
        escape_quot(value_a);
        string_appendf(field_a, "{name:\"%s\", value:\"%s\"}",
                string_rawstr(name_a),
                string_rawstr(value_a));
        string_free(name_a);
        string_free(value_a);
        string_append(content, string_rawstr(field_a));
        string_free(field_a);
        if (iterator_next(it)) string_append(content, ",");
    }
Exemple #2
0
// This returns the URL of Bibledit Cloud that faces the user.
string config_logic_site_url (void * webserver_request)
{
  // When the administrator has entered a fixed value for the user-facing URL, take that.
  // It overrides everything.
  string url = config_logic_manual_user_facing_url ();
  if (!url.empty ()) return url;
  
  // If a webserver request is passed, take the host from there.
  // The results is that in a situation where 192.168.2.6 is the same as localhost,
  // uses can connect from localhost and also from 192.168.2.6.
  // In the past there was a situation that the admin set up a central server for the whole team on his localhost.
  // Then team members that connected to 192.168.2.6 were forwarded to localhost (which of course failed).
  // This solution deals with that.
  if (webserver_request) {
    Webserver_Request * request = (Webserver_Request *) webserver_request;
    if (!request->host.empty ()) {
      url = get_base_url (request);
      return url;
    }
  }
  
  // No URL found yet.
  // This occurs during scheduled tasks that require the URL to add it to emails sent out.
  // Take the URL stored on login.
  url = Database_Config_General::getSiteURL ();
  return url;
}
Exemple #3
0
// This function redirects the browser to "path".
// "path" is an absolute value.
void redirect_browser (Webserver_Request * request, string path)
{
  // A location header needs to contain an absolute url, like http://localhost/some.
  // See 14.30 in the specification http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html.
  string location = get_base_url (request) + path;
  request->header = "Location: " + location;
  request->response_code = 302;
}
Exemple #4
0
// From the base url get the site id and site env
static void initialize_site(void) {
    char *str = strdup(get_base_url());
    char *token;
    const char *delim = "/";
    int idx;

    // If there is no base url, we'll fill with a marker ("(null)")
    for (idx = BASEURL_FIRST; idx <= BASEURL_EIGHTH; idx++) {
        log_key_value[idx] = "(null)";
    }

    /* get the first token */
    token = strtok(str, delim);

    idx = BASEURL_FIRST;
    /* walk through other tokens */
    while( token != NULL ) {
        log_key_value[idx++] = strndup(token, KVITEM_SIZE);
        token = strtok(NULL, delim);
    }
    free(str);
    return;
}
Exemple #5
0
string setup_index (void * webserver_request)
{
  Webserver_Request * request = (Webserver_Request *) webserver_request;
  
  Assets_View view;

  // Get the existing Administrators.
  vector <string> admins = request->database_users ()->getAdministrators ();

  // Admins do not yet exist: Allow to enter an admin.
  if (admins.empty ()) {
    if (!request->post ["Submit"].empty ()) {
      string admin_username = request->post ["admin_username"];
      string admin_password = request->post ["admin_password"];
      string admin_email = request->post ["admin_email"];
      vector <string> errors;
      if (admin_username.length() < 5) errors.push_back ("Choose a longer username.");
      if (admin_password.length() < 7) errors.push_back ("Choose a longer password.");
      if (admin_email.length() < 5) errors.push_back ("Enter a valid email address.");
      if (errors.empty()) {
        // Store admin details.
        setup_set_admin_details (admin_username, admin_password, admin_email);
        setup_complete_gui ();
        // Store web site's base URL.
        string siteUrl = get_base_url (request);
        Database_Config_General::setSiteURL (siteUrl);
        // Redirect.
        redirect_browser (request, index_index_url ());
      } else {
        view.enable_zone ("errors");
        view.set_variable ("error", filter_string_implode (errors, " "));
      }
    }
  }

  // Enable appropriate zones: Either enter admin's details, or else display the details.
  if (admins.empty ()) {
    view.enable_zone ("enteradmin");
    view.enable_zone ("enteruser");
    view.enable_zone ("enterpass");
    view.enable_zone ("entermail");
    view.enable_zone ("displaysubmit");
  } else {
    string usernames;
    string emails;
    for (unsigned int i = 0; i < admins.size(); i++) {
      if (i) {
        usernames.append (" / ");
        emails.append (" / ");
      }
      usernames.append (admins[i]);
      emails.append (request->database_users ()->getUserToEmail (admins[i]));
    }
    view.set_variable ("usernames", usernames);
    view.set_variable ("emails", emails);
    view.enable_zone ("displayok");
    view.set_variable ("readonly", "readonly");
    // If the admin's are already there, then the setup has completed.
    // The automatic page refresh will kick in, and navigate to the main screen.
    Database_Config_General::setInstalledInterfaceVersion (config_logic_version ());
  }

  return view.render ("setup", "index");
}
Exemple #6
0
CURL *session_request_init(const char *path, const char *query_string, bool tmp_session) {
    CURL *session;
    char *full_url = NULL;
    char *escaped_path;
    static const char *funcname = "session_request_init";

    // If the whole cluster is sad, avoid access altogether for a given period of time.
    // Calls to this function, on detecting this error, set ENETDOWN, which is appropriate
    if (use_saint_mode()) {
        log_print(LOG_NOTICE, SECTION_SESSION_DEFAULT, "%s: already in saint mode", funcname);
        return NULL;
    }

    session = get_session(tmp_session);

    if (!session) {
        log_print(LOG_CRIT, SECTION_SESSION_DEFAULT, "%s: session handle NULL.", funcname);
        return NULL;
    }

    curl_easy_reset(session);

    // Whether we created a new resolve_slist or not, we still need to
    // make the setopt call for CURLOPT_RESOLVE.
    // Otherwise, libcurl will revert to its default, call getaddrinfo
    // on its own, and return the unsorted, unbalanced, first entry.
    log_print(LOG_INFO, SECTION_SESSION_DEFAULT, "%s: Sending resolve_slist (%p) to curl",
        funcname, node_status.resolve_slist);
    curl_easy_setopt(session, CURLOPT_RESOLVE, node_status.resolve_slist);
    curl_easy_setopt(session, CURLOPT_DEBUGFUNCTION, session_debug);
    curl_easy_setopt(session, CURLOPT_VERBOSE, 1L);

    escaped_path = escape_except_slashes(session, path);
    if (escaped_path == NULL) {
        log_print(LOG_CRIT, SECTION_SESSION_DEFAULT, "%s: Allocation failed in escape_except_slashes.", funcname);
        return NULL;
    }

    if (query_string == NULL) {
        asprintf(&full_url, "%s%s", get_base_url(), escaped_path);
    }
    else {
        asprintf(&full_url, "%s%s?%s", get_base_url(), escaped_path, query_string);
    }
    if (full_url == NULL) {
        log_print(LOG_CRIT, SECTION_SESSION_DEFAULT, "%s: Allocation failed in asprintf.", funcname);
        return NULL;
    }
    curl_free(escaped_path);
    curl_easy_setopt(session, CURLOPT_URL, full_url);
    log_print(LOG_INFO, SECTION_SESSION_DEFAULT, "%s: Initialized request to URL: %s", funcname, full_url);
    free(full_url);

    if (ca_certificate != NULL)
        curl_easy_setopt(session, CURLOPT_CAINFO, ca_certificate);
    if (client_certificate != NULL) {
        curl_easy_setopt(session, CURLOPT_SSLCERT, client_certificate);
        curl_easy_setopt(session, CURLOPT_SSLKEY, client_certificate);
    }
    curl_easy_setopt(session, CURLOPT_SSL_VERIFYHOST, 0);
    curl_easy_setopt(session, CURLOPT_SSL_VERIFYPEER, 1);
    curl_easy_setopt(session, CURLOPT_FOLLOWLOCATION, 1);
    curl_easy_setopt(session, CURLOPT_CONNECTTIMEOUT_MS, 1200);
    curl_easy_setopt(session, CURLOPT_TIMEOUT, 60);
    curl_easy_setopt(session, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
    curl_easy_setopt(session, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);

    return session;
}
void LLFloaterMessageLog::conditionalLog(LogPayload entry)
{	
	if(!mMessageLogFilterApply)
		childSetText("log_status_text", llformat("Showing %d messages of %d", mFloaterMessageLogItems.size(), mMessagesLogged));

	FloaterMessageItem item = new LLEasyMessageLogEntry(entry, mEasyMessageReader);


	std::set<std::string>::const_iterator end_msg_name = item->mNames.end();
	std::set<std::string>::iterator iter_msg_name = item->mNames.begin();

	bool have_positive = false;

	for(; iter_msg_name != end_msg_name; ++iter_msg_name)
	{
		std::string find_name = *iter_msg_name;
		LLStringUtil::toLower(find_name);

		//keep the message if we allowed its name so long as one of its other names hasn't been blacklisted
		if(!have_positive && !mMessageLogFilter.mPositiveNames.empty())
		{
			if(std::find(mMessageLogFilter.mPositiveNames.begin(), mMessageLogFilter.mPositiveNames.end(), find_name) != mMessageLogFilter.mPositiveNames.end())
				have_positive = true;
		}
		if(!mMessageLogFilter.mNegativeNames.empty())
		{
			if(std::find(mMessageLogFilter.mNegativeNames.begin(), mMessageLogFilter.mNegativeNames.end(), find_name) != mMessageLogFilter.mNegativeNames.end())
			{
				delete item;
			return;
			}
		}
		//we don't have any negative filters and we have a positive match
		else if(have_positive)
			break;
	}

	//we had a positive filter but no positive matches
	if(!mMessageLogFilter.mPositiveNames.empty() && !have_positive)
	{
		delete item;
		return;
	}

	mFloaterMessageLogItems.push_back(item); // moved from beginning...

	if(item->mType == LLEasyMessageLogEntry::HTTP_REQUEST)
	{
		mIncompleteHTTPConvos.insert(HTTPConvoMap::value_type(item->mRequestID, item));
	}

	std::string net_name("\?\?\?");
	BOOL outgoing = item->isOutgoing();
	switch(item->mType)
	{
	case LLEasyMessageLogEntry::TEMPLATE:
		{
			LLHost find_host = outgoing ? item->mToHost : item->mFromHost;
			net_name = find_host.getIPandPort();
			std::list<LLNetListItem*>::iterator end = sNetListItems.end();
			for(std::list<LLNetListItem*>::iterator iter = sNetListItems.begin(); iter != end; ++iter)
			{
				if((*iter)->mCircuitData->getHost() == find_host)
				{
					net_name = (*iter)->mName;
					break;
				}
			}
		}
		break;
	case LLEasyMessageLogEntry::HTTP_REQUEST:
		{
			std::string url = get_base_url(item->mURL);
			std::list<LLNetListItem*>::iterator end = sNetListItems.end();
			for(std::list<LLNetListItem*>::iterator iter = sNetListItems.begin(); iter != end; ++iter)
			{
				LLViewerRegion* regionp = LLWorld::getInstance()->getRegionFromHandle((*iter)->mHandle); //TODO: Find a better way to do this.
				if(regionp && regionp->getCapURLNames(url).size())
				{
					net_name = (*iter)->mName;
					break;
				}
			}
		}
		break;
	default:
		break;
	}
	//add the message to the messagelog scroller
	LLSD element;
	element["id"] = item->mID;
	LLSD& sequence_column = element["columns"][0];
	sequence_column["column"] = "sequence";
	sequence_column["value"] = llformat("%u", item->mSequenceID);

	LLSD& type_column = element["columns"][1];
	type_column["column"] = "type";
	switch(item->mType)
	{
	case LLEasyMessageLogEntry::TEMPLATE:
		type_column["value"] = "UDP";
		break;
	case LLEasyMessageLogEntry::HTTP_REQUEST:
		type_column["value"] = "HTTP";
		break;
	default:
		type_column["value"] = "\?\?\?";
	}

	LLSD& direction_column = element["columns"][2];
	direction_column["column"] = "direction";
	if(item->mType == LLEasyMessageLogEntry::TEMPLATE)
		direction_column["value"] = outgoing ? "to" : "from";
	else if(item->mType == LLEasyMessageLogEntry::HTTP_REQUEST)
		direction_column["value"] = "both";

	LLSD& net_column = element["columns"][3];
	net_column["column"] = "net";
	net_column["value"] = net_name;

	LLSD& name_column = element["columns"][4];
	name_column["column"] = "name";
	name_column["value"] = item->getName();

	LLSD& summary_column = element["columns"][5];
	summary_column["column"] = "summary";
	summary_column["value"] = item->mSummary;
	LLScrollListCtrl* scrollp = getChild<LLScrollListCtrl>("message_log");

	S32 scroll_pos = scrollp->getScrollPos();
	scrollp->addElement(element, ADD_BOTTOM);

	if(scroll_pos > scrollp->getItemCount() - scrollp->getPageLines() - 4)
		scrollp->setScrollPos(scrollp->getItemCount());
}