Exemplo n.º 1
0
Octstr *bb_print_status(int status_type)
{
    char *s, *lb;
    char *frmt, *footer;
    Octstr *ret, *str, *version;
    time_t t;

    if ((lb = bb_status_linebreak(status_type)) == NULL)
        return octstr_create("Un-supported format");

    t = time(NULL) - start_time;
    
    if (bb_status == BB_RUNNING)
        s = "running";
    else if (bb_status == BB_ISOLATED)
        s = "isolated";
    else if (bb_status == BB_SUSPENDED)
        s = "suspended";
    else if (bb_status == BB_FULL)
        s = "filled";
    else
        s = "going down";

    version = version_report_string("bearerbox");

    if (status_type == BBSTATUS_HTML) {
        frmt = "%s</p>\n\n"
               " <p>Status: %s, uptime %ldd %ldh %ldm %lds</p>\n\n"
               " <p>WDP: received %ld (%ld queued), sent %ld "
               "(%ld queued)</p>\n\n"
               " <p>SMS: received %ld (%ld queued), sent %ld "
               "(%ld queued), store size %ld<br>\n"
               " SMS: inbound (%.2f,%.2f,%.2f) msg/sec, "
               "outbound (%.2f,%.2f,%.2f) msg/sec</p>\n\n"
               " <p>DLR: received %ld, sent %ld<br>\n"
               " DLR: inbound (%.2f,%.2f,%.2f) msg/sec, outbound (%.2f,%.2f,%.2f) msg/sec<br>\n"
               " DLR: %ld queued, using %s storage</p>\n\n";
        footer = "<p>";
    } else if (status_type == BBSTATUS_WML) {
        frmt = "%s</p>\n\n"
               "   <p>Status: %s, uptime %ldd %ldh %ldm %lds</p>\n\n"
               "   <p>WDP: received %ld (%ld queued)<br/>\n"
               "      WDP: sent %ld (%ld queued)</p>\n\n"
               "   <p>SMS: received %ld (%ld queued)<br/>\n"
               "      SMS: sent %ld (%ld queued)<br/>\n"
               "      SMS: store size %ld<br/>\n"
               "      SMS: inbound (%.2f,%.2f,%.2f) msg/sec<br/>\n"
               "      SMS: outbound (%.2f,%.2f,%.2f) msg/sec</p>\n"
               "   <p>DLR: received %ld<br/>\n"
               "      DLR: sent %ld<br/>\n"
               "      DLR: inbound (%.2f,%.2f,%.2f) msg/sec<br/>\n"
               "      DLR: outbound (%.2f,%.2f,%.2f) msg/sec<br/>\n"
               "      DLR: %ld queued<br/>\n"
               "      DLR: using %s storage</p>\n\n";
        footer = "<p>";
    } else if (status_type == BBSTATUS_XML) {
        frmt = "<version>%s</version>\n"
               "<status>%s, uptime %ldd %ldh %ldm %lds</status>\n"
               "\t<wdp>\n\t\t<received><total>%ld</total><queued>%ld</queued>"
               "</received>\n\t\t<sent><total>%ld</total><queued>%ld</queued>"
               "</sent>\n\t</wdp>\n"
               "\t<sms>\n\t\t<received><total>%ld</total><queued>%ld</queued>"
               "</received>\n\t\t<sent><total>%ld</total><queued>%ld</queued>"
               "</sent>\n\t\t<storesize>%ld</storesize>\n\t\t"
               "<inbound>%.2f,%.2f,%.2f</inbound>\n\t\t"
               "<outbound>%.2f,%.2f,%.2f</outbound>\n\t\t"
               "</sms>\n"
               "\t<dlr>\n\t\t<received><total>%ld</total></received>\n\t\t"
               "<sent><total>%ld</total></sent>\n\t\t"
               "<inbound>%.2f,%.2f,%.2f</inbound>\n\t\t"
               "<outbound>%.2f,%.2f,%.2f</outbound>\n\t\t"
               "<queued>%ld</queued>\n\t\t<storage>%s</storage>\n\t</dlr>\n";
        footer = "";
    } else {
        frmt = "%s\n\nStatus: %s, uptime %ldd %ldh %ldm %lds\n\n"
               "WDP: received %ld (%ld queued), sent %ld (%ld queued)\n\n"
               "SMS: received %ld (%ld queued), sent %ld (%ld queued), store size %ld\n"
               "SMS: inbound (%.2f,%.2f,%.2f) msg/sec, "
               "outbound (%.2f,%.2f,%.2f) msg/sec\n\n"
               "DLR: received %ld, sent %ld\n"
               "DLR: inbound (%.2f,%.2f,%.2f) msg/sec, outbound (%.2f,%.2f,%.2f) msg/sec\n"
               "DLR: %ld queued, using %s storage\n\n";
        footer = "";
    }
    
    ret = octstr_format(frmt,
        octstr_get_cstr(version),
        s, t/3600/24, t/3600%24, t/60%60, t%60,
        counter_value(incoming_wdp_counter),
        gwlist_len(incoming_wdp) + boxc_incoming_wdp_queue(),
        counter_value(outgoing_wdp_counter), gwlist_len(outgoing_wdp) + udp_outgoing_queue(),
        counter_value(incoming_sms_counter), gwlist_len(incoming_sms),
        counter_value(outgoing_sms_counter), gwlist_len(outgoing_sms),
        store_messages(),
        load_get(incoming_sms_load,0), load_get(incoming_sms_load,1), load_get(incoming_sms_load,2),
        load_get(outgoing_sms_load,0), load_get(outgoing_sms_load,1), load_get(outgoing_sms_load,2),
        counter_value(incoming_dlr_counter), counter_value(outgoing_dlr_counter),
        load_get(incoming_dlr_load,0), load_get(incoming_dlr_load,1), load_get(incoming_dlr_load,2),
        load_get(outgoing_dlr_load,0), load_get(outgoing_dlr_load,1), load_get(outgoing_dlr_load,2),
        dlr_messages(), dlr_type());

    octstr_destroy(version);
    
    append_status(ret, str, boxc_status, status_type);
    append_status(ret, str, smsc2_status, status_type);
    octstr_append_cstr(ret, footer);
    
    return ret;
}
Exemplo n.º 2
0
static void httpd_serve(HTTPClient *client, Octstr *ourl, List *headers,
    	    	    	Octstr *body, List *cgivars)
{
    Octstr *reply, *final_reply, *url;
    char *content_type;
    char *header, *footer;
    int status_type;
    int i;
    long pos;

    reply = final_reply = NULL; /* for compiler please */
    url = octstr_duplicate(ourl);

    /* Set default reply format according to client
     * Accept: header */
    if (http_type_accepted(headers, "text/vnd.wap.wml")) {
	status_type = BBSTATUS_WML;
	content_type = "text/vnd.wap.wml";
    }
    else if (http_type_accepted(headers, "text/html")) {
	status_type = BBSTATUS_HTML;
	content_type = "text/html";
    }
    else if (http_type_accepted(headers, "text/xml")) {
	status_type = BBSTATUS_XML;
	content_type = "text/xml";
    } else {
	status_type = BBSTATUS_TEXT;
	content_type = "text/plain";
    }

    /* kill '/cgi-bin' prefix */
    pos = octstr_search(url, octstr_imm("/cgi-bin/"), 0);
    if (pos != -1)
        octstr_delete(url, pos, 9);
    else if (octstr_get_char(url, 0) == '/')
        octstr_delete(url, 0, 1);

    /* look for type and kill it */
    pos = octstr_search_char(url, '.', 0);
    if (pos != -1) {
        Octstr *tmp = octstr_copy(url, pos+1, octstr_len(url) - pos - 1);
        octstr_delete(url, pos, octstr_len(url) - pos);

        if (octstr_str_compare(tmp, "txt") == 0)
            status_type = BBSTATUS_TEXT;
        else if (octstr_str_compare(tmp, "html") == 0)
            status_type = BBSTATUS_HTML;
        else if (octstr_str_compare(tmp, "xml") == 0)
            status_type = BBSTATUS_XML;
        else if (octstr_str_compare(tmp, "wml") == 0)
            status_type = BBSTATUS_WML;

        octstr_destroy(tmp);
    }

    for (i=0; httpd_commands[i].command != NULL; i++) {
        if (octstr_str_compare(url, httpd_commands[i].command) == 0) {
            reply = httpd_commands[i].function(cgivars, status_type);
            break;
        }
    }

    /* check if command found */
    if (httpd_commands[i].command == NULL) {
        char *lb = bb_status_linebreak(status_type);
	reply = octstr_format("Unknown command `%S'.%sPossible commands are:%s",
            ourl, lb, lb);
        for (i=0; httpd_commands[i].command != NULL; i++)
            octstr_format_append(reply, "%s%s", httpd_commands[i].command, lb);
    }

    gw_assert(reply != NULL);

    if (status_type == BBSTATUS_HTML) {
	header = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\">\n"
 	    "<html>\n<title>" GW_NAME "</title>\n<body>\n<p>";
	footer = "</p>\n</body></html>\n";
	content_type = "text/html";
    } else if (status_type == BBSTATUS_WML) {
	header = "<?xml version=\"1.0\"?>\n"
            "<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.1//EN\" "
            "\"http://www.wapforum.org/DTD/wml_1.1.xml\">\n"
            "\n<wml>\n <card>\n  <p>";
	footer = "  </p>\n </card>\n</wml>\n";
	content_type = "text/vnd.wap.wml";
    } else if (status_type == BBSTATUS_XML) {
	header = "<?xml version=\"1.0\"?>\n"
            "<gateway>\n";
        footer = "</gateway>\n";
    } else {
	header = "";
	footer = "";
	content_type = "text/plain";
    }
    final_reply = octstr_create(header);
    octstr_append(final_reply, reply);
    octstr_append_cstr(final_reply, footer);
    
    /* debug("bb.http", 0, "Result: '%s'", octstr_get_cstr(final_reply));
     */
    http_destroy_headers(headers);
    headers = list_create();
    http_header_add(headers, "Content-Type", content_type);

    http_send_reply(client, HTTP_OK, headers, final_reply);

    octstr_destroy(url);
    octstr_destroy(ourl);
    octstr_destroy(body);
    octstr_destroy(reply);
    octstr_destroy(final_reply);
    http_destroy_headers(headers);
    http_destroy_cgiargs(cgivars);
}
Exemplo n.º 3
0
Octstr *boxc_status(int status_type)
{
    Octstr *tmp;
    char *lb, *ws;
    int i, boxes, para = 0;
    time_t orig, t;
    Boxc *bi;

    orig = time(NULL);

    /*
     * XXX: this will cause segmentation fault if this is called
     *    between 'destroy_list and setting list to NULL calls.
     *    Ok, this has to be fixed, but now I am too tired.
     */
    
    if ((lb = bb_status_linebreak(status_type))==NULL)
	    return octstr_create("Un-supported format");

    if (status_type == BBSTATUS_HTML)
	    ws = "&nbsp;&nbsp;&nbsp;&nbsp;";
    else if (status_type == BBSTATUS_TEXT)
	    ws = "    ";
    else
	    ws = "";

    if (status_type == BBSTATUS_HTML || status_type == BBSTATUS_WML)
	    para = 1;
    
    if (status_type == BBSTATUS_XML) {
        tmp = octstr_create ("");
        octstr_append_cstr(tmp, "<boxes>\n\t");
    }
    else
        tmp = octstr_format("%sBox connections:%s", para ? "<p>" : "", lb);
    boxes = 0;
    
    if (wapbox_list) {
	    gwlist_lock(wapbox_list);
	    for(i=0; i < gwlist_len(wapbox_list); i++) {
	        bi = gwlist_get(wapbox_list, i);
	        if (bi->alive == 0)
		        continue;
	        t = orig - bi->connect_time;
            if (status_type == BBSTATUS_XML)
	            octstr_format_append(tmp,
		        "<box>\n\t\t<type>wapbox</type>\n\t\t<IP>%s</IP>\n"
                "\t\t<status>on-line %ldd %ldh %ldm %lds</status>\n"
                "\t\t<ssl>%s</ssl>\n\t</box>\n",
				octstr_get_cstr(bi->client_ip),
				t/3600/24, t/3600%24, t/60%60, t%60,
#ifdef HAVE_LIBSSL
                conn_get_ssl(bi->conn) != NULL ? "yes" : "no"
#else 
                "not installed"
#endif
                );
            else
	            octstr_format_append(tmp,
		        "%swapbox, IP %s (on-line %ldd %ldh %ldm %lds) %s %s",
				ws, octstr_get_cstr(bi->client_ip),
				t/3600/24, t/3600%24, t/60%60, t%60, 
#ifdef HAVE_LIBSSL
                conn_get_ssl(bi->conn) != NULL ? "using SSL" : "",
#else
                "",
#endif 
                lb);
	            boxes++;
	       }
	       gwlist_unlock(wapbox_list);
        }
        if (smsbox_list) {
            gw_rwlock_rdlock(smsbox_list_rwlock);
	    for(i=0; i < gwlist_len(smsbox_list); i++) {
	        bi = gwlist_get(smsbox_list, i);
	        if (bi->alive == 0)
		        continue;
	        t = orig - bi->connect_time;
            if (status_type == BBSTATUS_XML)
	            octstr_format_append(tmp, "<box>\n\t\t<type>smsbox</type>\n"
                    "\t\t<id>%s</id>\n\t\t<IP>%s</IP>\n"
                    "\t\t<queue>%ld</queue>\n"
                    "\t\t<status>on-line %ldd %ldh %ldm %lds</status>\n"
                    "\t\t<ssl>%s</ssl>\n\t</box>",
                    (bi->boxc_id ? octstr_get_cstr(bi->boxc_id) : ""),
		            octstr_get_cstr(bi->client_ip),
		            gwlist_len(bi->incoming) + dict_key_count(bi->sent),
		            t/3600/24, t/3600%24, t/60%60, t%60,
#ifdef HAVE_LIBSSL
                    conn_get_ssl(bi->conn) != NULL ? "yes" : "no"
#else 
                    "not installed"
#endif
                    );
            else
                octstr_format_append(tmp, "%ssmsbox:%s, IP %s (%ld queued), (on-line %ldd %ldh %ldm %lds) %s %s",
                    ws, (bi->boxc_id ? octstr_get_cstr(bi->boxc_id) : "(none)"), 
                    octstr_get_cstr(bi->client_ip), gwlist_len(bi->incoming) + dict_key_count(bi->sent),
		            t/3600/24, t/3600%24, t/60%60, t%60, 
#ifdef HAVE_LIBSSL
                    conn_get_ssl(bi->conn) != NULL ? "using SSL" : "",
#else
                    "",
#endif 
                    lb);
	       boxes++;
	    }
	    gw_rwlock_unlock(smsbox_list_rwlock);
    }
    if (boxes == 0 && status_type != BBSTATUS_XML) {
	    octstr_destroy(tmp);
	    tmp = octstr_format("%sNo boxes connected", para ? "<p>" : "");
    }
    if (para)
	    octstr_append_cstr(tmp, "</p>");
    if (status_type == BBSTATUS_XML)
        octstr_append_cstr(tmp, "</boxes>\n");
    else
        octstr_append_cstr(tmp, "\n\n");
    return tmp;
}