/
cuckoo.ts
70 lines (61 loc) · 1.54 KB
/
cuckoo.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/**
* penguins-eggs
* command: cuckoo.ts
* author: Piero Proietti
* email: piero.proietti@gmail.com
* license: MIT
*/
import {Command, Flags} from '@oclif/core'
import network from '../classes/network'
import Utils from '../classes/utils'
import Pxe from '../classes/pxe'
import {ITftpOptions, IDhcpOptions} from '../interfaces/i-pxe'
const tftp = require('tftp')
export default class Cuckoo extends Command {
static flags = {
help: Flags.help({char: 'h'}),
}
static description = 'PXE start with proxy-dhcp'
static examples = [
'sudo eggs cuckoo',
]
async run(nest = '/home/eggs/mnt'): Promise<void> {
const {args, flags} = await this.parse(Cuckoo)
Utils.titles(this.id + ' ' + this.argv)
if (Utils.isRoot()) {
const pxeRoot = nest + '/pxe'
const pxe = new Pxe()
await pxe.fertilization()
await pxe.build()
const n = new network()
/**
* service proxy-dhcp
*/
const dhcpOptions: IDhcpOptions = {
subnet: n.cidr,
host: n.address,
tftpserver: n.address,
bios_filename: 'lpxelinux.0',
efi32_filename: 'ipxe32.efi',
efi64_filename: 'ipxe.efi',
}
pxe.dhcpStart(dhcpOptions)
/**
* service tftp
*/
const tftpOptions: ITftpOptions = {
host: n.address,
port: 69,
root: pxeRoot,
denyPUT: true,
}
await pxe.tftpStart(tftpOptions)
/**
* service http
*/
await pxe.httpStart()
} else {
Utils.useRoot(this.id)
}
}
}