Add function to create sections in maintenance.php.
This commit is contained in:
parent
b3b492592c
commit
250c66f44c
|
@ -17,46 +17,45 @@
|
||||||
* it to appear:
|
* it to appear:
|
||||||
* $config_dir/<section>/groups.txt
|
* $config_dir/<section>/groups.txt
|
||||||
*/
|
*/
|
||||||
include ("paths.inc.php");
|
include("paths.inc.php");
|
||||||
chdir($spoolnews_path);
|
chdir($spoolnews_path);
|
||||||
include "config.inc.php";
|
include "config.inc.php";
|
||||||
include ("$file_newsportal");
|
include("$file_newsportal");
|
||||||
|
|
||||||
// Change to webserver user if root
|
if ($argv[1] != '-newsection') {
|
||||||
$uinfo = posix_getpwnam($CONFIG['webserver_user']);
|
// Change to webserver user if root
|
||||||
/* Change to non root user */
|
$uinfo = posix_getpwnam($CONFIG['webserver_user']);
|
||||||
change_identity($uinfo["uid"], $uinfo["gid"]);
|
/* Change to non root user */
|
||||||
$processUser = posix_getpwuid(posix_geteuid());
|
change_identity($uinfo["uid"], $uinfo["gid"]);
|
||||||
if ($processUser['name'] != $CONFIG['webserver_user']) {
|
$processUser = posix_getpwuid(posix_geteuid());
|
||||||
|
if ($processUser['name'] != $CONFIG['webserver_user']) {
|
||||||
echo "You are running as: " . $processUser['name'] . "\n";
|
echo "You are running as: " . $processUser['name'] . "\n";
|
||||||
echo 'Please run this scripts as: ' . $CONFIG['webserver_user'] . "\n";
|
echo 'Please run this scripts as: ' . $CONFIG['webserver_user'] . "\n";
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
/* Everything below runs as $CONFIG['webserver_user'] */
|
/* Everything below runs as $CONFIG['webserver_user'] */
|
||||||
|
|
||||||
$processUser = posix_getpwuid(posix_geteuid());
|
$processUser = posix_getpwuid(posix_geteuid());
|
||||||
if ($processUser['name'] != $CONFIG['webserver_user']) {
|
if ($processUser['name'] != $CONFIG['webserver_user']) {
|
||||||
echo "You are running as: " . $processUser['name'] . "\n";
|
echo "You are running as: " . $processUser['name'] . "\n";
|
||||||
echo 'Please run this scripts as: ' . $CONFIG['webserver_user'] . "\n";
|
echo 'Please run this scripts as: ' . $CONFIG['webserver_user'] . "\n";
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
$logfile = $logdir . '/import.log';
|
$logfile = $logdir . '/import.log';
|
||||||
|
|
||||||
$lockfile = $lockdir . '/' . $config_name . '-spoolnews.lock';
|
$lockfile = $lockdir . '/' . $config_name . '-spoolnews.lock';
|
||||||
$cronfile = $spooldir . '/cron.disable';
|
|
||||||
|
|
||||||
$pid = file_get_contents($lockfile);
|
$pid = file_get_contents($lockfile);
|
||||||
if (posix_getsid($pid) === false || ! is_file($lockfile)) {
|
if (posix_getsid($pid) === false || ! is_file($lockfile)) {
|
||||||
print "Starting Import...\n";
|
print "Starting Import...\n";
|
||||||
file_put_contents($lockfile, getmypid()); // create lockfile
|
file_put_contents($lockfile, getmypid()); // create lockfile
|
||||||
} else {
|
} else {
|
||||||
print "Import currently running\n";
|
print "Import currently running\n";
|
||||||
exit();
|
exit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
touch($cronfile);
|
|
||||||
|
|
||||||
if (! isset($argv[1])) {
|
if (! isset($argv[1])) {
|
||||||
$argv[1] = "-help";
|
$argv[1] = "-help";
|
||||||
}
|
}
|
||||||
|
@ -82,6 +81,14 @@ if ($argv[1][0] == '-') {
|
||||||
import();
|
import();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case "-newsection":
|
||||||
|
if (!isset($argv[2])) {
|
||||||
|
echo "Please provide a section name\n";
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
echo "Creating section: " . $argv[2] . "\n";
|
||||||
|
echo create_section($argv[2]);
|
||||||
|
break;
|
||||||
case "-clean":
|
case "-clean":
|
||||||
clean_spool();
|
clean_spool();
|
||||||
break;
|
break;
|
||||||
|
@ -94,18 +101,60 @@ if ($argv[1][0] == '-') {
|
||||||
echo "-clean: Remove extraneous group db3 files\n";
|
echo "-clean: Remove extraneous group db3 files\n";
|
||||||
echo "-import: Import articles from a .db3 file (-import alt.test-articles)\n";
|
echo "-import: Import articles from a .db3 file (-import alt.test-articles)\n";
|
||||||
echo " You must first add group name to <config_dir>/<section>/groups.txt manually\n";
|
echo " You must first add group name to <config_dir>/<section>/groups.txt manually\n";
|
||||||
|
echo "-newsection: Create a new section for groups\n";
|
||||||
echo "-remove: Remove all data for a group (-remove alt.test)\n";
|
echo "-remove: Remove all data for a group (-remove alt.test)\n";
|
||||||
echo " You must also remove group name from <config_dir>/<section>/groups.txt manually\n";
|
echo " You must also remove group name from <config_dir>/<section>/groups.txt manually\n";
|
||||||
echo "-reset: Reset a group to restart from zero messages (-reset alt.test)\n";
|
echo "-reset: Reset a group to restart from zero messages (-reset alt.test)\n";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
unlink($cronfile);
|
|
||||||
exit();
|
exit();
|
||||||
} else {
|
} else {
|
||||||
unlink($cronfile);
|
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function create_section($section = false)
|
||||||
|
{
|
||||||
|
global $spooldir, $config_dir, $spoolnews_path, $CONFIG;
|
||||||
|
$menufile = $config_dir . '/menu.conf';
|
||||||
|
|
||||||
|
if (!isset($section)) {
|
||||||
|
return "Please include a section name\n";
|
||||||
|
}
|
||||||
|
$uinfo = posix_getpwnam($CONFIG['webserver_user']);
|
||||||
|
$spoolsection = $spooldir . '/' . $section;
|
||||||
|
$configsection = $config_dir . '/' . $section;
|
||||||
|
|
||||||
|
$websectionarray = explode('/', $spoolnews_path);
|
||||||
|
$websectionpath = substr($spoolnews_path, 0, strlen($spoolnews_path) - 9);
|
||||||
|
$websection = $websectionpath . $section;
|
||||||
|
$websection = $websectionpath . '/' . $section;
|
||||||
|
|
||||||
|
if (!file_exists($websection . '/newsportal.php')) {
|
||||||
|
echo "Creating symlinks " . $websection . "\n";
|
||||||
|
mkdir($websection);
|
||||||
|
exec("ln -s " . $websectionpath . '/rocksolid/*' . ' ' . $websection);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!file_exists($configsection . '/groups.txt')) {
|
||||||
|
mkdir($configsection);
|
||||||
|
echo 'Creating ' . $configsection . '/groups.txt' . "\n";
|
||||||
|
touch($configsection . '/groups.txt');
|
||||||
|
}
|
||||||
|
|
||||||
|
$menuexists = false;
|
||||||
|
$menudata = file($config_dir . '/menu.conf');
|
||||||
|
foreach ($menudata as $menuentry) {
|
||||||
|
if (strpos($menuentry, $section) !== false) {
|
||||||
|
$menuexists = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!$menuexists) {
|
||||||
|
file_put_contents($config_dir . '/menu.conf', $section . ":1:1", FILE_APPEND);
|
||||||
|
}
|
||||||
|
echo 'Please now edit ' . $configsection . "/groups.txt to add groups to this section\n";
|
||||||
|
}
|
||||||
|
|
||||||
function clean_spool()
|
function clean_spool()
|
||||||
{
|
{
|
||||||
global $logfile, $workpath, $spooldir;
|
global $logfile, $workpath, $spooldir;
|
||||||
|
@ -237,7 +286,7 @@ function remove_articles($group)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$overview_dbh = null;
|
$overview_dbh = null;
|
||||||
foreach($del_array as $delme) {
|
foreach ($del_array as $delme) {
|
||||||
delete_message($delme, $group);
|
delete_message($delme, $group);
|
||||||
echo "Deleting " . $delme . " from " . $group . "\n";
|
echo "Deleting " . $delme . " from " . $group . "\n";
|
||||||
}
|
}
|
||||||
|
@ -291,7 +340,7 @@ function import_articles($group)
|
||||||
$bytes = $bytes + mb_strlen($response, '8bit');
|
$bytes = $bytes + mb_strlen($response, '8bit');
|
||||||
if (trim($response) == "" || $lines > 0) {
|
if (trim($response) == "" || $lines > 0) {
|
||||||
$is_header = 0;
|
$is_header = 0;
|
||||||
$lines ++;
|
$lines++;
|
||||||
}
|
}
|
||||||
if ($is_header == 1) {
|
if ($is_header == 1) {
|
||||||
$response = str_replace("\t", " ", $response);
|
$response = str_replace("\t", " ", $response);
|
||||||
|
@ -309,8 +358,10 @@ function import_articles($group)
|
||||||
$article_date = $row['date'];
|
$article_date = $row['date'];
|
||||||
if (stripos($response, "Content-Type: ") === 0) {
|
if (stripos($response, "Content-Type: ") === 0) {
|
||||||
preg_match('/.*charset=.*/', $response, $te);
|
preg_match('/.*charset=.*/', $response, $te);
|
||||||
|
if (isset($te[0])) {
|
||||||
$content_type = explode("Content-Type: text/plain; charset=", $te[0]);
|
$content_type = explode("Content-Type: text/plain; charset=", $te[0]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (stripos($response, "References: ") === 0) {
|
if (stripos($response, "References: ") === 0) {
|
||||||
$this_references = explode('References: ', $response);
|
$this_references = explode('References: ', $response);
|
||||||
$references = $this_references[1];
|
$references = $this_references[1];
|
||||||
|
@ -329,7 +380,7 @@ function import_articles($group)
|
||||||
// add to database
|
// add to database
|
||||||
// CREATE SEARCH SNIPPET
|
// CREATE SEARCH SNIPPET
|
||||||
$this_snippet = get_search_snippet($body, $content_type[1]);
|
$this_snippet = get_search_snippet($body, $content_type[1]);
|
||||||
$xref = create_xref_from_msgid($msgid, $group, $local);
|
$xref = create_xref_from_msgid($mid[1], $group, $local);
|
||||||
$new_article_stmt->execute([
|
$new_article_stmt->execute([
|
||||||
$group,
|
$group,
|
||||||
$local,
|
$local,
|
||||||
|
@ -356,10 +407,11 @@ function import_articles($group)
|
||||||
$status = "respooled";
|
$status = "respooled";
|
||||||
$statusdate = time();
|
$statusdate = time();
|
||||||
$statusreason = "repair";
|
$statusreason = "repair";
|
||||||
|
$statusnotes = '';
|
||||||
add_to_history($group, $local, $mid[1], $status, $statusdate, $statusreason, $statusnotes);
|
add_to_history($group, $local, $mid[1], $status, $statusdate, $statusreason, $statusnotes);
|
||||||
echo "\nImported: " . $group . " " . $local;
|
echo "\nImported: " . $group . " " . $local;
|
||||||
file_put_contents($logfile, "\n" . format_log_date() . " " . $config_name . " Imported: " . $group . ":" . $local, FILE_APPEND);
|
file_put_contents($logfile, "\n" . format_log_date() . " " . $config_name . " Imported: " . $group . ":" . $local, FILE_APPEND);
|
||||||
$i ++;
|
$i++;
|
||||||
$references = "";
|
$references = "";
|
||||||
}
|
}
|
||||||
$new_article_dbh = null;
|
$new_article_dbh = null;
|
||||||
|
@ -373,4 +425,3 @@ function import_articles($group)
|
||||||
unlink($spooldir . '/' . $group . '-overboard.dat');
|
unlink($spooldir . '/' . $group . '-overboard.dat');
|
||||||
reset_group($group);
|
reset_group($group);
|
||||||
}
|
}
|
||||||
?>
|
|
||||||
|
|
Loading…
Reference in New Issue