function edit_group($arg, $replacement) { //pass groupName as arg and get it's config $original = get_config_string($arg); if ($original) { //print "<pre>Original: $original</pre>"; //backup the config file first if (copy(CONFIGFILE, CONFIGBACKUP)) { print "<p>Backup successfully created.</p>"; $contents = file_get_contents(CONFIGFILE); //replace old config string with new $new = str_replace($original, $replacement, $contents, $count0); print "<p>Group configs replaced: {$count0}</p>"; //print "<pre>$new</pre>"; if ($new && $count0 > 0) { file_put_contents(CONFIGFILE, $new); print "<p>File successfully written!</p>"; } else { "<p class='error'>Unable to match string in config file.</p>"; } } else { print "<p class='error'>Backup failed. Aborting change. \n\t\t\t\t\t\tVerify that backup directory is writeable.</p>"; } } else { print "<p class='error'>Unable to find group in config file, no changes made.</p>"; } }
function delete_group($arg) { //grab entire config definition as a string $config = get_config_string($arg); if ($config) { //make a backup copy of file first //$backup = BACKUPCONFIG; if (copy(CONFIGFILE, CONFIGBACKUP)) { print "<p>Backup successfully created.</p>"; $contents = file_get_contents(CONFIGFILE); //replace old config string with new //print "<pre>$config</pre>"; $new = str_replace($config, '', $contents, $count0); print "<p>Groups Deleted: {$count0}</p>"; //print "<pre>$new</pre>"; if (isset($new) && $count0 > 0) { //delete all instances where group is a child/member of another group //removes $group;|, $matchstring1 = '$' . $arg . ';|,'; //used for str_replace $pregString1 = '/\\$' . $arg . ';\\|,/'; //used for preg_match //removes $group;&, $matchstring2 = '$' . $arg . ';&,'; //used for str_replace $pregString2 = '/\\$' . $arg . ';\\&,/'; //used for preg_match $changecount = 0; if (preg_match($pregString1, $new)) { $new = str_replace($matchstring1, '', $new, $count1); //replace all matched instances of string //print "<p>Matched |, should be replaced.</p>"; if (isset($count1)) { $changecount += $count1; } } if (preg_match($pregString2, $new)) { $new = str_replace($matchstring2, '', $new, $count2); //print "<p>Matched & , should be replaced.</p>"; if (isset($count2)) { $changecount += $count2; } } //write to file file_put_contents(CONFIGFILE, $new); //check if write was successful if ($changecount > 0) { print "<p>Group has been removed as a member from {$changecount} other groups.</p>"; } print "<p>File successfully written!</p>"; } else { "<p class='error'>Unable to match string in config file.</p>"; } } else { print "<p class='error'>Backup failed. Aborting change. \n\t\t\t\t\t\tVerify that backup directory is writeable.</p>"; } } else { print "<p class='error'>Unable to find group in config file, no changes made.</p>"; } }