Skip to content
Snippets Groups Projects
Commit c1d78cb7 authored by Johannes Barstad's avatar Johannes Barstad
Browse files

documenting and removing unused code

parent aa528a75
Branches
No related tags found
No related merge requests found
...@@ -64,23 +64,13 @@ func UploadFileRetrieve(c *gin.Context) { ...@@ -64,23 +64,13 @@ func UploadFileRetrieve(c *gin.Context) {
logging.Logerror(err, "ERROR in RedisResponse, Fileupload API") logging.Logerror(err, "ERROR in RedisResponse, Fileupload API")
http.Error(c.Writer, "Failed retrieving api data.", http.StatusInternalServerError) http.Error(c.Writer, "Failed retrieving api data.", http.StatusInternalServerError)
return return
// Maybe do another call to delete the key from the database?
} }
/**
//var checkData utils.ResultFrontendResponse
err = json.Unmarshal(responseBytes, &checkdata)
if err!=nil {
fmt.Println(string(checkData))
}
fmt.Println(string(checkData))
*/
err = json.Unmarshal(responseBytes, &fileData) err = json.Unmarshal(responseBytes, &fileData)
if err != nil { if err != nil {
fmt.Println("Error handling redis response:" + err.Error()) fmt.Println("Error handling redis response:" + err.Error())
logging.Logerror(err, "ERROR handling redis response, fileupload API") logging.Logerror(err, "ERROR handling redis response, fileupload API")
http.Error(c.Writer, "Failed retrieving api data.", http.StatusInternalServerError) http.Error(c.Writer, "Failed retrieving api data.", http.StatusInternalServerError)
return return
// Maybe do another call to delete the key from the database?
} }
} }
...@@ -145,10 +135,11 @@ func UploadFile(c *gin.Context) { ...@@ -145,10 +135,11 @@ func UploadFile(c *gin.Context) {
logging.Logerror(err, "") logging.Logerror(err, "")
} }
// fetch API key
APIKey := utils.APIKeyVirusTotal APIKey := utils.APIKeyVirusTotal
// add API key to relevant header
req.Header.Add("X-Apikey", APIKey) req.Header.Add("X-Apikey", APIKey)
// error handle here, user should not be able to send requests without api key
// dynamically set content type, based on the formdata writer // dynamically set content type, based on the formdata writer
req.Header.Set("Content-Type", writer.FormDataContentType()) req.Header.Set("Content-Type", writer.FormDataContentType())
...@@ -156,6 +147,7 @@ func UploadFile(c *gin.Context) { ...@@ -156,6 +147,7 @@ func UploadFile(c *gin.Context) {
// perform the prepared API request // perform the prepared API request
res, err := http.DefaultClient.Do(req) res, err := http.DefaultClient.Do(req)
// as long as the request returns 200
if err != nil { if err != nil {
log.Println(err) log.Println(err)
logging.Logerror(err, "") logging.Logerror(err, "")
...@@ -163,13 +155,12 @@ func UploadFile(c *gin.Context) { ...@@ -163,13 +155,12 @@ func UploadFile(c *gin.Context) {
defer res.Body.Close() defer res.Body.Close()
// så lenge status 200
// read the response // read the response
contents, _ := ioutil.ReadAll(res.Body) contents, _ := ioutil.ReadAll(res.Body)
var jsonResponse utils.VirusTotalUploadID var jsonResponse utils.VirusTotalUploadID
// unmarshal contents
unmarshalledID := json.Unmarshal(contents, &jsonResponse) unmarshalledID := json.Unmarshal(contents, &jsonResponse)
if unmarshalledID != nil { if unmarshalledID != nil {
...@@ -177,6 +168,7 @@ func UploadFile(c *gin.Context) { ...@@ -177,6 +168,7 @@ func UploadFile(c *gin.Context) {
logging.Logerror(err, "") logging.Logerror(err, "")
} }
// fetch ID which is base64 encoded
encodedID := jsonResponse.Data.ID encodedID := jsonResponse.Data.ID
// decode provided values for virustotal report // decode provided values for virustotal report
......
...@@ -12,12 +12,9 @@ import ( ...@@ -12,12 +12,9 @@ import (
// CallVirusTotal returns data on a file id from virustotal // CallVirusTotal returns data on a file id from virustotal
func CallVirusTotal(id string) (response utils.ResultFrontendResponse, err error) { func CallVirusTotal(id string) (response utils.ResultFrontendResponse, err error) {
// VT key has been added. REMEMBER TO DEACTIVATE AND CHANGE BEFORE FINAL RELEASE.
// prepare request towards API // prepare request towards API
// Convert []byte to string and print to screen // Convert []byte to string and print to screen
APIKey := utils.APIKeyVirusTotal APIKey := utils.APIKeyVirusTotal
// remember to change api key, and reference it to a file instead
// as well as deactivate the key from the account, as it's leaked.
if id == "" { if id == "" {
log.Println("error, ID is empty") log.Println("error, ID is empty")
logging.Logerrorinfo("Error, ID is empty - Upload") logging.Logerrorinfo("Error, ID is empty - Upload")
...@@ -61,12 +58,10 @@ func CallVirusTotal(id string) (response utils.ResultFrontendResponse, err error ...@@ -61,12 +58,10 @@ func CallVirusTotal(id string) (response utils.ResultFrontendResponse, err error
log.Println("here is the test output we maybe want") log.Println("here is the test output we maybe want")
i := 0 i := 0
// TODO for later, remove teststruct, as it's only used to put into response, later
var testStruct = make([]utils.FrontendResponse2, len(vtResponse.Data.Attributes.LastAnalysisResults)) var testStruct = make([]utils.FrontendResponse2, len(vtResponse.Data.Attributes.LastAnalysisResults))
// iterate through results // iterate through results
for _, val := range vtResponse.Data.Attributes.LastAnalysisResults { for _, val := range vtResponse.Data.Attributes.LastAnalysisResults {
//log.Printf("testing, %s, %s", key, val)
// initialize struct // initialize struct
// print // print
log.Println(val) log.Println(val)
...@@ -85,11 +80,7 @@ func CallVirusTotal(id string) (response utils.ResultFrontendResponse, err error ...@@ -85,11 +80,7 @@ func CallVirusTotal(id string) (response utils.ResultFrontendResponse, err error
testStruct[i].EN.Description = vtResponse.Data.Attributes.Magic testStruct[i].EN.Description = vtResponse.Data.Attributes.Magic
testStruct[i].EN.Tags = vtResponse.Data.Attributes.TypeTag testStruct[i].EN.Tags = vtResponse.Data.Attributes.TypeTag
//testStruct.EN.Description =
// can also display the total status (last analysis stats) // can also display the total status (last analysis stats)
// this is an int ^^ so cant fill it in frontendresponse2
// question is, do we do it here or later
i++ i++
} }
...@@ -118,8 +109,6 @@ func CallVirusTotal(id string) (response utils.ResultFrontendResponse, err error ...@@ -118,8 +109,6 @@ func CallVirusTotal(id string) (response utils.ResultFrontendResponse, err error
response.NO.Result = "Filen er mistenkelig. Det anbefales å ikke videre håndtere filen. " response.NO.Result = "Filen er mistenkelig. Det anbefales å ikke videre håndtere filen. "
} }
//var engines int = len(vtResponse.Data.Attributes.LastAnalysisResults)
utils.SetResultFile(&response, i-1) utils.SetResultFile(&response, i-1)
log.Println(response) log.Println(response)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment