-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
195 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
name: "Server" | ||
|
||
functions: | ||
http_file_server: false | ||
local_send_server: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,37 @@ | ||
package config | ||
|
||
var Names = []string{ | ||
"Alpha", "Bravo", "Charlie", "Delta", "Echo", | ||
"Foxtrot", "Golf", "Hotel", "India", "Juliett", | ||
"Kilo", "Lima", "Mike", "November", "Oscar", | ||
"Papa", "Quebec", "Romeo", "Sierra", "Tango", | ||
"Uniform", "Victor", "Whiskey", "X-ray", "Yankee", "Zulu", | ||
import ( | ||
"io" | ||
"log" | ||
"os" | ||
|
||
"gopkg.in/yaml.v2" | ||
) | ||
|
||
type Config struct { | ||
NameOfDevice string `yaml:"name"` | ||
Functions struct { | ||
HttpFileServer bool `yaml:"http_file_server"` | ||
LocalSendServer bool `yaml:"local_send_server"` | ||
} `yaml:"functions"` | ||
} | ||
|
||
var NameOfDevice string = "Server" | ||
var ConfigData Config | ||
|
||
func init() { | ||
configFile, err := os.Open("config.yaml") | ||
if err != nil { | ||
log.Fatalf("Error opening config file: %v", err) | ||
} | ||
defer configFile.Close() | ||
|
||
bytes, err := io.ReadAll(configFile) | ||
if err != nil { | ||
log.Fatalf("Error reading config file: %v", err) | ||
} | ||
|
||
err = yaml.Unmarshal(bytes, &ConfigData) | ||
if err != nil { | ||
log.Fatalf("Error parsing config file: %v", err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package handlers | ||
|
||
import ( | ||
"html/template" | ||
"net/http" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
) | ||
|
||
const uploadDir = "./uploads" | ||
|
||
func GetFilesFromDir(dir string) ([]os.DirEntry, error) { | ||
entries, err := os.ReadDir(dir) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return entries, nil | ||
} | ||
|
||
func FileServerHandler(w http.ResponseWriter, r *http.Request) { | ||
file := strings.TrimPrefix(r.URL.Path, "/uploads/") | ||
http.ServeFile(w, r, filepath.Join(uploadDir, file)) | ||
} | ||
|
||
func IndexFileHandler(w http.ResponseWriter, r *http.Request) { | ||
dirPath := filepath.Join(uploadDir, strings.TrimPrefix(r.URL.Path, "/uploads/")) | ||
|
||
info, err := os.Stat(dirPath) | ||
if os.IsNotExist(err) { | ||
http.NotFound(w, r) | ||
return | ||
} else if err != nil { | ||
http.Error(w, err.Error(), http.StatusInternalServerError) | ||
return | ||
} | ||
|
||
if info.IsDir() { | ||
files, err := GetFilesFromDir(dirPath) | ||
if err != nil { | ||
http.Error(w, err.Error(), http.StatusInternalServerError) | ||
return | ||
} | ||
|
||
tmpl := template.Must(template.ParseFiles("templates/cloudstorage.html")) | ||
data := struct { | ||
Path string | ||
Files []os.DirEntry | ||
}{ | ||
Path: r.URL.Path, | ||
Files: files, | ||
} | ||
|
||
err = tmpl.Execute(w, data) | ||
if err != nil { | ||
http.Error(w, err.Error(), http.StatusInternalServerError) | ||
} | ||
} else { | ||
http.ServeFile(w, r, dirPath) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
body { | ||
font-family: Arial, sans-serif; | ||
background-color: #f4f4f4; | ||
margin: 0; | ||
padding: 0; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
min-height: 100vh; | ||
} | ||
.container { | ||
background-color: #fff; | ||
padding: 20px 40px; | ||
border-radius: 10px; | ||
box-shadow: 0 0 20px rgba(0, 0, 0, 0.1); | ||
width: 80%; | ||
max-width: 700px; | ||
box-sizing: border-box; | ||
} | ||
h1 { | ||
color: #333; | ||
text-align: center; | ||
margin-bottom: 30px; | ||
font-size: 2em; | ||
} | ||
ul { | ||
list-style: none; | ||
padding: 0; | ||
margin: 0; | ||
} | ||
li { | ||
margin: 10px 0; | ||
padding: 10px; | ||
border-radius: 5px; | ||
transition: background-color 0.3s, transform 0.3s; | ||
} | ||
li:hover { | ||
background-color: #f1f1f1; | ||
transform: scale(1.02); | ||
} | ||
a { | ||
text-decoration: none; | ||
color: #007BFF; | ||
font-weight: bold; | ||
} | ||
a:hover { | ||
text-decoration: underline; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Uploads</title> | ||
<link href="/static/css/style.css" rel="stylesheet"> | ||
</head> | ||
<body> | ||
<div class="container"> | ||
<h1>Uploads</h1> | ||
<ul> | ||
{{range .Files}} | ||
<li> | ||
{{if .IsDir}} | ||
<a href="{{$.Path}}{{.Name}}/">{{.Name}}/</a> | ||
{{else}} | ||
<a href="{{$.Path}}{{.Name}}">{{.Name}}</a> | ||
{{end}} | ||
</li> | ||
{{end}} | ||
</ul> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters