|
| 1 | +/** |
| 2 | + * simple login with password only |
| 3 | + */ |
| 4 | + |
| 5 | +import { |
| 6 | + isDev, |
| 7 | + isMac, |
| 8 | + isWin, |
| 9 | + packInfo, |
| 10 | + home, |
| 11 | + extIconPath, |
| 12 | + defaultUserName, |
| 13 | + cwd |
| 14 | +} from '../common/runtime-constants.js' |
| 15 | +import { migrationNotice } from './fancy-console.js' |
| 16 | +import fsFunctions from '../common/fs-functions.js' |
| 17 | +import copy from 'json-deep-copy' |
| 18 | +import { createToken } from './jwt.js' |
| 19 | +import { logDir } from '../server/session-log.js' |
| 20 | +import { resolve } from 'path' |
| 21 | +import fs from 'fs' |
| 22 | + |
| 23 | +const defaultAIPreset = { |
| 24 | + baseURLAI: 'https://ai.electerm.org/api/ai', |
| 25 | + apiPathAI: '/chat/completions', |
| 26 | + modelAI: 'mistral-small-latest', |
| 27 | + authHeaderNameAI: 'Authorization: Bearer', |
| 28 | + id: 'ai.electerm.org', |
| 29 | + nameAI: 'ai.electerm.org(default free)' |
| 30 | +} |
| 31 | + |
| 32 | +function buildServer () { |
| 33 | + return `http://${process.env.HOST}:${process.env.PORT}` |
| 34 | +} |
| 35 | + |
| 36 | +export async function index (req, res) { |
| 37 | + const server = process.env.SERVER || (isDev ? buildServer() : '') |
| 38 | + const cdn = process.env.CDN || server |
| 39 | + const hasNodePty = false |
| 40 | + // All session types the app knows about. |
| 41 | + const supportSessionTypes = [ |
| 42 | + 'ssh', |
| 43 | + 'telnet', |
| 44 | + 'rdp', |
| 45 | + 'vnc', |
| 46 | + 'ftp', |
| 47 | + 'spice' |
| 48 | + ] |
| 49 | + const data = { |
| 50 | + isDev, |
| 51 | + isMac, |
| 52 | + isWin, |
| 53 | + packInfo, |
| 54 | + home, |
| 55 | + version: packInfo.version, |
| 56 | + siteName: packInfo.name, |
| 57 | + defaultAIPreset, |
| 58 | + fsFunctions, |
| 59 | + isWebApp: true, |
| 60 | + disableUpgradeCheck: true, |
| 61 | + versionFile: 'version-android.html', |
| 62 | + downloadUpgradeFromBrowser: true, |
| 63 | + extIconPath: cdn + extIconPath, |
| 64 | + cdn, |
| 65 | + sessionLogPath: logDir, |
| 66 | + query: req.query, |
| 67 | + server, |
| 68 | + hasNodePty, |
| 69 | + needMigrate: false, |
| 70 | + supportSessionTypes |
| 71 | + } |
| 72 | + const { |
| 73 | + ENABLE_AUTH |
| 74 | + } = process.env |
| 75 | + if (!ENABLE_AUTH) { |
| 76 | + data.tokenElecterm = createToken() |
| 77 | + } |
| 78 | + data._global = copy(data) |
| 79 | + res.render('index', data) |
| 80 | +} |
0 commit comments