Ejemplo n.º 1
0
int processPostData(char *postData)
{

    char *token;
    char buf[1024];
    char decodedToken[100];
    char action[80];
    char section[80];
    char field[80];
    char value[80];
    int smartDnsUpdatePerformed;
    char smartDnsProviderPrimary[1024];
    char smartDnsProviderSecondary[1024];
    int n;

    sscanf(postData, "action=%[0-9a-zA-Z]", &action);
    if(compStr(action, "update", sizearray(action)))
    {
        token = strtok (postData,"&");
        while (token != NULL)
        {
            //check if contains / so we know it's a var to update
            urldecode2(decodedToken, token);
            if(strstr(decodedToken, "/") != NULL)
            {
                sscanf(decodedToken, "%[0-9a-zA-Z]/%[0-9a-zA-Z]=%[0-9a-zA-Z.:/_%-]", section, field, value);
                //check if DNS update and allowed to perform
                if(compStr(section, "DNS", sizearray(section)) && !compStr(field, "useDHCP", sizearray(field)) && (smartDnsUpdatePerformed == 1))
                {
                    //do nothing
                }
                else
                {
                    n = write_config_var(section, field, value);
                }
                //Check if an update for smartDNS selected which is not set to other
                if(compStr(section, "SmartDNS", sizearray(section)) && compStr(field, "selected", sizearray(section)) && !compStr(value, "other", sizearray(section)))
                {
                    strcpy(buf, "SmartDNS-");
                    strcat(buf, value);
                    //get DNS details for SmartDNS provider
                    read_config_var(buf, "primary", smartDnsProviderPrimary);
                    read_config_var(buf, "secondary", smartDnsProviderSecondary);
                    //set DNS details to selected SmartDNS Provider
                    n = write_config_var("DNS", "primary", smartDnsProviderPrimary);
                    n = write_config_var("DNS", "secondary", smartDnsProviderSecondary);
                    //set that DNS update has been performed so any unwanted commits don't occur after
                    smartDnsUpdatePerformed=1;
                }
            }
            token = strtok (NULL, "&");
        }

    }
}
Ejemplo n.º 2
0
// --------------------------------------------------------------------------
//! find the sequence str2 in str1, return the position and the pointer in str1, 
//! return the pos just before the sequence str2 in str1, -1 if not found
// --------------------------------------------------------------------------
int XipTreeRequestReceiver::strFindStr(char * str1, char * str2, int maxLenght, int sizeStr2, char * &ptrStr1)
{
	if(!str1 || !str2)	
		return -1;
		
	int pos = 0;
	ptrStr1 = str1;
	bool found = false;

	while(pos < maxLenght && !found)
	{
		if(*ptrStr1 == *str2)
			found = compStr(ptrStr1, str2, sizeStr2);

		++ptrStr1;
		++pos;
	}

	--ptrStr1;

	if(!found)
		return -1;
	else
		return pos-1;
}
Ejemplo n.º 3
0
bool cAlarmServer::loadAlarmData(TiXmlElement* element, cAlarmData* data)
{

   UtlString codeStr;
   UtlString idStr;
   UtlString compStr("");
   UtlString sevStr("minor");
   UtlString resStr("");
   UtlString groupName("disabled");
   bool actEmail = true;
   bool actSms = true;
   bool actLog = true;
   bool actTrap = true;
   int  filtMax = INT_MAX;
   int  filtMin = 0;
   if (element && data)
   {
      idStr = element->Attribute("id");
      if (idStr.isNull())
      {
         OsSysLog::add(FAC_ALARM, PRI_ERR,"code=%s: alarm ID is required", codeStr.data());
         return false;
      }

      TiXmlElement* codeElement = element->FirstChildElement("code");
      if ( !codeElement )
      {
         OsSysLog::add(FAC_ALARM, PRI_ERR,
               "id=%s: alarm code is required", element->Attribute("id"));
         return false;
      }
      textContentShallow(codeStr, codeElement);

      codeElement = element->FirstChildElement("severity");
      if ( codeElement )
      {
         textContentShallow(sevStr, codeElement);
      }
      else
      {
         OsSysLog::add(FAC_ALARM, PRI_WARNING,
               "id=%s: no severity; assuming %s", idStr.data(), sevStr.data());
      }

      codeElement = element->FirstChildElement("component");
      if ( codeElement )
      {
         textContentShallow(compStr, codeElement);
      }
      else
      {
         OsSysLog::add(FAC_ALARM, PRI_WARNING,"id=%s: no component; set to null", idStr.data());
      }

      codeElement = element->FirstChildElement("action");
      actLog   = getBoolAttribute(codeElement, "log", true);
      if ( codeElement )
      {
         // Get the alarm group name used for both regular emails and SMS emails.
         groupName = codeElement->Attribute("email");
         if (strcmp(groupName.data(), "disabled") == 0)
         {
            // All regular/SMS notifications for this alarm type must be disabled.
            actEmail = false;
            actSms = false;
            actTrap = false;
         }
      }
      codeElement = element->FirstChildElement("filter");
      filtMax  = getIntAttribute(codeElement, "max_reports", INT_MAX);
      filtMin  = getIntAttribute(codeElement, "min_threshold");
   }
   else
   {
      return false;
   }

   data->setAlarmId(idStr);
   data->setCode(codeStr);
   data->setSeverity(sevToSyslogPri(sevStr));
   data->setComponent(compStr);
   data->setShortTitle(idStr);  // default fallback title is internal id
   data->setDescription(idStr); // default fallback description is internal id
   data->setResolution(resStr);
   data->actions[cAlarmData::eActionLog] = actLog;
   data->actions[cAlarmData::eActionEmail] = actEmail;
   data->actions[cAlarmData::eActionSms] = actSms;
   data->actions[cAlarmData::eActionTrap] = actTrap;
   data->group_name = groupName;
   data->max_report = filtMax;
   data->min_threshold = filtMin;
   data->resetCount();

   return true;

}
Ejemplo n.º 4
0
int main(void)
{

    //Initialise variables for whitelist call
    char *var_d;
    char *var_b;
    char *var_t;
    char *var_s;
    char *var_a;

    char *data;
    char *token;
    char *key;
    char *value;

    FILE *ptr_file;
    char buf[1000];

    //Allocate memory to variables
    data = malloc(QS_LEN);
    token = malloc(QS_LEN);
    key = malloc(QS_LEN);
    value = malloc(QS_LEN);

    var_d = malloc(QS_LEN);
    var_b = malloc(QS_LEN);
    var_t = malloc(QS_LEN);
    var_s = malloc(QS_LEN);
    var_a = malloc(QS_LEN);

    //Query request string and allocate values received to variables
    if (getenv("QUERY_STRING"))
    {
        token = strtok (getenv("QUERY_STRING"),"&");
        while (token != NULL)
        {
            sscanf(token, "%[^=]=%65536s", key, value);
            if ( compStr(key, "d", sizearray(key) ))
            {
                strcpy(var_d, value);
            }
            if ( compStr(key, "b", sizearray(key) ))
            {
                strcpy(var_b, value);
            }
            if ( compStr(key, "t", sizearray(key) ))
            {
                strcpy(var_t, value);
            }
            if ( compStr(key, "s", sizearray(key) ))
            {
                strcpy(var_s, value);
            }
            if ( compStr(key, "a", sizearray(key) ))
            {
                strcpy(var_a, value);
            }
            token = strtok (NULL, "&");
        }
    }

    FILE *fp;
    mkdir("/data/eureka", 0777);
    char path[1035];

    //Check if Whitelist bypass to Google is enabled
    fp = popen("EurekaSettings get WhiteList useSelection", "r");
    //error out if command fails
    if (fp == NULL)
    {
        printf("Failed to run command\n" );
        return 0;
    }
    //compare value of EurekaSettings
    while (fgets(path, sizeof(path)-1, fp) != NULL)
    {
        if(compStr(path, "1"))
        {
            //Bypass enabled, redirect to Google
            printf( "HTTP/1.1 302 Object moved\n" );

            //Are we doing a whitelist pull, or app lookup?
            if (strlen(var_a) != 0)
            {
                // v2 app lookup, push to googles server as they are not using our whitelist service
                // TO-DO: Find all calls used by stock google so we can mimmic it here. For sure d and b are used -dd
                printf( "Location: https://clients3.google.com/cast/chromecast/device/app?a=%s&b=%s&d=%s\n\n\n", var_a, var_b, var_d);
            }
            else
            {
                // doing normal whitelist pull
                //If all device variables provided pass onto google
                if ((strlen(var_b) != 0) && (strlen(var_s) != 0) && (strlen(var_d) != 0) && (strlen(var_t) != 0))
                {
                    printf( "Location: http://clients3.google.com/cast/chromecast/device/baseconfig?b=%s&d=%s&t=%s&s=%s\n\n\n", var_b, var_d, var_t, var_s);
                }
                else
                {
                    //Not all device variables provided, check for device version config and pass to google
                    if(strlen(var_b) != 0)
                    {
                        printf( "Location: http://clients3.google.com/cast/chromecast/device/baseconfig?b=%s\n\n\n", var_b);
                    }
                    else
                    {
                        //device config version not provided, proceed to google emulating 14651
                        printf( "Location: http://clients3.google.com/cast/chromecast/device/baseconfig?b=14651\n\n\n" );
                    }
                }
            }
        }
        else
        {

            //Are we doing a whitelist pull, or app lookup?
            if (strlen(var_a) != 0)
            {
                // v2 app lookup using eureka server
                // I hate doing this, but we need to have the hashed serial to test for a "test" device -dd
                ptr_file=popen("busybox sha1sum /factory/serial.txt | busybox awk '{ print $1 }'","r");
                while (fgets(buf,1000, ptr_file)!=NULL)
                {
                    printf( "HTTP/1.1 302 Object moved\n" );
                    printf( "Location: http://pwl.team-eureka.com/applist.php?applookup=true&a=%s&serial=%s\n\n\n", var_a, buf );
                }
                pclose(ptr_file);
            }
            else
            {
                //Normal whitelist pull
                //Redirect not present, present local whitelist
                printf( "HTTP/1.1 200 OK\n" );
                printf( "Content-Type: application/json; charset=utf-8\n" );
                printf( "Cache-Control: no-cache, no-store, max-age=0, must-revalidate\n" );
                printf( "Pragma: no-cache\n" );
                printf( "Expires: Fri, 01 Jan 1990 00:00:00 GMT\n" );
                printf( "Date: Sat, 23 Nov 2013 01:15:47 GMT\n" );
                printf( "Content-Disposition: attachment; filename=\"json.txt\"; filename*=UTF-8''json.txt\n" );
                printf( "X-Content-Type-Options: nosniff\n" );
                printf( "X-Frame-Options: SAMEORIGIN\n" );
                printf( "X-XSS-Protection: 1; mode=block\n" );
                printf( "Server: GSE\n" );
                printf( "Alternate-Protocol: 443:quic\n" );
                printf( "Transfer-Encoding: chunked\n\n" );

                //Read whitelist from file, print to web.
                FILE *ptr_file;
                char buf[1000];

                //If web is up, force update check
                ptr_file = popen("ping -c 1 -w 1 google.com > /dev/null ; echo $?", "r");
                while (fgets(path, sizeof(path)-1, ptr_file) != NULL)
                {
                    if (compStr(path, "0\n", sizearray(path) ))
                    {
                        system( "busybox sh /system/usr/share/eureka-apps/whitelist-sync/whitelist-sync > /tmp/whitelist-sync.log" );
                    }
                }

                //check if whitelist apps.conf exists in data (if not use system apps.conf)
                if(access("/data/eureka/apps.conf", F_OK) != -1 )
                {
                    ptr_file =fopen("/data/eureka/apps.conf","r");
                }
                else
                {
                    ptr_file=fopen("/system/usr/share/eureka-apps/configs/apps.conf", "r");
                }

                while (fgets(buf,1000, ptr_file)!=NULL)
                    printf("%s",buf);
                fclose(ptr_file);
            }
        }
    }

    pclose(fp);
    return 0;

}
Ejemplo n.º 5
0
//main function for web services
int main(void)
{

    long n;
    char strPage[1023];
    char strFooters[1023];
    char strHeaders[1023];
    char strPopup[1023];
    char str[1024];
    char command[1024] = "echo Welcome to EurekaRom";
    char decodedCommand[1024];
    char *data;
    char *token;
    char *headers;
    char *page = NULL;
    const char *key, *value;
    char *postBuffer = NULL;
    int postRead;
    unsigned int postLen;
    char postData[4096];
    char * queryString;
    char query_action[1024];
    char query_section[1024];
    char query_field[1024];
    char query_value[1024];

    data = malloc(QS_LEN);
    token = malloc(QS_LEN);
    key = malloc(QS_LEN);
    value = malloc(QS_LEN);

    //Operations if POST detected
    if(compStr(getenv("REQUEST_METHOD"), "POST", sizearray(getenv("REQUEST_METHOD"))))
    {
        if (getenv("QUERY_STRING"))
        {
            token = strtok (getenv("QUERY_STRING"),"&");
            while (token != NULL)
            {
                sscanf(token, "%[^=]=%65536s", key, value);
                if ( compStr(key, "page", sizearray(key) ))
                {
                    strcpy(strPage, value);
                }
                token = strtok (NULL, "&");
            }
        }
        postRead = getline(&postBuffer, &postLen, stdin);
        if (-1 != postRead)
        {
            strcpy(postData, postBuffer);
        }
        if (compStr(strPage, "debug", sizearray(strPage) ))
        {
            sscanf(postData, "page=debug&command=%[^,]", command);
            urldecode2(decodedCommand, command);
            web_module_headers(strPage);
            web_module_debug(decodedCommand);
            web_module_footer();
        }
        if (compStr(strPage, "settings", sizearray(strPage) ))
        {
            processPostData(postData);
            web_module_headers(strPage);
            web_module_settings();
            web_module_footer();
        }
        free(postBuffer);
    }
    else
    {
        if (!getenv("QUERY_STRING"))
        {
            //no query string
            web_module_headers("home");
            web_module_home();
        }
        if (getenv("QUERY_STRING"))
        {
            //parse Query_STRING for page
            //query string present
            token = strtok (getenv("QUERY_STRING"),"&");
            while (token != NULL)
            {
                sscanf(token, "%[^=]=%65536s", key, value);
                if ( compStr(key, "page", sizearray(key) ))
                {
                    strcpy(strPage, value);
                }
                if ( compStr(key, "headers", sizearray(key) ))
                {
                    strcpy(strHeaders, value);
                }
                if ( compStr(key, "footers", sizearray(key) ))
                {
                    strcpy(strFooters, value);
                }
                if ( compStr(key, "popup", sizearray(key) ))
                {
                    strcpy(strPopup, value);
                }
                token = strtok (NULL, "&");
            }
            // Call this before headers
            if ( compStr(strPage, "dumpstate", sizearray(strPage) ))
            {
                dumpstate();
                exit(0);
            }
            //check for which page to load
            if ( compStr(strHeaders, "0", sizearray(strHeaders) ))
            {
            }
            else
            {
                web_module_headers(strPage);
            }
            if ( compStr(strPopup, "1", sizearray(strHeaders) ))
            {
                web_module_popup_headers(strPage);
            }
            if ( compStr(strPage, "home", sizearray(strPage) ))
            {
                web_module_home();
            }
            if ( compStr(strPage, "logcat", sizearray(strPage) ))
            {
                web_module_logcat();
            }
            if ( compStr(strPage, "forceeurekaupdate", sizearray(strPage) ))
            {
                forceeurekaupdate();
            }
            if ( compStr(strPage, "debug", sizearray(strPage) ))
            {
                web_module_debug(command);
            }
            if ( compStr(strPage, "settings", sizearray(strPage) ))
            {
                web_module_settings();
            }
            if ( compStr(strPage, "status", sizearray(strPage) ))
            {
                web_module_status();
            }
            if ( compStr(strPage, "companion", sizearray(strPage) ))
            {
                web_module_companion();
            }
            if ( compStr(strPage, "aboutus", sizearray(strPage) ))
            {
                web_module_aboutus();
            }
            if ( compStr(strPage, "Reboot", sizearray(strPage) ))
            {
                reboot();
            }
            if ( compStr(strPage, "sysupdate", sizearray(strPage) ))
            {
                sysupdate();
            }
            if ( compStr(strPage, "factorydatareset", sizearray(strPage) ))
            {
                factorydatareset();
            }
            if ( compStr(strFooters, "0", sizearray(strFooters) ))
            {
            }
            else
            {
                web_module_footer();
            }
        }
    }
}