⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bb_http.c

📁 The Kannel Open Source WAP and SMS gateway works as both an SMS gateway, for implementing keyword b
💻 C
📖 第 1 页 / 共 2 页
字号:
/* ====================================================================  * The Kannel Software License, Version 1.0  *  * Copyright (c) 2001-2004 Kannel Group   * Copyright (c) 1998-2001 WapIT Ltd.    * All rights reserved.  *  * Redistribution and use in source and binary forms, with or without  * modification, are permitted provided that the following conditions  * are met:  *  * 1. Redistributions of source code must retain the above copyright  *    notice, this list of conditions and the following disclaimer.  *  * 2. Redistributions in binary form must reproduce the above copyright  *    notice, this list of conditions and the following disclaimer in  *    the documentation and/or other materials provided with the  *    distribution.  *  * 3. The end-user documentation included with the redistribution,  *    if any, must include the following acknowledgment:  *       "This product includes software developed by the  *        Kannel Group (http://www.kannel.org/)."  *    Alternately, this acknowledgment may appear in the software itself,  *    if and wherever such third-party acknowledgments normally appear.  *  * 4. The names "Kannel" and "Kannel Group" must not be used to  *    endorse or promote products derived from this software without  *    prior written permission. For written permission, please   *    contact org@kannel.org.  *  * 5. Products derived from this software may not be called "Kannel",  *    nor may "Kannel" appear in their name, without prior written  *    permission of the Kannel Group.  *  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE  * DISCLAIMED.  IN NO EVENT SHALL THE KANNEL GROUP OR ITS CONTRIBUTORS  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,   * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT   * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR   * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,   * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE   * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,   * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  * ====================================================================  *  * This software consists of voluntary contributions made by many  * individuals on behalf of the Kannel Group.  For more information on   * the Kannel Group, please see <http://www.kannel.org/>.  *  * Portions of this software are based upon software originally written at   * WapIT Ltd., Helsinki, Finland for the Kannel project.   */ /* * bb_http.c : bearerbox http adminstration commands * * NOTE: this is a special bearerbox module - it does call *   functions from core module! (other modules are fully *    encapsulated, and only called outside) * * Kalle Marjola <rpr@wapit.com> 2000 for project Kannel */#include <errno.h>#include <signal.h>#include <unistd.h>#include "gwlib/gwlib.h"#include "bearerbox.h"/* passed from bearerbox core */extern volatile sig_atomic_t bb_status;/* our own thingies */static volatile sig_atomic_t httpadmin_running;static long	ha_port;static Octstr *ha_interface;static Octstr *ha_password;static Octstr *ha_status_pw;static Octstr *ha_allow_ip;static Octstr *ha_deny_ip;/*--------------------------------------------------------- * static functions *//* * check if the password matches. Return NULL if * it does (or is not required) */static Octstr *httpd_check_authorization(List *cgivars, int status){    Octstr *password;    static double sleep = 0.01;    password = http_cgi_variable(cgivars, "password");    if (status) {	if (ha_status_pw == NULL)	    return NULL;	if (password == NULL)	    goto denied;	if (octstr_compare(password, ha_password)!=0	    && octstr_compare(password, ha_status_pw)!=0)	    goto denied;    }    else {	if (password == NULL || octstr_compare(password, ha_password)!=0)	    goto denied;    }    sleep = 0.0;    return NULL;	/* allowed */denied:    gwthread_sleep(sleep);    sleep += 1.0;		/* little protection against brute force				 * password cracking */    return octstr_create("Denied");}/* * check if we still have time to do things */static Octstr *httpd_check_status(void){    if (bb_status == BB_SHUTDOWN || bb_status == BB_DEAD)	return octstr_create("Avalanche has already started, too late to "	    	    	     "save the sheeps");    return NULL;}    static Octstr *httpd_status(List *cgivars, int status_type){    Octstr *reply;    if ((reply = httpd_check_authorization(cgivars, 1))!= NULL) return reply;    return bb_print_status(status_type);}static Octstr *httpd_store_status(List *cgivars, int status_type){    Octstr *reply;    if ((reply = httpd_check_authorization(cgivars, 1))!= NULL) return reply;    return store_status(status_type);}static Octstr *httpd_loglevel(List *cgivars, int status_type){    Octstr *reply;    Octstr *level;    int new_loglevel;        if ((reply = httpd_check_authorization(cgivars, 0))!= NULL) return reply;    if ((reply = httpd_check_status())!= NULL) return reply;     /* check if new loglevel is given */    level = http_cgi_variable(cgivars, "level");    if (level) {        new_loglevel = atoi(octstr_get_cstr(level));        log_set_log_level(new_loglevel);        return octstr_format("log-level set to %d", new_loglevel);    }    else {        return octstr_create("New level not given");    }}static Octstr *httpd_shutdown(List *cgivars, int status_type){    Octstr *reply;    if ((reply = httpd_check_authorization(cgivars, 0))!= NULL) return reply;    if (bb_status == BB_SHUTDOWN)	bb_status = BB_DEAD;    else {	bb_shutdown();        gwthread_wakeup(MAIN_THREAD_ID);    }    return octstr_create("Bringing system down");}static Octstr *httpd_isolate(List *cgivars, int status_type){    Octstr *reply;    if ((reply = httpd_check_authorization(cgivars, 0))!= NULL) return reply;    if ((reply = httpd_check_status())!= NULL) return reply;    if (bb_isolate() == -1)	return octstr_create("Already isolated");    else	return octstr_create(GW_NAME " isolated from message providers");}static Octstr *httpd_suspend(List *cgivars, int status_type){    Octstr *reply;    if ((reply = httpd_check_authorization(cgivars, 0))!= NULL) return reply;    if ((reply = httpd_check_status())!= NULL) return reply;    if (bb_suspend() == -1)	return octstr_create("Already suspended");    else	return octstr_create(GW_NAME " suspended");}static Octstr *httpd_resume(List *cgivars, int status_type){    Octstr *reply;    if ((reply = httpd_check_authorization(cgivars, 0))!= NULL) return reply;    if ((reply = httpd_check_status())!= NULL) return reply;     if (bb_resume() == -1)	return octstr_create("Already running");    else	return octstr_create("Running resumed");}static Octstr *httpd_restart(List *cgivars, int status_type){    Octstr *reply;    if ((reply = httpd_check_authorization(cgivars, 0))!= NULL) return reply;    if ((reply = httpd_check_status())!= NULL) return reply;     if (bb_status == BB_SHUTDOWN) {        bb_status = BB_DEAD;        gwthread_wakeup_all();        return octstr_create("Trying harder to restart");    }    bb_restart();    return octstr_create("Restarting.....");}static Octstr *httpd_flush_dlr(List *cgivars, int status_type){    Octstr *reply;    if ((reply = httpd_check_authorization(cgivars, 0))!= NULL) return reply;    if ((reply = httpd_check_status())!= NULL) return reply;    if (bb_flush_dlr() == -1)	return octstr_create("Suspend " GW_NAME " before trying to flush DLR queue");    else	return octstr_create("DLR queue flushed");}static Octstr *httpd_stop_smsc(List *cgivars, int status_type){    Octstr *reply;    Octstr *smsc;    if ((reply = httpd_check_authorization(cgivars, 0))!= NULL) return reply;    if ((reply = httpd_check_status())!= NULL) return reply;    /* check if the smsc id is given */    smsc = http_cgi_variable(cgivars, "smsc");    if (smsc) {        if (bb_stop_smsc(smsc) == -1)            return octstr_format("Could not shut down smsc-id `%s'", octstr_get_cstr(smsc));        else            return octstr_format("SMSC `%s' shut down", octstr_get_cstr(smsc));    } else

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -