Files
cdn-star/admin/expert/edit_dapnetgateway.php
2026-07-19 18:27:27 +08:00

114 lines
3.9 KiB
PHP

<?php
// Load the language support
require_once('../config/language.php');
//Load the Pi-Star Release file
$pistarReleaseConfig = '/etc/pistar-release';
$configPistarRelease = array();
$configPistarRelease = parse_ini_file($pistarReleaseConfig, true);
//Load the Version Info
require_once('../config/version.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" lang="en">
<head>
<meta name="robots" content="index" />
<meta name="robots" content="follow" />
<meta name="language" content="English" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="Author" content="Andrew Taylor (MW0MWZ)" />
<meta name="Description" content="CDN Expert Editor" />
<meta name="KeyWords" content="CDN" />
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="pragma" content="no-cache" />
<link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon">
<meta http-equiv="Expires" content="0" />
<title>CDN - Digital Voice Dashboard - Expert Editor</title>
<link rel="stylesheet" type="text/css" href="../css/pistar-css.php" />
</head>
<body>
<div class="container">
<?php include './header-menu.inc'; ?>
<div class="contentwide">
<?php
// Do some file wrangling...
exec('sudo cp /etc/dapnetgateway /tmp/oXyEVXYSisDX.tmp');
exec('sudo chown www-data:www-data /tmp/oXyEVXYSisDX.tmp');
exec('sudo chmod 664 /tmp/oXyEVXYSisDX.tmp');
// ini file to open
$filepath = '/tmp/oXyEVXYSisDX.tmp';
// after the form submit
if($_POST) {
$data = $_POST;
//update ini file, call function
update_ini_file($data, $filepath);
}
// this is the function going to update your ini file
function update_ini_file($data, $filepath) {
$content = "";
// parse the ini file to get the sections
// parse the ini file using default parse_ini_file() PHP function
$parsed_ini = parse_ini_file($filepath, true);
foreach($data as $section=>$values) {
// UnBreak special cases
$section = str_replace("_", " ", $section);
$content .= "[".$section."]\n";
//append the values
foreach($values as $key=>$value) {
$content .= $key."=".$value."\n";
}
$content .= "\n";
}
// write it into file
if (!$handle = fopen($filepath, 'w')) {
return false;
}
$success = fwrite($handle, $content);
fclose($handle);
// Updates complete - copy the working file back to the proper location
exec('sudo mount -o remount,rw /'); // Make rootfs writable
exec('sudo cp /tmp/oXyEVXYSisDX.tmp /etc/dapnetgateway'); // Move the file back
exec('sudo chmod 644 /etc/dapnetgateway'); // Set the correct runtime permissions
exec('sudo chown root:root /etc/dapnetgateway'); // Set the owner
exec('sudo mount -o remount,ro /'); // Make rootfs read-only
// Reload the affected daemon
exec('sudo systemctl restart dapnetgateway.service'); // Reload the daemon
return $success;
}
// parse the ini file using default parse_ini_file() PHP function
$parsed_ini = parse_ini_file($filepath, true);
echo '<form action="" method="post">'."\n";
foreach($parsed_ini as $section=>$values) {
// keep the section as hidden text so we can update once the form submitted
echo "<input type=\"hidden\" value=\"$section\" name=\"$section\" />\n";
echo "<div class=\"settings-card\">\n";
echo "<h3>$section</h3>\n";
// print all other values as input fields, so can edit.
// note the name='' attribute it has both section and key
foreach($values as $key=>$value) {
echo "<div class=\"field-row\"><div>$key</div><div><input type=\"text\" name=\"{$section}[$key]\" value=\"$value\" /></div></div>\n";
}
echo "</div>\n";
echo '<div class="field-actions"><input type="submit" value="'.$lang['apply'].'" /></div>'."\n";
}
echo "</form>";
?>
</div>
</div>
</body>
</html>