added reading to the file, msi works on windows only. exe works if there is exiftool

This commit is contained in:
2024-06-19 14:40:32 +03:00
parent aa41b83964
commit afa56cb83e
5 changed files with 101 additions and 16 deletions

View File

@@ -2,13 +2,46 @@
<div class="container">
<h1>Upload a File</h1>
<form action="/upload" method="post" enctype="multipart/form-data">
<form action="/upload" method="post" enctype="multipart/form-data" target="noframe">
<div class="upload-btn-wrapper">
<button class="btn">Upload a file</button>
<input type="file" name="myFile" />
<input type="file" name="myFile" accept=".zip, .exe, .msi" />
</div>
<input type="submit" value="Upload" />
</form>
<button type="button" onclick="showContainer('form-container')" >fubarus</button>
</div>
<div class="form-container" oncontextmenu="showContainer('form-container')">
<form>
<div class="form-group">
<label for="PackageIdentifier">PackageIdentifier</label>
<input type="text" id="PackageIdentifier" name="PackageIdentifier">
</div>
<div class="form-group">
<label for="PackageVersion">PackageVersion</label>
<input type="text" id="PackageVersion" name="PackageVersion">
</div>
<div class="form-group">
<label for="InstallerType">InstallerType</label>
<input type="text" id="InstallerType" name="InstallerType">
</div>
<fieldset>
<legend>Installers</legend>
<div class="form-group">
<label for="InstallerUrl">InstallerUrl</label>
<input type="url" id="InstallerUrl" name="InstallerUrl">
</div>
<div class="form-group">
<label for="InstallerSha256">InstallerSha256</label>
<input type="text" id="InstallerSha256" name="InstallerSha256">
</div>
</fieldset>
<div class="form-group">
<label for="Dependencies">Dependencies</label>
<input type="text" id="Dependencies" name="Dependencies">
</div>
<input type="submit" value="Submit">
</form>
</div>
<iframe name="noframe" style="display: none;"></iframe>
{{end}}

View File

@@ -261,7 +261,7 @@ func upload() http.Handler {
fn,_:=os.OpenFile("Data/"+filename, os.O_CREATE, 0666)
fn.Write(fileBytes)
fn.Close()
getParamsFromExif("Data/"+filename)
log.Println(getDataFromFile("Data/"+filename))
})}
// index creates an HTTP handler that serves the main page with data from the database.

View File

@@ -3,9 +3,10 @@ package main
import (
"fmt"
"log"
"regexp"
"os"
"os/exec"
"regexp"
"runtime"
"strconv"
)
@@ -65,21 +66,55 @@ type DownloadElements struct {
// Printer struct is an empty struct. Its purpose is not clear from the provided code.
type Printer struct{}
func getDataFromFile(path string) map[string]string {
log.Println(regexp.MustCompile(`\.\w+$`).FindString(path))
switch extention := regexp.MustCompile(`\.\w+$`).FindString(path); extention {
case ".exe":
return getParamsFromExif(path)
case ".msi":
return getParamsFromMsi(path)
}
return make(map[string]string)
}
// getParamsFromExif extracts EXIF parameters from a file at the given path using the exiftool command.
// It returns a map where the keys are the EXIF parameter names and the values are the corresponding EXIF parameter values.
func getParamsFromExif(path string) map[string]string{
func getParamsFromExif(path string) map[string]string {
exiftool := os.Getenv("exiftool")
e,_ := exec.Command(exiftool, "-f", path).Output()
tags:=make(map[string]string)
spliter:=regexp.MustCompile(`\r?\n`)
crop:=spliter.Split(string(e),-1)
head := regexp.MustCompile(`\s+:\s`)
for _,c := range crop{
if(len(c)>1){
data:=head.Split(c,-1)
e, _ := exec.Command(exiftool, "-f", path).Output()
return splitData(e)
}
func splitData(commandOutput []byte) map[string]string {
tags := make(map[string]string)
spliter := regexp.MustCompile(`\r?\n`)
crop := spliter.Split(string(commandOutput), -1)
head := regexp.MustCompile(`\s+(:\s)?`)
for _, c := range crop {
if len(c) > 1 {
data := head.Split(c, -1)
log.Println("My Raw Data: ", c)
tags[data[0]]=data[1]}
tags[data[0]] = data[1]
}
}
log.Println(tags)
return tags
}
func getParamsFromMsi(path string) map[string]string {
if runtime.GOOS == "windows" {
// orca :=os.Getenv("orca")
// err:=os.Mkdir("tmpdir/extract", os.ModeAppend)
// if err != nil {
// log.Println("There was an error", err)
// }
// run:=exec.Command(orca, "-q", "-s", path, "-x", "tmpdir/extract")
// run.
} else {
msiinfo := os.Getenv("msiinfo")
e, _ := exec.Command(msiinfo, "export", path, "Property").Output()
return splitData(e)
}
return make(map[string]string)
}

View File

@@ -237,3 +237,16 @@ input[type="file"] {
background-color: #6a568b;
border-radius: 15px;
}
.form-container {
position: fixed; /* Fix position on the screen */
top: 0; /* Position at the top */
left: 0; /* Position at the left */
width: 100%; /* Full width */
height: 100%; /* Full height */
background-color: rgba(0, 0, 0, 0.8); /* Semi-transparent background */
z-index: 9999; /* Make it appear above other elements */
overflow: auto; /* Enable scroll if needed */
display: none; /* Center the form vertically */
align-items: center; /* Center the form vertically */
justify-content: center; /* Center the form horizontally */
}

View File

@@ -117,3 +117,7 @@ function scriptPackage(rowid, extracommand, line){
function convertHtml(dt){
return dt.replace("")
}
function showContainer(className){
classShow = document.getElementsByClassName(className)[0];
classShow.style.display = classShow.style.display=="flex"?"none":"flex";
}