Skip to content

Commit

Permalink
[release] v0.17.6
Browse files Browse the repository at this point in the history
  • Loading branch information
azukaar committed Jan 13, 2025
1 parent 7d497db commit 1abf4a0
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 12 deletions.
8 changes: 8 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## Version 0.17.6
- Can now chose between plain or formatted logs
- Added "force update" button in service mode
- Fixed issues related to fstab management

## Version 0.17.5
- Fixed issue with TCP proxy timeouts

## Version 0.17.4
- Hide update button in container
- Fix issue with allowHTTPLocal and the TCP Proxy
Expand Down
12 changes: 11 additions & 1 deletion client/src/api/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,15 @@ function terminal(startCmd = "bash") {
return new WebSocket(protocol + window.location.host + '/cosmos/api/terminal/'+startCmd)
}

function forceAutoUpdate() {
return wrap(fetch('/cosmos/api/force-server-update', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
}));
}

const isDemo = import.meta.env.MODE === 'demo';

let auth = _auth;
Expand Down Expand Up @@ -281,5 +290,6 @@ export {
terminal,
cron,
rclone,
restartServer
restartServer,
forceAutoUpdate
};
10 changes: 10 additions & 0 deletions client/src/pages/config/users/configman.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const ConfigManagement = () => {
const [saveLabel, setSaveLabel] = React.useState(t('global.saveAction'));
const {role} = useClientInfos();
const isAdmin = role === "2";
const [isCheckingUpdate, setIsCheckingUpdate] = React.useState(false);

function refresh() {
API.config.get().then((res) => {
Expand Down Expand Up @@ -295,6 +296,15 @@ const ConfigManagement = () => {
</Grid>

{status && !status.containerized && <>
<Grid item xs={3}>
<LoadingButton loading={isCheckingUpdate} variant="outlined" color="primary" onClick={() => {
setIsCheckingUpdate(true);
API.forceAutoUpdate().then(() => {
setIsCheckingUpdate(false);
})
}}>{t('mgmt.config.general.forceAutoUpdateButton')}</LoadingButton>
</Grid>

<CosmosCheckbox
label={t('mgmt.config.general.autoupdates')}
name="AutoUpdate"
Expand Down
1 change: 1 addition & 0 deletions client/src/utils/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
"mgmt.config.email.tlsCheckbox.tlsLabel": "SMTP Uses TLS",
"mgmt.config.email.usernameInput.usernameHelperText": "SMTP Username",
"mgmt.config.email.usernameInput.usernameLabel": "SMTP Username",
"mgmt.config.general.forceAutoUpdateButton": "Check for update now",
"mgmt.config.general.backupDirInput.backupDirHelperText": "Directory where backups will be stored (relative to the host server `/`)",
"mgmt.config.general.backupDirInput.backupDirLabel": "Backup Output Directory (relative to the host server `/`)",
"mgmt.config.general.configFileInfo": "This page allow you to edit the configuration file. Any Environment Variable overwritting configuration won't appear here.",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cosmos-server",
"version": "0.17.5",
"version": "0.17.6",
"description": "",
"main": "test-server.js",
"bugs": {
Expand Down
2 changes: 0 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@
<h3 align="center">Thanks to the sponsors:</h3></br>
<p align="center"><a href="https://github.com/soldier1"><img src="https://avatars.githubusercontent.com/soldier1" style="border-radius:48px" width="48" height="48" alt="null" title="null" /></a>
<a href="https://github.com/Fortcraft"><img src="https://avatars.githubusercontent.com/Fortcraft" style="border-radius:48px" width="48" height="48" alt="null" title="null" /></a>
<a href="https://github.com/Gordi90"><img src="https://avatars.githubusercontent.com/Gordi90" style="border-radius:48px" width="48" height="48" alt="Dér Kristóf Gordon" title="Dér Kristóf Gordon" /></a>
<a href="https://github.com/lilkidsuave"><img src="https://avatars.githubusercontent.com/lilkidsuave" style="border-radius:48px" width="48" height="48" alt="null" title="null" /></a>
<a href="https://github.com/phobes"><img src="https://avatars.githubusercontent.com/phobes" style="border-radius:48px" width="48" height="48" alt="Phobes" title="Phobes" /></a>
<a href="https://github.com/AstroMando"><img src="https://avatars.githubusercontent.com/AstroMando" style="border-radius:48px" width="48" height="48" alt="null" title="null" /></a>
<a href="https://github.com/riczescaran"><img src="https://avatars.githubusercontent.com/riczescaran" style="border-radius:48px" width="48" height="48" alt="Ricardo Escaran" title="Ricardo Escaran" /></a>
<a href="https://github.com/AKAHackoon"><img src="https://avatars.githubusercontent.com/AKAHackoon" style="border-radius:48px" width="48" height="48" alt="null" title="null" /></a>
<a href="https://github.com/factorten"><img src="https://avatars.githubusercontent.com/factorten" style="border-radius:48px" width="48" height="48" alt="Carr" title="Carr" /></a>
<a href="https://github.com/bgro82"><img src="https://avatars.githubusercontent.com/bgro82" style="border-radius:48px" width="48" height="48" alt="null" title="null" /></a>
</p><!-- /sponsors -->

Expand Down
1 change: 1 addition & 0 deletions src/httpServer.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ func InitServer() *mux.Router {
srapi.HandleFunc("/api/status", StatusRoute)
srapi.HandleFunc("/api/restart-server", restartHostMachineRoute)
srapi.HandleFunc("/_logs", LogsRoute)
srapi.HandleFunc("/api/force-server-update", ForceUpdateRoute)
srapi.HandleFunc("/api/can-send-email", CanSendEmail)
srapi.HandleFunc("/api/newInstall", NewInstallRoute)
srapi.HandleFunc("/api/logout", user.UserLogout)
Expand Down
2 changes: 1 addition & 1 deletion src/storage/mergerFS.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func MountMergerFS(paths []string, mountpoint string, opts string, permanent boo
}

// Format the fstab entry
fstabEntry := fmt.Sprintf("%s %s mergerfs use_ino,cache.files=partial,dropcacheonclose=true,allow_other,category.create=mfs%s 0 0\n", strings.Join(paths, ":"), mountpoint, opts)
fstabEntry := fmt.Sprintf("\n%s %s mergerfs use_ino,cache.files=partial,dropcacheonclose=true,allow_other,category.create=mfs%s 0 0\n", strings.Join(paths, ":"), mountpoint, opts)

// Append to /etc/fstab
file, err := os.OpenFile("/etc/fstab", os.O_APPEND|os.O_WRONLY, 0644)
Expand Down
16 changes: 13 additions & 3 deletions src/storage/mounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func Mount(path, mountpoint string, permanent bool, chown string) error {
}

// Format the fstab entry
fstabEntry := fmt.Sprintf("%s %s auto defaults 0 0\n", path, mountpoint)
fstabEntry := fmt.Sprintf("\n%s %s auto defaults 0 0\n", path, mountpoint)

// Append to /etc/fstab
file, err := os.OpenFile("/etc/fstab", os.O_APPEND|os.O_WRONLY, 0644)
Expand Down Expand Up @@ -183,6 +183,8 @@ func Unmount(mountpoint string, permanent bool) error {

// isMountPointInFstab checks if the given mountpoint is already in /etc/fstab.
func isMountPointInFstab(mountpoint string) (bool, error) {
mountpoint = strings.Replace(mountpoint, "/var/mnt/", "/mnt/", 1)

file, err := os.Open("/etc/fstab")
if err != nil {
return false, err
Expand All @@ -191,7 +193,7 @@ func isMountPointInFstab(mountpoint string) (bool, error) {

scanner := bufio.NewScanner(file)
for scanner.Scan() {
if strings.Contains(scanner.Text(), mountpoint) {
if strings.Contains(scanner.Text(), " " + mountpoint + " ") {
return true, nil
}
}
Expand All @@ -205,6 +207,8 @@ func isMountPointInFstab(mountpoint string) (bool, error) {

// removeFstabEntry removes an entry for the specified mountpoint from /etc/fstab.
func removeFstabEntry(mountpoint string) error {
mountpoint = strings.Replace(mountpoint, "/var/mnt/", "/mnt/", 1)

file, err := os.Open("/etc/fstab")
if err != nil {
return err
Expand All @@ -215,7 +219,11 @@ func removeFstabEntry(mountpoint string) error {
scanner := bufio.NewScanner(file)
for scanner.Scan() {
line := scanner.Text()
if !strings.Contains(line, mountpoint) {

isComment := strings.HasPrefix(line, "#")
isEmpty := len(strings.TrimSpace(line)) == 0

if !isEmpty && (!strings.Contains(line, " " + mountpoint + " ") || isComment) {
lines = append(lines, line)
}
}
Expand All @@ -224,6 +232,8 @@ func removeFstabEntry(mountpoint string) error {
return err
}

utils.Debug("[STORAGE] Writing new /etc/fstab")

return os.WriteFile("/etc/fstab", []byte(strings.Join(lines, "\n")), 0644)
}

Expand Down
19 changes: 16 additions & 3 deletions src/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,6 @@ func MemStatusRoute(w http.ResponseWriter, req *http.Request) {
}

if(req.Method == "GET") {


json.NewEncoder(w).Encode(map[string]interface{}{
"status": "OK",
"data": map[string]interface{}{
Expand Down Expand Up @@ -175,7 +173,7 @@ func LogsRoute(w http.ResponseWriter, req *http.Request) {

if(req.Method == "GET") {
// read log file
logFile, err := os.Open(utils.CONFIGFOLDER + "cosmos.log")
logFile, err := os.Open(utils.CONFIGFOLDER + "cosmos.plain.log")

if err != nil {
utils.Error("Logs: Error reading log file", err)
Expand Down Expand Up @@ -205,6 +203,21 @@ func LogsRoute(w http.ResponseWriter, req *http.Request) {
}
}

func ForceUpdateRoute(w http.ResponseWriter, req *http.Request) {
if utils.AdminOnly(w, req) != nil {
return
}

if(req.Method == "POST") {
utils.Log("API: Force update")
checkUpdatesAvailable()
} else {
utils.Error("Logs: Method not allowed" + req.Method, nil)
utils.HTTPError(w, "Method not allowed", http.StatusMethodNotAllowed, "HTTP001")
return
}
}

func restartHostMachineRoute(w http.ResponseWriter, req *http.Request) {
if utils.AdminOnly(w, req) != nil {
return
Expand Down
18 changes: 17 additions & 1 deletion src/utils/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ type LogLevel int
var (
logger *log.Logger
errorLogger *log.Logger

loggerPlain *log.Logger
errorLoggerPlain *log.Logger
)

func InitLogs() {
Expand All @@ -51,6 +54,14 @@ func InitLogs() {
Compress: true,
}

ljLoggerPlain := &lumberjack.Logger{
Filename: CONFIGFOLDER + "cosmos.plain.log",
MaxSize: 15, // megabytes
MaxBackups: 2,
MaxAge: 16, // days
Compress: true,
}

// Create a multi-writer to log to both file and stdout
// multiWriter := io.MultiWriter(ljLogger, os.Stdout)

Expand All @@ -60,6 +71,9 @@ func InitLogs() {
// Create loggers
logger = log.New(ljLogger, "", log.Ldate|log.Ltime)
errorLogger = log.New(ljLogger, "", log.Ldate|log.Ltime)

loggerPlain = log.New(ljLoggerPlain, "", log.Ldate|log.Ltime)
errorLoggerPlain = log.New(ljLoggerPlain, "", log.Ldate|log.Ltime)
}

func RawLogMessage(level LogLevel, prefix, prefixColor, color, message string) {
Expand All @@ -69,14 +83,16 @@ func RawLogMessage(level LogLevel, prefix, prefixColor, color, message string) {

log.Println(logString)

if logger == nil || errorLogger == nil {
if logger == nil || errorLogger == nil || loggerPlain == nil || errorLoggerPlain == nil {
return
}

if level >= ERROR {
errorLogger.Println(logString)
errorLoggerPlain.Println(prefix + " " + message)
} else {
logger.Println(logString)
loggerPlain.Println(prefix + " " + message)
}
}
}
Expand Down

0 comments on commit 1abf4a0

Please sign in to comment.