int bbssec_main(void) { db_res_t *r1 = db_query("SELECT id, name, descr, short_descr" " FROM board_sectors ORDER BY name ASC"); if (!r1) return BBS_EINVAL; db_res_t *res = db_query("SELECT b.name, b.descr, b.sector" " FROM boards b JOIN board_sectors s ON b.sector = s.id" " WHERE b.flag & %d <> 0", BOARD_FLAG_RECOMMEND); if (!res) { db_clear(r1); return BBS_EINVAL; } xml_header(NULL); printf("<bbssec>"); print_session(); int last = -1; for (int i = 0; i < db_res_rows(r1); ++i) { printf("<sec id='%s' desc='%s [%s]'>", db_get_value(r1, i, 1), db_get_value(r1, i, 2), db_get_value(r1, i, 3)); int sid = db_get_integer(r1, i, 0); last = show_sector(sid, res, last); printf("</sec>"); } db_clear(res); db_clear(r1); printf("</bbssec>"); return 0; }
void mapreg_reload (void) { if (mapreg_dirty) script_save_mapreg(); db_clear (mapreg_db); db_clear (mapregstr_db); script_load_mapreg(); }
int web_fav(void) { if (!session_id()) return BBS_ELGNREQ; xml_header(NULL); printf("<bbsfav>"); print_session(); db_res_t *res = db_query("SELECT b.id, b.name, b.descr FROM boards b" " JOIN fav_boards f ON b.id = f.board WHERE f.user_id = %d", session_uid()); if (res) { for (int i = 0; i < db_res_rows(res); ++i) { int bid = db_get_integer(res, i, 0); const char *name = db_get_value(res, i, 1); GBK_BUFFER(descr, BOARD_DESCR_CCHARS); convert_u2g(db_get_value(res, i, 2), gbk_descr); printf("<brd bid='%d' brd='%s'>", bid, name); xml_fputs(gbk_descr); printf("</brd>"); } } db_clear(res); printf("</bbsfav>"); return 0; }
static bool _get_session(const char *uname, const char *key) { user_id_t uid = get_user_id(uname); if (uid > 0) { session_id_t sid = session_get_web_cache(uid, key, fromhost); if (sid > 0) { session_set_id(sid); session_set_uid(uid); return true; } db_res_t *res = db_query("SELECT id, active FROM sessions" " WHERE user_id = %"DBIdUID" AND session_key = %s AND web", uid, key); if (res && db_res_rows(res) == 1) { sid = db_get_session_id(res, 0, 0); bool active = db_get_bool(res, 0, 1); if (active || activate_session(sid, uname)) { session_set_id(sid); session_set_uid(uid); session_set_web_cache(uid, key, session_id(), fromhost); } } db_clear(res); } return session_id(); }
int web_sel(void) { xml_header("bbssel"); printf("<bbssel>"); print_session(); const char *brd = web_get_param("brd"); if (*brd != '\0') { char name[BOARD_NAME_LEN + 3]; snprintf(name, sizeof(name), "%%%s%%", brd); db_res_t *res = db_query(BOARD_SELECT_QUERY_BASE "WHERE lower(b.name) LIKE %s", name); if (res && db_res_rows(res) > 0) { board_t board; for (int i = 0; i < db_res_rows(res); ++i) { res_to_board(res, i, &board); if (has_read_perm(&board)) { board_to_gbk(&board); printf("<brd dir='%d' title='%s' desc='%s' />", is_board_dir(&board), board.name, board.descr); } } } else { printf("<notfound/>"); } db_clear(res); } printf("</bbssel>"); return 0; }
bool black_list_rm(user_id_t uid, user_id_t blocked) { db_res_t *res = db_cmd("DELETE FROM blacklists" " WHERE user_id = %"DBIdUID" AND blocked = %"DBIdUID, uid, blocked); db_clear(res); return res; }
void edit_followed_note(user_id_t follower, user_id_t followed, const char *notes) { if (string_validate_utf8(notes, FOLLOW_NOTE_CCHARS, false) < 0) return; db_res_t *res = db_cmd("UPDATE follows SET notes = %s" "WHERE user_id = %"DBIdUID" AND follower = %"DBIdUID, notes, followed, follower); db_clear(res); }
bool am_followed_by(const char *uname) { db_res_t *res = db_query("SELECT f.followed" " FROM follows f JOIN users u ON f.follower = u.id" " WHERE user_id = %"DBIdUID" AND lower(u.name) = lower(%s)", session_uid(), uname); int rows = res ? db_res_rows(res) : 0; db_clear(res); return rows; }
bool is_blocked(const char *uname) { db_res_t *res = db_query("SELECT b.blocked FROM blacklists b" " JOIN alive_users u ON b.user_id = u.id" " WHERE b.blocked = %"DBIdUID" AND lower(u.name) = lower(%s)", session_uid(), uname); int rows = res ? db_res_rows(res) : 0; db_clear(res); return rows; }
static bool activate_session(session_id_t sid, const char *uname) { db_res_t *res = db_cmd("UPDATE sessions SET active = TRUE, stamp = %t" " WHERE id = %"DBIdSID, fb_time(), sid); db_clear(res); if (res) return !do_web_login(uname, NULL, false); return false; }
bool black_list_edit(user_id_t uid, user_id_t blocked, const char *notes) { if (string_validate_utf8(notes, BLACK_LIST_NOTE_CCHARS, false) < 0) return false; db_res_t *res = db_cmd("UPDATE blacklists SET notes = %s" " WHERE user_id = %"DBIdUID" AND blocked = %"DBIdUID, notes, uid, blocked); db_clear(res); return res; }
int unfollow(user_id_t follower, user_id_t followed) { db_res_t *res = db_cmd("DELETE FROM follows WHERE user_id = %"DBIdUID " AND follower = %"DBIdUID, followed, follower); if (res) { int ret = db_cmd_rows(res); db_clear(res); return ret; } return 0; }
bool black_list_add(user_id_t uid, const char *blocked, const char *notes) { if (string_validate_utf8(notes, BLACK_LIST_NOTE_CCHARS, false) < 0) return false; user_id_t block_id = get_user_id(blocked); if (block_id <= 0 || block_id == uid) return false; db_res_t *res = db_cmd("INSERT INTO blacklists" " (user_id, blocked, notes, stamp)" " VALUES (%d, %d, %s, current_timestamp)", uid, block_id, notes); db_clear(res); return res; }
static int show_title_detail(int record) { db_res_t *res = db_query("SELECT title, approved FROM titles" " WHERE record_id = %d AND user_id = %"DBIdUID, record, session_uid()); if (!res || db_res_rows(res) <= 0) { db_clear(res); return BBS_EINVAL; } GBK_BUFFER(title, TITLE_CCHARS); convert_u2g(db_get_value(res, 0, 0), gbk_title); xml_header(NULL); printf("<bbspropdetail>"); print_session(); //% printf("<prop>自定义身份%s: %s</prop></bbspropdetail>", printf("<prop>\xd7\xd4\xb6\xa8\xd2\xe5\xc9\xed\xb7\xdd%s: %s</prop></bbspropdetail>", //% db_get_bool(res, 0, 1) ? "" : "[尚在审核]", gbk_title); db_get_bool(res, 0, 1) ? "" : "[\xc9\xd0\xd4\xda\xc9\xf3\xba\xcb]", gbk_title); db_clear(res); return 0; }
/* { groups: [ { name: OPTIONAL TEXT, descr: OPTIONAL TEXT, boards: [ { id: INTEGER, name: TEXT, unread: OPTIONAL BOOLEAN }, ... ] }, ... ] } */ int api_board_fav(void) { if (!session_id()) return WEB_ERROR_LOGIN_REQUIRED; xml_node_t *root = set_response_root("bbs-board-fav", XML_NODE_ANONYMOUS_JSON, XML_ENCODING_UTF8); xml_node_t *groups = xml_new_node("groups", XML_NODE_CHILD_ARRAY); xml_add_child(root, groups); query_t *q = query_new(0); query_select(q, "board, name, folder"); query_from(q, "fav_boards"); query_where(q, "user_id = %"DBIdUID, session_uid()); db_res_t *boards = query_exec(q); q = query_new(0); query_select(q, "id, name, descr"); query_from(q, "fav_board_folders"); query_where(q, "user_id = %"DBIdUID, session_uid()); db_res_t *folders = query_exec(q); if (folders && boards) { attach_group(groups, boards, FAV_BOARD_ROOT_FOLDER); for (int i = db_res_rows(folders) - 1; i >= 0; --i) { int id = db_get_integer(folders, i, 0); xml_node_t *group = attach_group(groups, boards, id); xml_attr_string(group, "name", db_get_value(folders, i, 1), true); xml_attr_string(group, "descr", db_get_value(folders, i, 2), true); } } db_clear(folders); db_clear(boards); return WEB_OK; }
/** * Follow a person. * @param follower The follower id. * @param followed The name of followed person. * @param notes Notes. * @return Affected rows. */ int follow(user_id_t follower, const char *followed, const char *notes) { if (notes) { if (string_validate_utf8(notes, FOLLOW_NOTE_CCHARS, false) < 0) return 0; } else { notes = ""; } user_id_t uid = get_user_id(followed); if (!uid) return 0; db_res_t *res = db_cmd("INSERT INTO follows (user_id, follower, notes)" " VALUES (%"DBIdUID", %"DBIdUID", %s)", uid, follower, notes); if (res) { int ret = db_cmd_rows(res); db_clear(res); return ret; } return 0; }
static void show_sessions_of_friends(void) { db_res_t *res = session_get_followed(); if (!res) return; fb_time_t now = fb_time(); for (int i = 0; i < db_res_rows(res); ++i) { bool visible = db_get_bool(res, i, 3); if (!visible && !HAS_PERM(PERM_SEECLOAK)) continue; session_id_t sid = db_get_session_id(res, i, 0); const char *uname = db_get_value(res, i, 2); const char *ip = db_get_value(res, i, 4); fb_time_t refresh = session_get_idle(sid); int status = get_user_status(sid); struct userec user; getuserec(uname, &user); int idle; if (refresh < 1 || status == ST_BBSNET) idle = 0; else idle = (now - refresh) / 60; if (HAS_DEFINE(user.userdefine, DEF_NOTHIDEIP)) ip = mask_host(ip); else ip = "......"; printf("<ov id='%s' action='%s' idle='%d' ip='%s'>", uname, session_status_descr(status), idle, ip); xml_fputs(user.username); printf("</ov>"); } db_clear(res); }
/** * Returns the database. If this function returns false, this has not * succeeded, and the caller should create the database after the * process has been daemonized. */ static bool glue_db_init_and_load(void) { const char *path = config_get_path(CONF_DB_FILE); bool ret; GError *error = NULL; if (!mapper_has_music_directory()) { if (path != NULL) g_message("Found " CONF_DB_FILE " setting without " CONF_MUSIC_DIR " - disabling database"); db_init(NULL); return true; } if (path == NULL) g_error(CONF_DB_FILE " setting missing"); db_init(path); ret = db_load(&error); if (!ret) { g_warning("Failed to load database: %s", error->message); g_error_free(error); if (!db_check()) exit(EXIT_FAILURE); db_clear(); /* run database update after daemonization */ return false; } return true; }
int web_all_boards(void) { xml_header(NULL); printf("<bbsall>"); print_session(); db_res_t *res = db_query(BOARD_SELECT_QUERY_BASE); if (!res) return BBS_EINTNL; for (int i = 0; i < db_res_rows(res); ++i) { board_t board; res_to_board(res, i, &board); if (!has_read_perm(&board)) continue; board_to_gbk(&board); printf("<brd dir='%d' title='%s' cate='%s' desc='%s' bm='%s' />", (board.flag & BOARD_FLAG_DIR) ? 1 : 0, board.name, board.categ, board.descr, board.bms); } db_clear(res); printf("</bbsall>"); return 0; }
int api_board_all(void) { db_res_t *res = db_query(BOARD_SELECT_QUERY_BASE); if (!res) return WEB_ERROR_INTERNAL; xml_node_t *root = set_response_root("bbs-board-all", XML_NODE_ANONYMOUS_JSON, XML_ENCODING_UTF8); xml_node_t *boards = xml_new_node("boards", XML_NODE_CHILD_ARRAY); xml_add_child(root, boards); for (int i = db_res_rows(res) - 1; i >= 0; --i) { board_t board; res_to_board(res, i, &board); if (!has_read_perm(&board)) continue; xml_node_t *node = xml_new_node("board", XML_NODE_ANONYMOUS_JSON); board_to_node(&board, node); xml_add_child(boards, node); } db_clear(res); return WEB_OK; }
int web_sector(void) { int sid = 0; board_t parent = { .id = 0 }; db_res_t *res = NULL; const char *sname = web_get_param("s"); if (*sname) { res = db_query("SELECT id, descr" " FROM board_sectors WHERE name = %s", sname); if (!res || db_res_rows(res) < 1) { db_clear(res); return BBS_EINVAL; } } else { const char *pname = web_get_param("board"); if (*pname) get_board(pname, &parent); else get_board_by_bid(strtol(web_get_param("bid"), NULL, 10), &parent); if (!parent.id || !(parent.flag & BOARD_FLAG_DIR) || !has_read_perm(&parent)) return BBS_ENOBRD; } xml_header(NULL); printf("<bbsboa link='%sdoc' ", get_post_list_type_string()); if (*sname) { char path[HOMELEN]; sprintf(path, "%s/info/egroup%d/icon.jpg", BBSHOME, (int) strtol(sname, NULL, 16)); if (dashf(path)) printf(" icon='%s'", path); const char *utf8_sector = db_get_value(res, 0, 1); if (web_request_type(UTF8)) { printf(" title='%s'>", utf8_sector); } else { GBK_BUFFER(sector, BOARD_SECTOR_NAME_CCHARS); convert_u2g(utf8_sector, gbk_sector); printf(" title='%s'>", gbk_sector); } sid = db_get_integer(res, 0, 0); db_clear(res); } else { if (web_request_type(UTF8)) { printf(" dir= '1' title='%s'>", parent.descr); } else { GBK_BUFFER(descr, BOARD_DESCR_CCHARS); convert_u2g(parent.descr, gbk_descr); printf(" dir= '1' title='%s'>", gbk_descr); } } if (sid) res = db_query(BOARD_SELECT_QUERY_BASE "WHERE b.sector = %d", sid); else res = db_query(BOARD_SELECT_QUERY_BASE "WHERE b.parent = %d", parent.id); if (res && db_res_rows(res) > 0) show_board(res); db_clear(res); print_session(); printf("</bbsboa>"); return 0; } int bbsclear_main(void) { if (!session_id()) return BBS_ELGNREQ; board_t board; if (!get_board(web_get_param("board"), &board) || !has_read_perm(&board)) return BBS_ENOBRD; session_set_board(board.id); const char *start = web_get_param("start"); brc_init(currentuser.userid, board.name); brc_clear_all(); brc_sync(currentuser.userid); char buf[STRLEN]; snprintf(buf, sizeof(buf), "doc?board=%s&start=%s", board.name, start); http_header(); refreshto(0, buf); printf("</head></html>"); return 0; } int bbsnot_main(void) { board_t board; if (!get_board(web_get_param("board"), &board) || !has_read_perm(&board)) return BBS_ENOBRD; if (board.flag & BOARD_FLAG_DIR) return BBS_EINVAL; session_set_board(board.id); char fname[HOMELEN]; snprintf(fname, sizeof(fname), "vote/%s/notes", board.name); mmap_t m; m.oflag = O_RDONLY; if (mmap_open(fname, &m) < 0) return BBS_ENOFILE; xml_header(NULL); printf("<bbsnot brd='%s'>", board.name); xml_fputs2((char *) m.ptr, m.size); mmap_close(&m); print_session(); printf("</bbsnot>"); return 0; }
static void online_users_free(online_users_t *up) { db_clear(up->res); free(up->users); up->users = NULL; }
/** * A player is attempting to modify the banlist * @param sd: Player data * @param chname: Channel name * @param pname: Player to ban or unban * @param flag: Ban options (0 - Ban, 1 - Unban, 2 - Unban all, 3 - Ban list) * @return 0 on success or -1 on failure */ int channel_pcban(struct map_session_data *sd, char *chname, char *pname, int flag){ struct Channel *channel; char output[CHAT_SIZE_MAX]; struct map_session_data *tsd = map_nick2sd(pname,false); if( channel_chk(chname,NULL,1) ) { clif_displaymessage(sd->fd, msg_txt(sd,1405));// Channel name must start with '#'. return -1; } channel = channel_name2channel(chname,sd,0); if( !channel ) { sprintf(output, msg_txt(sd,1407), chname);// Channel '%s' is not available. clif_displaymessage(sd->fd, output); return -1; } if( !pc_has_permission(sd, PC_PERM_CHANNEL_ADMIN) ) { if (channel->char_id != sd->status.char_id) { sprintf(output, msg_txt(sd,1412), chname);// You're not the owner of channel '%s'. clif_displaymessage(sd->fd, output); return -1; } else if (!channel_config.private_channel.ban) { sprintf(output, msg_txt(sd,765), chname); // You're not allowed to ban a player. clif_displaymessage(sd->fd, output); return -1; } } if(flag != 2 && flag != 3){ char banned; if(!tsd || pc_has_permission(tsd, PC_PERM_CHANNEL_ADMIN) ) { sprintf(output, msg_txt(sd,1464), pname);// Ban failed for player '%s'. clif_displaymessage(sd->fd, output); return -1; } banned = channel_haspcbanned(channel,tsd); if(!flag && banned==1) { sprintf(output, msg_txt(sd,1465), tsd->status.name);// Player '%s' is already banned from this channel. clif_displaymessage(sd->fd, output); return -1; } else if(flag==1 && banned==0) { sprintf(output, msg_txt(sd,1440), tsd->status.name);// Player '%s' is not banned from this channel. clif_displaymessage(sd->fd, output); return -1; } } else { if( !db_size(channel->banned) ) { sprintf(output, msg_txt(sd,1439), chname);// Channel '%s' contains no banned players. clif_displaymessage(sd->fd, output); return 0; } } //let properly alter the list now switch(flag){ case 0: { struct chan_banentry *cbe; if (!tsd) return -1; CREATE(cbe, struct chan_banentry, 1); cbe->char_id = tsd->status.char_id; strcpy(cbe->char_name,tsd->status.name); idb_put(channel->banned, tsd->status.char_id, cbe); channel_clean(channel,tsd,0); sprintf(output, msg_txt(sd,1437),tsd->status.name,chname); // Player '%s' is banned from the '%s' channel. break; } case 1: if (!tsd) return -1; idb_remove(channel->banned, tsd->status.char_id); sprintf(output, msg_txt(sd,1441),tsd->status.name,chname); // Player '%s' is unbanned from the '%s' channel. break; case 2: db_clear(channel->banned); sprintf(output, msg_txt(sd,1442),chname); // Cleared all bans from the '%s' channel. break; case 3: { DBIterator *iter = db_iterator(channel->banned); struct chan_banentry *cbe; sprintf(output, msg_txt(sd,1443), channel->name);// ---- '#%s' Ban List: clif_displaymessage(sd->fd, output); for( cbe = (struct chan_banentry *)dbi_first(iter); dbi_exists(iter); cbe = (struct chan_banentry *)dbi_next(iter) ) { //for all users if (cbe->char_name[0]) sprintf(output, "%d: %s",cbe->char_id,cbe->char_name); else sprintf(output, "%d: ****",cbe->char_id); clif_displaymessage(sd->fd, output); } dbi_destroy(iter); } return 0; } clif_displaymessage(sd->fd, output); return 0; }