summaryrefslogtreecommitdiffstats
path: root/modules-available/rebootcontrol/install.inc.php
blob: d45a2443da29305b4807f43246b1da25696cfef5 (plain) (blame)
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
70
71
72
73
74
75
76
77
<?php

$output = array();

$output[] = tableCreate('reboot_subnet', "
	`subnetid` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
	`start` INT(10) UNSIGNED NOT NULL,
	`end` INT(10) UNSIGNED NOT NULL,
	`fixed` BOOL NOT NULL,
	`isdirect` BOOL NOT NULL,
	`nextdirectcheck` INT(10) UNSIGNED NOT NULL DEFAULT '0',
	`lastseen` INT(10) UNSIGNED NOT NULL DEFAULT '0',
	`seencount` INT(10) UNSIGNED NOT NULL DEFAULT '0',
	PRIMARY KEY (`subnetid`),
 	UNIQUE KEY `range` (`start`, `end`)");

$output[] = tableCreate('reboot_jumphost', "
	`hostid` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
	`host` VARCHAR(100) NOT NULL,
	`port` SMALLINT(10) UNSIGNED NOT NULL,
	`username` VARCHAR(30) NOT NULL,
	`reachable` BOOL NOT NULL,
	`sshkey` BLOB NOT NULL,
	`script` BLOB NOT NULL,
	PRIMARY KEY (`hostid`)");

$output[] = tableCreate('reboot_jumphost_x_subnet', "
	`hostid` INT(10) UNSIGNED NOT NULL,
	`subnetid` INT(10) UNSIGNED NOT NULL,
	PRIMARY KEY (`hostid`, `subnetid`)");

$output[] = tableCreate('reboot_subnet_x_subnet', "
	`srcid` INT(10) UNSIGNED NOT NULL,
	`dstid` INT(10) UNSIGNED NOT NULL,
	`reachable` BOOL NOT NULL,
	`nextcheck` INT(10) UNSIGNED NOT NULL DEFAULT '0',
	PRIMARY KEY (`srcid`, `dstid`),
	KEY `nextcheck` (`nextcheck`)");

$output[] = tableCreate('reboot_scheduler', "
	`locationid` INT(11) NOT NULL,
	`action` ENUM('WOL', 'SHUTDOWN', 'REBOOT'),
	`nextexecution` INT(10) UNSIGNED NOT NULL DEFAULT 0,
	`options` BLOB,
	PRIMARY KEY (`locationid`)");

$output[] = tableAddConstraint('reboot_jumphost_x_subnet', 'hostid', 'reboot_jumphost', 'hostid',
	'ON UPDATE CASCADE ON DELETE CASCADE');
$output[] = tableAddConstraint('reboot_jumphost_x_subnet', 'subnetid', 'reboot_subnet', 'subnetid',
	'ON UPDATE CASCADE ON DELETE CASCADE');
$output[] = tableAddConstraint('reboot_subnet_x_subnet', 'srcid', 'reboot_subnet', 'subnetid',
	'ON UPDATE CASCADE ON DELETE CASCADE');
$output[] = tableAddConstraint('reboot_subnet_x_subnet', 'dstid', 'reboot_subnet', 'subnetid',
	'ON UPDATE CASCADE ON DELETE CASCADE');
$output[] = tableAddConstraint('reboot_scheduler', 'locationid', 'location', 'locationid',
	'ON UPDATE CASCADE ON DELETE CASCADE');

if (tableColumnKeyType('reboot_scheduler', 'action') === 'PRI') {
	Database::exec("DELETE FROM reboot_scheduler WHERE action <> 'wol'");
	$res = Database::exec("ALTER TABLE `reboot_scheduler` DROP PRIMARY KEY, ADD PRIMARY KEY (`locationid`)");
	$output[] = $res !== false ? UPDATE_DONE : UPDATE_FAILED;
}
if (strpos(tableColumnType('reboot_scheduler', 'action'), 'REBOOT') === false) {
	// Fiddle with column to rename ENUM values
	$res = Database::exec("ALTER TABLE `reboot_scheduler` MODIFY COLUMN `action` ENUM('sd', 'rb', 'WOL', 'SHUTDOWN', 'REBOOT')");
	handleUpdateResult($res);
	$res = Database::exec("UPDATE reboot_scheduler SET action =
		CASE WHEN action = 'sd' THEN 'SHUTDOWN' WHEN action = 'rb' THEN 'REBOOT' ELSE 'WOL' END");
	handleUpdateResult($res);
	$res = Database::exec("ALTER TABLE `reboot_scheduler` MODIFY COLUMN `action` ENUM('WOL', 'SHUTDOWN', 'REBOOT')");
	handleUpdateResult($res);
	$output[] = UPDATE_DONE;
}



responseFromArray($output);