mirror of
https://github.com/webmin/webmin.git
synced 2026-02-03 14:13:29 +00:00
Read and write ini files as the permission user
This commit is contained in:
@@ -13,7 +13,7 @@ print $text{'manual_desc'},"<p>\n";
|
||||
print &ui_form_start("save_manual.cgi", "form-data");
|
||||
print &ui_hidden("file", $in{'file'}),"\n";
|
||||
print &ui_hidden("oneini", $in{'oneini'}),"\n";
|
||||
print &ui_textarea("data", &read_file_contents($in{'file'}), 20, 80);
|
||||
print &ui_textarea("data", &read_file_contents_as_user($in{'file'}), 20, 80);
|
||||
print &ui_form_end([ [ "save", $text{'save'} ] ]);
|
||||
|
||||
&ui_print_footer("", $text{'index_return'});
|
||||
|
||||
@@ -231,6 +231,33 @@ else {
|
||||
}
|
||||
}
|
||||
|
||||
# read_file_contents_as_user(file)
|
||||
sub read_file_contents_as_user
|
||||
{
|
||||
local ($file) = @_;
|
||||
if ($access{'user'} && $access{'user'} ne 'root' && $< == 0) {
|
||||
return &eval_as_unix_user(
|
||||
$access{'user'}, sub { &read_file_contents($file) });
|
||||
}
|
||||
else {
|
||||
return &read_file_contents($file);
|
||||
}
|
||||
}
|
||||
|
||||
# write_file_contents_as_user(file, data)
|
||||
# Writes out the contents of some file
|
||||
sub write_file_contents_as_user
|
||||
{
|
||||
local ($file, $data) = @_;
|
||||
if ($access{'user'} && $access{'user'} ne 'root' && $< == 0) {
|
||||
return &eval_as_unix_user(
|
||||
$access{'user'}, sub { &write_file_contents($file, $data) });
|
||||
}
|
||||
else {
|
||||
&write_file_contents($file, $data);
|
||||
}
|
||||
}
|
||||
|
||||
# flush_file_lines_as_user(file)
|
||||
# Writes out a file as the Unix user configured in this module's ACL
|
||||
sub flush_file_lines_as_user
|
||||
|
||||
@@ -12,9 +12,7 @@ $in{'data'} =~ s/\r//g;
|
||||
$in{'data'} =~ /\S/ || &error($text{'manual_edata'});
|
||||
|
||||
# Save the file
|
||||
&open_lock_tempfile(FILE, ">$in{'file'}");
|
||||
&print_tempfile(FILE, $in{'data'});
|
||||
&close_tempfile(FILE);
|
||||
&write_file_contents_as_user($in{'file'}, $in{'data'});
|
||||
|
||||
&graceful_apache_restart();
|
||||
&webmin_log("manual", $in{'file'});
|
||||
|
||||
Reference in New Issue
Block a user