Browse Source

added radarr and lidarr socks

CauseFX 5 years ago
parent
commit
737dc02e46
3 changed files with 154 additions and 0 deletions
  1. 60 0
      api/classes/organizr.class.php
  2. 4 0
      api/config/default.php
  3. 90 0
      api/v2/routes/socks.php

+ 60 - 0
api/classes/organizr.class.php

@@ -5902,6 +5902,36 @@ class Organizr
 							'value' => $this->config['lidarrToken']
 						)
 					),
+					'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">Lidarr SOCKS API Connection</h3>
+										<p>Using this feature allows you to access the Lidarr API without having to reverse proxy it.  Just access it from: </p>
+										<code>' . $this->getServerPath() . 'api/v2/socks/lidarr/</code>
+									</div>
+								</div>
+							</div>'
+						),
+						array(
+							'type' => 'switch',
+							'name' => 'lidarrSocksEnabled',
+							'label' => 'Enable',
+							'value' => $this->config['lidarrSocksEnabled']
+						),
+						array(
+							'type' => 'select',
+							'name' => 'lidarrSocksAuth',
+							'label' => 'Minimum Authentication',
+							'value' => $this->config['lidarrSocksAuth'],
+							'options' => $groups
+						),
+					),
 					'Misc Options' => array(
 						array(
 							'type' => 'number',
@@ -6006,6 +6036,36 @@ class Organizr
 							'value' => $this->config['radarrToken']
 						)
 					),
+					'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">Radarr SOCKS API Connection</h3>
+										<p>Using this feature allows you to access the Radarr API without having to reverse proxy it.  Just access it from: </p>
+										<code>' . $this->getServerPath() . 'api/v2/socks/radarr/</code>
+									</div>
+								</div>
+							</div>'
+						),
+						array(
+							'type' => 'switch',
+							'name' => 'radarrSocksEnabled',
+							'label' => 'Enable',
+							'value' => $this->config['radarrSocksEnabled']
+						),
+						array(
+							'type' => 'select',
+							'name' => 'radarrSocksAuth',
+							'label' => 'Minimum Authentication',
+							'value' => $this->config['radarrSocksAuth'],
+							'options' => $groups
+						),
+					),
 					'Queue' => array(
 						array(
 							'type' => 'switch',

+ 4 - 0
api/config/default.php

@@ -61,8 +61,12 @@ return array(
 	'sonarrSocksAuth' => '999',
 	'lidarrURL' => '',
 	'lidarrToken' => '',
+	'lidarrSocksEnabled' => false,
+	'lidarrSocksAuth' => '999',
 	'radarrURL' => '',
 	'radarrToken' => '',
+	'radarrSocksEnabled' => false,
+	'radarrSocksAuth' => '999',
 	'couchpotatoURL' => '',
 	'couchpotatoToken' => '',
 	'sickrageURL' => '',

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

@@ -43,4 +43,94 @@ $app->any('/socks/sonarr/{route:.*}', function ($request, $response) {
 	return $response
 		->withHeader('Content-Type', 'application/json;charset=UTF-8')
 		->withStatus($GLOBALS['responseCode']);
+});
+$app->any('/socks/radarr/{route:.*}', function ($request, $response) {
+	$Organizr = ($request->getAttribute('Organizr')) ?? new Organizr();
+	$error = false;
+	if (!$Organizr->config['radarrSocksEnabled']) {
+		$error = true;
+		$Organizr->setAPIResponse('error', 'Radarr SOCKS module is not enabled', 409);
+	}
+	if (!$Organizr->qualifyRequest($Organizr->config['radarrSocksAuth'], true)) {
+		$error = true;
+	}
+	if (!$error) {
+		$new = str_ireplace('/api/v2/socks/radarr', '', $request->getUri()->getPath());
+		$getParams = ($_GET) ? '?' . http_build_query($_GET) : '';
+		$url = $Organizr->qualifyURL($Organizr->config['radarrURL']) . $new . $getParams;
+		$url = $Organizr->cleanPath($url);
+		$options = ($Organizr->localURL($url)) ? array('verify' => false) : array();
+		$headers = [];
+		if ($request->hasHeader('X-Api-Key')) {
+			$headerKey = $request->getHeaderLine('X-Api-Key');
+			$headers['X-Api-Key'] = $headerKey;
+		}
+		switch ($request->getMethod()) {
+			case 'GET':
+				$call = Requests::get($url, $headers, $options);
+				break;
+			case 'POST':
+				$call = Requests::post($url, $headers, $Organizr->apiData($request), $options);
+				break;
+			case 'DELETE':
+				$call = Requests::delete($url, $headers, $options);
+				break;
+			case 'PUT':
+				$call = Requests::put($url, $headers, $Organizr->apiData($request), $options);
+				break;
+			default:
+				$call = Requests::get($url, $headers, $options);
+		}
+		$response->getBody()->write($call->body);
+	} else {
+		$response->getBody()->write(jsonE($GLOBALS['api']));
+	}
+	return $response
+		->withHeader('Content-Type', 'application/json;charset=UTF-8')
+		->withStatus($GLOBALS['responseCode']);
+});
+$app->any('/socks/lidarr/{route:.*}', function ($request, $response) {
+	$Organizr = ($request->getAttribute('Organizr')) ?? new Organizr();
+	$error = false;
+	if (!$Organizr->config['lidarrSocksEnabled']) {
+		$error = true;
+		$Organizr->setAPIResponse('error', 'Lidarr SOCKS module is not enabled', 409);
+	}
+	if (!$Organizr->qualifyRequest($Organizr->config['lidarrSocksAuth'], true)) {
+		$error = true;
+	}
+	if (!$error) {
+		$new = str_ireplace('/api/v2/socks/lidarr', '', $request->getUri()->getPath());
+		$getParams = ($_GET) ? '?' . http_build_query($_GET) : '';
+		$url = $Organizr->qualifyURL($Organizr->config['lidarrURL']) . $new . $getParams;
+		$url = $Organizr->cleanPath($url);
+		$options = ($Organizr->localURL($url)) ? array('verify' => false) : array();
+		$headers = [];
+		if ($request->hasHeader('X-Api-Key')) {
+			$headerKey = $request->getHeaderLine('X-Api-Key');
+			$headers['X-Api-Key'] = $headerKey;
+		}
+		switch ($request->getMethod()) {
+			case 'GET':
+				$call = Requests::get($url, $headers, $options);
+				break;
+			case 'POST':
+				$call = Requests::post($url, $headers, $Organizr->apiData($request), $options);
+				break;
+			case 'DELETE':
+				$call = Requests::delete($url, $headers, $options);
+				break;
+			case 'PUT':
+				$call = Requests::put($url, $headers, $Organizr->apiData($request), $options);
+				break;
+			default:
+				$call = Requests::get($url, $headers, $options);
+		}
+		$response->getBody()->write($call->body);
+	} else {
+		$response->getBody()->write(jsonE($GLOBALS['api']));
+	}
+	return $response
+		->withHeader('Content-Type', 'application/json;charset=UTF-8')
+		->withStatus($GLOBALS['responseCode']);
 });