New: Command line arguments for Custom Scripts are no longer supported

pull/3191/head
Mark McDowall 5 years ago committed by GitHub
parent 1af3e0bd93
commit 8137a776b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -2,13 +2,13 @@ import PropTypes from 'prop-types';
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { createSelector } from 'reselect';
import { fetchDevices, clearDevices } from 'Store/Actions/deviceActions';
import { fetchOptions, clearOptions } from 'Store/Actions/providerOptionActions';
import DeviceInput from './DeviceInput';
function createMapStateToProps() {
return createSelector(
(state, { value }) => value,
(state) => state.devices,
(state) => state.providerOptions,
(value, devices) => {
return {
@ -37,8 +37,8 @@ function createMapStateToProps() {
}
const mapDispatchToProps = {
dispatchFetchDevices: fetchDevices,
dispatchClearDevices: clearDevices
dispatchFetchOptions: fetchOptions,
dispatchClearOptions: clearOptions
};
class DeviceInputConnector extends Component {
@ -51,7 +51,7 @@ class DeviceInputConnector extends Component {
}
componentWillUnmount = () => {
// this.props.dispatchClearDevices();
this.props.dispatchClearOptions();
}
//
@ -61,10 +61,14 @@ class DeviceInputConnector extends Component {
const {
provider,
providerData,
dispatchFetchDevices
dispatchFetchOptions
} = this.props;
dispatchFetchDevices({ provider, providerData });
dispatchFetchOptions({
action: 'getDevices',
provider,
providerData
});
}
//
@ -92,8 +96,8 @@ DeviceInputConnector.propTypes = {
providerData: PropTypes.object.isRequired,
name: PropTypes.string.isRequired,
onChange: PropTypes.func.isRequired,
dispatchFetchDevices: PropTypes.func.isRequired,
dispatchClearDevices: PropTypes.func.isRequired
dispatchFetchOptions: PropTypes.func.isRequired,
dispatchClearOptions: PropTypes.func.isRequired
};
export default connect(createMapStateToProps, mapDispatchToProps)(DeviceInputConnector);

@ -20,7 +20,7 @@ function getType(type) {
return inputTypes.NUMBER;
case 'path':
return inputTypes.PATH;
case 'filepath':
case 'filePath':
return inputTypes.PATH;
case 'select':
return inputTypes.SELECT;
@ -60,6 +60,7 @@ function ProviderFieldFormGroup(props) {
value,
type,
advanced,
hidden,
pending,
errors,
warnings,
@ -68,6 +69,13 @@ function ProviderFieldFormGroup(props) {
...otherProps
} = props;
if (
hidden === 'hidden' ||
(hidden === 'hiddenIfNotSet' && !value)
) {
return null;
}
return (
<FormGroup
advancedSettings={advancedSettings}
@ -86,7 +94,7 @@ function ProviderFieldFormGroup(props) {
errors={errors}
warnings={warnings}
pending={pending}
includeFiles={type === 'filepath' ? true : undefined}
includeFiles={type === 'filePath' ? true : undefined}
onChange={onChange}
{...otherProps}
/>
@ -108,6 +116,7 @@ ProviderFieldFormGroup.propTypes = {
value: PropTypes.any,
type: PropTypes.string.isRequired,
advanced: PropTypes.bool.isRequired,
hidden: PropTypes.string,
pending: PropTypes.bool.isRequired,
errors: PropTypes.arrayOf(PropTypes.object).isRequired,
warnings: PropTypes.arrayOf(PropTypes.object).isRequired,

@ -4,7 +4,6 @@ import * as blacklist from './blacklistActions';
import * as calendar from './calendarActions';
import * as captcha from './captchaActions';
import * as customFilters from './customFilterActions';
import * as devices from './deviceActions';
import * as commands from './commandActions';
import * as episodes from './episodeActions';
import * as episodeFiles from './episodeFileActions';
@ -15,6 +14,7 @@ import * as interactiveImportActions from './interactiveImportActions';
import * as oAuth from './oAuthActions';
import * as organizePreview from './organizePreviewActions';
import * as paths from './pathActions';
import * as providerOptions from './providerOptionActions';
import * as queue from './queueActions';
import * as releases from './releaseActions';
import * as rootFolders from './rootFolderActions';
@ -36,7 +36,6 @@ export default [
captcha,
commands,
customFilters,
devices,
episodes,
episodeFiles,
episodeHistory,
@ -46,6 +45,7 @@ export default [
oAuth,
organizePreview,
paths,
providerOptions,
queue,
releases,
rootFolders,

@ -8,7 +8,7 @@ import { set } from './baseActions';
//
// Variables
export const section = 'devices';
export const section = 'providerOptions';
//
// State
@ -23,32 +23,27 @@ export const defaultState = {
//
// Actions Types
export const FETCH_DEVICES = 'devices/fetchDevices';
export const CLEAR_DEVICES = 'devices/clearDevices';
export const FETCH_OPTIONS = 'devices/fetchOptions';
export const CLEAR_OPTIONS = 'devices/clearOptions';
//
// Action Creators
export const fetchDevices = createThunk(FETCH_DEVICES);
export const clearDevices = createAction(CLEAR_DEVICES);
export const fetchOptions = createThunk(FETCH_OPTIONS);
export const clearOptions = createAction(CLEAR_OPTIONS);
//
// Action Handlers
export const actionHandlers = handleThunks({
[FETCH_DEVICES]: function(getState, payload, dispatch) {
const actionPayload = {
action: 'getDevices',
...payload
};
[FETCH_OPTIONS]: function(getState, payload, dispatch) {
dispatch(set({
section,
isFetching: true
}));
const promise = requestAction(actionPayload);
const promise = requestAction(payload);
promise.done((data) => {
dispatch(set({
@ -56,7 +51,7 @@ export const actionHandlers = handleThunks({
isFetching: false,
isPopulated: true,
error: null,
items: data.devices || []
items: data.options || []
}));
});
@ -76,7 +71,7 @@ export const actionHandlers = handleThunks({
export const reducers = createHandleActions({
[CLEAR_DEVICES]: function(state) {
[CLEAR_OPTIONS]: function(state) {
return updateSectionState(state, section, defaultState);
}

@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using NzbDrone.Common.EnvironmentInfo;
namespace NzbDrone.Common.Disk
{
public static class SystemFolders
{
public static List<string> GetSystemFolders()
{
if (OsInfo.IsWindows)
{
return new List<string> { Environment.GetFolderPath(Environment.SpecialFolder.Windows) };
}
if (OsInfo.IsOsx)
{
return new List<string> { "/System" };
}
return new List<string>
{
"/bin",
"/boot",
"/lib",
"/sbin",
"/proc"
};
}
}
}

@ -72,6 +72,9 @@
<Reference Include="ICSharpCode.SharpZipLib">
<HintPath>..\packages\ICSharpCode.SharpZipLib.Patched.0.86.5\lib\net20\ICSharpCode.SharpZipLib.dll</HintPath>
</Reference>
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.ValueTuple.4.5.0\lib\net461\System.ValueTuple.dll</HintPath>
</Reference>
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq" />
</ItemGroup>
@ -97,6 +100,7 @@
<Compile Include="Disk\RelativeFileSystemModel.cs" />
<Compile Include="Disk\FileSystemModel.cs" />
<Compile Include="Disk\FileSystemResult.cs" />
<Compile Include="Disk\SystemFolders.cs" />
<Compile Include="EnvironmentInfo\IOsVersionAdapter.cs" />
<Compile Include="EnvironmentInfo\IPlatformInfo.cs" />
<Compile Include="EnvironmentInfo\OsVersionModel.cs" />

@ -108,11 +108,7 @@ namespace NzbDrone.Common.Processes
public Process Start(string path, string args = null, StringDictionary environmentVariables = null, Action<string> onOutputDataReceived = null, Action<string> onErrorDataReceived = null)
{
if (PlatformInfo.IsMono && path.EndsWith(".exe", StringComparison.InvariantCultureIgnoreCase))
{
args = GetMonoArgs(path, args);
path = "mono";
}
(path, args) = GetPathAndArgs(path, args);
var logger = LogManager.GetLogger(new FileInfo(path).Name);
@ -192,11 +188,7 @@ namespace NzbDrone.Common.Processes
public Process SpawnNewProcess(string path, string args = null, StringDictionary environmentVariables = null, bool noWindow = false)
{
if (PlatformInfo.IsMono && path.EndsWith(".exe", StringComparison.InvariantCultureIgnoreCase))
{
args = GetMonoArgs(path, args);
path = "mono";
}
(path, args) = GetPathAndArgs(path, args);
_logger.Debug("Starting {0} {1}", path, args);
@ -361,9 +353,19 @@ namespace NzbDrone.Common.Processes
return processes;
}
private string GetMonoArgs(string path, string args)
private (string Path, string Args) GetPathAndArgs(string path, string args)
{
return string.Format("--debug {0} {1}", path, args);
if (PlatformInfo.IsMono && path.EndsWith(".exe", StringComparison.InvariantCultureIgnoreCase))
{
return ("mono", $"--debug {path} {args}");
}
if (OsInfo.IsWindows && path.EndsWith(".bat", StringComparison.InvariantCultureIgnoreCase))
{
return ("cmd.exe", $"/c {path} {args}");
}
return (path, args);
}
}
}

@ -6,4 +6,5 @@
<package id="NLog" version="4.5.3" targetFramework="net462" />
<package id="SharpRaven" version="2.4.0" targetFramework="net462" />
<package id="System.Runtime.InteropServices.RuntimeInformation" version="4.3.0" targetFramework="net462" />
<package id="System.ValueTuple" version="4.5.0" targetFramework="net462" />
</packages>

@ -19,6 +19,7 @@ namespace NzbDrone.Core.Annotations
public bool Advanced { get; set; }
public Type SelectOptions { get; set; }
public string Section { get; set; }
public HiddenType Hidden { get; set; }
}
public enum FieldType
@ -30,7 +31,6 @@ namespace NzbDrone.Core.Annotations
Select,
Path,
FilePath,
Hidden,
Tag,
Action,
Url,
@ -38,4 +38,11 @@ namespace NzbDrone.Core.Annotations
OAuth,
Device
}
public enum HiddenType
{
Visible,
Hidden,
HiddenIfNotSet
}
}

@ -6,6 +6,7 @@ using System.Linq;
using FluentValidation.Results;
using NLog;
using NzbDrone.Common.Disk;
using NzbDrone.Common.Extensions;
using NzbDrone.Common.Processes;
using NzbDrone.Core.ThingiProvider;
using NzbDrone.Core.Tv;
@ -133,22 +134,33 @@ namespace NzbDrone.Core.Notifications.CustomScript
failures.Add(new NzbDroneValidationFailure("Path", "File does not exist"));
}
try
foreach (var systemFolder in SystemFolders.GetSystemFolders())
{
var environmentVariables = new StringDictionary();
environmentVariables.Add("Sonarr_EventType", "Test");
var processOutput = ExecuteScript(environmentVariables);
if (processOutput.ExitCode != 0)
if (systemFolder.IsParentPath(Settings.Path))
{
failures.Add(new NzbDroneValidationFailure(string.Empty, $"Script exited with code: {processOutput.ExitCode}"));
failures.Add(new NzbDroneValidationFailure("Path", $"Must not be a descendant of '{systemFolder}'"));
}
}
catch (Exception ex)
if (failures.Empty())
{
_logger.Error(ex);
failures.Add(new NzbDroneValidationFailure(string.Empty, ex.Message));
try
{
var environmentVariables = new StringDictionary();
environmentVariables.Add("Sonarr_EventType", "Test");
var processOutput = ExecuteScript(environmentVariables);
if (processOutput.ExitCode != 0)
{
failures.Add(new NzbDroneValidationFailure(string.Empty, $"Script exited with code: {processOutput.ExitCode}"));
}
}
catch (Exception ex)
{
_logger.Error(ex);
failures.Add(new NzbDroneValidationFailure(string.Empty, ex.Message));
}
}
return new ValidationResult(failures);
@ -165,5 +177,10 @@ namespace NzbDrone.Core.Notifications.CustomScript
return processOutput;
}
private bool ValidatePathParent(string possibleParent, string path)
{
return possibleParent.IsParentPath(path);
}
}
}

@ -11,6 +11,7 @@ namespace NzbDrone.Core.Notifications.CustomScript
public CustomScriptSettingsValidator()
{
RuleFor(c => c.Path).IsValidPath();
RuleFor(c => c.Arguments).Empty().WithMessage("Arguments are no longer supported for custom scripts");
}
}
@ -21,7 +22,7 @@ namespace NzbDrone.Core.Notifications.CustomScript
[FieldDefinition(0, Label = "Path", Type = FieldType.FilePath)]
public string Path { get; set; }
[FieldDefinition(1, Label = "Arguments", HelpText = "Arguments to pass to the script")]
[FieldDefinition(1, Label = "Arguments", HelpText = "Arguments to pass to the script", Hidden = HiddenType.HiddenIfNotSet)]
public string Arguments { get; set; }
public NzbDroneValidationResult Validate()

@ -13,22 +13,22 @@ namespace NzbDrone.Core.Notifications.Plex.HomeTheater
//These need to be kept in the same order as XBMC Settings, but we don't want them displayed
[FieldDefinition(2, Label = "Username", Type = FieldType.Hidden)]
[FieldDefinition(2, Label = "Username", Hidden = HiddenType.Hidden)]
public new string Username { get; set; }
[FieldDefinition(3, Label = "Password", Type = FieldType.Hidden)]
[FieldDefinition(3, Label = "Password", Hidden = HiddenType.Hidden)]
public new string Password { get; set; }
[FieldDefinition(5, Label = "GUI Notification", Type = FieldType.Hidden)]
[FieldDefinition(5, Label = "GUI Notification", Type = FieldType.Checkbox, Hidden = HiddenType.Hidden)]
public new bool Notify { get; set; }
[FieldDefinition(6, Label = "Update Library", HelpText = "Update Library on Download & Rename?", Type = FieldType.Hidden)]
[FieldDefinition(6, Label = "Update Library", HelpText = "Update Library on Download & Rename?", Type = FieldType.Checkbox, Hidden = HiddenType.Hidden)]
public new bool UpdateLibrary { get; set; }
[FieldDefinition(7, Label = "Clean Library", HelpText = "Clean Library after update?", Type = FieldType.Hidden)]
[FieldDefinition(7, Label = "Clean Library", HelpText = "Clean Library after update?", Type = FieldType.Checkbox, Hidden = HiddenType.Hidden)]
public new bool CleanLibrary { get; set; }
[FieldDefinition(8, Label = "Always Update", HelpText = "Update Library even when a video is playing?", Type = FieldType.Hidden)]
[FieldDefinition(8, Label = "Always Update", HelpText = "Update Library even when a video is playing?", Type = FieldType.Checkbox, Hidden = HiddenType.Hidden)]
public new bool AlwaysUpdate { get; set; }
}
}

@ -56,7 +56,7 @@ namespace NzbDrone.Core.Notifications.PushBullet
return new
{
devices = devices.Where(d => d.Nickname.IsNotNullOrWhiteSpace())
options = devices.Where(d => d.Nickname.IsNotNullOrWhiteSpace())
.OrderBy(d => d.Nickname, StringComparer.InvariantCultureIgnoreCase)
.Select(d => new
{

@ -1,6 +1,5 @@
using System;
using FluentValidation.Validators;
using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Common.Disk;
using NzbDrone.Common.Extensions;
namespace NzbDrone.Core.Validation.Paths
@ -16,33 +15,13 @@ namespace NzbDrone.Core.Validation.Paths
{
var folder = context.PropertyValue.ToString();
if (OsInfo.IsWindows)
foreach (var systemFolder in SystemFolders.GetSystemFolders())
{
var windowsFolder = Environment.GetFolderPath(Environment.SpecialFolder.Windows);
context.MessageFormatter.AppendArgument("systemFolder", windowsFolder);
if (windowsFolder.PathEquals(folder))
{
context.MessageFormatter.AppendArgument("relationship", "set to");
return false;
}
if (windowsFolder.IsParentPath(folder))
{
context.MessageFormatter.AppendArgument("relationship", "child of");
return false;
}
}
else if (OsInfo.IsOsx)
{
var systemFolder = "/System";
context.MessageFormatter.AppendArgument("systemFolder", systemFolder);
if (systemFolder.PathEquals(folder))
{
context.MessageFormatter.AppendArgument("relationship", "child of");
context.MessageFormatter.AppendArgument("relationship", "set to");
return false;
}
@ -54,36 +33,6 @@ namespace NzbDrone.Core.Validation.Paths
return false;
}
}
else
{
var folders = new[]
{
"/bin",
"/boot",
"/lib",
"/sbin",
"/proc"
};
foreach (var f in folders)
{
context.MessageFormatter.AppendArgument("systemFolder", f);
if (f.PathEquals(folder))
{
context.MessageFormatter.AppendArgument("relationship", "child of");
return false;
}
if (f.IsParentPath(folder))
{
context.MessageFormatter.AppendArgument("relationship", "child of");
return false;
}
}
}
return true;
}

@ -15,6 +15,7 @@ namespace Sonarr.Http.ClientSchema
public bool Advanced { get; set; }
public List<SelectOption> SelectOptions { get; set; }
public string Section { get; set; }
public string Hidden { get; set; }
public Field Clone()
{

@ -100,8 +100,8 @@ namespace Sonarr.Http.ClientSchema
HelpLink = fieldAttribute.HelpLink,
Order = fieldAttribute.Order,
Advanced = fieldAttribute.Advanced,
Type = fieldAttribute.Type.ToString().ToLowerInvariant(),
Section = fieldAttribute.Section,
Type = fieldAttribute.Type.ToString().FirstCharToLower(),
Section = fieldAttribute.Section
};
if (fieldAttribute.Type == FieldType.Select)
@ -109,6 +109,11 @@ namespace Sonarr.Http.ClientSchema
field.SelectOptions = GetSelectOptions(fieldAttribute.SelectOptions);
}
if (fieldAttribute.Hidden != HiddenType.Visible)
{
field.Hidden = fieldAttribute.Hidden.ToString().FirstCharToLower();
}
var valueConverter = GetValueConverter(propertyInfo.PropertyType);
result.Add(new FieldMapping

Loading…
Cancel
Save