From 1430cbcf879575bd9d3379deb597a0ddb9d5d847 Mon Sep 17 00:00:00 2001 From: FelixTz Date: Thu, 5 Oct 2023 20:46:05 +0200 Subject: [PATCH] Added proper authorization for default topic Added translation with words.js --- .gitignore | 4 ++-- admin/i18n/de/translations.json | 16 ++++++++++---- admin/i18n/en/translations.json | 19 ++++++++++------ admin/i18n/es/translations.json | 16 ++++++++++---- admin/i18n/fr/translations.json | 16 ++++++++++---- admin/i18n/it/translations.json | 16 ++++++++++---- admin/i18n/nl/translations.json | 16 ++++++++++---- admin/i18n/pl/translations.json | 16 ++++++++++---- admin/i18n/pt/translations.json | 16 ++++++++++---- admin/i18n/ru/translations.json | 16 ++++++++++---- admin/i18n/uk/translations.json | 16 ++++++++++---- admin/i18n/zh-cn/translations.json | 16 ++++++++++---- admin/jsonConfig.json | 35 ++++++++++++++++++++++++++---- admin/words.js | 22 +++++++++++++++++++ io-package.json | 21 +++++++++++++----- main.js | 28 ++++++++++++++---------- package.json | 2 +- 17 files changed, 220 insertions(+), 71 deletions(-) create mode 100644 admin/words.js diff --git a/.gitignore b/.gitignore index 3bf582b..280d316 100644 --- a/.gitignore +++ b/.gitignore @@ -13,5 +13,5 @@ iobroker.*.tgz Thumbs.db # i18n intermediate files -admin/i18n/flat.txt -admin/i18n/*/flat.txt \ No newline at end of file +admin/i18nrhjkkj/flat.txt +admin/i18nrhjkkj/*/flat.txt \ No newline at end of file diff --git a/admin/i18n/de/translations.json b/admin/i18n/de/translations.json index 9ab77b3..99b67b8 100644 --- a/admin/i18n/de/translations.json +++ b/admin/i18n/de/translations.json @@ -1,5 +1,13 @@ { - "ntfy adapter settings": "Adaptereinstellungen für ntfy", - "option1": "Option 1", - "option2": "Option 2" -} \ No newline at end of file + "serverURL": "URL zum Ntfy-Server", + "defaultTopic": "Standard Topic", + "defaultUsername": "Standard-Benutzername", + "defaultPassword": "Standard-Passwort", + "defaultAccessToken": "Standard-API-Token", + "helpServerURL": "URL ohne Topic – https://ntfy-server.sh", + "helpDefaultAccessToken": "Nur wenn Benutzername/Passwort nicht verwendet wird", + "defaultTopicAuth": "Standard-Topic-Authentifizierung", + "defaultTopicAuthNone": "Keine Authentifikation", + "defaultTopicAuthUser": "Benutzer/Passwort", + "defaultTopicAuthToken": "Zugangstoken" +} diff --git a/admin/i18n/en/translations.json b/admin/i18n/en/translations.json index f8c43f1..2fddecb 100644 --- a/admin/i18n/en/translations.json +++ b/admin/i18n/en/translations.json @@ -1,8 +1,13 @@ { - "ntfy adapter settings": "Adapter settings for ntfy", - "serverURL": "URL zum Ntfy-Server", - "defaultTopic": "Default Topic", - "defaultUsername": "Default Username", - "defaultPassword": "Default Password", - "defaultAccessToken": "Default Access Token" -} \ No newline at end of file + "serverURL": "URL zum Ntfy-Server", + "defaultTopic": "Default Topic", + "defaultUsername": "Default Username", + "defaultPassword": "Default Password", + "defaultAccessToken": "Default Access Token", + "helpServerURL": "URL without Topic - https://ntfy-server.sh", + "helpDefaultAccessToken": "Only if username/password is not used", + "defaultTopicAuth": "Default Topic Authentication", + "defaultTopicAuthNone": "No Authentication", + "defaultTopicAuthUser": "User Authentication", + "defaultTopicAuthToken": "Access Token" +} diff --git a/admin/i18n/es/translations.json b/admin/i18n/es/translations.json index 273ca17..577ce29 100644 --- a/admin/i18n/es/translations.json +++ b/admin/i18n/es/translations.json @@ -1,5 +1,13 @@ { - "ntfy adapter settings": "Ajustes del adaptador para ntfy", - "option1": "Opción 1", - "option2": "opcion 2" -} \ No newline at end of file + "serverURL": "URL del servidor Ntfy", + "defaultTopic": "Tema predeterminado", + "defaultUsername": "Nombre de usuario predeterminado", + "defaultPassword": "Contraseña predeterminada", + "defaultAccessToken": "Token de acceso predeterminado", + "helpServerURL": "URL sin tema: https://ntfy-server.sh", + "helpDefaultAccessToken": "Sólo si no se utiliza nombre de usuario/contraseña", + "defaultTopicAuth": "Autenticación de tema predeterminada", + "defaultTopicAuthNone": "Sin autenticacion", + "defaultTopicAuthUser": "Autenticacion de usuario", + "defaultTopicAuthToken": "Token de acceso" +} diff --git a/admin/i18n/fr/translations.json b/admin/i18n/fr/translations.json index 7efc993..6aa08b9 100644 --- a/admin/i18n/fr/translations.json +++ b/admin/i18n/fr/translations.json @@ -1,5 +1,13 @@ { - "ntfy adapter settings": "Paramètres d'adaptateur pour ntfy", - "option1": "Option 1", - "option2": "Option 2" -} \ No newline at end of file + "serverURL": "URL vers le serveur Ntfy", + "defaultTopic": "Sujet par défaut", + "defaultUsername": "Nom d'utilisateur par défaut", + "defaultPassword": "Mot de passe par défaut", + "defaultAccessToken": "Jeton d'accès par défaut", + "helpServerURL": "URL sans sujet - https://ntfy-server.sh", + "helpDefaultAccessToken": "Uniquement si le nom d'utilisateur/mot de passe n'est pas utilisé", + "defaultTopicAuth": "Authentification du sujet par défaut", + "defaultTopicAuthNone": "Pas d'authentification", + "defaultTopicAuthUser": "Authentification d'utilisateur", + "defaultTopicAuthToken": "Jeton d'accès" +} diff --git a/admin/i18n/it/translations.json b/admin/i18n/it/translations.json index 24f2043..ab3930c 100644 --- a/admin/i18n/it/translations.json +++ b/admin/i18n/it/translations.json @@ -1,5 +1,13 @@ { - "ntfy adapter settings": "Impostazioni dell'adattatore per ntfy", - "option1": "opzione 1", - "option2": "opzione 2" -} \ No newline at end of file + "serverURL": "URL del server Ntfy", + "defaultTopic": "Argomento predefinito", + "defaultUsername": "Nome utente predefinito", + "defaultPassword": "Password predefinita", + "defaultAccessToken": "Token di accesso predefinito", + "helpServerURL": "URL senza argomento: https://ntfy-server.sh", + "helpDefaultAccessToken": "Solo se non viene utilizzato nome utente/password", + "defaultTopicAuth": "Autenticazione argomento predefinita", + "defaultTopicAuthNone": "Nessuna autenticazione", + "defaultTopicAuthUser": "Autenticazione utente", + "defaultTopicAuthToken": "Token di accesso" +} diff --git a/admin/i18n/nl/translations.json b/admin/i18n/nl/translations.json index c744761..2b195be 100644 --- a/admin/i18n/nl/translations.json +++ b/admin/i18n/nl/translations.json @@ -1,5 +1,13 @@ { - "ntfy adapter settings": "Adapterinstellingen voor ntfy", - "option1": "Optie 1", - "option2": "Optie 2" -} \ No newline at end of file + "serverURL": "URL naar Ntfy-Server", + "defaultTopic": "Standaardonderwerp", + "defaultUsername": "Standaard gebruikersnaam", + "defaultPassword": "Standaard wachtwoord", + "defaultAccessToken": "Standaardtoegangstoken", + "helpServerURL": "URL zonder onderwerp - https://ntfy-server.sh", + "helpDefaultAccessToken": "Alleen als gebruikersnaam/wachtwoord niet wordt gebruikt", + "defaultTopicAuth": "Standaard onderwerpverificatie", + "defaultTopicAuthNone": "Geen authenticatie", + "defaultTopicAuthUser": "Gebruikersverificatie", + "defaultTopicAuthToken": "Toegangstoken" +} diff --git a/admin/i18n/pl/translations.json b/admin/i18n/pl/translations.json index 4133c63..e029b08 100644 --- a/admin/i18n/pl/translations.json +++ b/admin/i18n/pl/translations.json @@ -1,5 +1,13 @@ { - "ntfy adapter settings": "Ustawienia adaptera dla ntfy", - "option1": "opcja 1", - "option2": "Opcja 2" -} \ No newline at end of file + "serverURL": "Adres URL serwera Ntfy", + "defaultTopic": "Domyślny temat", + "defaultUsername": "Domyślna nazwa użytkownika", + "defaultPassword": "Domyślne hasło", + "defaultAccessToken": "Domyślny token dostępu", + "helpServerURL": "Adres URL bez tematu - https://ntfy-server.sh", + "helpDefaultAccessToken": "Tylko jeśli nazwa użytkownika/hasło nie jest używana", + "defaultTopicAuth": "Domyślne uwierzytelnianie tematu", + "defaultTopicAuthNone": "Brak autoryzacji", + "defaultTopicAuthUser": "Uwierzytelnianie użytkownika", + "defaultTopicAuthToken": "Token dostępu" +} diff --git a/admin/i18n/pt/translations.json b/admin/i18n/pt/translations.json index b693b1b..d56a494 100644 --- a/admin/i18n/pt/translations.json +++ b/admin/i18n/pt/translations.json @@ -1,5 +1,13 @@ { - "ntfy adapter settings": "Configurações do adaptador para ntfy", - "option1": "Opção 1", - "option2": "opção 2" -} \ No newline at end of file + "serverURL": "URL para servidor Ntfy", + "defaultTopic": "Tópico padrão", + "defaultUsername": "Nome de usuário padrão", + "defaultPassword": "Senha padrão", + "defaultAccessToken": "Token de acesso padrão", + "helpServerURL": "URL sem tópico - https://ntfy-server.sh", + "helpDefaultAccessToken": "Somente se nome de usuário/senha não for usado", + "defaultTopicAuth": "Autenticação de tópico padrão", + "defaultTopicAuthNone": "Sem autenticação", + "defaultTopicAuthUser": "Autenticação de usuário", + "defaultTopicAuthToken": "Token de acesso" +} diff --git a/admin/i18n/ru/translations.json b/admin/i18n/ru/translations.json index 5ed2683..ba9a5a7 100644 --- a/admin/i18n/ru/translations.json +++ b/admin/i18n/ru/translations.json @@ -1,5 +1,13 @@ { - "ntfy adapter settings": "Настройки адаптера для ntfy", - "option1": "Опция 1", - "option2": "вариант 2" -} \ No newline at end of file + "serverURL": "URL-адрес Ntfy-сервера", + "defaultTopic": "Тема по умолчанию", + "defaultUsername": "Имя пользователя по умолчанию", + "defaultPassword": "Пароль по умолчанию", + "defaultAccessToken": "Токен доступа по умолчанию", + "helpServerURL": "URL без темы — https://ntfy-server.sh", + "helpDefaultAccessToken": "Только если имя пользователя/пароль не используется", + "defaultTopicAuth": "Аутентификация темы по умолчанию", + "defaultTopicAuthNone": "Нет аутентификации", + "defaultTopicAuthUser": "Аутентификация пользователя", + "defaultTopicAuthToken": "Токен доступа" +} diff --git a/admin/i18n/uk/translations.json b/admin/i18n/uk/translations.json index 805d16b..fa5dd2b 100644 --- a/admin/i18n/uk/translations.json +++ b/admin/i18n/uk/translations.json @@ -1,5 +1,13 @@ { - "ntfy adapter settings": "Налаштування адаптера для ntfy", - "option1": "варіант1", - "option2": "варіант2" -} \ No newline at end of file + "serverURL": "URL-адреса сервера Ntfy", + "defaultTopic": "Тема за замовчуванням", + "defaultUsername": "Ім'я користувача за замовчуванням", + "defaultPassword": "Пароль за умовчанням", + "defaultAccessToken": "Маркер доступу за умовчанням", + "helpServerURL": "URL без теми - https://ntfy-server.sh", + "helpDefaultAccessToken": "Лише якщо ім’я користувача/пароль не використовується", + "defaultTopicAuth": "Автентифікація теми за замовчуванням", + "defaultTopicAuthNone": "Без автентифікації", + "defaultTopicAuthUser": "Автентифікація користувача", + "defaultTopicAuthToken": "Маркер доступу" +} diff --git a/admin/i18n/zh-cn/translations.json b/admin/i18n/zh-cn/translations.json index c4edd0b..e98f4ab 100644 --- a/admin/i18n/zh-cn/translations.json +++ b/admin/i18n/zh-cn/translations.json @@ -1,5 +1,13 @@ { - "ntfy adapter settings": "ntfy的适配器设置", - "option1": "选项1", - "option2": "选项2" -} \ No newline at end of file + "serverURL": "URL zum Ntfy 服务器", + "defaultTopic": "默认主题", + "defaultUsername": "默认用户名", + "defaultPassword": "默认密码", + "defaultAccessToken": "默认访问令牌", + "helpServerURL": "没有主题的 URL - https://ntfy-server.sh", + "helpDefaultAccessToken": "仅当不使用用户名/密码时", + "defaultTopicAuth": "默认主题认证", + "defaultTopicAuthNone": "无需验证", + "defaultTopicAuthUser": "用户认证", + "defaultTopicAuthToken": "访问令牌" +} diff --git a/admin/jsonConfig.json b/admin/jsonConfig.json index 644b5c7..3ca3b15 100644 --- a/admin/jsonConfig.json +++ b/admin/jsonConfig.json @@ -5,28 +5,55 @@ "serverURL": { "type": "text", "label": "serverURL", - "help": "URL without Topic - https://ntfy-server.sh", + "help": "helpServerURL", "newLine": true }, + "defaultSettingsHeader": { + "type": "header", + "text": "Default Settings Header", + "size": 4 + }, "defaultTopic": { "type": "text", "label": "defaultTopic", "newLine": true }, + "defaultTopicAuth": { + "type": "select", + "label": "defaultTopicAuth", + "options": [ + { + "label": "defaultTopicAuthNone", + "value": 0 + }, + { + "label": "defaultTopicAuthUser", + "value": 1 + }, + { + "label": "defaultTopicAuthToken", + "value": 2 + } + ], + "sm": 12, + "md": 6, + "lg": 3 + }, "defaultUsername": { "type": "text", "label": "defaultUsername", "newLine": true }, "defaultPassword": { - "type": "text", + "type": "password", "label": "defaultPassword", - "newLine": true + "visible": true, + "newLine": false }, "defaultAccessToken": { "type": "text", "label": "defaultAccessToken", - "help": "Only if username/password is not used", + "help": "helpDefaultAccessToken", "newLine": true } } diff --git a/admin/words.js b/admin/words.js new file mode 100644 index 0000000..83598f0 --- /dev/null +++ b/admin/words.js @@ -0,0 +1,22 @@ +/*global systemDictionary:true */ +/* ++===================== DO NOT MODIFY ======================+ +| This file was generated by translate-adapter, please use | +| `translate-adapter adminLanguages2words` to update it. | ++===================== DO NOT MODIFY ======================+ +*/ +'use strict'; + +systemDictionary = { + "serverURL": { "en": "URL zum Ntfy-Server", "de": "URL zum Ntfy-Server", "ru": "URL-адрес Ntfy-сервера", "pt": "URL para servidor Ntfy", "nl": "URL naar Ntfy-Server", "fr": "URL vers le serveur Ntfy", "it": "URL del server Ntfy", "es": "URL del servidor Ntfy", "pl": "Adres URL serwera Ntfy", "uk": "URL-адреса сервера Ntfy", "zh-cn": "URL zum Ntfy 服务器"}, + "defaultTopic": { "en": "Default Topic", "de": "Standard Topic", "ru": "Тема по умолчанию", "pt": "Tópico padrão", "nl": "Standaardonderwerp", "fr": "Sujet par défaut", "it": "Argomento predefinito", "es": "Tema predeterminado", "pl": "Domyślny temat", "uk": "Тема за замовчуванням", "zh-cn": "默认主题"}, + "defaultUsername": { "en": "Default Username", "de": "Standard-Benutzername", "ru": "Имя пользователя по умолчанию", "pt": "Nome de usuário padrão", "nl": "Standaard gebruikersnaam", "fr": "Nom d'utilisateur par défaut", "it": "Nome utente predefinito", "es": "Nombre de usuario predeterminado", "pl": "Domyślna nazwa użytkownika", "uk": "Ім'я користувача за замовчуванням", "zh-cn": "默认用户名"}, + "defaultPassword": { "en": "Default Password", "de": "Standard-Passwort", "ru": "Пароль по умолчанию", "pt": "Senha padrão", "nl": "Standaard wachtwoord", "fr": "Mot de passe par défaut", "it": "Password predefinita", "es": "Contraseña predeterminada", "pl": "Domyślne hasło", "uk": "Пароль за умовчанням", "zh-cn": "默认密码"}, + "defaultAccessToken": { "en": "Default Access Token", "de": "Standard-API-Token", "ru": "Токен доступа по умолчанию", "pt": "Token de acesso padrão", "nl": "Standaardtoegangstoken", "fr": "Jeton d'accès par défaut", "it": "Token di accesso predefinito", "es": "Token de acceso predeterminado", "pl": "Domyślny token dostępu", "uk": "Маркер доступу за умовчанням", "zh-cn": "默认访问令牌"}, + "helpServerURL": { "en": "URL without Topic - https://ntfy-server.sh", "de": "URL ohne Topic – https://ntfy-server.sh", "ru": "URL без темы — https://ntfy-server.sh", "pt": "URL sem tópico - https://ntfy-server.sh", "nl": "URL zonder onderwerp - https://ntfy-server.sh", "fr": "URL sans sujet - https://ntfy-server.sh", "it": "URL senza argomento: https://ntfy-server.sh", "es": "URL sin tema: https://ntfy-server.sh", "pl": "Adres URL bez tematu - https://ntfy-server.sh", "uk": "URL без теми - https://ntfy-server.sh", "zh-cn": "没有主题的 URL - https://ntfy-server.sh"}, + "helpDefaultAccessToken": { "en": "Only if username/password is not used", "de": "Nur wenn Benutzername/Passwort nicht verwendet wird", "ru": "Только если имя пользователя/пароль не используется", "pt": "Somente se nome de usuário/senha não for usado", "nl": "Alleen als gebruikersnaam/wachtwoord niet wordt gebruikt", "fr": "Uniquement si le nom d'utilisateur/mot de passe n'est pas utilisé", "it": "Solo se non viene utilizzato nome utente/password", "es": "Sólo si no se utiliza nombre de usuario/contraseña", "pl": "Tylko jeśli nazwa użytkownika/hasło nie jest używana", "uk": "Лише якщо ім’я користувача/пароль не використовується", "zh-cn": "仅当不使用用户名/密码时"}, + "defaultTopicAuth": { "en": "Default Topic Authentication", "de": "Standard-Topic-Authentifizierung", "ru": "Аутентификация темы по умолчанию", "pt": "Autenticação de tópico padrão", "nl": "Standaard onderwerpverificatie", "fr": "Authentification du sujet par défaut", "it": "Autenticazione argomento predefinita", "es": "Autenticación de tema predeterminada", "pl": "Domyślne uwierzytelnianie tematu", "uk": "Автентифікація теми за замовчуванням", "zh-cn": "默认主题认证"}, + "defaultTopicAuthNone": { "en": "No Authentication", "de": "Keine Authentifikation", "ru": "Нет аутентификации", "pt": "Sem autenticação", "nl": "Geen authenticatie", "fr": "Pas d'authentification", "it": "Nessuna autenticazione", "es": "Sin autenticacion", "pl": "Brak autoryzacji", "uk": "Без автентифікації", "zh-cn": "无需验证"}, + "defaultTopicAuthUser": { "en": "User Authentication", "de": "Benutzer/Passwort", "ru": "Аутентификация пользователя", "pt": "Autenticação de usuário", "nl": "Gebruikersverificatie", "fr": "Authentification d'utilisateur", "it": "Autenticazione utente", "es": "Autenticacion de usuario", "pl": "Uwierzytelnianie użytkownika", "uk": "Автентифікація користувача", "zh-cn": "用户认证"}, + "defaultTopicAuthToken": { "en": "Access Token", "de": "Zugangstoken", "ru": "Токен доступа", "pt": "Token de acesso", "nl": "Toegangstoken", "fr": "Jeton d'accès", "it": "Token di accesso", "es": "Token de acceso", "pl": "Token dostępu", "uk": "Маркер доступу", "zh-cn": "访问令牌"}, +}; \ No newline at end of file diff --git a/io-package.json b/io-package.json index 12359da..84886c3 100644 --- a/io-package.json +++ b/io-package.json @@ -5,7 +5,16 @@ "news": { "0.1.1": { "en": "first working release", - "de": "erste funktionierende Veröffentlichung" + "de": "erste funktionierende Veröffentlichung", + "ru": "первый рабочий релиз", + "pt": "primeira versão de trabalho", + "nl": "eerste werkende uitgave", + "fr": "première version de travail", + "it": "prima versione funzionante", + "es": "primera versión funcional", + "pl": "pierwsza wersja robocza", + "uk": "перший робочий випуск", + "zh-cn": "第一个工作版本" }, "0.0.1": { "en": "initial release", @@ -87,9 +96,11 @@ } ] }, - "native": { - - }, + "encryptedNative": [ + "defaultPassword", + "defaultAccessToken" + ], + "native": {}, "objects": [], "instanceObjects": [ { @@ -114,4 +125,4 @@ "native": {} } ] -} \ No newline at end of file +} diff --git a/main.js b/main.js index 3c2e9e9..c03c491 100644 --- a/main.js +++ b/main.js @@ -55,7 +55,7 @@ class ntfy extends utils.Adapter { return true; } checkAuth() { - if ( (!this.config.defaultUsername || !this.config.defaultPassword) && !this.config.defaultAccessToken) { + if ( this.config.defaultTopicAuth !== 1 && ((!this.config.defaultUsername || !this.config.defaultPassword) && !this.config.defaultAccessToken )) { this.log.info('Ntfy-Config: No Default Credentials are set (either username & password or access token'); return false; } @@ -67,10 +67,10 @@ class ntfy extends utils.Adapter { * * @param {ioBroker.Message} obj */ - onMessage(obj) { + async onMessage(obj) { if (typeof obj === 'object' && obj.message) { if (obj.command === 'send') { - if (this.checkConfig()) { + if (await this.checkConfig()) { this.sendMessage(obj); } } @@ -90,15 +90,19 @@ class ntfy extends utils.Adapter { this.messageTime = Date.now(); this.messageText = json; - axios.post(this.config.serverURL, json, { - auth: { - username: this.config.defaultUsername, - password: this.config.defaultPassword - } - }).catch(err => { - this.log.error(`Ntfy error: ${err}`); - this.log.error(`Ntfy error: ${JSON.stringify(err.response.data)}`); - }); + let axiosConfig = {}; + if (this.config.defaultTopicAuth === 1) { + axiosConfig = { headers: { 'Authorization': 'Basic ' + Buffer.from(this.config.defaultUsername + ':' + this.config.defaultPassword).toString('base64') } }; + } else if (this.config.defaultTopicAuth === 2) { + axiosConfig = { headers: { 'Authorization': 'Bearer ' + this.config.defaultAccessToken } }; + } + + axios.post(this.config.serverURL, json, axiosConfig) + .catch(err => { + this.log.error(`Ntfy error: ${err}`); + this.log.error(`Ntfy error: ${JSON.stringify(err.response.data)}`); + this.log.error(`Ntfy with config: ${JSON.stringify(axiosConfig)}`); + }); } } diff --git a/package.json b/package.json index 3fa06b5..44dc806 100644 --- a/package.json +++ b/package.json @@ -66,7 +66,7 @@ "test": "npm run test:js && npm run test:package", "check": "tsc --noEmit -p tsconfig.check.json", "lint": "eslint .", - "translate": "translate-adapter", + "translate": "translate-adapter && translate-adapter adminLanguages2words", "release": "release-script" }, "bugs": {