Beispiel #1
0
static void formLoadUserManagement(webs_t wp, char *path, char *query)
{
	char	*ok;

	a_assert(wp);

	ok = websGetVar(wp, T("ok"), T("")); 

	websHeader(wp);
	websMsgStart(wp);

	if (gstricmp(ok, T("ok")) != 0) {
		websWrite(wp, T("Load Cancelled."));
	} else if (umRestore(NULL) != 0) {
		websWrite(wp, T("ERROR: Unable to load user configuration."));
	} else {
		websWrite(wp, T("User configuration was re-loaded successfully."));
	}

	websMsgEnd(wp);
	websFooter(wp);
	websDone(wp, 200);
}
Beispiel #2
0
static void formSaveUserManagement(webs_t wp, char_t *path, char_t *query)
{
	char_t	*ok;

	a_assert(wp);

	ok = websGetVar(wp, T("ok"), T("")); 

	websHeader(wp);
	websMsgStart(wp);

	if (gstricmp(ok, T("ok")) != 0) {
		websWrite(wp, T("Save Cancelled."));
	} else if (umCommit(NULL) != 0) {
		websWrite(wp, T("ERROR: Unable to save user configuration."));
	} else {
		websWrite(wp, T("User configuration was saved successfully."));
	}

	websMsgEnd(wp);
	websFooter(wp);
	websDone(wp, 200);
}
Beispiel #3
0
static void printersrv(webs_t wp, char_t *path, char_t *query)
{
	char_t *enable;

	// fetch from web input
	enable = websGetVar(wp, T("enabled"), T(""));
	// set to nvram
	nvram_bufset(RT2860_NVRAM, "PrinterSrvEnabled", enable);
	nvram_commit(RT2860_NVRAM);

	// setup device
	doSystem("killall p910nd");
	if (0 == strcmp(enable, "1"))
	{
		doSystem("p910nd -b -f /dev/lp0");
	}

	// debug print
	websHeader(wp);
	websWrite(wp, T("<h2>Printer Server Settings</h2><br>\n"));
	websWrite(wp, T("enabled: %s<br>\n"), enable);
	websFooter(wp);
	websDone(wp, 200);
}
Beispiel #4
0
static void formAddUser(webs_t wp, char_t *path, char_t *query)
{
	char_t	*userid, *pass1, *pass2, *group, *enabled, *ok;
	bool_t bDisable;
	int	nCheck;

	a_assert(wp);

	userid = websGetVar(wp, T("user"), T("")); 
	pass1 = websGetVar(wp, T("password"), T("")); 
	pass2 = websGetVar(wp, T("passconf"), T("")); 
	group = websGetVar(wp, T("group"), T("")); 
	enabled = websGetVar(wp, T("enabled"), T("")); 
	ok = websGetVar(wp, T("ok"), T("")); 

	websHeader(wp);
	websMsgStart(wp);

	if (gstricmp(ok, T("ok")) != 0) {
		websWrite(wp, T("Add User Cancelled"));
	} else if (gstrcmp(pass1, pass2) != 0) {
		websWrite(wp, T("Confirmation Password did not match."));
	} else {
		if (enabled && *enabled && (gstrcmp(enabled, T("on")) == 0)) {
			bDisable = FALSE;
		} else {
			bDisable = TRUE;
		}

		nCheck = umAddUser(userid, pass1, group, 0, bDisable);
		if (nCheck != 0) {
			char_t * strError;

			switch (nCheck) {
			case UM_ERR_DUPLICATE:
				strError = T("User already exists.");
				break;

			case UM_ERR_BAD_NAME:
				strError = T("Invalid user name.");
				break;

			case UM_ERR_BAD_PASSWORD:
				strError = T("Invalid password.");
				break;

			case UM_ERR_NOT_FOUND:
				strError = T("Invalid or unselected group.");
				break;

			default:
				strError = T("Error writing user record.");
				break;
			}

			websWrite(wp, T("Unable to add user, \"%s\".  %s"),
				userid, strError);
		} else {
			websWrite(wp, T("User, \"%s\" was successfully added."),
				userid);
		}
	}

	websMsgEnd(wp);
	websFooter(wp);
	websDone(wp, 200);
}
Beispiel #5
0
static void formAddGroup(webs_t wp, char_t *path, char_t *query)
{
	char_t			*group, *enabled, *privilege, *method, *ok, *pChar;
	int				nCheck;
	short			priv;
	accessMeth_t	am;
	bool_t			bDisable;

	a_assert(wp);

	group = websGetVar(wp, T("group"), T("")); 
	method = websGetVar(wp, T("method"), T("")); 
	enabled = websGetVar(wp, T("enabled"), T("")); 
	privilege = websGetVar(wp, T("privilege"), T("")); 
	ok = websGetVar(wp, T("ok"), T("")); 

	websHeader(wp);
	websMsgStart(wp);

	if (gstricmp(ok, T("ok")) != 0) {
		websWrite(wp, T("Add Group Cancelled."));
	} else if ((group == NULL) || (*group == 0)) {
		websWrite(wp, T("No Group Name was entered."));
	} else if (umGroupExists(group)) {
		websWrite(wp, T("ERROR: Group, \"%s\" already exists."), group);
	} else {
		if (privilege && *privilege) {
/*
 *			privilege is a mulitple <SELECT> var, and must be parsed.
 *			Values for these variables are space delimited.
 */
			priv = 0;
			for (pChar = privilege; *pChar; pChar++) {
				if (*pChar == ' ') {
					*pChar = '\0';
					priv |= gatoi(privilege);
					*pChar = ' ';
					privilege = pChar + 1;
				}
			}
			priv |= gatoi(privilege);
		} else {
			priv = 0;
		}

		if (method && *method) {
			am = (accessMeth_t) gatoi(method);
		} else {
			am = AM_FULL;
		}

		if (enabled && *enabled && (gstrcmp(enabled, T("on")) == 0)) {
			bDisable = FALSE;
		} else {
			bDisable = TRUE;
		}

		nCheck = umAddGroup(group, priv, am, 0, bDisable);
		if (nCheck != 0) {
			websWrite(wp, T("Unable to add group, \"%s\", code: %d "),
				group, nCheck);
		} else {
			websWrite(wp, T("Group, \"%s\" was successfully added."), 
				group);
		}
	}

	websMsgEnd(wp);
	websFooter(wp);
	websDone(wp, 200);
}
Beispiel #6
0
static void formAddAccessLimit( webs_t wp, char_t* path, char_t* query )
{
    char_t*			url, *method, *group, *secure, *ok;
    int				nCheck;
    accessMeth_t	am;
    short			nSecure;
    a_assert( wp );
    url = websGetVar( wp, T( "url" ), T( "" ) );
    group = websGetVar( wp, T( "group" ), T( "" ) );
    method = websGetVar( wp, T( "method" ), T( "" ) );
    secure = websGetVar( wp, T( "secure" ), T( "" ) );
    ok = websGetVar( wp, T( "ok" ), T( "" ) );
    websHeader( wp );
    websMsgStart( wp );

    if ( gstricmp( ok, T( "ok" ) ) != 0 )
    {
        websWrite( wp, T( "Add Access Limit Cancelled." ) );
    }

    else if ( ( url == NULL ) || ( *url == 0 ) )
    {
        websWrite( wp, T( "ERROR:  No URL was entered." ) );
    }

    else if ( umAccessLimitExists( url ) )
    {
        websWrite( wp, T( "ERROR:  An Access Limit for [%s] already exists." ),
                   url );
    }

    else
    {
        if ( method && *method )
        {
            am = ( accessMeth_t ) gatoi( method );
        }

        else
        {
            am = AM_FULL;
        }

        if ( secure && *secure )
        {
            nSecure = ( short ) gatoi( secure );
        }

        else
        {
            nSecure = 0;
        }

        nCheck = umAddAccessLimit( url, am, nSecure, group );

        if ( nCheck != 0 )
        {
            websWrite( wp, T( "Unable to add Access Limit for [%s]" ),	url );
        }

        else
        {
            websWrite( wp, T( "Access limit for [%s], was successfully added." ),
                       url );
        }
    }

    websMsgEnd( wp );
    websFooter( wp );
    websDone( wp, 200 );
}
Beispiel #7
0
static void QoSSetup(webs_t wp, char_t *path, char_t *query)
{
    char_t *qos_enable, *qos_model, *upload_bandwidth, *download_bandwidth, *upload_bandwidth_custom, *download_bandwidth_custom;
    char_t *highest_upload_queue_rate, *highest_upload_queue_ceil, *high_upload_queue_rate, *high_upload_queue_ceil, *default_upload_queue_rate, *default_upload_queue_ceil, *low_upload_queue_rate, *low_upload_queue_ceil;
    char_t *highest_download_queue_rate, *highest_download_queue_ceil, *high_download_queue_rate, *high_download_queue_ceil, *default_download_queue_rate, *default_download_queue_ceil, *low_download_queue_rate, *low_download_queue_ceil;
    char_t *reserve_bandwidth;
    qos_enable = websGetVar(wp, T("QoSSelect"), T(""));
    qos_model = websGetVar(wp, T("Model"), T(""));
    upload_bandwidth = websGetVar(wp, T("UploadBandwidth"), T(""));
    download_bandwidth = websGetVar(wp, T("DownloadBandwidth"), T(""));
    upload_bandwidth_custom = websGetVar(wp, T("UploadBandwidth_Custom"), T(""));
    download_bandwidth_custom = websGetVar(wp, T("DownloadBandwidth_Custom"), T(""));

    reserve_bandwidth = websGetVar(wp, T("ReserveBandwidth"), T(""));

    highest_upload_queue_rate  = websGetVar(wp, T("highest_upload_queue_rate"), T(""));
    high_upload_queue_rate  = websGetVar(wp, T("high_upload_queue_rate"), T(""));
    default_upload_queue_rate  = websGetVar(wp, T("default_upload_queue_rate"), T(""));
    low_upload_queue_rate  = websGetVar(wp, T("low_upload_queue_rate"), T(""));

    highest_upload_queue_ceil  = websGetVar(wp, T("highest_upload_queue_ceil"), T(""));
    high_upload_queue_ceil  = websGetVar(wp, T("high_upload_queue_ceil"), T(""));
    default_upload_queue_ceil  = websGetVar(wp, T("default_upload_queue_ceil"), T(""));
    low_upload_queue_ceil  = websGetVar(wp, T("low_upload_queue_ceil"), T(""));

    highest_download_queue_rate  = websGetVar(wp, T("highest_download_queue_rate"), T(""));
    high_download_queue_rate  = websGetVar(wp, T("high_download_queue_rate"), T(""));
    default_download_queue_rate  = websGetVar(wp, T("default_download_queue_rate"), T(""));
    low_download_queue_rate  = websGetVar(wp, T("low_download_queue_rate"), T(""));

    highest_download_queue_ceil  = websGetVar(wp, T("highest_download_queue_ceil"), T(""));
    high_download_queue_ceil  = websGetVar(wp, T("high_download_queue_ceil"), T(""));
    default_download_queue_ceil  = websGetVar(wp, T("default_download_queue_ceil"), T(""));
    low_download_queue_ceil  = websGetVar(wp, T("low_download_queue_ceil"), T(""));

    if(!qos_enable || !strlen(qos_enable))
        return;

    if(!strcmp(upload_bandwidth, "custom"))
        if(!upload_bandwidth_custom)
            return;
    if(!strcmp(download_bandwidth, "custom"))
        if(!download_bandwidth_custom)
            return;

    if(!strcmp(qos_enable, "1") /* bi-dir */ || !strcmp(qos_enable, "2") /* upload */ || !strcmp(qos_enable, "3") /* download */ || !strcmp(qos_enable, "4") /* port based */) {
        if(!strlen(upload_bandwidth))
            return;
        if(!strlen(download_bandwidth))
            return;
    }
    nvram_bufset(RT2860_NVRAM, "QoSEnable", qos_enable);

    if(!strcmp(qos_enable, "1") /* bi-dir */ || !strcmp(qos_enable, "2")/* upload */ || !strcmp(qos_enable, "3") /* download */ || !strcmp(qos_enable, "4") /* port based */) {
        char postfix[16];
        strncpy(postfix, upload_bandwidth_custom, sizeof(postfix));
        if(!strchr(postfix, 'k') && !strchr(postfix, 'K')  && !strchr(postfix, 'm') && !strchr(postfix, 'M') )
            strncat(postfix, "k", sizeof(postfix));
        nvram_bufset(RT2860_NVRAM, "QoSUploadBandwidth_custom", postfix);
        strncpy(postfix, download_bandwidth_custom, sizeof(postfix));
        if(!strchr(postfix, 'k') && !strchr(postfix, 'K')  && !strchr(postfix, 'm') && !strchr(postfix, 'M') )
            strncat(postfix, "k", sizeof(postfix));

        nvram_bufset(RT2860_NVRAM, "QoSDownloadBandwidth_custom", postfix);
        nvram_bufset(RT2860_NVRAM, "QoSUploadBandwidth", upload_bandwidth);
        nvram_bufset(RT2860_NVRAM, "QoSDownloadBandwidth", download_bandwidth);

        nvram_bufset(RT2860_NVRAM, "QoSReserveBandwidth", reserve_bandwidth);

        nvram_bufset(RT2860_NVRAM, "QoSModel", qos_model);

        if(highest_upload_queue_rate && strlen(highest_upload_queue_rate))
            nvram_bufset(RT2860_NVRAM, "QoSAF5ULRate", highest_upload_queue_rate);
        if(high_upload_queue_rate && strlen(high_upload_queue_rate))
            nvram_bufset(RT2860_NVRAM, "QoSAF2ULRate", high_upload_queue_rate);
        if(default_upload_queue_rate && strlen(default_upload_queue_rate))
            nvram_bufset(RT2860_NVRAM, "QoSAF6ULRate", default_upload_queue_rate);
        if(low_upload_queue_rate && strlen(low_upload_queue_rate))
            nvram_bufset(RT2860_NVRAM, "QoSAF1ULRate", low_upload_queue_rate);

        if(highest_upload_queue_ceil && strlen(highest_upload_queue_ceil))
            nvram_bufset(RT2860_NVRAM, "QoSAF5ULCeil", highest_upload_queue_ceil);
        if(high_upload_queue_ceil && strlen(high_upload_queue_ceil))
            nvram_bufset(RT2860_NVRAM, "QoSAF2ULCeil", high_upload_queue_ceil);
        if(default_upload_queue_ceil && strlen(default_upload_queue_ceil))
            nvram_bufset(RT2860_NVRAM, "QoSAF6ULCeil", default_upload_queue_ceil);
        if(low_upload_queue_ceil && strlen(low_upload_queue_ceil))
            nvram_bufset(RT2860_NVRAM, "QoSAF1ULCeil", low_upload_queue_ceil);

        if(highest_download_queue_rate && strlen(highest_download_queue_rate))
            nvram_bufset(RT2860_NVRAM, "QoSAF5DLRate", highest_download_queue_rate);
        if(high_download_queue_rate && strlen(high_download_queue_rate))
            nvram_bufset(RT2860_NVRAM, "QoSAF2DLRate", high_download_queue_rate);
        if(default_download_queue_rate && strlen(default_download_queue_rate))
            nvram_bufset(RT2860_NVRAM, "QoSAF6DLRate", default_download_queue_rate);
        if(low_download_queue_rate && strlen(low_download_queue_rate))
            nvram_bufset(RT2860_NVRAM, "QoSAF1DLRate", low_download_queue_rate);

        if(highest_download_queue_ceil && strlen(highest_download_queue_ceil))
            nvram_bufset(RT2860_NVRAM, "QoSAF5DLCeil", highest_download_queue_ceil);
        if(high_download_queue_ceil && strlen(high_download_queue_ceil))
            nvram_bufset(RT2860_NVRAM, "QoSAF2DLCeil", high_download_queue_ceil);
        if(default_download_queue_ceil && strlen(default_download_queue_ceil))
            nvram_bufset(RT2860_NVRAM, "QoSAF6DLCeil", default_download_queue_ceil);
        if(low_download_queue_ceil && strlen(low_download_queue_ceil))
            nvram_bufset(RT2860_NVRAM, "QoSAF1DLCeil", low_download_queue_ceil);

    }

    //
    nvram_commit(RT2860_NVRAM);

    QoSRestart();

    websHeader(wp);

    websWrite(wp, T("qos_enable: %s<br>\n"), qos_enable);
    websWrite(wp, T("upload bandwidth: %s<br>\n"), upload_bandwidth);
    websWrite(wp, T("download bandwidth: %s<br>\n"), download_bandwidth);
    websFooter(wp);
    websDone(wp, 200);
}
Beispiel #8
0
static void qosClassifier(webs_t wp, char_t *path, char_t *query)
{
    char rule[8192];
    const char *old_rule;
    char tmp[8];

    char_t *dir, *af_index, *dp_index, *comment, *mac_address, *dip_address, *sip_address, *pktlenfrom, *pktlento,
           *protocol, *dprf, *dprt, *sprf, *sprt, *layer7, *dscp, *ingress_if, *remark ;
    int af_index_i, dp_index_i, sprf_int, dprf_int, sprt_int, dprt_int;

    dir = websGetVar(wp, T("dir"), T(""));
    af_index = websGetVar(wp, T("af_index"), T(""));
    dp_index = websGetVar(wp, T("dp_index"), T(""));
    comment = websGetVar(wp, T("comment"), T(""));
    mac_address = websGetVar(wp, T("mac_address"), T(""));
    dip_address = websGetVar(wp, T("dip_address"), T(""));
    sip_address = websGetVar(wp, T("sip_address"), T(""));
    pktlenfrom = websGetVar(wp, T("pktlenfrom"), T(""));
    pktlento = websGetVar(wp, T("pktlento"), T(""));
    protocol = websGetVar(wp, T("protocol"), T(""));
    dprf = websGetVar(wp, T("dFromPort"), T(""));
    dprt = websGetVar(wp, T("dToPort"), T(""));
    sprf = websGetVar(wp, T("sFromPort"), T(""));
    sprt = websGetVar(wp, T("sToPort"), T(""));
    layer7 = websGetVar(wp, T("layer7"), T(""));
    dscp = websGetVar(wp, T("dscp"), T(""));
    ingress_if = "";
    remark =  websGetVar(wp, T("remark_dscp"), T(""));

    if(!dir || !af_index || !dp_index || !comment || !remark)
        return;

    if(!strlen(dir) || !strlen(af_index) || !strlen(dp_index) || strlen(comment) > 32)
        return;

    // i know you will try to break our box... ;)
    if(strchr(comment, ';') || strchr(comment, ','))
        return;

    af_index_i = atoi(af_index);
    dp_index_i = atoi(dp_index);
    /*
    	if(qosGetIndexByName(af_index_i, dp_index_i, comment) != -1){
    		// This name is not unique.
    		// return;
    	}
    */
    // pkt len from/to must be co-exist.
    if( (!strlen(pktlenfrom) && strlen(pktlento)) ||
            (strlen(pktlenfrom) && !strlen(pktlento)) )
        return;

    if(!strlen(protocol)) {
        if(	!strlen(mac_address) && !strlen(sip_address) && !strlen(dip_address) &&
                !strlen(dscp) /*&& !strlen(ingress_if)*/ && !strlen(pktlenfrom) )
            return;
        layer7 = "";
    } else if(!strcmp(protocol, "TCP") || !strcmp(protocol, "UDP")) {
        if(!strlen(dprf) && !strlen(sprf))
            return;
        layer7 = "";
    } else if(!strcmp(protocol, "Application")) {
        if(!strlen(layer7))
            return;
    } else if(!strcmp(protocol, "ICMP")) {
        layer7 = "";	// do nothing.
    } else
        return;

    // we dont trust user input.....
    if(strlen(mac_address)) {
        if(!isMacValid(mac_address))
            return;
    }

    if(strlen(sip_address)) {
        if(!isIpNetmaskValid(sip_address))
            return;
    }

    if(strlen(dip_address)) {
        if(!isIpNetmaskValid(dip_address))
            return;
    }


    if(!strlen(sprf)) {
        sprf_int = 0;
    } else {
        sprf_int = atoi(sprf);
        if(sprf_int == 0 || sprf_int > 65535)
            return;
    }
    if(!strlen(sprt)) {
        sprt_int = 0;
    } else {
        sprt_int = atoi(sprt);
        if(sprt_int ==0 || sprt_int > 65535)
            return;
    }
    if(!strlen(dprf)) {
        dprf_int = 0;
    } else {
        dprf_int = atoi(dprf);
        if(dprf_int == 0 || dprf_int > 65535)
            return;
    }
    if(!strlen(dprt)) {
        dprt_int = 0;
    } else {
        dprt_int = atoi(dprt);
        if(dprt_int == 0 || dprt_int > 65535)
            return;
    }

    if(!strcmp(remark, "Auto")) {
        if(af_index_i == 5 && dp_index_i == 1) {				/* EF class */
            remark = "EF";
        } else if(af_index_i == 6 && dp_index_i == 1) {		/* BE class */
            remark = "BE";
        } else {                                 /* AF classes */
            snprintf(tmp, sizeof(tmp), "AF%d%d", af_index_i, dp_index_i);
            remark = tmp;
        }
    }

    if(!strcmp(dir, "Download"))
        old_rule = nvram_bufget(RT2860_NVRAM, "QoSDLRules");
    else
        old_rule = nvram_bufget(RT2860_NVRAM, "QoSULRules");

    if(!old_rule || !strlen(old_rule))
        snprintf(rule, sizeof(rule), "%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s", comment, af_index, dp_index, mac_address, protocol, dip_address, sip_address, pktlenfrom, pktlento, dprf, dprt, sprf, sprt, layer7, dscp, ingress_if, remark);
    else
        snprintf(rule, sizeof(rule), "%s;%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s", old_rule, comment, af_index, dp_index, mac_address, protocol, dip_address, sip_address, pktlenfrom, pktlento, dprf, dprt, sprf, sprt, layer7, dscp, ingress_if, remark);

    if(!strcmp(dir, "Download"))
        nvram_bufset(RT2860_NVRAM, "QoSDLRules", rule);
    else
        nvram_bufset(RT2860_NVRAM, "QoSULRules", rule);
    nvram_commit(RT2860_NVRAM);

    QoSRestart();

//	websHeader(wp);
    websWrite(wp, T("HTTP/1.0 200 OK\n"));
    websWrite(wp, T("Server: %s\r\n"), WEBS_NAME);
    websWrite(wp, T("Pragma: no-cache\n"));
    websWrite(wp, T("Cache-control: no-cache\n"));
    websWrite(wp, T("Content-Type: text/html\n"));
    websWrite(wp, T("\n"));
    websWrite(wp, T("<html>\n<head>\n"));
    websWrite(wp, T("<title>My Title</title>"));
    websWrite(wp, T("<link rel=\"stylesheet\" href=\"/style/normal_ws.css\" type=\"text/css\">"));
    websWrite(wp, T("<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">"));
    websWrite(wp, T("</head>\n<body onload=\"opener.location.reload();window.close();\">\n"));

    websWrite(wp, T("name: %s<br>\n"), comment);
    websWrite(wp, T("dir: %s<br>\n"), dir);
    websWrite(wp, T("mac: %s<br>\n"), mac_address);
    websWrite(wp, T("ingress interface: %s<br>\n"), ingress_if);
    websWrite(wp, T("sip_address: %s<br>\n"), sip_address);
    websWrite(wp, T("sFromPort: %s<br>\n"), sprf);
    websWrite(wp, T("sToPort: %s<br>\n"), sprt);
    websWrite(wp, T("dip_address: %s<br>\n"), dip_address);
    websWrite(wp, T("dFromPort: %s<br>\n"), dprf);
    websWrite(wp, T("dToPort: %s<br>\n"), dprt);
    websWrite(wp, T("protocol: %s<br>\n"), protocol);
    websWrite(wp, T("application: %s<br>\n"), layer7);
    websWrite(wp, T("dscp: %s<br>\n"), dscp);
    websWrite(wp, T("remark: %s<br>\n"), remark);

    websFooter(wp);
    websDone(wp, 200);
}