feat: implement IPC handlers for Nginx and Apache configuration management and service lifecycle control

This commit is contained in:
Ümit Tunç
2026-04-01 20:43:11 +03:00
parent da1640c334
commit 2bc793662e
5 changed files with 89 additions and 17 deletions
+27 -16
View File
@@ -161,12 +161,13 @@ async function rebuildApacheConfig(forceProjects: boolean = false): Promise<{ bi
const configPath = path.join(configService.getBasePath(), 'generated_configs', 'httpd.conf')
// Check if manual edit exists
// Check if manual edit exists for global config
let skipGlobal = false
if (fs.existsSync(configPath) && !forceProjects) {
const content = fs.readFileSync(configPath, 'utf8')
if (content.includes('# MANUAL_EDIT')) {
console.log('Skipping Apache config generation (Manual Edit detected)')
return { binPath, apacheDir, configPath }
console.log('Skipping Apache global config generation (Manual Edit detected)')
skipGlobal = true
}
}
@@ -181,6 +182,14 @@ async function rebuildApacheConfig(forceProjects: boolean = false): Promise<{ bi
const projectConfPath = path.join(projectsConfDir, `${p.host}.conf`)
let shouldGenerate = forceProjects || !fs.existsSync(projectConfPath)
// If file exists, check if it was manually edited (though we don't have a UI for this yet, good for future)
if (!shouldGenerate && fs.existsSync(projectConfPath)) {
const currentContent = fs.readFileSync(projectConfPath, 'utf8')
if (!currentContent.includes('# MANUAL_EDIT')) {
shouldGenerate = true
}
}
if (shouldGenerate) {
const phpPort = portMappingService.getPhpPort(p.phpVersion)
let normalizedPath = p.path.replace(/\\/g, '/')
@@ -194,20 +203,22 @@ async function rebuildApacheConfig(forceProjects: boolean = false): Promise<{ bi
}
}
const projectsInclusion = projects.length > 0
? `Include "${projectsConfDir.replace(/\\/g, '/')}/*.conf"`
: ''
if (!skipGlobal) {
const projectsInclusion = projects.length > 0
? `Include "${projectsConfDir.replace(/\\/g, '/')}/*.conf"`
: ''
await configService.generateConfig('httpd.conf.template', 'httpd.conf', {
PORT: settings.apachePort || '8080',
LISTEN_ADDRESS: settings.allowRemoteAccess ? '0.0.0.0' : '127.0.0.1',
PHP_PORT: settings.phpPort,
ROOT: rootPath.replace(/\\/g, '/'),
SRVROOT: apacheRoot.replace(/\\/g, '/'),
LOG_DIR: logDir.replace(/\\/g, '/'),
PHPMYADMIN_DIR: phpMyAdminService.getPath().replace(/\\/g, '/'),
PROJECTS: projectsInclusion
})
await configService.generateConfig('httpd.conf.template', 'httpd.conf', {
PORT: settings.apachePort || '8080',
LISTEN_ADDRESS: settings.allowRemoteAccess ? '0.0.0.0' : '127.0.0.1',
PHP_PORT: settings.phpPort,
ROOT: rootPath.replace(/\\/g, '/'),
SRVROOT: apacheRoot.replace(/\\/g, '/'),
LOG_DIR: logDir.replace(/\\/g, '/'),
PHPMYADMIN_DIR: phpMyAdminService.getPath().replace(/\\/g, '/'),
PROJECTS: projectsInclusion
})
}
return { binPath, apacheDir, configPath }
}
+32
View File
@@ -259,8 +259,40 @@ export class PhpManagerService {
}
fs.writeFileSync(iniPath, finalLines.join('\n'), 'utf8')
await this.ensureFcgiSettings(version)
return { success: true, message: `Extension ${extName} ${enabled ? 'enabled' : 'disabled'}` }
}
async ensureFcgiSettings(version: string): Promise<boolean> {
const phpDir = path.join(this.binDir, `php-${version}`)
const iniPath = path.join(phpDir, 'php.ini')
if (!fs.existsSync(iniPath)) return false
let content = fs.readFileSync(iniPath, 'utf8')
const lines = content.split(/\r?\n/)
let forceRedirectSet = false
let fixPathinfoSet = false
const newLines = lines.map(line => {
const trimmed = line.trim()
if (trimmed.startsWith('cgi.force_redirect') || trimmed.startsWith(';cgi.force_redirect')) {
forceRedirectSet = true
return 'cgi.force_redirect = 0'
}
if (trimmed.startsWith('cgi.fix_pathinfo') || trimmed.startsWith(';cgi.fix_pathinfo')) {
fixPathinfoSet = true
return 'cgi.fix_pathinfo = 1'
}
return line
})
if (!forceRedirectSet) newLines.push('cgi.force_redirect = 0')
if (!fixPathinfoSet) newLines.push('cgi.fix_pathinfo = 1')
fs.writeFileSync(iniPath, newLines.join('\n'), 'utf8')
return true
}
}
export const phpManagerService = new PhpManagerService()