[RPC_I_ACTION] = { .name = "action", .type = BLOBMSG_TYPE_STRING },
};
+enum {
+ RPC_RC_DATA,
+ __RPC_RC_MAX
+};
+
+static const struct blobmsg_policy rpc_rclocal_policy[__RPC_RC_MAX] = {
+ [RPC_RC_DATA] = { .name = "data", .type = BLOBMSG_TYPE_STRING },
+};
+
enum {
RPC_K_KEYS,
__RPC_K_MAX
}
}
+static int
+rpc_luci2_rclocal_get(struct ubus_context *ctx, struct ubus_object *obj,
+ struct ubus_request_data *req, const char *method,
+ struct blob_attr *msg)
+{
+ FILE *f;
+ char data[4096] = { 0 };
+
+ if (!(f = fopen("/etc/rc.local", "r")))
+ return rpc_errno_status();
+
+ fread(data, sizeof(data) - 1, 1, f);
+ fclose(f);
+
+ blob_buf_init(&buf, 0);
+ blobmsg_add_string(&buf, "data", data);
+
+ ubus_send_reply(ctx, req, buf.head);
+ return 0;
+}
+
+static int
+rpc_luci2_rclocal_set(struct ubus_context *ctx, struct ubus_object *obj,
+ struct ubus_request_data *req, const char *method,
+ struct blob_attr *msg)
+{
+ FILE *f;
+ struct blob_attr *tb[__RPC_RC_MAX];
+
+ blobmsg_parse(rpc_rclocal_policy, __RPC_RC_MAX, tb,
+ blob_data(msg), blob_len(msg));
+
+ if (!tb[RPC_RC_DATA] || blobmsg_data_len(tb[RPC_RC_DATA]) >= 4096)
+ return UBUS_STATUS_INVALID_ARGUMENT;
+
+ if (!(f = fopen("/etc/rc.local", "w")))
+ return rpc_errno_status();
+
+ fwrite(blobmsg_data(tb[RPC_RC_DATA]),
+ blobmsg_data_len(tb[RPC_RC_DATA]) - 1, 1, f);
+
+ fclose(f);
+ return 0;
+}
+
static int
rpc_luci2_sshkeys_get(struct ubus_context *ctx, struct ubus_object *obj,
struct ubus_request_data *req, const char *method,
UBUS_METHOD_NOARG("init_list", rpc_luci2_init_list),
UBUS_METHOD("init_action", rpc_luci2_init_action,
rpc_init_policy),
+ UBUS_METHOD_NOARG("rclocal_get", rpc_luci2_rclocal_get),
+ UBUS_METHOD("rclocal_set", rpc_luci2_rclocal_set,
+ rpc_rclocal_policy),
UBUS_METHOD_NOARG("sshkeys_get", rpc_luci2_sshkeys_get),
UBUS_METHOD("sshkeys_set", rpc_luci2_sshkeys_set,
rpc_sshkey_policy),