mirror of
https://github.com/idanoo/autobrr
synced 2025-07-26 10:19:13 +00:00
feat(irc): support optional SASL and NickServ auth (#511)
* feat(irc): support SASL and NickServ auth * feat(irc): add missing fields * feat(irc): support SASL and NickServ auth * feat(irc): add missing fields * feat(irc): add validation * feat(indexers): unify and set required values * feat(irc): add postgres migrations * feat(irc): use nick as handlerkey * feat(irc): use account for nickserv * fix(irc): pg db migration
This commit is contained in:
parent
4ef0408f33
commit
4bf023d030
65 changed files with 1404 additions and 631 deletions
|
@ -87,7 +87,8 @@ interface IrcNetworkAddFormValues {
|
|||
port: number;
|
||||
tls: boolean;
|
||||
pass: string;
|
||||
nickserv: NickServ;
|
||||
nick: string;
|
||||
auth: IrcAuth;
|
||||
channels: IrcChannel[];
|
||||
}
|
||||
|
||||
|
@ -114,6 +115,7 @@ export function IrcNetworkAddForm({ isOpen, toggle }: AddFormProps) {
|
|||
const onSubmit = (data: unknown) => {
|
||||
mutation.mutate(data as IrcNetwork);
|
||||
};
|
||||
|
||||
const validate = (values: FormikValues) => {
|
||||
const errors = {} as FormikErrors<FormikValues>;
|
||||
if (!values.name)
|
||||
|
@ -125,8 +127,11 @@ export function IrcNetworkAddForm({ isOpen, toggle }: AddFormProps) {
|
|||
if (!values.server)
|
||||
errors.server = "Required";
|
||||
|
||||
if (!values.nickserv || !values.nickserv.account)
|
||||
errors.nickserv = { account: "Required" };
|
||||
if (!values.nick)
|
||||
errors.nick = "Required";
|
||||
|
||||
// if (!values.auth || !values.auth.account)
|
||||
// errors.auth = { account: "Required" };
|
||||
|
||||
return errors;
|
||||
};
|
||||
|
@ -138,7 +143,9 @@ export function IrcNetworkAddForm({ isOpen, toggle }: AddFormProps) {
|
|||
port: 6667,
|
||||
tls: false,
|
||||
pass: "",
|
||||
nickserv: {
|
||||
nick: "",
|
||||
auth: {
|
||||
mechanism: "SASL_PLAIN",
|
||||
account: ""
|
||||
},
|
||||
channels: []
|
||||
|
@ -185,14 +192,20 @@ export function IrcNetworkAddForm({ isOpen, toggle }: AddFormProps) {
|
|||
help="Network password"
|
||||
/>
|
||||
<TextFieldWide
|
||||
name="nickserv.account"
|
||||
label="NickServ Account"
|
||||
placeholder="NickServ Account"
|
||||
name="nick"
|
||||
label="Nick"
|
||||
placeholder="bot nick"
|
||||
required={true}
|
||||
/>
|
||||
<TextFieldWide
|
||||
name="auth.account"
|
||||
label="Auth Account"
|
||||
placeholder="Auth Account"
|
||||
required={true}
|
||||
/>
|
||||
<PasswordFieldWide
|
||||
name="nickserv.password"
|
||||
label="NickServ Password"
|
||||
name="auth.password"
|
||||
label="Auth Password"
|
||||
/>
|
||||
<PasswordFieldWide name="invite_command" label="Invite command" />
|
||||
|
||||
|
@ -210,8 +223,9 @@ interface IrcNetworkUpdateFormValues {
|
|||
server: string;
|
||||
port: number;
|
||||
tls: boolean;
|
||||
nickserv?: NickServ;
|
||||
pass: string;
|
||||
nick: string;
|
||||
auth?: IrcAuth;
|
||||
invite_command: string;
|
||||
channels: Array<IrcChannel>;
|
||||
}
|
||||
|
@ -245,6 +259,7 @@ export function IrcNetworkUpdateForm({
|
|||
});
|
||||
|
||||
const onSubmit = (data: unknown) => {
|
||||
console.log("submit: ", data);
|
||||
mutation.mutate(data as IrcNetwork);
|
||||
};
|
||||
|
||||
|
@ -263,10 +278,8 @@ export function IrcNetworkUpdateForm({
|
|||
errors.port = "Required";
|
||||
}
|
||||
|
||||
if (!values.nickserv?.account) {
|
||||
errors.nickserv = {
|
||||
account: "Required"
|
||||
};
|
||||
if (!values.nick) {
|
||||
errors.nick = "Required";
|
||||
}
|
||||
|
||||
return errors;
|
||||
|
@ -283,10 +296,11 @@ export function IrcNetworkUpdateForm({
|
|||
server: network.server,
|
||||
port: network.port,
|
||||
tls: network.tls,
|
||||
nickserv: network.nickserv,
|
||||
nick: network.nick,
|
||||
pass: network.pass,
|
||||
channels: network.channels,
|
||||
invite_command: network.invite_command
|
||||
auth: network.auth,
|
||||
invite_command: network.invite_command,
|
||||
channels: network.channels
|
||||
};
|
||||
|
||||
return (
|
||||
|
@ -328,19 +342,44 @@ export function IrcNetworkUpdateForm({
|
|||
<PasswordFieldWide
|
||||
name="pass"
|
||||
label="Password"
|
||||
help="Network password"
|
||||
help="Network password, not commonly used."
|
||||
/>
|
||||
|
||||
<TextFieldWide
|
||||
name="nickserv.account"
|
||||
label="NickServ Account"
|
||||
placeholder="NickServ Account"
|
||||
name="nick"
|
||||
label="Nick"
|
||||
placeholder="nick"
|
||||
required={true}
|
||||
/>
|
||||
<PasswordFieldWide
|
||||
name="nickserv.password"
|
||||
label="NickServ Password"
|
||||
/>
|
||||
|
||||
<div className="border-t border-gray-200 dark:border-gray-700 py-5">
|
||||
<div className="px-4 space-y-1 mb-8">
|
||||
<Dialog.Title className="text-lg font-medium text-gray-900 dark:text-white">Identification</Dialog.Title>
|
||||
<p className="text-sm text-gray-500 dark:text-gray-400">
|
||||
Identify with SASL or NickServ. Most networks support SASL but some don't.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<SelectField<IrcAuthMechanism>
|
||||
name="auth.mechanism"
|
||||
label="Mechanism"
|
||||
options={IrcAuthMechanismTypeOptions}
|
||||
/>
|
||||
|
||||
<TextFieldWide
|
||||
name="auth.account"
|
||||
label="Account"
|
||||
placeholder="Auth Account"
|
||||
help="NickServ / SASL account. For grouped nicks try the main."
|
||||
/>
|
||||
|
||||
<PasswordFieldWide
|
||||
name="auth.password"
|
||||
label="Password"
|
||||
help="NickServ / SASL password."
|
||||
/>
|
||||
|
||||
</div>
|
||||
|
||||
<PasswordFieldWide name="invite_command" label="Invite command" />
|
||||
|
||||
|
@ -349,4 +388,118 @@ export function IrcNetworkUpdateForm({
|
|||
)}
|
||||
</SlideOver>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
interface SelectFieldProps<T> {
|
||||
name: string;
|
||||
label: string;
|
||||
options: OptionBasicTyped<T>[]
|
||||
}
|
||||
|
||||
function SelectField<T>({ name, label, options }: SelectFieldProps<T>) {
|
||||
return (
|
||||
<div className="flex items-center justify-between space-y-1 px-4 sm:space-y-0 sm:grid sm:grid-cols-3 sm:gap-4">
|
||||
<div>
|
||||
<label
|
||||
htmlFor={name}
|
||||
className="block text-sm font-medium text-gray-900 dark:text-white"
|
||||
>
|
||||
{label}
|
||||
</label>
|
||||
</div>
|
||||
<div className="sm:col-span-2">
|
||||
<Field name={name} type="select">
|
||||
{({
|
||||
field,
|
||||
form: { setFieldValue, resetForm }
|
||||
}: FieldProps) => (
|
||||
<Select
|
||||
{...field}
|
||||
id={name}
|
||||
isClearable={true}
|
||||
isSearchable={true}
|
||||
components={{
|
||||
Input,
|
||||
Control,
|
||||
Menu,
|
||||
Option
|
||||
}}
|
||||
placeholder="Choose a type"
|
||||
styles={{
|
||||
singleValue: (base) => ({
|
||||
...base,
|
||||
color: "unset"
|
||||
})
|
||||
}}
|
||||
theme={(theme) => ({
|
||||
...theme,
|
||||
spacing: {
|
||||
...theme.spacing,
|
||||
controlHeight: 30,
|
||||
baseUnit: 2
|
||||
}
|
||||
})}
|
||||
value={field?.value && options.find(o => o.value == field?.value)}
|
||||
onChange={(option) => {
|
||||
resetForm();
|
||||
|
||||
// const opt = option as SelectOption;
|
||||
// setFieldValue("name", option?.label ?? "")
|
||||
setFieldValue(
|
||||
field.name,
|
||||
option.value ?? ""
|
||||
);
|
||||
}}
|
||||
options={options}
|
||||
/>
|
||||
)}
|
||||
</Field>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
import Select, { components, ControlProps, InputProps, MenuProps, OptionProps } from "react-select";
|
||||
import { IrcAuthMechanismTypeOptions, OptionBasicTyped } from "../../domain/constants";
|
||||
import { Dialog } from "@headlessui/react";
|
||||
|
||||
const Input = (props: InputProps) => {
|
||||
return (
|
||||
<components.Input
|
||||
{...props}
|
||||
inputClassName="outline-none border-none shadow-none focus:ring-transparent"
|
||||
className="text-gray-400 dark:text-gray-100"
|
||||
children={props.children}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
const Control = (props: ControlProps) => {
|
||||
return (
|
||||
<components.Control
|
||||
{...props}
|
||||
className="p-1 block w-full dark:bg-gray-800 border border-gray-300 dark:border-gray-700 rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500 dark:text-gray-100 sm:text-sm"
|
||||
children={props.children}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
const Menu = (props: MenuProps) => {
|
||||
return (
|
||||
<components.Menu
|
||||
{...props}
|
||||
className="dark:bg-gray-800 border border-gray-300 dark:border-gray-700 dark:text-gray-400 rounded-md shadow-sm"
|
||||
children={props.children}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
const Option = (props: OptionProps) => {
|
||||
return (
|
||||
<components.Option
|
||||
{...props}
|
||||
className="dark:text-gray-400 dark:bg-gray-800 dark:hover:bg-gray-900 dark:focus:bg-gray-900"
|
||||
children={props.children}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue