<?php require_once './config.php'; use nzedb\Groups; $page = new AdminPage(); $groups = new Groups(['Settings' => $page->settings]); $id = 0; // Set the current action. $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'view'; switch ($action) { case 'submit': if ($_POST["id"] == "") { // Add a new group. $groups->add($_POST); } else { // Update an existing group. $groups->update($_POST); } header("Location:" . WWW_TOP . "/group-list.php"); break; case 'view': default: if (isset($_GET["id"])) { $page->title = "Newsgroup Edit"; $id = $_GET["id"]; $group = $groups->getByID($id); } else { $page->title = "Newsgroup Add"; $group = ['id' => '', 'name' => '', 'description' => '', 'minfilestoformrelease' => 0, 'active' => 0, 'backfill' => 0, 'minsizetoformrelease' => 0, 'first_record' => 0, 'last_record' => 0, 'backfill_target' => 0]; } $page->smarty->assign('group', $group);
/** * @param object $nzbXML Reference of simpleXmlObject with NZB contents. * @param bool|string $useNzbName Use the NZB file name as release name? * @return bool * * @access protected */ protected function scanNZBFile(&$nzbXML, $useNzbName = false) { $totalFiles = $totalSize = $groupID = 0; $isBlackListed = $groupName = $firstName = $posterName = $postDate = false; // Go through the NZB, get the details, look if it's blacklisted, look if we have the groups. foreach ($nzbXML->file as $file) { $totalFiles++; $groupID = -1; // Get the nzb info. if ($firstName === false) { $firstName = (string) $file->attributes()->subject; } if ($posterName === false) { $posterName = (string) $file->attributes()->poster; } if ($postDate === false) { $postDate = date("Y-m-d H:i:s", (int) $file->attributes()->date); } // Make a fake message array to use to check the blacklist. $msg = ["Subject" => (string) $file->attributes()->subject, "From" => (string) $file->attributes()->poster, "Message-ID" => ""]; // Get the group names, group_id, check if it's blacklisted. $groupArr = []; foreach ($file->groups->group as $group) { $group = (string) $group; // If group_id is -1 try to get a group_id. if ($groupID === -1) { if (array_key_exists($group, $this->allGroups)) { $groupID = $this->allGroups[$group]; if (!$groupName) { $groupName = $group; } } else { $groupID = $this->groups->add(['name' => $group, 'description' => 'Added by NZBimport script.', 'backfill_target' => 0, 'first_record' => 0, 'last_record' => 0, 'active' => 0, 'backfill' => 0]); $this->allGroups[$group] = $groupID; $this->echoOut("Adding missing group: ({$group})"); } } // Add all the found groups to an array. $groupArr[] = $group; // Check if this NZB is blacklisted. if ($this->binaries->isBlacklisted($msg, $group)) { $isBlackListed = true; break; } } // If we found a group and it's not blacklisted. if ($groupID !== -1 && !$isBlackListed) { // Get the size of the release. if (count($file->segments->segment) > 0) { foreach ($file->segments->segment as $segment) { $totalSize += (int) $segment->attributes()->bytes; } } } else { if ($isBlackListed) { $errorMessage = "Subject is blacklisted: " . utf8_encode(trim($firstName)); } else { $errorMessage = "No group found for " . $firstName . " (one of " . implode(', ', $groupArr) . " are missing"; } $this->echoOut($errorMessage); return false; } } // Try to insert the NZB details into the DB. return $this->insertNZB(['subject' => $firstName, 'useFName' => $useNzbName, 'postDate' => empty($postDate) ? date("Y-m-d H:i:s") : $postDate, 'from' => empty($posterName) ? '' : $posterName, 'group_id' => $groupID, 'groupName' => $groupName, 'totalFiles' => $totalFiles, 'totalSize' => $totalSize]); }