diff --git a/dist/scripts/taglines.txt b/dist/scripts/data/taglines.txt similarity index 100% rename from dist/scripts/taglines.txt rename to dist/scripts/data/taglines.txt diff --git a/dist/scripts/mainmenu.lua b/dist/scripts/mainmenu.lua index e9f6b39..d82c498 100644 --- a/dist/scripts/mainmenu.lua +++ b/dist/scripts/mainmenu.lua @@ -20,7 +20,7 @@ function menu() -- display tagline - local tLines = readLines("scripts/taglines.txt"); + local tLines = readLines(bbs_data_path() .. "taglines.txt"); local rand = math.random(#tLines); diff --git a/src/bbs.c b/src/bbs.c index 092d6c7..a21d117 100644 --- a/src/bbs.c +++ b/src/bbs.c @@ -689,7 +689,7 @@ void automessage_display() { } void runbbs_real(int socket, char *ip, int ssh) { - char buffer[1024]; + char buffer[PATH_MAX]; char password[17]; struct stat s; @@ -878,7 +878,7 @@ tryagain: user = gUser; } } - sprintf(buffer, "%s/nodeinuse.%d", conf.bbs_path, mynode); + snprintf(buffer, PATH_MAX, "%s/nodeinuse.%d", conf.bbs_path, mynode); nodefile = fopen(buffer, "w"); if (!nodefile) { dolog("Error opening nodefile!"); @@ -889,15 +889,25 @@ tryagain: fputs(user->loginname, nodefile); fclose(nodefile); - sprintf(buffer, "%s/node%d/nodemsg.txt", conf.bbs_path, mynode); + snprintf(buffer, PATH_MAX, "%s/node%d/nodemsg.txt", conf.bbs_path, mynode); if (stat(buffer, &s) == 0) { unlink(buffer); } + snprintf(buffer, PATH_MAX, "%s/node%d/lua/", conf.bbs_path, mynode); + + if (stat(buffer, &s) == 0) { + recursive_delete(buffer); + } + + #if defined(ENABLE_WWW) www_expire_old_links(); #endif + + + // do post-login dolog("%s logged in, on node %d", user->loginname, mynode); broadcast("%s logged in, on node %d", user->loginname, mynode); @@ -918,7 +928,7 @@ tryagain: if (conf.script_path != NULL) { - sprintf(buffer, "%s/login_stanza.lua", conf.script_path); + snprintf(buffer, PATH_MAX, "%s/login_stanza.lua", conf.script_path); if (stat(buffer, &s) == 0) { L = luaL_newstate(); luaL_openlibs(L); @@ -980,7 +990,7 @@ void do_logout() { int do_internal_logout = 1; if (conf.script_path != NULL) { - sprintf(buffer, "%s/logout_stanza.lua", conf.script_path); + snprintf(buffer, PATH_MAX, "%s/logout_stanza.lua", conf.script_path); if (stat(buffer, &s) == 0) { L = luaL_newstate(); luaL_openlibs(L); diff --git a/src/lua_glue.c b/src/lua_glue.c index 3ab70a8..86102c4 100644 --- a/src/lua_glue.c +++ b/src/lua_glue.c @@ -336,6 +336,20 @@ int l_readMessage(lua_State *L) { return 1; } +int l_dataPath(lua_State *L) { + char buffer[PATH_MAX]; + struct stat s; + snprintf(buffer, PATH_MAX, "%s/data/", conf.script_path); + + if (stat(buffer, &s) != 0) { + mkdir(buffer, 0755); + } + + lua_pushstring(L, buffer); + + return 1; +} + int l_tempPath(lua_State *L) { char buffer[PATH_MAX]; struct stat s; @@ -350,6 +364,11 @@ int l_tempPath(lua_State *L) { return 1; } +int l_userSecurity(lua_State *L) { + lua_pushnumber(L, gUser->sec_level); + return 1; +} + int l_postMessage(lua_State *L) { int confr = lua_tointeger(L, 1); int area = lua_tointeger(L, 2); @@ -576,6 +595,10 @@ void lua_push_cfunctions(lua_State *L) { lua_setglobal(L, "bbs_temp_path"); lua_pushcfunction(L, l_postMessage); lua_setglobal(L, "bbs_post_message"); + lua_pushcfunction(L, l_dataPath); + lua_setglobal(L, "bbs_data_path"); + lua_pushcfunction(L, l_userSecurity); + lua_setglobal(L, "bbs_user_security"); } void do_lua_script(char *script) {