權限設定 apache
# visudo -f /etc/sudoers
增加
apache ALL=NOPASSWD: /backups/script.sh
/backups/script.sh針對這檔案不需要密碼
-----------------
網頁
<?php
$dirPath = '../../backup';
if (is_dir($dirPath)) {
$dir = opendir($dirPath);
while ($file = readdir($dir)) {
if (preg_match("/.ldif/i", $file)) {
echo '<a href="?file=' . $file . '">' . $file . '</a>';
echo '<br>';
}
}
closedir($dir);
}
if (isset($_GET['file'])) {
$result = shell_exec('sudo ../../../../backups/script.sh' . ' ' . $_GET['file'] . ' 2>&1');
echo $result;
}
留言
張貼留言