char * pigwidgeoncgi_main(void)
{
undefined *puVar1;
char *pcVar2;
int iVar3;
__pid_t _Var4;
int iVar5;
int *piVar6;
void *__ptr;
undefined4 uVar7;
undefined **ppuVar8;
undefined **ppuVar9;
char *__s;
char *pcVar10;
int iVar11;
char acStack_128 [128];
char acStack_a8 [128];
pcVar2 = getenv("REQUEST_METHOD") //possible issue identified - semgrep
if (pcVar2 == (char *)0x0) {
pcVar2 = "no REQUEST";
}
else {
iVar11 = strcasecmp(pcVar2,"POST");
if (iVar11 == 0) {
uVar7 = 0x400;
}
else {
iVar11 = strcasecmp(pcVar2,"GET");
if (iVar11 != 0) {
pcVar2 = "unsupported HTTP request";
goto LAB_0040a490;
}
uVar7 = 0x40;
}
iVar11 = cgibin_parse_request(FUN_0040a9c0,0,uVar7);
if (iVar11 < 0) {
pcVar2 = "unable to parse HTTP request";
}
else {
iVar11 = sess_ispoweruser();
if (iVar11 != 0) {
iVar11 = sobj_new();
if (iVar11 != 0) {
sess_get_uid(iVar11);
puVar1 = PTR_LOOP_00430440;
ppuVar8 = (undefined **)0x0;
do {
ppuVar9 = (undefined **)puVar1;
if (ppuVar8 != (undefined **)0x0) {
ppuVar9 = (undefined **)*ppuVar8;
}
if ((ppuVar9 == &PTR_LOOP_00430440) || (ppuVar9 == (undefined **)0x0))
goto LAB_0040a5ac;
iVar3 = strcmp("ACTIONS",ppuVar9[2]);
ppuVar8 = ppuVar9;
} while (iVar3 != 0);
if ((ppuVar9[3] != (char *)0x0) && (pcVar2 = strdup(ppuVar9[3]), pcVar2 != (char *)0x0)) { //possible issue identified - semgrep
_Var4 = getpid();
puVar1 = PTR_LOOP_00430440;
ppuVar8 = (undefined **)0x0;
do {
ppuVar9 = (undefined **)puVar1;
if (ppuVar8 != (undefined **)0x0) {
ppuVar9 = (undefined **)*ppuVar8;
}
if ((ppuVar9 == &PTR_LOOP_00430440) || (ppuVar9 == (undefined **)0x0))
goto LAB_0040a67c;
iVar3 = strcmp("DELAY_ACTIVATE",ppuVar9[2]);
ppuVar8 = ppuVar9;
} while (iVar3 != 0);
if (ppuVar9[3] == (char *)0x0) {
LAB_0040a67c:
iVar3 = 0;
}
else {
iVar3 = atoi(ppuVar9[3]);
}
__s = pcVar2;
do {
pcVar10 = strchr(__s,0x2c);
if (pcVar10 != (char *)0x0) {
*pcVar10 = '\0';
pcVar10 = pcVar10 + 1;
}
iVar5 = strcmp(__s,"SETCFG");
if (iVar5 == 0) {
uVar7 = sobj_get_string(iVar11);
sprintf(acStack_128,"%s\nACTION=SETCFG\nPREFIX=%s/%s","/htdocs/webinc/wand.php",
"/runtime/session",uVar7) //possible issue identified - semgrep
xmldbc_ephp_wb(0,0,acStack_128,acStack_a8,0x80);
}
else {
iVar5 = strcmp(__s,"ACTIVATE");
if (iVar5 == 0) {
uVar7 = sobj_get_string(iVar11);
sprintf(acStack_128,
"%s\nACTION=ACTIVATE\nPREFIX=%s/%s\nSHELL=/var/run/wand_activate_%d.sh",
"/htdocs/webinc/wand.php","/runtime/session",uVar7,_Var4) //possible issue identified - semgrep
xmldbc_ephp_wb(0,0,acStack_128,acStack_a8,0x80);
sprintf(acStack_128,"wandact:%d:sh /var/run/wand_activate_%d.sh",iVar3,_Var4) //possible issue identified - semgrep
xmldbc_timer(0,0,acStack_128);
}
else {
iVar5 = strcmp(__s,"SAVE");
if (iVar5 == 0) {
lxmldbc_system("/etc/scripts/dbsave.sh") //possible issue identified - semgrep
}
}
}
__s = pcVar10;
} while (pcVar10 != (char *)0x0);
goto LAB_0040a838;
}
}
LAB_0040a5ac:
strcpy(acStack_a8,"malloc error") //possible issue identified - semgrep
pcVar2 = (char *)0x0;
pcVar10 = (char *)0xffffffff;
goto LAB_0040a838;
}
pcVar2 = "no power";
}
}
LAB_0040a490:
strcpy(acStack_a8,pcVar2) //possible issue identified - semgrep
pcVar2 = (char *)0x0;
pcVar10 = (char *)0xffffffff;
iVar11 = 0;
LAB_0040a838:
puts("HTTP/1.1 200 OK\r\nContent-Type: text/xml\r\n\r");
puts("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
puts("<pigwidgeon>");
if (pcVar10 == (char *)0x0) {
printf("<result>OK</result><essage />");
}
else {
printf("<result>FAILED</result><essage>%s</message>\n",acStack_a8);
}
puts("</pigwidgeon>");
if (pcVar2 != (char *)0x0) {
free(pcVar2);
}
if (iVar11 != 0) {
sobj_del(iVar11);
}
while (puVar1 = PTR_LOOP_00430440, (undefined **)PTR_LOOP_00430440 != &PTR_LOOP_00430440) {
piVar6 = *(int **)(PTR_LOOP_00430440 + 4);
iVar11 = *(int *)PTR_LOOP_00430440;
__ptr = *(void **)(PTR_LOOP_00430440 + 8);
*piVar6 = iVar11;
*(int **)(iVar11 + 4) = piVar6;
*(undefined4 *)puVar1 = 0;
*(undefined4 *)(puVar1 + 4) = 0;
if (__ptr != (void *)0x0) {
free(__ptr);
}
if (*(void **)(puVar1 + 0xc) != (void *)0x0) {
free(*(void **)(puVar1 + 0xc));
}
free(puVar1);
}
return pcVar10;
}