started adding List view for files
ci/woodpecker/push/woodpecker Pipeline failed Details

templ
Johannes Bülow 2023-08-07 19:02:27 +02:00
parent 1556d50cbf
commit a4019a8342
Signed by untrusted user who does not match committer: jmb
GPG Key ID: B56971CF7B8F83A6
29 changed files with 610 additions and 211 deletions

View File

@ -432,8 +432,8 @@
<routine id="172" parent="1" name="fts5"/>
<schema id="173" parent="1" name="main">
<Current>1</Current>
<IntrospectionTimestamp>2023-07-29.10:48:13.483</IntrospectionTimestamp>
<LocalIntrospectionTimestamp>2023-07-29.08:48:13</LocalIntrospectionTimestamp>
<IntrospectionTimestamp>2023-08-06.18:53:01.268</IntrospectionTimestamp>
<LocalIntrospectionTimestamp>2023-08-06.16:53:01</LocalIntrospectionTimestamp>
</schema>
<argument id="174" parent="16">
<ArgumentDirection>R</ArgumentDirection>
@ -1475,58 +1475,66 @@
<DasType>INTEGER|0s</DasType>
<Position>11</Position>
</column>
<column id="518" parent="504" name="created">
<DasType>DATE|0s</DasType>
<column id="518" parent="504" name="file_cmd">
<DasType>TEXT|0s</DasType>
<Position>12</Position>
</column>
<foreign-key id="519" parent="504">
<column id="519" parent="504" name="created">
<DasType>DATE|0s</DasType>
<Position>13</Position>
</column>
<column id="520" parent="504" name="extension">
<DasType>TEXT|0s</DasType>
<Position>14</Position>
</column>
<foreign-key id="521" parent="504">
<ColNames>status_id</ColNames>
<RefColNames>id</RefColNames>
<RefTableName>status</RefTableName>
</foreign-key>
<index id="520" parent="504" name="sqlite_autoindex_files_1">
<index id="522" parent="504" name="sqlite_autoindex_files_1">
<ColNames>id</ColNames>
<NameSurrogate>1</NameSurrogate>
<Unique>1</Unique>
</index>
<key id="521" parent="504">
<key id="523" parent="504">
<ColNames>id</ColNames>
<Primary>1</Primary>
<UnderlyingIndexName>sqlite_autoindex_files_1</UnderlyingIndexName>
</key>
<column id="522" parent="505" name="type">
<column id="524" parent="505" name="type">
<DasType>TEXT|0s</DasType>
<Position>1</Position>
</column>
<column id="523" parent="505" name="name">
<column id="525" parent="505" name="name">
<DasType>TEXT|0s</DasType>
<Position>2</Position>
</column>
<column id="524" parent="505" name="tbl_name">
<column id="526" parent="505" name="tbl_name">
<DasType>TEXT|0s</DasType>
<Position>3</Position>
</column>
<column id="525" parent="505" name="rootpage">
<column id="527" parent="505" name="rootpage">
<DasType>INT|0s</DasType>
<Position>4</Position>
</column>
<column id="526" parent="505" name="sql">
<column id="528" parent="505" name="sql">
<DasType>TEXT|0s</DasType>
<Position>5</Position>
</column>
<column id="527" parent="506" name="id">
<column id="529" parent="506" name="id">
<DasType>INTEGER|0s</DasType>
<Position>1</Position>
</column>
<column id="528" parent="506" name="name">
<column id="530" parent="506" name="name">
<DasType>TEXT|0s</DasType>
<Position>2</Position>
</column>
<column id="529" parent="506" name="comment">
<column id="531" parent="506" name="comment">
<DasType>TEXT|0s</DasType>
<Position>3</Position>
</column>
<key id="530" parent="506">
<key id="532" parent="506">
<ColNames>id</ColNames>
<Primary>1</Primary>
</key>

View File

@ -1,2 +1,2 @@
#n:main
!<md> [1690620493483, 0, null, null, -2147483648, -2147483648]
!<md> [1691340781268, 0, null, null, -2147483648, -2147483648]

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="KubernetesSettings">
<option name="contextName" value="nathan" />
</component>
</project>

View File

@ -1,36 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AnalysisUIOptions">
<option name="ANALYZE_INJECTED_CODE" value="false" />
<option name="SCOPE_TYPE" value="3" />
</component>
<component name="AutoImportSettings">
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="eeedfed2-369e-4948-a46c-18edddaeec9c" name="Changes" comment="">
<change afterPath="$PROJECT_DIR$/.idea/jsLibraryMappings.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/assets/custom.css" afterDir="false" />
<change afterPath="$PROJECT_DIR$/build.Dockerfile" afterDir="false" />
<change afterPath="$PROJECT_DIR$/database/fileproperties.go" afterDir="false" />
<change afterPath="$PROJECT_DIR$/files/staticanalysis.go" afterDir="false" />
<change afterPath="$PROJECT_DIR$/templates/fileview.gohtml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/web/fileview.go" afterDir="false" />
<change afterPath="$PROJECT_DIR$/web/index.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/.gitignore" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/kubernetes-settings.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.woodpecker.yml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/assets/favicon.ico" afterDir="false" />
<change afterPath="$PROJECT_DIR$/assets/logo.svg" afterDir="false" />
<change afterPath="$PROJECT_DIR$/database/fileList.go" afterDir="false" />
<change afterPath="$PROJECT_DIR$/database/filesTable.go" afterDir="false" />
<change afterPath="$PROJECT_DIR$/templates/filelist.gohtml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/tests/mainTest.go" afterDir="false" />
<change afterPath="$PROJECT_DIR$/web/filelist.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/dataSources/0bebdc19-f5a3-492c-af2a-c7e835e6291d.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/dataSources/0bebdc19-f5a3-492c-af2a-c7e835e6291d.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/dataSources/0bebdc19-f5a3-492c-af2a-c7e835e6291d/storage_v2/_src_/schema/main.uQUzAA.meta" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/dataSources/0bebdc19-f5a3-492c-af2a-c7e835e6291d/storage_v2/_src_/schema/main.uQUzAA.meta" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/filegate.iml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/filegate.iml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Dockerfile" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/assets/bootstrap.bundle.min.js" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/assets/bootstrap.min.css" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/README.md" beforeDir="false" afterPath="$PROJECT_DIR$/README.md" afterDir="false" />
<change beforePath="$PROJECT_DIR$/database/fileproperties.go" beforeDir="false" afterPath="$PROJECT_DIR$/database/fileInfo.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/database/sqlitemanager.go" beforeDir="false" afterPath="$PROJECT_DIR$/database/sqlitemanager.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/files/filemanager.go" beforeDir="false" afterPath="$PROJECT_DIR$/files/filemanager.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/files/staticanalysis.go" beforeDir="false" afterPath="$PROJECT_DIR$/files/staticanalysis.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/go.mod" beforeDir="false" afterPath="$PROJECT_DIR$/go.mod" afterDir="false" />
<change beforePath="$PROJECT_DIR$/go.sum" beforeDir="false" afterPath="$PROJECT_DIR$/go.sum" afterDir="false" />
<change beforePath="$PROJECT_DIR$/main.go" beforeDir="false" afterPath="$PROJECT_DIR$/main.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/sqliteschema.sql" beforeDir="false" afterPath="$PROJECT_DIR$/sqliteschema.sql" afterDir="false" />
<change beforePath="$PROJECT_DIR$/templates/fileview.gohtml" beforeDir="false" afterPath="$PROJECT_DIR$/templates/fileview.gohtml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/templates/footer.gohtml" beforeDir="false" afterPath="$PROJECT_DIR$/templates/footer.gohtml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/templates/header.gohtml" beforeDir="false" afterPath="$PROJECT_DIR$/templates/header.gohtml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/templates/index.gohtml" beforeDir="false" afterPath="$PROJECT_DIR$/templates/index.gohtml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/templates/menu.gohtml" beforeDir="false" afterPath="$PROJECT_DIR$/templates/menu.gohtml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/templates/submitsuccess.gohtml" beforeDir="false" afterPath="$PROJECT_DIR$/templates/submitsuccess.gohtml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/web/fileview.go" beforeDir="false" afterPath="$PROJECT_DIR$/web/fileview.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/web/index.go" beforeDir="false" afterPath="$PROJECT_DIR$/web/index.go" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -62,53 +68,55 @@
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent">{
&quot;keyToString&quot;: {
&quot;DefaultGoTemplateProperty&quot;: &quot;Go File&quot;,
&quot;DefaultHtmlFileTemplate&quot;: &quot;HTML File&quot;,
&quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;,
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
&quot;RunOnceActivity.go.formatter.settings.were.checked&quot;: &quot;true&quot;,
&quot;RunOnceActivity.go.migrated.go.modules.settings&quot;: &quot;true&quot;,
&quot;RunOnceActivity.go.modules.automatic.dependencies.download&quot;: &quot;true&quot;,
&quot;SHARE_PROJECT_CONFIGURATION_FILES&quot;: &quot;true&quot;,
&quot;WebServerToolWindowFactoryState&quot;: &quot;false&quot;,
&quot;git-widget-placeholder&quot;: &quot;main&quot;,
&quot;go.import.settings.migrated&quot;: &quot;true&quot;,
&quot;last_opened_file_path&quot;: &quot;/home/johannes/git/go/filegate&quot;,
&quot;list.type.of.created.stylesheet&quot;: &quot;CSS&quot;,
&quot;node.js.detected.package.eslint&quot;: &quot;true&quot;,
&quot;node.js.detected.package.tslint&quot;: &quot;true&quot;,
&quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;,
&quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;,
&quot;nodejs_package_manager_path&quot;: &quot;npm&quot;,
&quot;ruby.rails.projectView.checked&quot;: &quot;true&quot;,
&quot;run.code.analysis.last.selected.profile&quot;: &quot;pProject Default&quot;,
&quot;settings.editor.selected.configurable&quot;: &quot;database.query.execution&quot;,
&quot;vue.rearranger.settings.migration&quot;: &quot;true&quot;
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"DefaultGoTemplateProperty": "Go File",
"DefaultHtmlFileTemplate": "HTML File",
"RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
"RunOnceActivity.go.formatter.settings.were.checked": "true",
"RunOnceActivity.go.migrated.go.modules.settings": "true",
"RunOnceActivity.go.modules.automatic.dependencies.download": "true",
"SHARE_PROJECT_CONFIGURATION_FILES": "true",
"WebServerToolWindowFactoryState": "false",
"git-widget-placeholder": "main",
"go.import.settings.migrated": "true",
"last_opened_file_path": "/home/johannes/git/go/filegate/templates",
"list.type.of.created.stylesheet": "CSS",
"node.js.detected.package.eslint": "true",
"node.js.detected.package.tslint": "true",
"node.js.selected.package.eslint": "(autodetect)",
"node.js.selected.package.tslint": "(autodetect)",
"nodejs_package_manager_path": "npm",
"ruby.rails.projectView.checked": "true",
"run.code.analysis.last.selected.profile": "pProject Default",
"settings.editor.selected.configurable": "database.query.execution",
"vue.rearranger.settings.migration": "true"
},
&quot;keyToStringList&quot;: {
&quot;DatabaseDriversLRU&quot;: [
&quot;sqlite&quot;
"keyToStringList": {
"DatabaseDriversLRU": [
"sqlite"
],
&quot;com.intellij.ide.scratch.LRUPopupBuilder$1/&quot;: [
&quot;SQLite&quot;
"com.intellij.ide.scratch.LRUPopupBuilder$1/": [
"SQLite"
],
&quot;com.intellij.ide.scratch.LRUPopupBuilder$1/SQL Dialect&quot;: [
&quot;SQLite&quot;
"com.intellij.ide.scratch.LRUPopupBuilder$1/SQL Dialect": [
"SQLite"
]
}
}</component>
}]]></component>
<component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS">
<recent name="$PROJECT_DIR$/templates" />
</key>
<key name="MoveFile.RECENT_KEYS">
<recent name="$PROJECT_DIR$/" />
<recent name="$PROJECT_DIR$/src/" />
<recent name="$PROJECT_DIR$/database" />
<recent name="$PROJECT_DIR$/files/" />
</key>
</component>
<component name="RunManager" selected="Go Build.go build jmbit.de/filegate">
<component name="RunManager" selected="Go Build.go run .">
<configuration default="true" type="GoApplicationRunConfiguration" factoryName="Go Application">
<module name="filegate" />
<working_directory value="$PROJECT_DIR$" />
@ -118,11 +126,10 @@
<filePath value="$PROJECT_DIR$" />
<method v="2" />
</configuration>
<configuration name="go build jmbit.de/filegate" type="GoApplicationRunConfiguration" factoryName="Go Application" temporary="true" nameIsGenerated="true">
<configuration name="go run ." type="GoApplicationRunConfiguration" factoryName="Go Application" temporary="true">
<module name="filegate" />
<working_directory value="$PROJECT_DIR$" />
<kind value="PACKAGE" />
<package value="jmbit.de/filegate" />
<kind value="DIRECTORY" />
<directory value="$PROJECT_DIR$" />
<filePath value="$PROJECT_DIR$/main.go" />
<method v="2" />
@ -165,7 +172,7 @@
</configuration>
<recent_temporary>
<list>
<item itemvalue="Go Build.go build jmbit.de/filegate" />
<item itemvalue="Go Build.go run ." />
<item itemvalue="Docker.Dockerfile" />
<item itemvalue="Docker.Dockerfile builder" />
<item itemvalue="Docker.Dockerfile builder" />
@ -190,12 +197,26 @@
<workItem from="1690869711729" duration="6366000" />
<workItem from="1691214763755" duration="2778000" />
<workItem from="1691302477675" duration="4305000" />
<workItem from="1691320722229" duration="5760000" />
<workItem from="1691335565690" duration="7160000" />
<workItem from="1691389092008" duration="8058000" />
</task>
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="3" />
</component>
<component name="Vcs.Log.Tabs.Properties">
<option name="TAB_STATES">
<map>
<entry key="MAIN">
<value>
<State />
</value>
</entry>
</map>
</option>
</component>
<component name="VgoProject">
<settings-migrated>true</settings-migrated>
</component>

