Exemplo n.º 1
0
int main()
{
    CGI *cgi;
    NEOERR *err;
    int ret;

    //sleep(20);
    mtc_init(TC_ROOT"login");
    mconfig_parse_file(SITE_CONFIG, &g_cfg);

    err = cgi_init(&cgi, NULL);
    DIE_NOK_CGI(err);
    err = cgi_parse(cgi);
    DIE_NOK_CGI(err);

    mdb_conn *conn = NULL;
    ret = mdb_init(&conn, DB_DSN);
    mdb_opfinish_json(ret, cgi->hdf, conn);

    ret = login_get(cgi, conn);
    mdb_opfinish_json(ret, cgi->hdf, conn);
    mjson_output_hdf(cgi->hdf, 0);
    
#ifdef DEBUG_HDF
    hdf_write_file(cgi->hdf, TC_ROOT"hdf.login");
#endif

    mdb_destroy(conn);
    cgi_destroy(&cgi);
    return 0;
}
Exemplo n.º 2
0
static void p_cgi_dealloc (CGIObject *ho)
{
  if (ho->cgi)
  {
    cgi_destroy (&(ho->cgi));
  }
  Py_XDECREF(ho->hdf);
  PyObject_DEL(ho);
}
Exemplo n.º 3
0
CGI::~CGI()
{
    for (std::list<Filter *>::iterator p = _filters.begin(); p != _filters.end(); ++p) {
        delete *p;
    }

    void **cgiptr = &_cgi_handle;
    ::CGI * &cgi = *reinterpret_cast< ::CGI **>(cgiptr);
    cgi_destroy(&cgi);
}
Exemplo n.º 4
0
int main(int argc, char **argv, char **envp)
{
	CGI *cgi = NULL;
	NEOERR *err;
	mdb_conn *conn = NULL;

	char *s, *u, *p, *r, *jcbk;

	mtc_init("test");
	mconfig_parse_file(SITE_CONFIG, &g_cfg);

	if (mdb_init(&conn, DB_DSN) != MDB_ERR_NONE) {
		mtc_err("init db error %s", mdb_get_errmsg(conn));
		printf("Content-Type: text/html; charset=UTF-8\r\n\r\n");
		printf("{errcode: %d}", SAM_ERR_INIT);
		return 1;
	}
	
	err = cgi_init(&cgi, NULL);
	if (err != STATUS_OK) {
		mtc_err("init cgi error");
		printf("Content-Type: text/html; charset=UTF-8\r\n\r\n");
		printf("初始化错误");
		return 1;
	}
	err = cgi_parse(cgi);
	if (err != STATUS_OK) {
		mtc_err("parse cgi error");
		hdf_set_value(cgi->hdf, PRE_OUTPUT".errmsg", "初始化出错");
		goto finish;
	}

	u = hdf_get_value(cgi->hdf, PRE_COOKIE".samuser", NULL);
	s = hdf_get_value(cgi->hdf, PRE_COOKIE".samkey", NULL);
	if (s && u) {
		if (user_has_login(conn, u, s)) {
			hdf_set_copy(cgi->hdf, PRE_OUTPUT".samuser", PRE_COOKIE".samuser");
			hdf_set_copy(cgi->hdf, PRE_OUTPUT".samkey", PRE_COOKIE".samkey");
			hdf_set_value(cgi->hdf, PRE_OUTPUT".rcode", "1");
			goto finish;
		}
	}

	hdf_set_value(cgi->hdf, PRE_OUTPUT".rcode", "2");

finish:
	cgi_display(cgi, F_TPL_TEST);
	cgi_destroy(&cgi);
	mdb_destroy(conn);
	return 0;
}
Exemplo n.º 5
0
Arquivo: viki.c Projeto: kingiol/cmoon
int main(int argc, char **argv, char **envp)
{
    CGI *cgi;
    NEOERR *err;
    int ret;

    HASH *dbh;
    HASH *tplh;
    session_t *session = NULL;
    char *requri, *jsoncb;

    int (*data_handler)(CGI *cgi, HASH *dbh, session_t *session);
    void *lib;

    //sleep(20);
    mconfig_parse_file(SITE_CONFIG, &g_cfg);
    mtc_init(TC_ROOT"viki");

    ret = ltpl_init(&tplh);
    if (ret != RET_RBTOP_OK) {
        mtc_err("init templates error");
        mutil_redirect("初始化模板失败", TGT_SELF, URL_CLOSE, true);
        return ret;
    }

    ret = ldb_init(&dbh);
    if (ret != RET_RBTOP_OK) {
        mtc_err("init db error");
        mutil_redirect("初始化数据库失败", TGT_SELF, URL_CLOSE, true);
        return ret;
    }

    lib = dlopen(NULL, RTLD_NOW|RTLD_GLOBAL);
    if (lib == NULL) {
        mtc_err("possible? %s", dlerror());
        mutil_redirect("初始化库函数失败", TGT_SELF, URL_CLOSE, true);
        return 1;
    }
    
#ifndef DROP_FCGI
    cgiwrap_init_emu(NULL, &read_cb, &printf_cb, &write_cb, NULL, NULL, NULL);
    while (FCGI_Accept() >= 0) {
#endif
        cgiwrap_init_std(argc, argv, environ);
        err = cgi_init(&cgi, NULL);
        JUMP_NOK_CGI(err, response);
        err = cgi_parse(cgi);
        JUMP_NOK_CGI(err, response);

#ifdef NCGI_MODE
        hdf_set_value(cgi->hdf, PRE_REQ_URI_RW, "/csc/hc");
        hdf_set_value(cgi->hdf, PRE_COOKIE".uin", "1001");
        hdf_set_value(cgi->hdf, PRE_COOKIE".uname", "bigml");
        hdf_set_value(cgi->hdf, PRE_COOKIE".musn", "8Y]u0|v=*MS]U3J");
#endif
        
        ret = session_init(cgi->hdf, dbh, &session);
        if (ret != RET_RBTOP_OK) {
            mtc_err("init session failure");
            goto response;
        }

        requri = hdf_get_value(cgi->hdf, PRE_REQ_URI_RW, "NULL");
        if (mutil_client_attack(cgi->hdf, requri, LMT_CLI_ATTACK,
                                PERIOD_CLI_ATTACK)) {
            goto response;
        }
        
        ret = lfile_access_rewrited(cgi, dbh, session);
        if (ret != RET_RBTOP_OK) {
            goto response;
        }

        data_handler = lutil_get_data_handler(lib, cgi);
        if (data_handler == NULL) {
            mtc_err("get handler failure");
            ret = RET_RBTOP_NEXIST;
            goto response;
        }

        ret = (*data_handler)(cgi, dbh, session);
        
    response:
        if (cgi != NULL && cgi->hdf != NULL) {
#ifdef DEBUG_HDF
            hdf_write_file(cgi->hdf, TC_ROOT"hdf.viki");
#endif
            switch (CGI_REQ_TYPE(cgi)) {
            case CGI_REQ_HTML:
                if (CGI_REQ_METHOD(cgi) != CGI_REQ_GET) {
                    goto resp_ajax;
                }
                if (ret != RET_RBTOP_OK && ret == RET_RBTOP_NEXIST) {
                    cgi_redirect(cgi, "/404.html");
                } else {
                    ret = ltpl_render(cgi, tplh, session);
                    if (ret != RET_RBTOP_OK) {
                        if (ret == RET_RBTOP_NEXIST)
                            cgi_redirect(cgi, "/404.html");
                        else
                            cgi_redirect(cgi, "/503.html");
                    }
                }
                break;
            case CGI_REQ_AJAX:
            resp_ajax:
                ldb_opfinish_json(ret, cgi->hdf, NULL, 0);
                jsoncb = hdf_get_value(cgi->hdf, PRE_REQ_AJAX_FN, NULL);
                if (jsoncb != NULL) {
                    mjson_execute_hdf(cgi->hdf, jsoncb, session->tm_cache_browser);
                } else {
                    mjson_output_hdf(cgi->hdf, session->tm_cache_browser);
                }
                break;
            default:
                cgi_redirect(cgi, "/503.html");
                break;
            }
            cgi_destroy(&cgi);
            session_destroy(&session);
        }
#ifndef DROP_FCGI
    }
#endif

    ldb_destroy(dbh);
    ltpl_destroy(tplh);
    mconfig_cleanup(&g_cfg);
    return 0;
}
Exemplo n.º 6
0
int main(int argc, char **argv, char **envp)
{
	CGI *cgi = NULL;
	NEOERR *err;
	mdb_conn *conn = NULL;

	/* skey, user, pass, return jsoncallback*/
	char *s, *u, *p, *r, *jcbk;
	/* keeptime(hours)  */
	int t;
	char tm[LEN_TM_GMT];
	
	//sleep(20);
	mtc_init("login");
	mconfig_parse_file(SITE_CONFIG, &g_cfg);
	mutil_wrap_fcgi(argc, argv, envp);
	if (mdb_init(&conn, DB_DSN) != MDB_ERR_NONE) {
		mtc_err("init db error %s", mdb_get_errmsg(conn));
		printf("Content-Type: text/html; charset=UTF-8\r\n\r\n");
		printf("{errcode: %d}", SAM_ERR_INIT);
		return 1;
	}
	
#ifndef DROP_FCGI
	while (FCGI_Accept() >= 0) {
#endif

		/*
		 * cgi init 
		 */
		err = cgi_init(&cgi, NULL);
		if (err != STATUS_OK) {
			mtc_err("init cgi error");
			printf("Content-Type: text/html; charset=UTF-8\r\n\r\n");
			printf("{errcode: %d}", SAM_ERR_INIT);
			goto opfinish;
		}
		err = cgi_parse(cgi);
		if (err != STATUS_OK) {
			mtc_err("parse cgi error");
			hdf_set_int_value(cgi->hdf, PRE_OUTPUT".errcode", SAM_ERR_PARSE);
			goto opfinish;
		}
#if 0
		if (mutil_client_attack_cookie(cgi->hdf, "login", 30, 60)) {
			mtc_err("client attack");
			hdf_set_int_value(cgi->hdf, PRE_OUTPUT".errcode", SAM_ERR_NEEDREST);
			goto opfinish;
		}
#endif

		u = hdf_get_value(cgi->hdf, PRE_COOKIE".samuser", NULL);
		s = hdf_get_value(cgi->hdf, PRE_COOKIE".samkey", NULL);
		if (s && u) {
			if (user_has_login(conn, u, s)) {
				hdf_set_copy(cgi->hdf, PRE_OUTPUT".samuser", PRE_COOKIE".samuser");
				hdf_set_copy(cgi->hdf, PRE_OUTPUT".samkey", PRE_COOKIE".samkey");
				goto done;
			}
		}
		
		u = hdf_get_value(cgi->hdf, PRE_QUERY".u", NULL);
		p = hdf_get_value(cgi->hdf, PRE_QUERY".p", NULL);
		if (!u || !p) {
			mtc_err("parameter miss %s %s", u, p);
			hdf_set_int_value(cgi->hdf, PRE_OUTPUT".errcode", SAM_ERR_NEEDINPUT);
			goto opfinish;
		}
		s = user_login_auth(conn, u, p);
		if (!s) {
			mtc_err("login error %s %s", u, p);
			hdf_set_int_value(cgi->hdf, PRE_OUTPUT".errcode", SAM_ERR_PASSW);
			goto opfinish;
		}

		cgiwrap_write(P3P_HEADER, strlen(P3P_HEADER));
		cgi_cookie_set(cgi, "samuser", u, NULL, SITE_DOMAIN, NULL, 1, 0);
		cgi_cookie_set(cgi, "samkey", s, NULL, SITE_DOMAIN, NULL, 1, 0);
#if 0
		t = hdf_get_int_value(cgi->hdf, PRE_QUERY".t", 0);
		mmisc_getdatetime_gmt(tm, sizeof(tm), "%A, %d-%b-%Y %T GMT", 60*60*t);
		cgi_cookie_set(cgi, "samkey", s, NULL, SITE_DOMAIN, tm, 1, 0);
#endif
		
		hdf_set_value(cgi->hdf, PRE_OUTPUT".samuser", u);
		hdf_set_value(cgi->hdf, PRE_OUTPUT".samkey", s);
		free(s);

	done:
		/*
		 * TODO set samkey, samuser to app's domain
		 * DONE this is done by jsonp
		 */
		hdf_set_value(cgi->hdf, PRE_OUTPUT".success", "1");
	opfinish:
		if (cgi) {
			r = hdf_get_value(cgi->hdf, PRE_QUERY".r", NULL);
			if (r) {
				cgi_redirect(cgi, r);
			} else {
				jcbk = hdf_get_value(cgi->hdf, PRE_QUERY".jsoncallback", NULL);
				if (jcbk != NULL) {
					mjson_execute_hdf(cgi->hdf, jcbk, 0);
				} else {
					mjson_output_hdf(cgi->hdf, 0);
				}
			}
#ifdef DEBUG_HDF
			hdf_write_file(cgi->hdf, HF_LOG_PATH"hdf.login");
#endif
			cgi_destroy(&cgi);
		}
		
#ifndef DROP_FCGI
 	} /* FCGI_Accept() */
#endif

	mdb_destroy(conn);
	return 0;
}
Exemplo n.º 7
0
int main(int argc, char **argv, char **envp)
{
    CGI *cgi;
    NEOERR *err = STATUS_OK;

    HASH *dbh, *tplh, *evth;
    session_t *session = NULL;
    char *temps;
    int http_max_upload;

    NEOERR* (*data_handler)(CGI *cgi, HASH *dbh, HASH *evth, session_t *session);
    void *lib;
    
    //sleep(20);
    mutil_makesure_coredump();
    mtc_init(TC_ROOT"viki");

    err = lerr_init();
    DIE_NOK_CGI(err);
    
    err = mcfg_parse_file(SITE_CONFIG, &g_cfg);
    DIE_NOK_CGI(err);

    err = mtpl_set_tplpath(PATH_TPL);
    DIE_NOK_CGI(err);

    err = mtpl_InConfigRend_init(PATH_TPL"/config/email", "email", &g_datah);
    DIE_NOK_CGI(err);

    err = mtpl_InConfigRend_init(PATH_TPL"/config/inbox", "inbox", &g_datah);
    DIE_NOK_CGI(err);

    err = ltpl_init(&tplh, NULL);
    DIE_NOK_CGI(err);

    err = hash_insert(g_datah, "runtime_templates", (void*)tplh);
    DIE_NOK_CGI(err);

    err = ldb_init(&dbh);
    DIE_NOK_CGI(err);

    err = levt_init(&evth);
    DIE_NOK_CGI(err);

    lib = dlopen(NULL, RTLD_NOW|RTLD_GLOBAL);
    if (!lib) {
        err = nerr_raise(NERR_SYSTEM, "dlopen %s", dlerror());
        DIE_NOK_CGI(err);
    }
    
#ifdef USE_FASTCGI
    cgiwrap_init_emu(NULL, &read_cb, &printf_cb, &write_cb, NULL, NULL, NULL);
    while (FCGI_Accept() >= 0) {
#endif
        cgiwrap_init_std(argc, argv, environ);
        err = cgi_init(&cgi, NULL);
        if (err != STATUS_OK) goto response;
        
        http_max_upload = hdf_get_int_value(g_cfg, PRE_CONFIG".http_max_upload", 0);
        if (http_max_upload > 0) {
            err = mcs_register_upload_parse_cb(cgi, &http_max_upload);
            if (err != STATUS_OK) goto response;
        }
        
        err = cgi_parse(cgi);
        if (err != STATUS_OK) goto response;

#ifdef NCGI_MODE
        hdf_set_value(cgi->hdf, PRE_REQ_URI_RW, "/image/member/pic");
        hdf_set_value(cgi->hdf, PRE_COOKIE".uin", "1001");
        hdf_set_value(cgi->hdf, PRE_COOKIE".uname", "bigml");
        hdf_set_value(cgi->hdf, PRE_COOKIE".musn", "8Y]u0|v=*MS]U3J");
        hdf_set_value(cgi->hdf, PRE_QUERY".ip", "222.247.56.14");
        hdf_set_value(cgi->hdf, PRE_QUERY".to", "cj_BXTSJ");
        hdf_set_value(cgi->hdf, PRE_QUERY".s", "koldddd");
        hdf_set_value(cgi->hdf, PRE_QUERY".JsonCallback", "Ape.transport.read");
        hdf_set_value(cgi->hdf, PRE_QUERY".type", "phone");
        hdf_set_value(cgi->hdf, PRE_QUERY".mid", "485010473");
#endif
        
        err = session_init(cgi, dbh, &session);
        if (err != STATUS_OK) goto response;

        if (lutil_client_attack(cgi->hdf, session, "lcs_uname")) {
            err = nerr_raise(LERR_ATTACK, "%s need a rest, babey!", session->dataer);
            goto response;
        }
        
        if ((data_handler = lutil_get_data_handler(lib, cgi, session)) == NULL) {
            err = nerr_raise(LERR_MISS_DATA, "dataer %s not found", session->dataer);
            goto response;
        }

        err = (*data_handler)(cgi, dbh, evth, session);
        
    response:
        if (cgi != NULL && cgi->hdf != NULL) {
            lerr_opfinish_json(err, cgi->hdf);

            if (!session) session = session_default();
            switch (session->reqtype) {
            case CGI_REQ_HTML:
                err = ltpl_render(cgi, tplh, session);
                if (err != STATUS_OK) {
                    SAFE_FREE(session->render);
                    if (nerr_match(err, LERR_MISS_TPL)) {
                        session->render = strdup("404");
                    } else {
                        session->render = strdup("503");
                    }
                    TRACE_NOK(err);
                    err = ltpl_render(cgi, tplh, session);
                    TRACE_NOK(err);
                }
                break;
            case CGI_REQ_AJAX:
            resp_ajax:
                temps = hdf_get_value(cgi->hdf, PRE_REQ_AJAX_FN, NULL);
                if (temps != NULL) {
                    mjson_execute_hdf(cgi->hdf, temps, session->tm_cache_browser);
                } else {
                    mjson_output_hdf(cgi->hdf, session->tm_cache_browser);
                }
                break;
            case CGI_REQ_IMAGE:
                temps = hdf_get_value(cgi->hdf, PRE_OUTPUT".302", NULL);
                if (temps) {
                    cgi_redirect_uri(cgi, temps);
                } else if (session->data) {
                    mimg_output(session->data);
                    session->data = NULL;
                } else goto resp_ajax;
                break;
            default:
                cgi_redirect(cgi, "/503.html");
                break;
            }
            
#ifdef DEBUG_HDF
            hdf_write_file(cgi->hdf, TC_ROOT"hdf.viki");
#endif
            
            cgi_destroy(&cgi);
            session_destroy(&session);
            cgi = NULL;
            session = NULL;
        }
#ifdef USE_FASTCGI
    }
#endif

    levt_destroy(evth);
    ldb_destroy(dbh);
    ltpl_destroy(tplh);
    mtpl_InConfigRend_destroy(g_datah);
    mcfg_cleanup(&g_cfg);

    return 0;
}
Exemplo n.º 8
0
void ewf_request_end(ewf_request_t *request)
{
	NBU_UNUSED(request);
	
	cgi_destroy(&cgi);
}
Exemplo n.º 9
0
int main(int argc, char **argv, char **envp)
{
	CGI *cgi = NULL;
	NEOERR *err;
	mdb_conn *conn = NULL;

	/* skey, user, pass, return jsoncallback*/
	char *s, *u, *r, *jcbk;
	
	//sleep(20);
	mtc_init("logout");
	mconfig_parse_file(SITE_CONFIG, &g_cfg);
	mutil_wrap_fcgi(argc, argv, envp);
	if (mdb_init(&conn, DB_DSN) != MDB_ERR_NONE) {
		mtc_err("init db error %s", mdb_get_errmsg(conn));
		printf("Content-Type: text/html; charset=UTF-8\r\n\r\n");
		printf("{errcode: %d}", SAM_ERR_INIT);
		return 1;
	}
	
#ifndef DROP_FCGI
	while (FCGI_Accept() >= 0) {
#endif

		/*
		 * cgi init 
		 */
		err = cgi_init(&cgi, NULL);
		if (err != STATUS_OK) {
			mtc_err("init cgi error");
			printf("Content-Type: text/html; charset=UTF-8\r\n\r\n");
			printf("{errcode: %d}", SAM_ERR_INIT);
			goto opfinish;
		}
		err = cgi_parse(cgi);
		if (err != STATUS_OK) {
			mtc_err("parse cgi error");
			hdf_set_int_value(cgi->hdf, PRE_OUTPUT".errcode", SAM_ERR_PARSE);
			goto opfinish;
		}

		u = hdf_get_value(cgi->hdf, PRE_COOKIE".samuser", NULL);
		s = hdf_get_value(cgi->hdf, PRE_COOKIE".samkey", NULL);
		if (s && u) {
			if (user_has_login(conn, u, s)) {
				user_logout(conn, u);
				cgi_cookie_clear(cgi, "samuser", SITE_DOMAIN, NULL);
				cgi_cookie_clear(cgi, "samkey", SITE_DOMAIN, NULL);
				hdf_set_value(cgi->hdf, PRE_OUTPUT".success", "1");
				goto opfinish;
			}
		}
		hdf_set_int_value(cgi->hdf, PRE_OUTPUT".errcode", SAM_ERR_NOTLOGIN);
	opfinish:
		if (cgi) {
			r = hdf_get_value(cgi->hdf, PRE_QUERY".r", NULL);
			if (r) {
				cgi_redirect(cgi, r);
			} else {
				jcbk = hdf_get_value(cgi->hdf, PRE_QUERY".jsoncallback", NULL);
				if (jcbk != NULL) {
					mjson_execute_hdf(cgi->hdf, jcbk, 0);
				} else {
					mjson_output_hdf(cgi->hdf, 0);
				}
			}
#ifdef DEBUG_HDF
			hdf_write_file(cgi->hdf, HF_LOG_PATH"hdf.logout");
#endif
			cgi_destroy(&cgi);
		}
		
#ifndef DROP_FCGI
 	} /* FCGI_Accept() */
#endif

	mdb_destroy(conn);
	return 0;
}
Exemplo n.º 10
0
void api_end( void )
{
    cgi_destroy( &cgi );
}