[Home]WikiPatches/DoEditConfig

UseModWiki | WikiPatches | RecentChanges | Preferences

Edit config file for admins via wiki web. (If no changes: "Try Again").

The Patch

sub DoOtherRequest {
...
+} elsif ($action eq "editconfig") {
+    &DoEditConfig();
Two news subs:
 
+sub DoEditConfig {
+  my ($status, $configfile);
+  
+  print &GetHeader('', T('Config'), '');
+  if (!&UserIsAdmin()) {
+    print T('You do not have administrator privileges');
+  } else {
+    ($status, $configfile) = &ReadFile("$ConfigFile");
+    $configfile = ""  if (!$status);    
+    print &GetFormStart();
+    print &GetHiddenValue("edit_config", 1), "\n";
+    print &GetTextArea('configfile', $configfile, 10, 40);
+    print '<br>', $q->submit(-name=>'Save', -value=>T('Save')), "\n";
+    print $q->endform;
+  }
+  print &GetMinimumFooter();
+}
+
+sub DoUpdateConfigFile {
+  my ($newList, $fname);
+  my ($status, $data);
+    
+  print &GetHeader('', T('Updating Config File'), '');
+  return  if (!&UserIsAdminOrError());
+  $fname = "$DataDir/config.pl";
+  ($status, $data) = &ReadFile($fname);
+  $newList = &GetParam("configfile", "#Empty file");
+  if (!$status) {
+    print '<br>' . T('Undefined config file.');
+    print '<br>' . T('Use $UseConfig   = 1; into script in order to use config file.');
+    print '<br>' . T('and copy a config file to $DataDir.');
+    print '<br>' . T('or Use $UseConfig   = 0; into script in order to do not look for config.');
+  } elsif ($newList eq "") { 
+    print "<p>", T('Anyway, resubmit with at least one space character if you prefer to remove.');       
+  } elsif ($newList eq $data) {
+    print "Config file are identical. Not updated.";
+    print '<br>' . &ScriptLink("action=config", T('Try Again'));  
+  } elsif ($newList =~ /^\s*$/s) {
+    unlink($fname);
+    print "<p>Removed config file";
+  } else {
+    &WriteStringToFile($fname, $newList);
+    print "<p>", T('Updated config file');
+  }
+  print &GetMinimumFooter();
+}
Add
Sub GetAdminBar {
...
+ $result .= '<br>' . &ScriptLink("action=editconfig", T("Config"));

If the script runs as "www-data", then the wikidb, etc. files must also be owned by "www-data", (apache2 runs as user www-data, for instance). See the documentation of your web server for details. (See cuestion: Q: What should the following file permissions be? at UseModWiki/Install) --JuanmaMP

UseModWiki | WikiPatches | RecentChanges | Preferences
Edit text of this page | View other revisions | Search MetaWiki
Last edited November 28, 2009 12:18 pm by JuanmaMP (diff)
Search: