Example #1
0
int main(void)
{
#ifdef ENABLE_FASTCGI
    while(FCGI_Accept() >= 0) {
#endif
    qentry_t *req = qcgireq_parse(NULL, 0);

    // fetch queries
    time_t expire = (time_t)req->getint(req, "expire");
    char *mode  = req->getstr(req, "mode", false);
    char *name  = req->getstr(req, "name", false);
    char *value = req->getstr(req, "value", false);

    // start session.
    qentry_t *sess = qcgisess_init(req, NULL);

    // Mose case, you don't need to set timeout. this is just example
    if (expire > 0) qcgisess_settimeout(sess, expire);

    if (mode) {
        switch (mode[0]) {
            case 's': // set
                req->putstr(sess, name, value, true);
                break;
            case 'r': // remove
                req->remove(sess, name);
                break;
            case 'd': // destroy
                qcgisess_destroy(sess);
                qcgires_setcontenttype(req, "text/plain");
                printf("Session destroyed.\n");
#ifdef ENABLE_FASTCGI
                continue;
#else
                return 0;
#endif
            case 'v': // view
            default:
                break;
        }
    }
    // screen out
    qcgires_setcontenttype(req, "text/plain");
    req->print(sess, stdout, true);

    // save session & free allocated memories
    qcgisess_save(sess);
    sess->free(sess);
    req->free(req);
#ifdef ENABLE_FASTCGI
    }
#endif
    return 0;
}
Example #2
0
int main(void)
{
    // Parse queries.
    FILE *fp;

    qentry_t *req = qcgireq_parse(NULL, 0);

    // Get ID 
    char *id = (char *)req->getstr(req, "id", false);
    if (id == NULL) id = "(nothing)";

    // Get PW
    char *pw = (char *)req->getstr(req, "pw", false);
    if (pw == NULL) pw = "(nothing)";

    // Print out
    qcgires_setcontenttype(req, "text/html");
    fp = fopen("../config.html", "r");
    while(!feof(fp))
    {
		char	buf[1024];

		if (fgets(buf, sizeof(buf), fp) != 0)
			puts(buf);
	}

	fclose(fp);
    // De-allocate memories
    req->free(req);
    return 0;
}
Example #3
0
int	FTMC_Page(qentry_t *pReq)
{
	char	szBuf[1024];
    char	*lpszCmd = pReq->getstr(pReq, "cmd", false);
	char	szInnerFileName[1024];

	qcgires_setcontenttype(pReq, "text/html");

	FILE *fp = fopen("/www/contents/base", "r");
	if (fp == NULL)
	{
		return	-1;	
	}

	while(fgets(szBuf, sizeof(szBuf), fp))
	{
		if (strstr(szBuf, "###SCRIPT###") != 0)
		{
			snprintf(szInnerFileName, sizeof(szInnerFileName), "/www/scripts/%s.js", lpszCmd);
			FILE *ifp = fopen(szInnerFileName, "r");
			if (ifp != NULL)
			{
				printf("<script type='text/javascript'>\n");
				while(fgets(szBuf, sizeof(szBuf), ifp))
				{
					printf(szBuf);	
				}
				printf("</script>\n");
				
				fclose(ifp);
			}
		}
		else if (strstr(szBuf, "###CONTENT###") != 0)
		{
			snprintf(szInnerFileName, sizeof(szInnerFileName), "/www/contents/%s", lpszCmd);
			FILE *ifp = fopen(szInnerFileName, "r");
			if (ifp != NULL)
			{
				while(fgets(szBuf, sizeof(szBuf), ifp))
				{
					printf(szBuf);	
				}
				
				fclose(ifp);
			}
		}
		else
		{
			printf(szBuf);	
		}
	}

	fclose(fp);

    return	0;
}
Example #4
0
int main(void){
    pci_init();
#ifdef ENABLE_FASTCGI
    while(FCGI_Accept() >= 0) {
#endif
    qentry_t *req = qcgireq_parse(NULL, 0);
    
    char *name  = req->getstr(req, "username", true);
    if(name == NULL){
        qcgires_redirect(req, BAD_REGISTER);
        goto end;
    }

    char *admin = req->getstr(req, "adminpassword", true);
    if(admin == NULL){
    	qcgires_redirect(req, BAD_REGISTER);
    	free(name);
    	goto end;
    }

    if(strncmp(admin, ADMIN_SECRET, strlen(ADMIN_SECRET)) != 0){
    	fprintf(stderr, "%s%s\n", "Invalid Registration Attempt: ", admin);
    	qcgires_redirect(req, BAD_REGISTER);
    	free(name);
    	free(admin);
    	goto end;
    }

    if( create_user(name) == 1 ){   	
    	/* Log the User in */
    	qentry_t *sess = NULL;
		sess = qcgisess_init(req, NULL);
        qcgisess_settimeout(sess, SESSION_TIME);
		if(sess){
            sess->putstr(sess, "username", name, true);
            qcgisess_save(sess);
            sess->free(sess);            
        } 
        qcgires_redirect(req, APPLICATION);
    }else{
    	fprintf(stderr, "%s%s\n", "Could not create user: "******"text/html");
    // De-allocate memories
    req->free(req);
#ifdef ENABLE_FASTCGI
    }
#endif
    return 0;
}
Example #5
0
int main(void)
{
    // Parse (COOKIE/GET/POST) queries.
    qentry_t *req = qcgireq_parse(NULL, 0);
    qcgires_setcontenttype(req, "text/html");

    printf("Your order : ");
    qentobj_t obj;
    memset((void *)&obj, 0, sizeof(obj)); // must be cleared before call
    while (req->getnext(req, &obj, "checklist", false) == true) {
        printf("<b>%s</b> \n", (char *)obj.data);
    }

    req->free(req);
    return 0;
}
Example #6
0
int FTMC_SSID(qentry_t *pReq)
{
	FTMC_PROFILE_CONFIG xConfig;
	char	*lpszCmd	= (char *)pReq->getstr(pReq, "cmd", false);
	char	*lpszUserID = (char *)pReq->getstr(pReq, "id", false);
	char	*lpszPasswd = (char *)pReq->getstr(pReq, "pw", false);
	char    *lpszSeed	= (char *)pReq->getstr(pReq, "seed", false);

	if (strcmp(lpszCmd, "get") == 0)
	{
		if (FTMC_LoadProfileConfig(&xConfig) < 0)
		{
			return	-1;	
		}

		qcgires_setcontenttype(pReq, "text/xml");
		printf("<?xml version='1.0' encoding='ISO-8859-1'?>\n");
		printf("<FTM-50>\n");

		if ((strcmp(lpszUserID, xConfig.szUserID) != 0) || 
			(strcmp(lpszPasswd, xConfig.szPasswd) != 0) || 
			(lpszSeed == NULL))
		{
			printf("<RET>ERROR</RET>\n");			
		}
		else
		{
			char	szTag[64];

			FTMC_MakeSSID(lpszSeed, szTag, sizeof(szTag));
			FTMC_SaveSSID(szTag, time(0));
			printf("<SSID>%s</SSID>\n", szTag);
			printf("<RET>OK</RET>\n");	

		}
		printf("</FTM-50>\n");

		return	0;
	}

    return	-1;
}
Example #7
0
int main(void)
{
#ifdef ENABLE_FASTCGI
    while(FCGI_Accept() >= 0) {
#endif
    // Parse queries.
    qentry_t *req = qcgireq_parse(NULL, 0);

    // Get values
    char *value = (char *)req->getstr(req, "query", false);
    if (value == NULL) value = "(nothing)";

    // Print out
    qcgires_setcontenttype(req, "text/html");
    printf("You entered: <b>%s</b>\n", value);

    // De-allocate memories
    req->free(req);
#ifdef ENABLE_FASTCGI
    }
#endif
    return 0;
}
int IOT_SecurityMode(qentry_t *pReq) 
{
		int STOP=FALSE;		
		int res;
		int serialFD = open_port(MODEM);
		char buf[BUFSIZE];
		//memset(buf,0,BUFSIZE);

		// Parse queries.
		qentry_t *req = qcgireq_parse(NULL, 0);

		// Get values
		char *value = (char *)req->getstr(req, "cmd", false);
		if (strcmp(value, "state") == 0)
		{
				write(serialFD, "AT#EMSE?\r" , strlen("AT#EMSE?\r"));
				while (STOP==FALSE) {

						res = read(serialFD,buf,255);
						buf[res]=0;
						//printf("%s:%d\n", buf, res);
						if (strstr(buf, "OK") != NULL) {
								STOP=TRUE;
								qcgires_setcontenttype(req, "text/xml");
								printf("<data>\n");
								printf("<res>OK</res>\n");
								printf("<text>%s</text>\n", buf);
								printf("</data>");
						}
						else if (strstr(buf, "ERROR") != NULL) {
								STOP=TRUE;
								qcgires_setcontenttype(req, "text/xml");
								printf("<data>\n");
								printf("<res>ERROR</res>\n");
								printf("<text>%s</text>\n", buf);
								printf("</data>\n");
						}
						
				}

		} else if (strcmp(value, "set") == 0) {

				char *integrity = req->getstrf(req, false, "integrity");
				char *ciphering = req->getstrf(req, false, "ciphering");
				char *fakesecurity = req->getstrf(req, false, "fakesecurity");
				
				char command[100];
				sprintf(command, "AT#EMSE=%s,%s,%s\r", integrity, ciphering, fakesecurity);
				write(serialFD, command, strlen(command));
				while (STOP==FALSE) {

						res = read(serialFD,buf,255);
						buf[res]=0;
						//printf("%s:%d\n", buf, res);
						if (strstr(buf, "OK") != NULL) {
								STOP=TRUE;
								qcgires_setcontenttype(req, "text/xml");
								printf("<data>\n");
								printf("<res>OK</res>\n");
								printf("<command>%s</command>\n", command);
								printf("<text>%s</text>\n", buf);
								printf("</data>");
						}
						else if (strstr(buf, "ERROR") != NULL) {
								STOP=TRUE;
								qcgires_setcontenttype(req, "text/xml");
								printf("<data>\n");
								printf("<command>%s</command>\n", command);
								printf("<res>ERROR</res>\n");
								printf("<text>%s</text>\n", buf);
								printf("</data>\n");
						}

				}

		}
		close(serialFD);
		return 0;
}
Example #9
0
int FTMC_OTA(qentry_t *pReq)
{
		char *lpszCmd = pReq->getstr(pReq, "cmd", false);
		
		int res;
		int serialFD = open_port(MODEM);
		char buf[BUFSIZE];
		memset(buf,0,BUFSIZE);

		FILE *fp;

		if (strcmp(lpszCmd, "status") == 0)
		{
			//write(serialFD, "AT+CRSM=178,28480,1,4,0", strlen("AT+CRSM=178,28480,1,4,0"));
		}
		else if (strcmp(lpszCmd, "ota") == 0)
		{
			//int res;
			//int serialFD = open_port(MODEM);
			//char buf[BUFSIZE];
			//memset(buf,0,BUFSIZE);
			write(serialFD, "AT#COMS=00\r" , strlen("AT#COMS=00\r"));
			//sleep(60);
			while (STOP==FALSE) {
					res = read(serialFD,buf,255);
					buf[res]=0;
					//printf("test = %s", buf);
					//printf(":%s:%d\n", buf, res);
					if (strstr(buf, "#105") != NULL) {
							STOP=TRUE;
							//=========== OTA 인증 성공 ===========
							qcgires_setcontenttype(pReq, "text/xml");
							printf("<?xml version='1.0' encoding='ISO-8859-1'?>\n");	
							printf("<OTA_REQUEST>\n");
							printf("<RESULT>SUCCESS</RESULT>\n");
							printf("</OTA_REQUEST>\n");
					} else if (strstr(buf, "#308:3") != NULL) {
							STOP=TRUE;
							//=========== OTA 중단(IMEI 등록이 안된 USIM) =============
							qcgires_setcontenttype(pReq, "text/xml");
							printf("<?xml version='1.0' encoding='ISO-8859-1'?>\n");
							printf("<OTA_REQUEST>\n");
							printf("<RESULT>STOP</RESULT>\n");
							printf("</OTA_REQUEST>\n");
					} else if (strstr(buf, "#308:7") != NULL) {
							STOP=TRUE;
							//=========== OTA 다시시도 =============
							qcgires_setcontenttype(pReq, "text/xml");
							printf("<?xml version='1.0' encoding='ISO-8859-1'?>\n");
							printf("<OTA_REQUEST>\n");
							printf("<RESULT>RESTART</RESULT>\n");
							printf("</OTA_REQUEST>\n");
					}
			}
			//read( serialFD, buf, BUFSIZE );
			//printf("The string is: %s", buf);
			close(serialFD);
			return 0;

		}
		else if (strcmp(lpszCmd, "pppd") == 0)
		{
				fp = popen("killall mmon", "r");
				if (fp != NULL)
				{       
						pclose(fp);                
				}

				fp = popen("service pppd stop", "r");
				if (fp != NULL)
				{
						pclose(fp);
						qcgires_setcontenttype(pReq, "text/xml");
						printf("<?xml version='1.0' encoding='ISO-8859-1'?>\n");
						printf("<OTA_REQUEST>\n");
						printf("<RESULT>OK</RESULT>\n");
						printf("</OTA_REQUEST>\n");
				}
		}
		else if (strcmp(lpszCmd, "modem") == 0)
		{
				fp = popen("service mdmctrl restart", "r");
				if (fp != NULL)
				{
						pclose(fp);
						qcgires_setcontenttype(pReq, "text/xml");
						printf("<?xml version='1.0' encoding='ISO-8859-1'?>\n");
						printf("<OTA_REQUEST>\n");
						printf("<RESULT>OK</RESULT>\n");
						printf("</OTA_REQUEST>\n");
				}
		}
		else
		{
			//printf("<OTA_REQUEST>\n");
			//printf("<RESULT>FAIL</RESULT>\n");
			//printf("</OTA_REQUEST>\n");
		}
		return 0;
}		
Example #10
0
int main(void){
    pci_init();
#ifdef ENABLE_FASTCGI
    while(FCGI_Accept() >= 0) {
#endif
    qentry_t *req = qcgireq_parse(NULL, 0);
    char * username = NULL; 

    qentry_t *sess = NULL;
	sess = qcgisess_init(req, NULL);
    qcgisess_settimeout(sess, SESSION_TIME);
	if(sess == NULL){
		qcgires_redirect(req, LOGIN);
		qcgisess_save(sess);
		goto end;
	} 

	username =  sess->getstr(sess, "username", true);
	sess->putstr(sess, "username", username, true);
    qcgisess_save(sess);

    if(username == NULL){
        fprintf(stderr, "%s\n", "Session expired");
        qcgires_redirect(req, LOGIN);
        qcgisess_save(sess);
        goto end;  
    }
    

    char * message = NULL;
    char * targetUser = NULL;
    message = req->getstr(req, "message", true);
    targetUser = req->getstr(req, "user", true);

    if(message == NULL || targetUser == NULL){
        free(username);
    	if(message != NULL) free(message);
    	if(targetUser != NULL) free(targetUser);
    	goto end;
    }

    int success = updateConversation(username, targetUser, message);
    if(success == 0) qcgires_redirect(req, BAD_TALK);
    else qcgires_redirect(req, APPLICATION);

    free(username);
    free(message);
    free(targetUser);


    // De-allocate memories
    end:
    qcgires_setcontenttype(req, "text/html");
    if(sess){
    	sess->free(sess); 
    }
    req->free(req);
#ifdef ENABLE_FASTCGI
    }
#endif
    return 0;
}
Example #11
0
int main( int argc, char **argv )
{
    char            *value                  = NULL;
    char            *token                  = NULL;

    int             cnv_value               = 0;
    long            cnv_long                = 0;
    unsigned short  speed                   = 0;
    unsigned char   trans                   = 0;
    unsigned char * sat                     = NULL;

    int             brake[BRAKE_BAS]        = { 0, };
    int             brake_check             = 0;
    unsigned char   brake_sum               = 0;
    unsigned char   brake_tcs               = 0;
    unsigned char   brake_abs               = 0;
    unsigned char   brake_scs               = 0;
    unsigned char   brake_bba               = 0;
    unsigned char * brake_value[BRAKE_SIZE] = { 0, };

    unsigned short  size_width              = 0;
    unsigned short  size_length             = 0;

    qentobj_t       obj;

    char            buff[BUFF_SIZE]         = { 0, };
    size_t          size                    = 0;

    unsigned char   psid[3]                 = { 0, };
    int i = 0;

    /* parse queries. */
    qentry_t *req = qcgireq_parse( NULL, 0 );

    /* debug */
    qcgires_setcontenttype( req, "text/plain" );

    /* get value */
    //-- msgID --//
    value = (char *)req->getstr( req, "msgid", false );
    cnv_value = atoi( value );
    bsm.msgid = (unsigned char)cnv_value;
    
    //-- blob.msgcnt --//
    value = (char *)req->getstr( req, "msgcnt", false );
    cnv_value = atoi( value );
    bsm_blob_converter( (unsigned char *)&cnv_value, ONE_BYTE );

    //-- blob.id(ip addres) --//
    value = (char *)req->getstr( req, "id", false );
    token = strtok( value, ". " );
    if( token == NULL )
    {
        cnv_value = 0;
        bsm_blob_converter( (unsigned char *)&cnv_value, FOUR_BYTE );
    }
    else
    {
        while( token != NULL )
        {
            cnv_value = atoi( token );
            bsm_blob_converter( (unsigned char *)&cnv_value, ONE_BYTE );
            token = strtok( NULL, ". " );
        }
    }
   
    //-- blob.secmark --//
    value = (char *)req->getstr( req, "secmark", false );
    cnv_value = atoi( value );
    bsm_blob_converter( (unsigned char *)&cnv_value, TWO_BYTE );
    
    //-- blob.latitude --//
    value = (char *)req->getstr( req, "latitude", false );
    cnv_long = atol( value );
    bsm_blob_converter( (unsigned char *)&cnv_long, FOUR_BYTE );

    //-- blob.longitude --//
    value = (char *)req->getstr( req, "longitude", false );
    cnv_long = atoi( value );
    bsm_blob_converter( (unsigned char *)&cnv_long, FOUR_BYTE );

    //-- blob.elevation --//
    value = (char *)req->getstr( req, "elevation", false );
    cnv_value = atoi( value );
    bsm_blob_converter( (unsigned char *)&cnv_value, TWO_BYTE );

    //-- blob.accuracy --//
    value = (char *)req->getstr( req, "major", false );
    cnv_value = atoi( value );
    bsm_blob_converter( (unsigned char *)&cnv_value, ONE_BYTE );

    value = (char *)req->getstr( req, "minor", false );
    cnv_value = atoi( value );
    bsm_blob_converter( (unsigned char *)&cnv_value, ONE_BYTE );

    value = (char *)req->getstr( req, "orientation", false );
    cnv_value = atoi( value );
    bsm_blob_converter( (unsigned char *)&cnv_value, TWO_BYTE );

    //-- blob.speed and transmission --//
    value = (char *)req->getstr( req, "speed", false );
    speed = atoi( value );

    value = (char *)req->getstr( req, "transmission", false );
    trans = atoi( value );

    speed_and_trans( (unsigned char *)&speed, (unsigned char *)&trans );

    //-- blob.heading --//
    value = (char *)req->getstr( req, "heading", false );
    cnv_value = atoi( value );
    bsm_blob_converter( (unsigned char *)&cnv_value, TWO_BYTE );

    //-- blob.steering wheel --//
    value = (char *)req->getstr( req, "steering", false );
    cnv_value = atoi( value );
    bsm_blob_converter( (unsigned char *)&cnv_value, ONE_BYTE );


    //-- blob.accel set --//
    value = (char *)req->getstr( req, "longitudinal", false );
    cnv_value = atoi( value );
    bsm_blob_converter( (unsigned char *)&cnv_value, TWO_BYTE );

    value = (char *)req->getstr( req, "lateral", false );
    cnv_value = atoi( value );
    bsm_blob_converter( (unsigned char *)&cnv_value, TWO_BYTE );

    value = (char *)req->getstr( req, "vertical", false );
    cnv_value = atoi( value );
    bsm_blob_converter( (unsigned char *)&cnv_value, ONE_BYTE );

    value = (char *)req->getstr( req, "raw_rate", false );
    cnv_value = atoi( value );
    bsm_blob_converter( (unsigned char *)&cnv_value, TWO_BYTE );

    //-- blob.brake data --//
    memset( (void *)&obj, 0, sizeof( obj ) );
    brake_check = 0;
    brake_sum   = 0;

    while( req->getnext( req, &obj, "checklist_brake", false ) == true )
    {
        brake[brake_check] = atoi( (char *)obj.data );
        brake_sum += brake[brake_check];
        brake_check++;
    }
    brake_value[0] = (unsigned char *)&brake_sum;

    value = (char *)req->getstr( req, "tcs", false );
    brake_tcs = atoi( value );
    brake_value[1] = (unsigned char *)&brake_tcs;

    value = (char *)req->getstr( req, "abs", false );
    brake_abs = atoi( value );
    brake_value[2] = (unsigned char *)&brake_abs;

    value = (char *)req->getstr( req, "scs", false );
    brake_scs = atoi( value );
    brake_value[3] = (unsigned char *)&brake_scs;

    value = (char *)req->getstr( req, "bba", false );
    brake_bba = atoi( value );
    brake_value[4] = (unsigned char *)&brake_bba;

    brake_data( brake_value );

    //-- blob.size width/length --//
    value = (char *)req->getstr( req, "size_width", false );
    size_width = atoi( value ) << 4;

    value = (char *)req->getstr( req, "size_length", false );
    size_length = atoi( value );
    
    size_converter( (unsigned char *)&size_width, (unsigned char *)&size_length );

//    display_bsm();

    size = request_encode( INP_DER, &bsm, buff, BUFF_SIZE );

    printf( "-------------------------------------------------------------------------------\n" );
    printf( "bsm incoding data( %d )\n", size );
    for( i = 0; i < size; i++ )
    {
        if( (i % 16) == 0 ) printf( "\n" );
        printf(" %02x ", buff[i] );
    }
    printf( "\n" );


    psid[0] = 0xC0;
    psid[1] = 0x03;
    psid[2] = 0x05;
    
    WSM_WaveShortMessage_request( psid, buff, size );

//    request_decode( OUT_DER, buff, size );

    /* de-allocate memories */
    req->free( req );

    return 0;
}
Example #12
0
int main(void){
    pci_init();
#ifdef ENABLE_FASTCGI
    while(FCGI_Accept() >= 0) {
#endif
    qentry_t *req = qcgireq_parse(NULL, 0);

    qentry_t *sess = NULL;
    sess = qcgisess_init(req, NULL);
    qcgisess_settimeout(sess, SESSION_TIME);
    qcgires_setcontenttype(req, "application/json");    
    if(!sess){
        printf("%s", "{ text : \"Your Session has expired please login again\"}");
        goto end;
    }

    char *name  = sess->getstr(sess, "username", true);
    if(name == NULL){
        printf("%s", "{ text : \"Your Session has expired and your username could not be determined, please login again\"}");
        goto end;
    }

    if(sess){
        sess->putstr(sess, "username", name, true);
        qcgisess_save(sess);                
    }

    printf("{\"text\":");
    char * target = req->getstr(req, "target", true);
    if(target == NULL){
        printf("\"you must select a user to talk to\"}");
        free(name);
        goto end;
    }

    char * filename = req->getstr(req, "f", true);
    if(filename == NULL){
        printf("\"You must choose a file to read\"}");
        free(name);
        free(target);
        goto end;
    }


    FILE * fp = getConversationByFileName(name, target, filename);
    if(fp == NULL){
        free(name);
        printf("%s%s%s","\"Could not open conversation with user for reading: ", target,"\"}");
        free(target);
        free(filename);
        goto end;
    }

    int cOrEOF;
    char c;
    printf("\"");
    while( (cOrEOF = fgetc(fp)) != EOF){
        c = (char)cOrEOF;
        if(c == '"') printf("\\%c", c);
        else if(c == '\n') printf("<br/>");
        else printf("%c", c);
    }
    fclose(fp);

    printf("\"}");
    free(filename);
    free(target);
    free(name);
    end:
    if(sess){
        sess->free(sess);   
    }
    // De-allocate memories
    req->free(req);
#ifdef ENABLE_FASTCGI
    }
#endif
    return 0;
}