25
.woodpecker.yml Normal file
View File

@ -0,0 +1,25 @@
steps:
build:
image: git.jmbit.de/filegate/filegate-utility:builder
environment:
# Needed if you want to cross-compile and package the binary in a container.
- CGO_ENABLED=1
# Select your target OS:
- GOOS=linux
# Select your target architecture:
- GOARCH=amd64
- GIN_MODE=release
commands:
- go get
- go mod download
- go build
test:
image: git.jmbit.de/filegate/filegate-utility:builder
environment:
- CGO_ENABLED=1
- GOOS=linux
- GIN_MODE=debug
commands:
- go get
- go mod download
- go test

View File

@ -5,7 +5,8 @@ Filegate is implemented in Go using the Gin framework and the Podman bindings to
tasks, like providing a Web browser to download files, convert dangerous files to less dangerous formats, or allow
manual analysis
# Icon
Based on https://pictogrammers.com/library/mdi/icon/gate/ and https://pictogrammers.com/library/mdi/icon/floppy/

BIN
assets/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

47
assets/logo.svg Normal file
View File

@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
width="256"
height="256"
viewBox="0 0 67.733334 67.733333"
version="1.1"
id="svg1"
xml:space="preserve"
inkscape:version="1.3 (0e150ed6c4, 2023-07-21)"
sodipodi:docname="logo.svg"
inkscape:export-filename="favicon.ico"
inkscape:export-xdpi="96"
inkscape:export-ydpi="96"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg"><sodipodi:namedview
id="namedview1"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:showpageshadow="2"
inkscape:pageopacity="0.0"
inkscape:pagecheckerboard="0"
inkscape:deskcolor="#d1d1d1"
inkscape:document-units="mm"
inkscape:zoom="0.82760241"
inkscape:cx="342.55579"
inkscape:cy="117.81019"
inkscape:window-width="1803"
inkscape:window-height="1133"
inkscape:window-x="0"
inkscape:window-y="0"
inkscape:window-maximized="1"
inkscape:current-layer="layer1" /><defs
id="defs1" /><g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"><path
d="M 8.0853991,0.78451506 A 7.3920023,7.3920023 0 0 0 0.69335078,8.1765634 V 59.920486 A 7.3920023,7.3920023 0 0 0 8.0853991,67.312534 H 59.829322 a 7.3920023,7.3920023 0 0 0 7.392049,-7.392048 V 10.024541 L 57.981345,0.78451506 H 52.437413 V 22.960522 a 3.696001,3.696001 0 0 1 -3.696094,3.695954 H 19.173403 A 3.696001,3.696001 0 0 1 15.477308,22.960522 V 0.78451506 H 8.0853991 M 33.957362,4.4804703 V 22.960522 H 45.045365 V 4.4804703 H 33.957362 M 15.477308,34.048525 h 36.960105 a 3.696001,3.696001 0 0 1 3.695956,3.695954 V 59.920486 H 11.781354 V 37.744479 a 3.696001,3.696001 0 0 1 3.695954,-3.695954 z"
id="path1"
style="stroke-width:3.696" /><path
d="m 27.958367,34.241724 v 10.051639 h -4.020701 v -8.041326 h -4.020624 v 8.041326 h -4.020701 v -4.020625 h -4.0207 V 64.39679 h 4.0207 v -4.020701 h 4.020701 v 4.020701 h 4.020624 v -4.020701 h 4.020701 v 4.020701 h 4.020701 v -4.020701 h 4.020625 v 4.020701 h 4.020701 v -4.020701 h 4.020699 v 4.020701 h 4.020625 v -4.020701 h 4.020701 V 64.39679 H 56.10312 V 40.272738 h -4.020701 v 4.020625 h -4.020701 v -8.041326 h -4.020625 v 8.041326 H 40.020394 V 34.241724 H 35.999693 V 44.293363 H 31.979068 V 34.241724 h -4.020701 m -12.062026,14.07234 h 4.020701 v 8.041324 h -4.020701 v -8.041324 m 8.041325,0 h 4.020701 v 8.041324 h -4.020701 v -8.041324 m 8.041402,0 h 4.020625 v 8.041324 h -4.020625 v -8.041324 m 8.041326,0 h 4.020699 v 8.041324 h -4.020699 v -8.041324 m 8.041324,0 h 4.020701 v 8.041324 h -4.020701 z"
id="path1-6"
style="stroke-width:2.01034" /></g></svg>

