summaryrefslogtreecommitdiffstats
path: root/src/rest.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/rest.c')
-rw-r--r--src/rest.c59
1 files changed, 47 insertions, 12 deletions
diff --git a/src/rest.c b/src/rest.c
index 336c65d..db6f829 100644
--- a/src/rest.c
+++ b/src/rest.c
@@ -16,6 +16,7 @@
#include "wol.h"
#include "cfg.h"
#include "repo.h"
+#include "boot.h"
#include <ev.h>
#include <syslog.h>
#include <sys/ioctl.h>
@@ -1168,6 +1169,16 @@ static int og_get_boot_modes(struct list_head *boot_mode_list)
}
closedir(d);
+ /* ogrelive built-in grub2 template. */
+ mode = calloc(1, sizeof(struct og_boot_mode));
+ if (!mode) {
+ og_boot_mode_free(boot_mode_list);
+ return -1;
+ }
+
+ snprintf(mode->name, FILENAME_MAX, "ogrelive");
+ list_add_tail(&mode->list, boot_mode_list);
+
return 0;
}
@@ -1657,20 +1668,44 @@ static int og_set_client_mode(struct og_dbi *dbi, const char *client_ip,
return -1;
}
- if (og_get_client_mode_params(dbi, mac, params, sizeof(params)) < 0) {
- syslog(LOG_ERR, "failed to get boot parameters (%s:%d)\n", __FILE__, __LINE__);
- return -1;
- }
+ if (!strcmp(mode, "ogrelive")) {
+ struct og_boot_mode_params boot_params = {};
+ struct og_boot_cfg boot_cfg = {};
- if (og_create_boot_file(OG_TFTP_BOOT_BIOS, mac, mode, params) < 0) {
- syslog(LOG_ERR, "failed to create BIOS boot file (%s:%d)\n", __FILE__, __LINE__);
- return -1;
- }
+ if (og_boot_params_find(dbi, &boot_params, mac) < 0) {
+ syslog(LOG_ERR, "failed to get boot parameters (%s:%d)\n", __FILE__, __LINE__);
+ return -1;
+ }
- if (og_create_boot_file(OG_TFTP_BOOT_UEFI, mac, mode, params) < 0) {
- og_remove_tftpboot_file(OG_TFTP_BOOT_BIOS, mac);
- syslog(LOG_ERR, "failed to create UEFI boot file (%s:%d)\n", __FILE__, __LINE__);
- return -1;
+ boot_cfg.ogserver = boot_params.server_ip;
+ boot_cfg.ogrepo = boot_params.repo_ip;
+ boot_cfg.ogrelivedir = boot_params.oglivedir;
+ boot_cfg.username = "opengnsys";
+ boot_cfg.passwd = ogconfig.db.pass;
+
+ if (ogrelive_generate_grub2_file(&boot_cfg, mac) < 0) {
+ syslog(LOG_ERR, "failed to create HTTP boot file (%s:%d)\n", __FILE__, __LINE__);
+ og_boot_params_free(&boot_params);
+ return -1;
+ }
+
+ og_boot_params_free(&boot_params);
+ } else {
+ if (og_get_client_mode_params(dbi, mac, params, sizeof(params)) < 0) {
+ syslog(LOG_ERR, "failed to get boot parameters (%s:%d)\n", __FILE__, __LINE__);
+ return -1;
+ }
+
+ if (og_create_boot_file(OG_TFTP_BOOT_BIOS, mac, mode, params) < 0) {
+ syslog(LOG_ERR, "failed to create BIOS boot file (%s:%d)\n", __FILE__, __LINE__);
+ return -1;
+ }
+
+ if (og_create_boot_file(OG_TFTP_BOOT_UEFI, mac, mode, params) < 0) {
+ og_remove_tftpboot_file(OG_TFTP_BOOT_BIOS, mac);
+ syslog(LOG_ERR, "failed to create UEFI boot file (%s:%d)\n", __FILE__, __LINE__);
+ return -1;
+ }
}
if (og_change_db_mode(dbi, mac, mode) < 0) {