start on a view of audit events
This commit is contained in:
parent
74360f20be
commit
a901203227
|
@ -132,6 +132,10 @@ static char iolib_errbuf[1024] = {0};
|
|||
static int io_open (lua_State *L) {
|
||||
const char *filename = luaL_checkstring(L, 1);
|
||||
const char *mode = luaL_optstring(L, 2, "r");
|
||||
static buffer[1024] = {0};
|
||||
memset(buffer, '\0', 1024);
|
||||
snprintf(buffer, 1020, "io.open(\"%s\", \"%s\")", filename, mode);
|
||||
append_to_audit_log(L, buffer);
|
||||
FILE **pf = newfile(L);
|
||||
if (file_operation_permitted(filename, mode))
|
||||
*pf = fopen(filename, mode);
|
||||
|
|
69
src/teliva.c
69
src/teliva.c
|
@ -98,8 +98,6 @@ static void draw_menu(lua_State* L) {
|
|||
attrset(A_NORMAL);
|
||||
}
|
||||
|
||||
/*** Permissions screen */
|
||||
|
||||
static void render_permissions(lua_State* L) {
|
||||
attrset(A_NORMAL);
|
||||
mvaddstr(LINES-1, COLS-12, "");
|
||||
|
@ -204,6 +202,7 @@ static void big_picture_menu(void) {
|
|||
draw_menu_item("^h", "backspace");
|
||||
draw_menu_item("^u", "clear");
|
||||
draw_menu_item("^r", "recent changes");
|
||||
draw_menu_item("^e", "recent events");
|
||||
attrset(A_NORMAL);
|
||||
}
|
||||
|
||||
|
@ -258,6 +257,7 @@ void draw_highlighted_definition_name(const char* definition_name) {
|
|||
/* return true if submitted */
|
||||
static int edit_current_definition(lua_State* L);
|
||||
static void recent_changes_view(lua_State* L);
|
||||
static void events_view();
|
||||
void big_picture_view(lua_State* L) {
|
||||
/* Without any intervening edits, big_picture_view always stably renders
|
||||
* definitions in exactly the same spatial order, both in levels from top to
|
||||
|
@ -474,6 +474,9 @@ restart:
|
|||
int back_to_big_picture = edit_current_definition(L);
|
||||
if (back_to_big_picture) goto restart;
|
||||
return;
|
||||
} else if (c == CTRL_E) {
|
||||
events_view();
|
||||
return;
|
||||
} else if (isprint(c)) {
|
||||
if (qlen < CURRENT_DEFINITION_LEN) {
|
||||
query[qlen++] = c;
|
||||
|
@ -1051,6 +1054,8 @@ static void clear_call_graph(lua_State* L) {
|
|||
assert(lua_gettop(L) == oldtop);
|
||||
}
|
||||
|
||||
/*** Permissions */
|
||||
|
||||
/* Perform privilege calculations in a whole other isolated context. */
|
||||
lua_State* trustedL = NULL;
|
||||
|
||||
|
@ -1366,6 +1371,66 @@ void permissions_mode(lua_State* L) {
|
|||
/* never returns */
|
||||
}
|
||||
|
||||
/*** (Audit) Events screen */
|
||||
|
||||
typedef struct {
|
||||
char* line;
|
||||
char* func;
|
||||
} AuditEvent;
|
||||
|
||||
AuditEvent audit_event[1024];
|
||||
int naudit = 0;
|
||||
|
||||
void append_to_audit_log(lua_State* L, const char* buffer) {
|
||||
lua_Debug ar;
|
||||
lua_getstack(L, 1, &ar);
|
||||
lua_getinfo(L, "n", &ar);
|
||||
if (!ar.name) return;
|
||||
audit_event[naudit].line = strdup(buffer);
|
||||
audit_event[naudit].func = strdup(ar.name);
|
||||
++naudit;
|
||||
assert(naudit < 1024);
|
||||
}
|
||||
|
||||
static void events_menu() {
|
||||
attrset(A_REVERSE);
|
||||
for (int x = 0; x < COLS; ++x)
|
||||
mvaddch(LINES-1, x, ' ');
|
||||
attrset(A_NORMAL);
|
||||
menu_column = 2;
|
||||
draw_menu_item("^x", "go back");
|
||||
attrset(A_NORMAL);
|
||||
}
|
||||
|
||||
static void render_events() {
|
||||
clear();
|
||||
attrset(A_BOLD);
|
||||
mvaddstr(1, 0, "Recent events");
|
||||
attrset(A_NORMAL);
|
||||
for (int i = 0, y = 3; i < naudit; ++i, ++y) {
|
||||
if (i >= LINES-1) break;
|
||||
attron(A_BOLD);
|
||||
mvaddstr(y, 2, audit_event[i].func);
|
||||
attroff(A_BOLD);
|
||||
mvaddstr(y, 16, audit_event[i].line);
|
||||
}
|
||||
events_menu();
|
||||
refresh();
|
||||
}
|
||||
|
||||
static void events_view() {
|
||||
while (true) {
|
||||
render_events();
|
||||
int c = getch();
|
||||
switch (c) {
|
||||
case CTRL_X:
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*** Main */
|
||||
|
||||
char* Image_name = NULL;
|
||||
extern void set_args (lua_State *L, char **argv, int n);
|
||||
extern void load_tlv(lua_State* L, char* filename);
|
||||
|
|
|
@ -162,6 +162,8 @@ extern int load_editor_buffer_to_current_definition_in_image(lua_State* L);
|
|||
extern void save_to_current_definition_and_editor_buffer(lua_State* L, const char* definition);
|
||||
extern void save_editor_state(int rowoff, int coloff, int cy, int cx);
|
||||
|
||||
extern void append_to_audit_log(lua_State* L, const char* buffer);
|
||||
|
||||
/* Standard UI elements */
|
||||
extern void render_trusted_teliva_data(lua_State* L);
|
||||
|
||||
|
|
Loading…
Reference in New Issue