diff --git a/Blacklight/Sharing.php b/Blacklight/Sharing.php deleted file mode 100755 index 4b0cdaa28..000000000 --- a/Blacklight/Sharing.php +++ /dev/null @@ -1,557 +0,0 @@ - null, - 'NNTP' => null, - ]; - $options += $defaults; - - $this->nntp = ($options['NNTP'] instanceof NNTP ? $options['NNTP'] : new NNTP()); - - // Get all sharing info from DB. - $check = DB::selectOne('SELECT * FROM sharing'); - - // Initiate sharing settings if this is the first time.. - if (empty($check)) { - $check = $this->initSettings(); - } - - // Second check to make sure nothing went wrong. - if (empty($check)) { - return; - } - - // Cache sharing settings. - $this->siteSettings = $check; - unset($check); - - // Convert to bool to speed up checking. - $this->siteSettings->hide_users = (int) $this->siteSettings->hide_users === 1; - $this->siteSettings->auto_enable = (int) $this->siteSettings->auto_enable === 1; - $this->siteSettings->posting = (int) $this->siteSettings->posting === 1; - $this->siteSettings->fetching = (int) $this->siteSettings->fetching === 1; - $this->siteSettings->enabled = (int) $this->siteSettings->enabled === 1; - $this->siteSettings->start_position = (int) $this->siteSettings->start_position === 1; - } - - /** - * Main method. - * - * @throws \Exception - */ - public function start(): void - { - // Admin has disabled sharing so return. - if ($this->siteSettings->enabled === false) { - return; - } - - if ($this->nntp === null) { - $this->nntp = new NNTP(); - $this->nntp->doConnect(); - } - - if ($this->siteSettings->fetching) { - $this->fetchAll(); - } - $this->matchComments(); - if ($this->siteSettings->posting) { - $this->postAll(); - $this->postSC(); - } - } - - /** - * Initialise of reset sharing settings. - * - * - * @param string $siteGuid Optional hash (must be sha1) we can set the site guid to. - * @return mixed - */ - public function initSettings(&$siteGuid = '') - { - DB::statement('TRUNCATE TABLE sharing'); - $siteName = uniqid('nntmux_', true); - DB::insert( - sprintf( - ' - INSERT INTO sharing - (site_name, site_guid, max_push, max_pull, hide_users, start_position, auto_enable, fetching, max_download) - VALUES (%s, %s, 40 , 20000, 1, 1, 1, 1, 150)', - escapeString($siteName), - escapeString(($siteGuid === '' ? sha1($siteName) : $siteGuid)) - ) - ); - - return DB::selectOne('SELECT * FROM sharing'); - } - - /** - * Post all new comments to usenet. - */ - protected function postAll() - { - // Get all comments that we have not posted yet. - $newComments = DB::select( - sprintf( - 'SELECT rc.text, rc.id, UNIX_TIMESTAMP(rc.created_at) AS unix_time, u.username, HEX(r.nzb_guid) AS nzb_guid - FROM release_comments rc - INNER JOIN users u ON rc.users_id = u.id - INNER JOIN releases r on rc.releases_id = r.id - WHERE (rc.shared = 0 or issynced = 1) LIMIT %d', - $this->siteSettings->max_push - ) - ); - - // Check if we have any comments to push. - if (\count($newComments) === 0) { - return; - } - - echo '(Sharing) Starting to upload comments.'.PHP_EOL; - - // Loop over the comments. - foreach ($newComments as $comment) { - $this->postComment($comment); - } - - echo PHP_EOL.'(Sharing) Finished uploading comments.'.PHP_EOL; - } - - /** - * @throws \Exception - */ - protected function postSC() - { - // Get all comments from spotnab that we have not posted yet. - $newComments = DB::select( - sprintf( - 'SELECT id, text, UNIX_TIMESTAMP(created_at) AS unix_time, - username, nzb_guid FROM release_comments - WHERE issynced = 1 AND shared = 1 AND shareid = "" - ORDER BY id DESC' - ) - ); - - // Check if we have any comments to push. - if (\count($newComments) === 0) { - return; - } - - echo '(Sharing) Starting to upload spotnab comments.'.PHP_EOL; - - // Loop over the comments. - foreach ($newComments as $comment) { - $this->postComment($comment); - } - - echo PHP_EOL.'(Sharing) Finished uploading spotnab comments.'.PHP_EOL; - } - - /** - * @throws \Exception - */ - protected function postComment(&$row) - { - // Create a unique identifier for this comment. - $sid = sha1($row->unix_time.$row->text.$row->nzb_guid); - - // Check if the comment is already shared. - $check = DB::selectOne(sprintf('SELECT id FROM release_comments WHERE shareid = %s', escapeString($sid))); - if ($check === null) { - // Example of a subject. - //(_nZEDb_)nZEDb_533f16e46a5091.73152965_3d12d7c1169d468aaf50d5541ef02cc88f3ede10 - [1/1] "92ba694cebc4fbbd0d9ccabc8604c71b23af1131" (1/1) yEnc - - // Attempt to upload the comment to usenet. - $success = $this->nntp->postArticle( - self::group, - '(_nZEDb_)'.$this->siteSettings->site_name.'_'.$this->siteSettings->site_guid.' - [1/1] "'.$sid.'" yEnc (1/1)', - json_encode( - [ - 'USER' => $this->siteSettings->hide_users ? 'ANON' : $row->username, - 'TIME' => $row->unix_time, - 'SID' => $sid, - 'RID' => $row->nzb_guid, - 'BODY' => $row->text, - ] - ), - '' - ); - - // Check if we succesfully uploaded it. - if ($success === true && $this->nntp->isError($success) === false) { - // Update DB to say we posted the article. - DB::update( - sprintf( - ' - UPDATE release_comments - SET shared = 1, shareid = %s - WHERE id = %d', - escapeString($sid), - $row->id - ) - ); - - echo '.'; - } - } else { - // Update the DB to say it's shared. - DB::update(sprintf('UPDATE release_comments SET shared = 1 WHERE id = %d', $row->id)); - } - } - - /** - * Match added comments to releases. - */ - protected function matchComments() - { - $res = DB::select( - ' - SELECT r.id - FROM release_comments rc - INNER JOIN releases r USING (nzb_guid) - WHERE rc.releases_id = 0' - ); - $found = \count($res); - if ($found > 0) { - foreach ($res as $row) { - DB::update( - sprintf( - ' - UPDATE release_comments rc - INNER JOIN releases r USING (nzb_guid) - SET rc.releases_id = %d, r.comments = r.comments + 1 - WHERE r.id = %d - AND rc.releases_id = 0', - $row->id, - $row->id - ) - ); - } - if (config('nntmux.echocli')) { - echo "(Sharing) Matched $found comments.".PHP_EOL; - } - } - - // Update first time seen. - DB::update( - sprintf( - " - UPDATE sharing_sites ss - INNER JOIN - (SELECT siteid, created_at - FROM release_comments - WHERE created_at > '2005-01-01' - GROUP BY siteid - ORDER BY created_at ASC) rc - ON ss.site_guid = rc.siteid - SET ss.first_time = rc.created_at - WHERE ss.first_time IS NULL OR ss.first_time > rc.created_at" - ) - ); - } - - /** - * Get all new comments from usenet. - */ - protected function fetchAll() - { - // Get NNTP group data. - $group = $this->nntp->selectGroup(self::group, false, true); - - // Check if there's an issue. - if ($this->nntp->isError($group)) { - return; - } - - // Check if this is the first time, set our oldest article. - if ((int) $this->siteSettings->last_article === 0) { - // If the user picked to start from the oldest, get the oldest. - if ($this->siteSettings->start_position === true) { - $this->siteSettings->last_article = $ourOldest = $group['first']; - // Else get the newest. - } else { - $this->siteSettings->last_article = $ourOldest = (string) ($group['last'] - $this->siteSettings->max_download); - if ($ourOldest < $group['first']) { - $this->siteSettings->last_article = $ourOldest = $group['first']; - } - } - } else { - $ourOldest = (string) ($this->siteSettings->last_article + 1); - } - - // Set our newest to our oldest wanted + max pull setting. - $newest = (string) ($ourOldest + $this->siteSettings->max_pull); - - // Check if our newest wanted is newer than the group's newest, set to group's newest. - if ($newest >= $group['last']) { - $newest = $group['last']; - } - - // We have nothing to do, so return. - if ($ourOldest > $newest) { - return; - } - - if (config('nntmux.echocli')) { - echo '(Sharing) Starting to fetch new comments.'.PHP_EOL; - } - - // Get the wanted aritcles - $headers = $this->nntp->getOverview($ourOldest.'-'.$newest, true, false); - - // Check if we received nothing or there was an error. - if ($this->nntp->isError($headers) || \count($headers) === 0) { - return; - } - - $found = $total = $currentArticle = 0; - // Loop over NNTP headers until we find comments. - foreach ($headers as $header) { - // Check if the article is missing. - if (! isset($header['Number'])) { - continue; - } - - // Get the current article number. - $currentArticle = $header['Number']; - - // Break out of the loop if we have downloaded more comments than the user wants. - if ($found > $this->siteSettings->max_download) { - break; - } - - $hits = []; - //(_nZEDb_)nZEDb_533f16e46a5091.73152965_3d12d7c1169d468aaf50d5541ef02cc88f3ede10 - [1/1] "92ba694cebc4fbbd0d9ccabc8604c71b23af1131" (1/1) yEnc - if ($header['From'] === '' && - preg_match('/^\(_nZEDb_\)(?P.+?)_(?P[a-f0-9]{40}) - \[1\/1\] "(?P[a-f0-9]{40})" yEnc \(1\/1\)$/i', $header['Subject'], $hits)) { - // Check if this is from our own site. - if ($hits['guid'] === $this->siteSettings->site_guid) { - continue; - } - - // Check if we already have the comment. - $check = DB::selectOne( - sprintf( - 'SELECT id FROM release_comments WHERE shareid = %s', - escapeString($hits['sid']) - ) - ); - - // We don't have it, so insert it. - if ($check === null) { - // Check if we have the site and if it is enabled. - $check = DB::selectOne( - sprintf( - 'SELECT enabled FROM sharing_sites WHERE site_guid = %s', - escapeString($hits['guid']) - ) - ); - - if ($check === null) { - // Check if the user has auto enable on. - if ($this->siteSettings->auto_enable === false) { - // Insert the site so the admin can enable it later on. - DB::insert( - sprintf( - ' - INSERT INTO sharing_sites - (site_name, site_guid, last_time, first_time, enabled, comments) - VALUES (%s, %s, NOW(), NOW(), 0, 0)', - escapeString($hits['site']), - escapeString($hits['guid']) - ) - ); - - continue; - } - - // Insert the site as enabled since the user has auto enabled on. - DB::insert( - sprintf( - ' - INSERT INTO sharing_sites - (site_name, site_guid, last_time, first_time, enabled, comments) - VALUES (%s, %s, NOW(), NOW(), 1, 0)', - escapeString($hits['site']), - escapeString($hits['guid']) - ) - ); - } elseif ((int) $check->enabled === 0) { - continue; - } - - // Insert the comment, if we got it, update the site to increment comment count. - if ($this->insertNewComment($header['Message-ID'], $hits['guid'])) { - DB::update( - sprintf( - ' - UPDATE sharing_sites SET comments = comments + 1, last_time = NOW(), site_name = %s WHERE site_guid = %s', - escapeString($hits['site']), - escapeString($hits['guid']) - ) - ); - $found++; - if (config('nntmux.echocli')) { - echo '.'; - if ($found % 40 === 0) { - echo '['.$found.']'.PHP_EOL; - } - } - } - } - } - // Update once in a while in case the user cancels the script. - if ($total++ % 10 === 0) { - $this->siteSettings->lastarticle = $currentArticle; - DB::update(sprintf('UPDATE sharing SET last_article = %d', $currentArticle)); - } - } - - if ($currentArticle > 0) { - // Update sharing's last article number. - $this->siteSettings->lastarticle = $currentArticle; - DB::update(sprintf('UPDATE sharing SET last_article = %d', $currentArticle)); - } - - if (config('nntmux.echocli')) { - if ($found > 0) { - echo PHP_EOL.'(Sharing) Fetched '.$found.' new comments.'.PHP_EOL; - } else { - echo '(Sharing) Finish looking for new comments, but did not find any.'.PHP_EOL; - } - } - } - - /** - * Fetch a comment and insert it. - * - * @param string $messageID Message-ID for the article. - * @param string $siteID id of the site. - * - * @throws \Exception - */ - protected function insertNewComment(&$messageID, &$siteID): bool - { - // Get the article body. - $body = $this->nntp->getMessages(self::group, $messageID); - - // Check if there's an error. - if ($this->nntp->isError($body)) { - return false; - } - - // Decompress the body. - $body = @gzinflate($body); - if ($body === false) { - return false; - } - - // JSON Decode the body. - $body = json_decode($body, true); - if ($body === false) { - return false; - } - - // Just in case. - if (! isset($body['USER'], $body['SID']) || ! isset($body['RID']) || ! isset($body['TIME']) | ! isset($body['BODY'])) { - return false; - } - $cid = md5($body['SID'].$body['USER'].$body['TIME'].$siteID); - - // Insert the comment. - $unixTime = $body['TIME'] > time() ? time() : $body['TIME']; - if (DB::insert( - sprintf( - ' - INSERT IGNORE INTO release_comments - (text, created_at, issynced, shareid, cid, gid, nzb_guid, siteid, username, users_id, releases_id, shared, host, sourceID) - VALUES (%s, FROM_UNIXTIME(%s), 1, %s, %s, %s, %s, %s, %s, 0, 0, 2, "", 999)', - escapeString($body['BODY']), - $unixTime, - escapeString($body['SID']), - escapeString($cid), - escapeString($body['RID']), - escapeString($body['RID']), - escapeString($siteID), - escapeString((strpos($body['USER'] === 0, 'sn-') !== false ? 'SH_ANON' : 'SH_'.$body['USER'])) - ) - ) - ) { - return true; - } - - return false; - } -} diff --git a/Blacklight/processing/PostProcess.php b/Blacklight/processing/PostProcess.php index 1620d9282..fe837dad6 100755 --- a/Blacklight/processing/PostProcess.php +++ b/Blacklight/processing/PostProcess.php @@ -21,7 +21,6 @@ use Blacklight\processing\tv\TMDB; use Blacklight\processing\tv\TraktTv; use Blacklight\processing\tv\TVDB; use Blacklight\processing\tv\TVMaze; -use Blacklight\Sharing; use Blacklight\XXX; use dariusiii\rarinfo\Par2Info; use Illuminate\Support\Carbon; @@ -92,7 +91,6 @@ class PostProcess { $this->processAdditional($nntp); $this->processNfos($nntp); - $this->processSharing($nntp); $this->processMovies(); $this->processMusic(); $this->processConsoles(); @@ -192,17 +190,6 @@ class PostProcess } } - /** - * Process comments. - * - * - * @throws \Exception - */ - public function processSharing(NNTP $nntp): void - { - (new Sharing(['NNTP' => $nntp]))->start(); - } - /** * Process all TV related releases which will assign their series/episode/rage data. * diff --git a/app/Http/Controllers/Admin/AdminAjaxController.php b/app/Http/Controllers/Admin/AdminAjaxController.php index d6b59b421..a0dbc1cc1 100644 --- a/app/Http/Controllers/Admin/AdminAjaxController.php +++ b/app/Http/Controllers/Admin/AdminAjaxController.php @@ -3,9 +3,6 @@ namespace App\Http\Controllers\Admin; use App\Http\Controllers\BasePageController; -use App\Models\ReleaseComment; -use App\Models\Sharing; -use App\Models\SharingSite; use App\Models\UsenetGroup; use Blacklight\Binaries; use Blacklight\Regexes; @@ -87,69 +84,6 @@ class AdminAjaxController extends BasePageController ($request->has('backfill_status') ? (int) $request->input('backfill_status') : 0) ); break; - - case 'sharing_toggle_status': - SharingSite::query()->where('id', $request->input('site_id'))->update(['enabled' => $request->input('site_status')]); - echo($request->input('site_status') === 1 ? 'Activated' : 'Deactivated').' site '.$request->input('site_id'); - break; - - case 'sharing_toggle_enabled': - Sharing::query()->update(['enabled' => $request->input('enabled_status')]); - echo($request->input('enabled_status') === 1 ? 'Enabled' : 'Disabled').' sharing!'; - break; - - case 'sharing_start_position': - Sharing::query()->update(['start_position' => $request->input('start_position')]); - echo($request->input('start_position') === 1 ? 'Enabled' : 'Disabled').' fetching from start of group!'; - break; - - case 'sharing_reset_settings': - $guid = Sharing::query()->first(['site_guid']); - $guid = ($guid === null ? '' : $guid['site_guid']); - (new \Blacklight\Sharing(['Settings' => $this->settings]))->initSettings($guid); - echo 'Re-initiated sharing settings!'; - break; - - case 'sharing_purge_site': - $guid = SharingSite::query()->where('id', $request->input('purge_site'))->first(['site_guid']); - if ($guid === null) { - echo 'Error purging site '.$request->input('purge_site').'!'; - } else { - $ids = ReleaseComment::query()->where('siteid', $guid['site_guid'])->get(['id']); - $total = $ids->count(); - if ($total > 0) { - foreach ($ids as $id) { - ReleaseComment::deleteComment($id['id']); - } - } - SharingSite::query()->where('id', $request->input('purge_site'))->update(['comments' => 0]); - echo 'Deleted '.$total.' comments for site '.$request->input('purge_site'); - } - break; - - case 'sharing_toggle_posting': - Sharing::query()->update(['posting' => $request->input('posting_status')]); - echo($request->input('posting_status') === 1 ? 'Enabled' : 'Disabled').' posting!'; - break; - - case 'sharing_toggle_fetching': - Sharing::query()->update(['fetching' => $request->input('fetching_status')]); - echo($request->input('fetching_status') === 1 ? 'Enabled' : 'Disabled').' fetching!'; - break; - - case 'sharing_toggle_site_auto_enabling': - Sharing::query()->update(['auto_enable' => $request->input('auto_status')]); - echo($request->input('auto_status') === 1 ? 'Enabled' : 'Disabled').' automatic site enabling!'; - break; - - case 'sharing_toggle_hide_users': - Sharing::query()->update(['hide_users' => $request->input('hide_status')]); - echo($request->input('hide_status') === 1 ? 'Enabled' : 'Disabled').' hiding of user names!'; - break; - - case 'sharing_toggle_all_sites': - SharingSite::query()->update(['enabled' => $request->input('toggle_all')]); - break; } } } diff --git a/app/Http/Controllers/Admin/AdminSharingController.php b/app/Http/Controllers/Admin/AdminSharingController.php deleted file mode 100644 index 3c05740f1..000000000 --- a/app/Http/Controllers/Admin/AdminSharingController.php +++ /dev/null @@ -1,62 +0,0 @@ -setAdminPrefs(); - - $meta_title = $title = 'Sharing Settings'; - - $allSites = SharingSite::query()->orderByDesc('id')->paginate(config('nntmux.items_per_cover_page')); - if ($allSites->total() === 0) { - $allSites = false; - } - - $ourSite = Sharing::query()->first(); - - if (! empty($request->all())) { - if (! empty($request->input('sharing_name')) && ! preg_match('/\s+/', $request->input('sharing_name')) && strlen($request->input('sharing_name')) < 255) { - $site_name = trim($request->input('sharing_name')); - } else { - $site_name = $ourSite['site_name']; - } - if (! empty($request->input('sharing_maxpush')) && is_numeric($request->input('sharing_maxpush'))) { - $max_push = trim($request->input('sharing_maxpush')); - } else { - $max_push = $ourSite['max_push']; - } - if (! empty($request->input('sharing_maxpoll')) && is_numeric($request->input('sharing_maxpush'))) { - $max_pull = trim($request->input('sharing_maxpoll')); - } else { - $max_pull = $ourSite['max_pull']; - } - if (! empty($request->input('sharing_maxdownload')) && is_numeric($request->input('sharing_maxdownload'))) { - $max_download = trim($request->input('sharing_maxdownload')); - } else { - $max_download = $ourSite['max_download']; - } - Sharing::query() - ->update(compact('site_name', 'max_push', 'max_pull', 'max_download')); - - $ourSite = $ourSite = Sharing::query()->first(); - } - - $this->smarty->assign(['local' => $ourSite, 'sites' => $allSites]); - - $content = $this->smarty->fetch('sharing.tpl'); - - $this->smarty->assign(compact('title', 'meta_title', 'content')); - $this->adminrender(); - } -} diff --git a/app/Models/Sharing.php b/app/Models/Sharing.php deleted file mode 100644 index 15f00f3a8..000000000 --- a/app/Models/Sharing.php +++ /dev/null @@ -1,65 +0,0 @@ - realpath(base_path()).'/database/fixtures', - - /* - |-------------------------------------------------------------------------- - | Fixture chunk size - |-------------------------------------------------------------------------- - | - | The size of each insert chunk columns x rows <= $chunk_size. - | - */ - 'chunk_size' => 500, -]; diff --git a/resources/views/themes/admin/adminmenu.tpl b/resources/views/themes/admin/adminmenu.tpl index dba1c8d72..f50342c9f 100644 --- a/resources/views/themes/admin/adminmenu.tpl +++ b/resources/views/themes/admin/adminmenu.tpl @@ -183,7 +183,7 @@ @@ -191,9 +191,6 @@ View Comments - - Comment Sharing Settings -
- - - - - - - - - - - {foreach from=$sites item=site} - - - - - - - - - - {/foreach} -
idNameFirst seenLast seenStatusComments
{$site.id}{$site.site_name}{$site.first_time|timeago}{$site.last_time|timeago} - {if $site.enabled=="1"} - - {else} - - {/if} - {$site.comments} - -
- {$sites->onEachSide(5)->links()} - {else} -

No remote sites found in your database.

- {/if} -
-
diff --git a/resources/views/themes/admin/tmux-edit.tpl b/resources/views/themes/admin/tmux-edit.tpl index 29c5580d3..a9bf791b8 100644 --- a/resources/views/themes/admin/tmux-edit.tpl +++ b/resources/views/themes/admin/tmux-edit.tpl @@ -499,33 +499,6 @@ -
- Comment Sharing - - - - - - - - - -
- {html_radios id="run_sharing" name='run_sharing' values=$yesno_ids output=$yesno_names - selected=$site->run_sharing separator='
'} - -
Run Comment Sharing from within tmux if you have it enabled in Admin->Comment - Sharing - Settings. -
-
- - -
Set the sleep time between updates
-
-
-
Fix Release Names