Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7f20612b94 | |||
| 624f7bc7c6 |
@@ -60,7 +60,7 @@ func run() int {
|
||||
|
||||
cfg, err = codit.LoadConfigFilesWithEnvPrefix(configPaths, codit.EnvPrefixFromServerId(PROGRAM_NAME))
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "ERROR: load config - %v\n", err)
|
||||
fmt.Fprintf(os.Stderr, "ERROR: load config - %s\n", err.Error())
|
||||
return 1
|
||||
}
|
||||
if logFile != "" {
|
||||
@@ -68,7 +68,7 @@ func run() int {
|
||||
}
|
||||
logger, err = newLoggerFromConfig(PROGRAM_NAME, cfg)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "ERROR: init logger - %v\n", err)
|
||||
fmt.Fprintf(os.Stderr, "ERROR: init logger - %s\n", err.Error())
|
||||
return 1
|
||||
}
|
||||
defer logger.Close()
|
||||
@@ -79,14 +79,15 @@ func run() int {
|
||||
|
||||
server, err = codit.NewServerWithId(&cfg, logger, PROGRAM_NAME)
|
||||
if err != nil {
|
||||
logger.Write("", codit.LOG_ERROR, "init app: %v", err)
|
||||
logger.Write("", codit.LOG_ERROR, "init app - %s", err.Error())
|
||||
return 1
|
||||
}
|
||||
defer server.Close()
|
||||
logger.Write("", codit.LOG_INFO, "started %s %s - %s", PROGRAM_NAME, PROGRAM_VERSION, server.InfoString())
|
||||
|
||||
err = server.ServeContext(ctx)
|
||||
if err != nil {
|
||||
logger.Write("", codit.LOG_ERROR, "server failed: %v", err)
|
||||
logger.Write("", codit.LOG_ERROR, "server failed - %s", err.Error())
|
||||
return 1
|
||||
}
|
||||
logger.Write("", codit.LOG_INFO, "shutdown complete - %s %s", PROGRAM_NAME, PROGRAM_VERSION)
|
||||
|
||||
@@ -459,20 +459,23 @@ func (s *Store) ListActiveSessions(now int64) ([]models.GUISession, error) {
|
||||
var out []models.GUISession
|
||||
var err error
|
||||
rows, err = s.Query(`SELECT s.id, u.public_id, u.username, u.display_name, u.is_admin,
|
||||
s.created_at, s.expires_at, s.totp_verified,
|
||||
s.created_at, s.expires_at, COALESCE(t.enabled, 0), s.totp_verified,
|
||||
CASE WHEN s.oidc_id_token != '' THEN 1 ELSE 0 END
|
||||
FROM sessions s JOIN users u ON u.id = s.user_id
|
||||
LEFT JOIN user_totp t ON t.user_id = u.id
|
||||
WHERE s.expires_at > ?
|
||||
ORDER BY s.created_at DESC`, now)
|
||||
if err != nil { return nil, err }
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
var item models.GUISession
|
||||
var totpEnabled int64
|
||||
var totp int64
|
||||
var oidc int64
|
||||
err = rows.Scan(&item.ID, &item.UserID, &item.Username, &item.DisplayName, &item.IsAdmin,
|
||||
&item.CreatedAt, &item.ExpiresAt, &totp, &oidc)
|
||||
&item.CreatedAt, &item.ExpiresAt, &totpEnabled, &totp, &oidc)
|
||||
if err != nil { return nil, err }
|
||||
item.TOTPEnabled = totpEnabled != 0
|
||||
item.TOTPVerified = totp != 0
|
||||
item.HasOIDC = oidc != 0
|
||||
out = append(out, item)
|
||||
|
||||
@@ -10,6 +10,7 @@ type GUISession struct {
|
||||
IsAdmin bool `json:"is_admin"`
|
||||
CreatedAt int64 `json:"created_at"`
|
||||
ExpiresAt int64 `json:"expires_at"`
|
||||
TOTPEnabled bool `json:"totp_enabled"`
|
||||
TOTPVerified bool `json:"totp_verified"`
|
||||
HasOIDC bool `json:"has_oidc"`
|
||||
Current bool `json:"current"`
|
||||
|
||||
@@ -747,6 +747,10 @@ func (app *Server) stopBackgroundManagers() {
|
||||
if app.notify_relay != nil { app.notify_relay.Wait() }
|
||||
}
|
||||
|
||||
func (app *Server) InfoString() string {
|
||||
return fmt.Sprintf("%s (%s)", app.serverId, app.siteName)
|
||||
}
|
||||
|
||||
func (app *Server) Serve() error {
|
||||
return app.ServeContext(context.Background())
|
||||
}
|
||||
|
||||
+3
-3
@@ -1,3 +1,3 @@
|
||||
VITE_APP_SERVER_ID=codit
|
||||
VITE_APP_SERVER_TITLE=Codit
|
||||
VITE_APP_SITE_NAME=
|
||||
VITE_APP_SERVER_ID=server
|
||||
VITE_APP_SERVER_TITLE=Server
|
||||
VITE_APP_SITE_NAME=Site
|
||||
|
||||
@@ -1905,6 +1905,7 @@ export interface GUISession {
|
||||
is_admin: boolean
|
||||
created_at: number
|
||||
expires_at: number
|
||||
totp_enabled: boolean
|
||||
totp_verified: boolean
|
||||
has_oidc: boolean
|
||||
current: boolean
|
||||
|
||||
@@ -21,11 +21,11 @@ declare global {
|
||||
const runtime = window.__APP_INFO__
|
||||
|
||||
export const defaultAppBrand: AppBrand = {
|
||||
server_id: runtime?.server_id || import.meta.env.VITE_APP_SERVER_ID || 'codit',
|
||||
server_title: runtime?.server_title || import.meta.env.VITE_APP_SERVER_TITLE || 'Codit',
|
||||
site_name: runtime?.site_name || import.meta.env.VITE_APP_SITE_NAME || 'Codit',
|
||||
storagePrefix: runtime?.server_id || import.meta.env.VITE_APP_SERVER_ID || 'codit',
|
||||
sanURIPrefix: `urn:${runtime?.server_id || import.meta.env.VITE_APP_SERVER_ID || 'codit'}:user:`
|
||||
server_id: runtime?.server_id || import.meta.env.VITE_APP_SERVER_ID || 'server',
|
||||
server_title: runtime?.server_title || import.meta.env.VITE_APP_SERVER_TITLE || 'Server',
|
||||
site_name: runtime?.site_name || import.meta.env.VITE_APP_SITE_NAME || 'Site',
|
||||
storagePrefix: runtime?.server_id || import.meta.env.VITE_APP_SERVER_ID || 'server',
|
||||
sanURIPrefix: `urn:${runtime?.server_id || import.meta.env.VITE_APP_SERVER_ID || 'server'}:user:`
|
||||
}
|
||||
|
||||
export const BrandContext = createContext<AppBrand>(defaultAppBrand)
|
||||
|
||||
@@ -102,7 +102,7 @@ export default function AdminSessionsPage() {
|
||||
renderCell: (s) => (
|
||||
<Box sx={{ display: 'flex', alignItems: 'center', gap: 0.5 }}>
|
||||
<Chip size="small" variant="outlined" label={s.has_oidc ? 'OIDC' : 'password'} sx={{ height: 18 }} />
|
||||
{s.totp_verified ? <Chip size="small" variant="outlined" color="success" label="2FA" sx={{ height: 18 }} /> : null}
|
||||
{s.totp_enabled && s.totp_verified ? <Chip size="small" variant="outlined" color="success" label="2FA" sx={{ height: 18 }} /> : null}
|
||||
</Box>
|
||||
)
|
||||
},
|
||||
|
||||
@@ -7,8 +7,9 @@ export default defineConfig({
|
||||
{
|
||||
// in the development, i want the same text replacement as backend/server.go
|
||||
name: "replace-placeholder",
|
||||
apply: "serve", // only in the development server mode
|
||||
transformIndexHtml(html) {
|
||||
return html.replaceAll("%SERVER_ID%", "codit").replaceAll("%SERVER_NAME%", "Codit").replaceAll("%SITE_NAME%", "Codit Development Via Vite");
|
||||
return html.replaceAll("%SERVER_ID%", "codit").replaceAll("%SERVER_TITLE%", "Codit").replaceAll("%SITE_NAME%", "Codit Development Via Vite");
|
||||
}
|
||||
}
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user