Skip to content

Commit

Permalink
update dyndns noip
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanwerfling committed Oct 24, 2024
1 parent 4d937f7 commit df8dd0e
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 8 deletions.
40 changes: 39 additions & 1 deletion backend/src/inc/Provider/NoIp/NoIp.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,35 @@
import {
DynDnsClientHostsOptions,
DynDnsClientUpdateOptions,
DynDnsClientUpdateResult, IDynDnsClient,
DynDnsClientUpdateResult,
IDynDnsClient,
Logger
} from 'flyingfish_core';
import got from 'got';

export type NoIpReturn = {
statusCode: string;
msg?: string;
};

/**
* NoIP
* @see https://www.noip.com/de-DE/integrate/request
* @see https://www.noip.com/de-DE/integrate/response
*/
export class NoIp implements IDynDnsClient {

public static readonly URL = 'https://{auth}dynupdate.no-ip.com/nic/update';

public static readonly RETURN_GOOD = 'good';
public static readonly RETURN_NOCHG = 'nochg';
public static readonly RETURN_NOHOST = 'nohost';
public static readonly RETURN_BADAUTH = 'badauth';
public static readonly RETURN_BADAGENT = 'badagent';
public static readonly RETURN_DONATOR = '!donator';
public static readonly RETURN_ABUSE = 'abuse';
public static readonly RETURN_911 = '911';

/**
* Static Name
*/
Expand Down Expand Up @@ -56,6 +73,10 @@ export class NoIp implements IDynDnsClient {
return 'unknow';
}

protected _parseReturn(str: string): NoIpReturn {

}

/**
* Update hostname[s] with the IP
* @param {DynDnsClientUpdateOptions} options
Expand All @@ -68,7 +89,24 @@ export class NoIp implements IDynDnsClient {
};

try {
const url = NoIp.URL.replace('{auth}', '');

const response = await got({
url: url,
username: options.username,
password: options.password,
headers: {
'User-Agent': 'Flyingfish Flyingfish/1 https://flying-fish.gitbook.io/flyingfish'
}
});

Logger.getLogger().info(`NoIP::update: http status code: ${response.statusCode}`);

if (response.statusCode === 200) {
if (response.body !== '') {
const result = this._parseReturn(response.body);
}
}
} catch (e) {
Logger.getLogger().error(e);
}
Expand Down
16 changes: 9 additions & 7 deletions backend/tests/Provider/NoIp/NoIp.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {IDynDnsClient} from 'flyingfish_core/dist/src';
import {DynDnsProviders} from '../../../src/inc/Provider/DynDnsProviders';
import {IDynDns} from '../../../src/inc/Provider/IDynDns';
import {SchemaMatchers} from '../../../src/types/ExpectSchema';

expect.extend(SchemaMatchers);
Expand All @@ -8,7 +8,7 @@ describe('testing dyndns client noip', () => {
let username: string|null = null;
let password: string|null = null;
let hostname: string|null = null;
let provider: IDynDns|null = null;
let provider: IDynDnsClient|null = null;

beforeAll(async() => {
if (process.env.TESTS_BACKEND_DYNCLIENT_NOIP_USERNAME) {
Expand Down Expand Up @@ -40,11 +40,13 @@ describe('testing dyndns client noip', () => {
expect(provider).not.toBeNull();

if (provider) {
const result = await provider.update(
'wrongname',
'password',
'3.4.5.6'
);
const result = await provider.update({
username: 'wrongname',
password: 'password',
ip: '3.4.5.6',
ip6: null,
hostname: []
});

expect(result.result).toBe(false);
}
Expand Down

0 comments on commit df8dd0e

Please sign in to comment.