int
__fastcall main(
int
a1,
char
**a2,
char
**a3)
{
content_length =
getenv
(
"CONTENT_LENGTH"
);
content_type =
getenv
(
"CONTENT_TYPE"
);
request_uri =
getenv
(
"REQUEST_URI"
);
cookie =
getenv
(
"HTTP_COOKIE"
);
memset
(sessionID, 0, 0x400u);
boundaryStrBuf = StrBufCreate();
fileStrBuf = StrBufCreate();
if
( content_length )
content_length = (
const
char
*)
atoi
(content_length);
contentBuffer =
malloc
((
size_t
)(content_length + 1));
contentBuffer[
fread
(contentBuffer, 1u, (
size_t
)content_length, (
FILE
*)_bss_start)] = 0;
if
( content_type &&
strstr
(content_type,
"boundary="
)) {
StrBufSetStr(boundaryStr,
"--"
);
boundaryIndex =
strstr
(content_type,
"boundary"
);
StrBufAppendStr(boundaryStr, boundaryIndex + 9);
}
contentSize =
memset
(multipartContentArray, 0,
sizeof
(multipartContentArray));
multipartContentArray[1] = (
int
)getNameValue;
multipartContentArray[2] = (
int
)writeInputLog;
contentJsonObject = json_object_new_object(contentSize);
boundary = StrBufToStr(boundaryStr)
multipartObject = multipart_parser_init(boundary, (
int
)multipartContentArray);
contentBufferStringLength =
strlen
(contentBuffer);
multipart_parser_execute(multiPartHeap, contentBuffer, contentBufferStringLength);
multipart_parser_free(multiPartHeap);
jsonutil_get_string(contentJsonObject, &jsonFilePath,
"\"file.path\""
, -1);
jsonutil_get_string(contentJsonObject, &jsonFileName,
"\"filename\""
, -1);
jsonutil_get_string(contentJsonObject, &f1leType,
"\"pathparam\""
, -1);
jsonutil_get_string(contentJsonObject, &jsonFileParam,
"\"fileparam\""
, -1);
jsonutil_get_string(contentJsonObject, &jsonDestination,
"\"destination\""
, -1);
jsonutil_get_string(contentJsonObject, &jsonOption,
"\"option\""
, -1);
jsonutil_get_string(contentJsonObject, &jsonCertName,
"\"cert_name\""
, -1);
jsonutil_get_string(contentJsonObject, &jsonCertType,
"\"cert_type\""
, -1);
jsonutil_get_string(contentJsonObject, &jsonPassword,
"\"password\""
, -1);
if
( cookie )
get_strtok_value(cookie,
"sessionid="
,
";"
, sessionID);
if
( !jsonFilePath || match_regex(
"^/tmp/upload/[0-9]{10}$"
, jsonFilePath) ) {
puts
(
"Content-type: text/html\n"
);
printf
(
"Error Input"
);
goto
END;
}
if
( jsonFileName ) {
if
(
strstr
(jsonFileName,
".xml"
) ) {
fileType =
"Configuration"
;
}
else
if
(
strstr
(jsonFileName,
".img"
) ){
fileType =
"Firmware"
;
}
StrBufSetStr(fileNameBuffer, jsonFileName);
}
fileName = (
const
char
*)StrBufToStr(fileNameBuffer);
result = moveFile(jsonPathPa1am, fileName, jsonFileParam);
if
(result){
put(errorMsg);
goto
END;
}
if
( !
strcmp
(request_uri,
"/api/operations/ciscosb-file:form-file-upload"
) ) {
authorize(sessionID, fileType, fileName, jsonFilePath);
}
END:
StrBufFree(&boundaryStr);
StrBufFree(&fileNameBuffer);
json_object_put(contentJsonObject);
SYSTEM(
"rm -f %s/* > /dev/null 2>&1"
,
"/tmp/upload"
);
return
0;
}