After

Width:  |  Height:  |  Size: 2.8 KiB

57
database/fileInfo.go Normal file
View File

@ -0,0 +1,57 @@
package database
import (
"fmt"
"log"
"time"
)
type Status struct {
id int
Name string
Comment string
}
type FileInfo struct {
Id string
Name string
Url string
Mime string
OriginalName string
Comment string
Size int
Sha256 string
Sha1 string
Md5 string
StatusID int
FileCmd string
Created string
Extension string
Status Status
}
func GetFileInfo(id string) FileInfo {
db := sqliteConnect()
defer sqliteDisconnect(db)
var fileInfo FileInfo
row := db.QueryRow(
`SELECT id, name, url, mime, original_name, comment, size, sha256, sha1, md5, status_id, created
FROM files WHERE id LIKE ?`, id)
log.Println(fmt.Sprintf("Getting info for %s", id))
var createDateUnix int64
if err := row.Scan(&fileInfo.Id, &fileInfo.Name, &fileInfo.Url, &fileInfo.Mime, &fileInfo.OriginalName,
&fileInfo.Comment, &fileInfo.Size, &fileInfo.Sha256, &fileInfo.Sha1, &fileInfo.Md5, &fileInfo.StatusID,
&createDateUnix); err != nil {
log.Println("Error scanning row:", err)
}
createDate := time.Unix(createDateUnix, 0)
fileInfo.Created = createDate.String()
if err := db.QueryRow(`SELECT name, comment FROM status WHERE id = ?`, fileInfo.StatusID).Scan(&fileInfo.Status.Name,
&fileInfo.Status.Comment); err != nil {
log.Println("Error scanning row:", err)
}
return fileInfo
}

56
database/fileList.go Normal file
View File

@ -0,0 +1,56 @@
package database
import (
"database/sql"
"log"
"time"
)
type ListItem struct {
Id string
Name string
OriginalName string
Size int64
MimeType string
Status string
Comment string
Created string
}
func GetFileList(page int, count int) ([]ListItem, error) {
db := sqliteConnect()
var returnList []ListItem
firstEntry := (page - 1) * count
lastEntry := page * count
query, err := db.Query(`SELECT files.id, files.name, files.original_name, files.size, files.mime, status.name, files.comment, files.created
FROM files, status
WHERE files.status_id = status.id
OFFSET ? ROWS FETCH NEXT ? ROWS ONLY;`, firstEntry, lastEntry)
if err != nil {
log.Println(err)
return nil, err
}
defer func(query *sql.Rows) {
err := query.Close()
if err != nil {
log.Println(err)
}
}(query)
defer sqliteDisconnect(db)
for query.Next() {
var entry ListItem
var unixTime int64
err := query.Scan(&entry.Id, &entry.Name, &entry.OriginalName, &entry.Size, &entry.MimeType, &entry.Status, &entry.Comment, &unixTime)
if err != nil {
log.Println(err)
return nil, err
}
entry.Created = time.Unix(unixTime, 0).String()
}
if err := query.Err(); err != nil {
log.Println(err)
return nil, err
}
return returnList, nil
}

View File

