示例#1
0
文件: globalopt.c 项目: stanxii/hfc
static void reset(HttpConn *conn) {
    char str[16] = {0};
    cchar *role = getSessionVar("role");
    if(role == NULL){
        rendersts(str, 9);
        render(str);
        return;
    }
    if((strcmp(role, "root") !=0) && (strcmp(role, "admin") !=0)){
        rendersts(str, 5);//无权限
        render(str);
        return;
    }

	restoreFactory(tmpip);
	rendersts(str, 1);
	render(str);
	//add optlog
    Edi *db = ediOpen("db/muxnms.mdb", "mdb", EDI_AUTO_SAVE);
    EdiRec *optlog = ediCreateRec(db, "optlog");
    if(optlog == NULL){
       printf("================>>>optlog is NULL!!\n");
       return;
    }
    time_t curTime;
    time(&curTime);
    memset(optstr, 0, 256);
    sprintf(optstr, "{'user': '******', 'desc': '恢复出厂设置.', 'level': '2', 'logtime':'%d'}", getSessionVar("userName"), curTime);
    MprJson  *row = mprParseJson(optstr);
    if(ediSetFields(optlog, row) == 0){
       printf("================>>>ediSetFields Failed!!\n");
    }
    ediUpdateRec(db, optlog);
    //ediClose(db);
}
示例#2
0
EdiRec *espCreateRec(HttpConn *conn, cchar *tableName, MprHash *params)
{
    Edi         *edi;
    EdiRec      *rec;

    edi = espGetDatabase(conn);
    if ((rec = ediCreateRec(edi, tableName)) == 0) {
        return 0;
    }
    ediSetFields(rec, params);
    return espSetRec(conn, rec);
}
示例#3
0
文件: globalopt.c 项目: stanxii/hfc
static void setDevip(HttpConn *conn) {
    char str[16] = {0};
    cchar *role = getSessionVar("role");
    if(role == NULL){
        rendersts(str, 9);
        render(str);
        return;
    }
    if((strcmp(role, "root") !=0) && (strcmp(role, "admin") !=0)){
        rendersts(str, 5);//无权限设置Ip
        render(str);
        return;
    }
	cchar *param = espGetQueryString(conn);

	char newip[16] = {0};
	char newgatway[16] = {0};
	char submask[16] = {0};
	char* ptr = strchr(param, '&');
    int pos = ptr-param;
	substr(param, 0, pos, newip);
	char *ptr1 = strrchr (param, '&');
	int flag = ptr1 - param;
	substr(param, pos + 1, flag, newgatway);
	substr(param, flag + 1, strlen(param), submask);
	unsigned int vip = ntohl( inet_addr( newip ) );
	unsigned int tmpgatway = ntohl( inet_addr( newgatway ) );
	unsigned int tmpsubmask = ntohl( inet_addr( submask ) );
	if(0 == setIp(tmpip, vip)){
		setGateway(tmpip, tmpgatway);
		getSubMask(tmpip, tmpsubmask);
	}
	rendersts(str, 1);
	render(str);
	//add optlog
    Edi *db = ediOpen("db/muxnms.mdb", "mdb", EDI_AUTO_SAVE);
    EdiRec *optlog = ediCreateRec(db, "optlog");
    if(optlog == NULL){
       printf("================>>>optlog is NULL!!\n");
       return;
    }
    time_t curTime;
    time(&curTime);
    memset(optstr, 0, 256);
    sprintf(optstr, "{'user': '******', 'desc': '设备修改IP【IP:%s】.', 'level': '2', 'logtime':'%d'}", getSessionVar("userName"),newip, curTime);
    MprJson  *row = mprParseJson(optstr);
    if(ediSetFields(optlog, row) == 0){
       printf("================>>>ediSetFields Failed!!\n");
    }
    ediUpdateRec(db, optlog);
    //ediClose(db);
}
示例#4
0
文件: globalopt.c 项目: stanxii/hfc
static void setPassword(HttpConn *conn) {
    char str[16] = {0};
    cchar *role = getSessionVar("role");
    if(role == NULL){
        rendersts(str, 9);
        render(str);
        return;
    }
    if((strcmp(role, "root") !=0) && (strcmp(role, "admin") !=0)){
        rendersts(str, 5);//无权限
        render(str);
        return;
    }
    MprJson *jsonparam = mprParseJson(espGetQueryString(conn));
    cchar *oldpassword = mprGetJson(jsonparam, "oldpassword");
    cchar *newpassword = mprGetJson(jsonparam, "newpassword");

    cchar *username = getSessionVar("userName");
    //Edi *db = ediOpen("db/muxnms.mdb", "mdb", EDI_AUTO_SAVE );
    EdiRec *user = readRecWhere("user", "username", "==", username);
    MprJson *userjson = mprParseJson(ediRecAsJson(user, 0));
    //printf("=======password====%s========%s\n", oldpassword, mprGetJson(userjson, "password"));
    if(strcmp(oldpassword, mprGetJson(userjson, "password")) == 0){
        ediSetField(user, "password", newpassword);
        updateRec(user);
        rendersts(str, 1);
    }else{
        rendersts(str, 0);
    }
    //ediClose(db);
    render(str);
    //add optlog
    Edi *db = ediOpen("db/muxnms.mdb", "mdb", EDI_AUTO_SAVE);
    EdiRec *optlog = ediCreateRec(db, "optlog");
    if(optlog == NULL){
       printf("================>>>optlog is NULL!!\n");
       return;
    }
    time_t curTime;
    time(&curTime);
    memset(optstr, 0, 256);
    sprintf(optstr, "{'user': '******', 'desc': '用户修改了密码.', 'level': '2', 'logtime':'%d'}", getSessionVar("userName"), curTime);
    MprJson  *row = mprParseJson(optstr);
    if(ediSetFields(optlog, row) == 0){
       printf("================>>>ediSetFields Failed!!\n");
    }
    ediUpdateRec(db, optlog);
    //ediClose(db);
}
示例#5
0
文件: espAbbrev.c 项目: embedthis/esp
PUBLIC EdiRec *createRec(cchar *tableName, MprJson *params)
{
    return setRec(ediSetFields(ediCreateRec(getDatabase(), tableName), params));
}