UNPKG

@remote.it/core

Version:

Core remote.it JavasScript/TypeScript library

219 lines (196 loc) 4.04 kB
export class ServiceType { defaultPort?: number name: string id: number hex: string constructor(args: { defaultPort?: number name: string id: number hex: string }) { this.defaultPort = args.defaultPort this.name = args.name this.id = args.id this.hex = args.hex } } const ALL_SERVICES = { // 0 Camera Viewer tcp: new ServiceType({ name: 'TCP', defaultPort: 445, id: 1, hex: '01', }), // 2 Telnet // 3 SVN vnc: new ServiceType({ name: 'VNC', defaultPort: 5900, id: 4, hex: '04', }), rdp: new ServiceType({ name: 'RDP', defaultPort: 3389, id: 5, hex: '05', }), // 6 Share httpProxy: new ServiceType({ name: 'HTTP reverse proxy', defaultPort: 80, id: 7, hex: '07', }), httpsProxy: new ServiceType({ name: 'HTTPS reverse proxy', defaultPort: 443, id: 8, hex: '08', }), // 9 Reserved // 10 HTTPS // 11 iTunes // 12 File Folder // 13 Printer // 14 Tversity // 15 Video // 16 Video // 17 Photo Folder // 18 Camera Folder // 19 Camera Viewer // 20 Microsoft Media // 21 RDP Plus // 22 My Tunes // 23 DVR Viewer // 24 DVR // 25 Video Stream // 26 Network Storage // 27 Network Storage ssh: new ServiceType({ name: 'SSH', defaultPort: 22, id: 28, hex: '1C', }), // 29 Generic TCP // 30 Basic Web // 33 Secure Web http: new ServiceType({ defaultPort: 80, name: 'HTTP', id: 30, hex: '1E', }), https: new ServiceType({ defaultPort: 443, name: 'HTTPS', id: 33, hex: '21', }), samba: new ServiceType({ defaultPort: 445, name: 'Samba', id: 34, hex: '22', }), bulk: new ServiceType({ name: 'Bulk Service', defaultPort: 65535, id: 35, hex: '23', }), nxWitness: new ServiceType({ defaultPort: 7001, name: 'NX Witness', id: 37, hex: '25', }), nextCloud: new ServiceType({ defaultPort: 443, name: 'NextCloud', id: 38, hex: '26', }), openVPN: new ServiceType({ defaultPort: 1194, name: 'Open VPN', id: 39, hex: '27', }), multiport: new ServiceType({ defaultPort: 65535, name: 'MultiPort', id: 40, hex: '28', }), } type ServiceKey = keyof typeof ALL_SERVICES export class ServiceTypes { static all = ALL_SERVICES static get tcp() { return this.findByKey('tcp') } static get vnc() { return this.findByKey('vnc') } static get rdp() { return this.findByKey('rdp') } static get httpProxy() { return this.findByKey('httpProxy') } static get httpsProxy() { return this.findByKey('httpsProxy') } static get ssh() { return this.findByKey('ssh') } static get http() { return this.findByKey('http') } static get https() { return this.findByKey('https') } static get samba() { return this.findByKey('samba') } static get bulk() { return this.findByKey('bulk') } static get nxWitness() { return this.findByKey('nxWitness') } static get nextCloud() { return this.findByKey('nextCloud') } static get openVPN() { return this.findByKey('openVPN') } static get multiport() { return this.findByKey('multiport') } static findByKey(key: ServiceKey) { const match = this.all[key] if (!match) throw new Error('could not find service type with key: ' + key) return match } static findByTypeString(type: string) { const hex = type.split(':')[1] return this.findByHex(hex) } static findByHex(hex: string): ServiceType { const match = Object.values(this.all).find( (t: ServiceType) => t.hex === hex ) if (!match) throw new Error('could not find service type with hex: ' + hex) return match } static findByID(id: number): ServiceType { const match = Object.values(this.all).find((t: ServiceType) => t.id === id) if (!match) throw new Error('could not find service type with id: ' + id) return match } }