29 lines
4 KiB
PHP
29 lines
4 KiB
PHP
<?php
|
|
include 'auth.php';
|
|
require_once __DIR__ . '/includes/config_manager.php';
|
|
$page_title='Samba - BastionGuard WebUI'; $active_page='samba.php';
|
|
$samba=bg_samba_load_config(); $cfg=['enabled'=>$samba['enabled'], 'shares'=>$samba['shares']];
|
|
$creds=bg_samba_credentials_summary(); $output='';
|
|
if($_SERVER['REQUEST_METHOD']==='POST'){
|
|
csrf_validate(); $a=$_POST['action']??'';
|
|
if($a==='save'){
|
|
$enabled=!empty($_POST['enabled']);
|
|
$shares=bg_normalize_lines($_POST['shares']??'');
|
|
$r=bg_samba_save_config($enabled, $shares);
|
|
bg_flash(($r['code']??1)===0?'success':'warning', ($r['code']??1)===0?'Samba configuration saved in ~/.config/BastionGuard/samba.conf.':($r['output']??'Samba save error.'));
|
|
bg_redirect('samba.php');
|
|
} elseif($a==='scan'){
|
|
$path=trim($_POST['path']??'');
|
|
if($path==='') $output='Invalid path.';
|
|
else { $res=bg_samba_scan_privileged($path); $output=($res['output']??'')."\n\nExit code: ".($res['code']??'?'); }
|
|
}
|
|
}
|
|
include 'includes/header.php'; include 'includes/sidebar.php'; ?>
|
|
<div class="page-title"><div><h1>Samba</h1><p>Reads and saves the real desktop UI file: <code><?= bg_e($samba['path']) ?></code>.</p></div><?= bg_status_badge($cfg['enabled'],'Samba scan enabled','Samba scan disabled') ?></div>
|
|
<div class="row g-4">
|
|
<div class="col-lg-6"><div class="card"><div class="card-body"><h5>Share configuration</h5><p class="small-muted">Read method: <?= bg_e($samba['read']['via'] ?? 'direct') ?> · File status: <?= !empty($samba['read']['exists']) ? 'present' : 'missing' ?></p><form method="post"><?php csrf_field(); ?><input type="hidden" name="action" value="save"><div class="form-check form-switch mb-3"><input class="form-check-input" type="checkbox" name="enabled" <?= $cfg['enabled']?'checked':'' ?>><label class="form-check-label">Enable Samba scan</label></div><label class="form-label">Paths/shares, one per line</label><textarea class="form-control samba-share" name="shares" rows="9" placeholder="smb://server/share/path or /mnt/share"><?= bg_e(implode("\n",$cfg['shares'])) ?></textarea><button class="btn btn-primary mt-3">Save configuration</button></form></div></div></div>
|
|
<div class="col-lg-6"><div class="card mb-4"><div class="card-body"><h5><?= bg_e(bg_t('samba_scan_helper')) ?></h5><?php if($cfg['shares']): ?><table class="table"><thead><tr><th>Share</th><th>Credentials</th><th></th></tr></thead><tbody><?php foreach($cfg['shares'] as $s): $base=preg_match('#^(smb://[^/]+/[^/]+)#',$s,$m)?$m[1]:$s; $cr=$creds['items'][$base]??null; ?><tr><td><code><?= bg_e($s) ?></code></td><td><?php if($cr): ?><span class="badge text-bg-success">user <?= bg_e($cr['user']) ?></span><?php else: ?><span class="badge text-bg-secondary">none</span><?php endif; ?></td><td><form method="post"><?php csrf_field(); ?><input type="hidden" name="action" value="scan"><input type="hidden" name="path" value="<?= bg_e($s) ?>"><button class="btn btn-sm btn-primary"><i class="bi bi-search"></i> Scan now</button></form></td></tr><?php endforeach; ?></tbody></table><?php else: ?><p class="text-muted">No share configured in the Samba file.</p><?php endif; ?></div></div>
|
|
<div class="card"><div class="card-body"><h5>Detected SMB credentials</h5><p class="small-muted">File: <code><?= bg_e($creds['path']) ?></code> via <?= bg_e($creds['read']['via'] ?? 'direct') ?>. Passwords are not displayed.</p><?php if($creds['items']): ?><ul class="list-group list-group-flush"><?php foreach($creds['items'] as $share=>$cr): ?><li class="list-group-item px-0"><code><?= bg_e($share) ?></code><br><span class="small-muted">user: <?= bg_e($cr['user'] ?: '-') ?> · password: <?= $cr['has_pass']?'present':'empty' ?></span></li><?php endforeach; ?></ul><?php else: ?><p class="text-muted">No SMB credentials in cred.conf.</p><?php endif; ?></div></div></div>
|
|
<?php if($output): ?><div class="col-12"><div class="card"><div class="card-body"><h5>Output</h5><?php bg_render_log($output); ?></div></div></div><?php endif; ?>
|
|
</div>
|
|
<?php include 'includes/footer.php'; ?>
|