@ -1,72 +0,0 @@
package database
import (
"fmt"
"log"
)
type Status struct {
id int
name string
comment string
}
type FileInfo struct {
Id string
Name string
Url string
Mime string
OrignalName string
Comment string
Size int
Sha256 string
Sha1 string
Md5 string
StatusID int
FileCmd string
Created string
Extension string
Status Status
}
func SetFileSize(id string, size int64) {
db := sqliteConnect()
_, err := db.Exec(`UPDATE files SET size = ? WHERE id LIKE ?;`, size, id)
log.Println(fmt.Sprintf("Adding Size %d to File %s", size, id))
if err != nil {
log.Println(err)
}
sqliteDisconnect(db)
}
func UpdateTextColumn(id string, field string, content string) {
db := sqliteConnect()
_, err := db.Exec(`UPDATE files SET ? = ? WHERE id LIKE ?;`, field, content, id)
log.Println(fmt.Sprintf("Adding %s %s to File %s", field, content, id))
if err != nil {
log.Println(err)
}
sqliteDisconnect(db)
}
func GetFileInfo(id string) FileInfo {
db := sqliteConnect()
var fileInfo FileInfo
row := db.QueryRow(
`SELECT id, name, url, mime, original_name, comment, size, sha256, sha1, md5, status_id, created
FROM files WHERE id LIKE ?`, id)
log.Println(fmt.Sprintf("Getting info for %s", id))
if err := row.Scan(&fileInfo.Id, &fileInfo.Name, &fileInfo.Url, &fileInfo.Mime, &fileInfo.OrignalName,
&fileInfo.Comment, &fileInfo.Size, &fileInfo.Sha256, &fileInfo.Sha1, &fileInfo.Md5, &fileInfo.StatusID,
&fileInfo.Created); err != nil {
log.Println("Error scanning row:", err)
}
if err := db.QueryRow(`SELECT name, comment FROM status WHERE id = ?`, fileInfo.StatusID).Scan(&fileInfo.Status.name,
&fileInfo.Status.comment); err != nil {
log.Println("Error scanning row:", err)
}
return fileInfo
}

43
database/filesTable.go Normal file
View File

@ -0,0 +1,43 @@
package database
import (
"fmt"
"log"
)
func UpdateOriginalName(id string, originalName string) {
db := sqliteConnect()
_, err := db.Exec(`UPDATE files SET original_name = ? WHERE id LIKE ?;`, originalName, id)
log.Println(fmt.Sprintf("Adding OG name %s to File %s", originalName, id))
if err != nil {
log.Println(err)
}
sqliteDisconnect(db)
}
func SetSimpleAttributes(id string, mime string, size int64, sha256 string, sha1 string, md5 string, fileCmd string, extension string) {
db := sqliteConnect()
_, err := db.Exec(`UPDATE files SET
mime = ?,
size = ?,
sha256 = ?,
sha1 = ?,
md5 = ?,
file_cmd = ?,
extension = ?
WHERE id = ?;`, mime, size, sha256, sha1, md5, fileCmd, extension, id)
if err != nil {
log.Println(err)
}
sqliteDisconnect(db)
}
func CountFilesEntries() int {
db := sqliteConnect()
defer sqliteDisconnect(db)
var count int
if err := db.QueryRow(`SELECT COUNT(id) FROM files`).Scan(&count); err != nil {
log.Println("Error Retrieving count of Entries in \"files\" table:", err)
}
return count
}

View File

