Browse Source

add sabnzbd socks component

CauseFX 5 years ago
parent
commit
33947b2f31
3 changed files with 47 additions and 0 deletions
  1. 2 0
      api/config/default.php
  2. 30 0
      api/homepage/sabnzbd.php
  3. 15 0
      api/v2/routes/socks.php

+ 2 - 0
api/config/default.php

@@ -88,6 +88,8 @@ return array(
 	'jdownloaderCombine' => false,
 	'sabnzbdURL' => '',
 	'sabnzbdToken' => '',
+	'sabnzbdSocksEnabled' => false,
+	'sabnzbdSocksAuth' => '999',
 	'sabnzbdCombine' => false,
 	'nzbgetURL' => '',
 	'nzbgetUsername' => '',

+ 30 - 0
api/homepage/sabnzbd.php

@@ -48,6 +48,36 @@ trait SabNZBdHomepageItem
 						'value' => $this->config['sabnzbdToken']
 					)
 				),
+				'API SOCKS' => array(
+					array(
+						'type' => 'html',
+						'override' => 12,
+						'label' => '',
+						'html' => '
+							<div class="panel panel-default">
+								<div class="panel-wrapper collapse in">
+									<div class="panel-body">
+										<h3 lang="en">Sabnzbd SOCKS API Connection</h3>
+										<p>Using this feature allows you to access the Sonarr API without having to reverse proxy it.  Just access it from: </p>
+										<code>' . $this->getServerPath() . 'api/v2/socks/sabnzbd/</code>
+									</div>
+								</div>
+							</div>'
+					),
+					array(
+						'type' => 'switch',
+						'name' => 'sabnzbdSocksEnabled',
+						'label' => 'Enable',
+						'value' => $this->config['sabnzbdSocksEnabled']
+					),
+					array(
+						'type' => 'select',
+						'name' => 'sabnzbdSocksAuth',
+						'label' => 'Minimum Authentication',
+						'value' => $this->config['sabnzbdSocksAuth'],
+						'options' => $this->groupOptions
+					),
+				),
 				'Misc Options' => array(
 					array(
 						'type' => 'select',

+ 15 - 0
api/v2/routes/socks.php

@@ -43,4 +43,19 @@ $app->any('/socks/lidarr/{route:.*}', function ($request, $response) {
 	return $response
 		->withHeader('Content-Type', 'application/json;charset=UTF-8')
 		->withStatus($GLOBALS['responseCode']);
+});
+$app->any('/socks/sabnzbd/{route:.*}', function ($request, $response) {
+	$Organizr = ($request->getAttribute('Organizr')) ?? new Organizr();
+	$socks = $Organizr->socks(
+		'sabnzbdURL',
+		'sabnzbdSocksEnabled',
+		'sabnzbdSocksAuth',
+		$request,
+		null
+	);
+	$data = $socks ?? jsonE($GLOBALS['api']);
+	$response->getBody()->write($data);
+	return $response
+		->withHeader('Content-Type', 'application/json;charset=UTF-8')
+		->withStatus($GLOBALS['responseCode']);
 });