@ -3,14 +3,14 @@ package database
import (
"database/sql"
"fmt"
_ "github.com/glebarez/go-sqlite"
_ "github.com/mattn/go-sqlite3"
"log"
"os"
"time"
)
func sqliteConnect() *sql.DB {
db, err := sql.Open("sqlite", "./db.sqlite")
db, err := sql.Open("sqlite3", "./db.sqlite")
if err != nil {
log.Fatal(err)
}
@ -45,7 +45,7 @@ func Setup() {
func CreateFile(id string, name string, url string, comment string) error {
db := sqliteConnect()
date := time.Now().String()
date := time.Now().Unix()
fmt.Printf("ID: %s, Name: %s, URL: %s, Comment: %s, date: %s", id, name, url, comment, date)
_, err := db.Exec(`INSERT INTO files (id, name, url, comment, status_id, created)
VALUES (?, ?, ?, ?, ?, ?)`, id, name, url, comment, 0, date)

View File

@ -2,8 +2,9 @@ package files
import (
"fmt"
"git.jmbit.de/filegate/filegate/database"
"github.com/gin-gonic/gin"
"io"
"jmbit.de/filegate/database"
"log"
"net/http"
"net/url"
@ -48,7 +49,7 @@ func DownloadFile(rawURL string, id string) error {
splitPath := strings.Split(path, "/")
fileName := splitPath[len(splitPath)-1]
fmt.Printf("Downloading file %s, OG Name: %s, Path: %s \n", id, fileName, path)
database.UpdateTextColumn(id, "original_name", fileName)
database.UpdateOriginalName(id, fileName)
targetFile, err := os.Create(fmt.Sprintf("./filestore/%s", id))
if err != nil {
log.Println(err)
@ -69,3 +70,18 @@ func DownloadFile(rawURL string, id string) error {
go RunStaticAnalysis(id)
return nil
}
func UploadFile(id string, c *gin.Context) error {
file, err := c.FormFile("file")
if err != nil {
return err
}
database.UpdateOriginalName(id, file.Filename)
err = c.SaveUploadedFile(file, fmt.Sprintf("./filestore/%s", id))
if err != nil {
return err
}
go RunStaticAnalysis(id)
return nil
}

View File

@ -5,8 +5,8 @@ import (
"crypto/sha1"
"crypto/sha256"
"fmt"
"git.jmbit.de/filegate/filegate/database"
"io"
"jmbit.de/filegate/database"
"log"
"os"
"os/exec"
@ -24,7 +24,7 @@ func mimeType(path string) string {
}
func fileExtension(path string) string {
fileOut, err := exec.Command("/usr/bin/file", "--extension", path).Output()
fileOut, err := exec.Command("/usr/bin/file", "-b", "--extension", path).Output()
if err != nil {
log.Println(err)
}
@ -55,9 +55,9 @@ func fileChecksums(path string) (string, string, string) {
if _, err := io.Copy(sha256Hash, input); err != nil {
log.Println(err)
}
md5Sum := string(md5Hash.Sum(nil))
sha1Sum := string(sha1Hash.Sum(nil))
sha256Sum := string(sha256Hash.Sum(nil))
md5Sum := fmt.Sprintf("%x", md5Hash.Sum(nil))
sha1Sum := fmt.Sprintf("%x", sha1Hash.Sum(nil))
sha256Sum := fmt.Sprintf("%x", sha256Hash.Sum(nil))
return md5Sum, sha1Sum, sha256Sum
}
@ -72,14 +72,11 @@ func fileSize(path string) int64 {
func RunStaticAnalysis(id string) {
filepath := fmt.Sprintf("./filestore/%s", id)
database.UpdateTextColumn(id, "mime", mimeType(filepath))
database.UpdateTextColumn(id, "file_cmd", fileCmd(filepath))
mimeType := mimeType(filepath)
fileCmd := fileCmd(filepath)
fileExtension := fileExtension(filepath)
fileSize := fileSize(filepath)
md5Sum, sha1Sum, sha256Sum := fileChecksums(filepath)
database.UpdateTextColumn(id, "md5", md5Sum)
database.UpdateTextColumn(id, "sha1", sha1Sum)
database.UpdateTextColumn(id, "sha256", sha256Sum)
database.UpdateTextColumn(id, "extension", fileExtension(filepath))
database.SetFileSize(id, fileSize(filepath))
database.SetSimpleAttributes(id, mimeType, fileSize, sha256Sum, sha1Sum, md5Sum, fileCmd, fileExtension)
}

13
go.mod
View File

@ -1,18 +1,17 @@
module jmbit.de/filegate
module git.jmbit.de/filegate/filegate
go 1.20
require (
github.com/gabriel-vasile/mimetype v1.4.2
github.com/gin-gonic/gin v1.9.1
github.com/glebarez/go-sqlite v1.21.2
github.com/google/uuid v1.3.0
github.com/mattn/go-sqlite3 v1.14.16
)
require (
github.com/bytedance/sonic v1.9.1 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
@ -25,7 +24,6 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
golang.org/x/arch v0.3.0 // indirect
@ -33,10 +31,7 @@ require (
golang.org/x/net v0.10.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/text v0.9.0 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
modernc.org/libc v1.22.5 // indirect
modernc.org/mathutil v1.5.0 // indirect
modernc.org/memory v1.5.0 // indirect
modernc.org/sqlite v1.23.1 // indirect
)

19
go.sum
View File

@ -7,16 +7,12 @@ github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583j
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU=
github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA=
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg=
github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU=
github.com/glebarez/go-sqlite v1.21.2 h1:3a6LFC4sKahUunAmynQKLZceZCOzUthkRkEAl9gAXWo=
github.com/glebarez/go-sqlite v1.21.2/go.mod h1:sfxdZyhQjTM2Wry3gVYWaW072Ri1WMdWJi0k6+3382k=
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
@ -30,7 +26,6 @@ github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaS
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26 h1:Xim43kblpZXfIBQsbuBVKCudVG457BR2GZFIz3uw3hQ=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
@ -42,6 +37,8 @@ github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q=
github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4=
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwpU1Y=
github.com/mattn/go-sqlite3 v1.14.16/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
@ -51,9 +48,6 @@ github.com/pelletier/go-toml/v2 v2.0.8 h1:0ctb6s9mE31h0/lhu+J6OPmVeDxJn+kYnJc2jZ
github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNcZljzZR9VXg+4=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
@ -84,6 +78,7 @@ golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng=
google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
@ -92,12 +87,4 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
modernc.org/libc v1.22.5 h1:91BNch/e5B0uPbJFgqbxXuOnxBQjlS//icfQEGmvyjE=
modernc.org/libc v1.22.5/go.mod h1:jj+Z7dTNX8fBScMVNRAYZ/jF91K8fdT2hYMThc3YjBY=
modernc.org/mathutil v1.5.0 h1:rV0Ko/6SfM+8G+yKiyI830l3Wuz1zRutdslNoQ0kfiQ=
modernc.org/mathutil v1.5.0/go.mod h1:mZW8CKdRPY1v87qxC/wUdX5O1qDzXMP5TH3wjfpga6E=
modernc.org/memory v1.5.0 h1:N+/8c5rE6EqugZwHii4IFsaJ7MUhoWX07J5tC/iI5Ds=
modernc.org/memory v1.5.0/go.mod h1:PkUhL0Mugw21sHPeskwZW4D6VscE/GQJOnIpCnW6pSU=
modernc.org/sqlite v1.23.1 h1:nrSBg4aRQQwq59JpvGEQ15tNxoO5pX/kUjcRNwSAGQM=
modernc.org/sqlite v1.23.1/go.mod h1:OrDj17Mggn6MhE+iPbBNf7RGKODDE9NFT0f3EwDzJqk=
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=

36
main.go
View File

@ -1,15 +1,24 @@
package main
import (
"embed"
"fmt"
"git.jmbit.de/filegate/filegate/database"
"git.jmbit.de/filegate/filegate/files"
"git.jmbit.de/filegate/filegate/web"
"github.com/gin-gonic/gin"
"jmbit.de/filegate/database"
"jmbit.de/filegate/files"
"jmbit.de/filegate/web"
"html/template"
"log"
"net/http"
"runtime"
)
//go:embed assets/jquery.min.js assets/custom.css assets/bootstrap/css/*.min.css assets/bootstrap/js/bootstrap.min.js assets/favicon.ico assets/logo.svg
var assetsFS embed.FS
//go:embed templates/*.gohtml
var templatesFS embed.FS
func main() {
if runtime.GOOS == "windows" {
fmt.Println("This Software is not supported on Windows")
@ -17,12 +26,27 @@ func main() {
database.Setup()
files.StorageDirectory()
router := gin.Default()
router.LoadHTMLGlob("templates/*")
router.Static("/assets", "./assets")
templates := template.Must(template.New("").ParseFS(templatesFS, "templates/*.gohtml"))
router.ForwardedByClientIP = true
err := router.SetTrustedProxies([]string{"127.0.0.1"})
if err != nil {
log.Println(err)
}
router.SetHTMLTemplate(templates)
router.StaticFS("/static", http.FS(assetsFS))
router.GET("/", web.GetIndex)
router.GET("/file/:id", web.GetFileView)
router.GET("/file/", web.GetFileList)
router.POST("/file/new", web.PostSubmitFileUrl)
err := router.Run("127.0.0.1:8080")
router.GET("favicon.ico", func(c *gin.Context) {
file, _ := assetsFS.ReadFile("assets/favicon.ico")
c.Data(
http.StatusOK,
"image/x-icon",
file,
)
})
err = router.Run("127.0.0.1:8080")
if err != nil {
log.Fatal(err)
}

View File

@ -18,7 +18,7 @@ CREATE TABLE IF NOT EXISTS files (
md5 TEXT,
status_id INTEGER,
file_cmd TEXT,
created DATE,
created INTEGER,
extension TEXT,
FOREIGN KEY (status_id)
REFERENCES status (id)

77
templates/filelist.gohtml Normal file
View File

@ -0,0 +1,77 @@
{{template "header.gohtml"}}
<div class="starter-template">
<div class="page-header">
<h1>Files</h1>
<p>List of all files and their Status</p>
<p>Total Files: {{.totalEntries}}</p>
</div>
<div id="pagination"></div>
<table class="table table-hover">
<tbody>
<tr>
<th>ID</th>
<th>Name</th>
<th>Original Name</th>
<th>Size</th>
<th>MIME Type</th>
<th>Status</th>
<th>Comment</th>
<th>Created</th>
</tr>
{{ range .FileList}}
<tr>
<td>{{ .Id}}</td>
<td>{{ .Name }}</td>
<td>{{ .OriginalName }}</td>
<td>{{ .Size }}</td>
<td>{{ .Mime }}</td>
<td>{{ .StatusName }}</td>
<td>{{ .Comment }}</td>
<td>{{ .Created }}</td>
</tr>
{{ end }}
</tbody>
</table>
</div>
<script>
// Generate pagination
function generatePagination(itemsPerPage, totalItems) {
// Calculate total pages
let totalPages = Math.ceil(totalItems / itemsPerPage);
let paginationHtml = '';
// Loop to generate page links
for (let i = 1; i <= totalPages; i++) {
paginationHtml += `
<li class="page-item">
<a class="page-link" href="#">${i}</a>
</li>
`;
}
// Output pagination
$('#pagination').html(paginationHtml);
}
// Usage
let itemsPerPage = {{.count}};
let totalItems = {{.totalEntries}};
generatePagination(itemsPerPage, totalItems);
$('#pagination').on('click', 'a', function(e){
// Get clicked page
let page = $(this).text();
// Load data for page
loadProducts(page);
e.preventDefault();
})
</script>
{{template "footer.gohtml"}}

View File

@ -1,8 +1,13 @@
<h1>{{ .title }}</h1>
<p>Status: {{ .fileInfo.Status.name }}</p>
<p>ID: {{ .fileInfo.Id }}</p>
{{template "header.gohtml"}}
<div class="starter-template">
<div class="page-header">
<h1>{{ .title }}</h1>
<p>Status: <span class="badge bg-secondary">{{ .fileInfo.Status.Name }}</span></p>
<p>ID: {{ .fileInfo.Id }}</p>
</div>
<h2>Basic Information</h2>
<table>
<table class="table table-hover">
<tbody>
<tr>
<td>Original Name</td>
@ -14,23 +19,25 @@
</tr>
<tr>
<td>File Size</td>
<td>{{ .fileInfo.Size }}</td>
<td>{{ .fileInfo.Size }} Bytes</td>
</tr>
<tr>
<td>Source URL</td>
<td>{{ .fileInfo.Url }}</td>
</tr>
</tbody>
<tr>
<td>File Extension(s)</td>
<td>{{ .fileInfo.Extension }}</td>
</tr>
<tr>
<td>Comment</td>
<td>{{ .fileInfo.Comment }}</td>
</tr>
</tbody>
</table>
<p> {{ .fileInfo.Comment }}</p>
5
<h2>Advanced Information</h2>
<table>
<table class="table">
<tbody>
<tr>
<td>"file" output</td>
@ -46,11 +53,13 @@
</tr>
<tr>
<td>MD5</td>
<td>{{ .fileInfo.MD5}}</td>
<td>{{ .fileInfo.Md5}}</td>
</tr>
<tr>
<td>Creation Date</td>
<td>{{ .fileInfo.Created}}</td>
</tr>
</tbody>
</table>
</table>
</div>
{{template "footer.gohtml"}}

View File

@ -4,7 +4,7 @@
</footer>
</div> <!-- End of main container -->
<script async src="/assets/jquery.min.js"></script>
<script async src="/assets/bootstrap/js/bootstrap.min.js"></script>
<script async src="/static/assets/jquery.min.js"></script>
<script async src="/static/assets/bootstrap/js/bootstrap.min.js"></script>
</body>
</html>

View File

@ -3,8 +3,8 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link type="text/css" href="/assets/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<link type="text/css" href="/assets/custom.css" rel="stylesheet">
<link type="text/css" href="/static/assets/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<link type="text/css" href="/static/assets/custom.css" rel="stylesheet">
<title>{{ .title }} | Filegate</title>
</head>
<body>

View File

@ -35,6 +35,38 @@
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<h2>Upload existing file</h2>
<div class="form-group">
<form action="/file/upload" method="POST" enctype="multipart/form-data">
<label for="name">Enter Name of the File</label>
<input type="text" name="name" id="name" class="form-control" required>
<label for="comment">Add a Comment with Context</label>
<input type="text" name="comment" id="comment" class="form-control" required>
<label for="file">Select File</label>
<input type="file" name="file" id="file">
<input type="submit" value="Download & Submit" class="btn btn-primary">
</form>
</div>
</div>
<div class="col-md-6">
<h2>Need Help?</h2>
<p>
Welcome to our help center!
Here you can find answers to common questions about using our product and services. We want to make sure you have the best possible experience.
If you're having issues or need help troubleshooting a problem, please browse our FAQ sections using the menu. We've divided help topics into categories to help you find what you need more easily.
Still can't find what you need? No problem! Contact our support team through the live chat widget on the bottom right. Our team is available 24/7 to provide friendly, knowledgeable support. Tell us what questions you have and how we can help.
For account-specific issues, you may need to provide some personal information so we can access your account. Don't worry - we take privacy and security very seriously. We'll never share your data without permission.
Thanks for choosing us! We hope you find our help center useful. Let us know if you have any other questions - we're always looking to improve. Our goal is ensure you have the best experience possible.
</p>
</div>
</div>
</div>
{{template "footer.gohtml"}}

View File

@ -1,5 +1,13 @@
{{template "header.gohtml"}}
<h1>{{ .title }}</h1>
<p>Thank you for submitting a File. You can view its status <a href="/file/{{.fileid}}">HERE</a> </p>
<div class="page-header">
<h1>{{ .title }}</h1>
<p>Thank you for submitting a File. You can view its status <a href="/file/{{.fileid}}">HERE</a></p>
<p>Redirecting...</p>
</div>
<script>
setTimeout(function () {
window.location.href = "/file/{{.fileid}}";
}, 3000)
</script>
{{template "footer.gohtml"}}

7
tests/mainTest.go Normal file
View File

@ -0,0 +1,7 @@
package main
import "testing"
func testIndex(t *testing.T) {
}

30
web/filelist.go Normal file
View File

@ -0,0 +1,30 @@
package web
import (
"git.jmbit.de/filegate/filegate/database"
"github.com/gin-gonic/gin"
"log"
"net/http"
"strconv"
)
func GetFileList(c *gin.Context) {
page, err := strconv.Atoi(c.DefaultQuery("page", "1"))
if err != nil {
log.Println(err)
}
count, err := strconv.Atoi(c.DefaultQuery("count", "50"))
if err != nil {
log.Println(err)
}
totalEntries := database.CountFilesEntries()
fileList, fileListErr := database.GetFileList(page, count)
content := gin.H{
"fileList": fileList,
"error": fileListErr,
"page": page,
"count": count,
"totalEntries": totalEntries,
}
c.HTML(http.StatusOK, "filelist.gohtml", content)
}

View File

@ -2,8 +2,8 @@ package web
import (
"fmt"
"git.jmbit.de/filegate/filegate/database"
"github.com/gin-gonic/gin"
"jmbit.de/filegate/database"
"net/http"
)

View File

@ -1,10 +1,10 @@
package web
import (
"git.jmbit.de/filegate/filegate/database"
"git.jmbit.de/filegate/filegate/files"
"github.com/gin-gonic/gin"
"github.com/google/uuid"
"jmbit.de/filegate/database"
"jmbit.de/filegate/files"
"log"
"net/http"
)
@ -39,3 +39,28 @@ func PostSubmitFileUrl(c *gin.Context) {
}
c.HTML(http.StatusOK, "submitsuccess.gohtml", content)
}
func PostUploadFile(c *gin.Context) {
id := uuid.New().String()
name := c.PostForm("name")
comment := c.PostForm("comment")
url := "uploaded"
err := database.CreateFile(id, name, url, comment)
if err != nil {
c.HTML(http.StatusBadRequest, "error.gohtml", gin.H{"title": "Error", "message": err})
log.Println(err)
return
}
err = files.UploadFile(id, c)
if err != nil {
c.HTML(http.StatusBadRequest, "error.gohtml", gin.H{"title": "Error", "message": err})
log.Println(err)
return
}
content := gin.H{
"title": "Success",
"fileid": id,
}
c.HTML(http.StatusOK, "submitsuccess.gohtml", content)
}