| 5 |
* |
* |
| 6 |
* Copyright (C) 2004-2025 Leaflet <leaflet@leafok.com> |
* Copyright (C) 2004-2025 Leaflet <leaflet@leafok.com> |
| 7 |
* |
* |
| 8 |
* Author: ytht <2391669999@qq.com> |
* Co-author: 老黑噜 <2391669999@qq.com> |
| 9 |
*/ |
*/ |
| 10 |
|
|
| 11 |
#ifdef HAVE_CONFIG_H |
#ifdef HAVE_CONFIG_H |
| 21 |
#include "log.h" |
#include "log.h" |
| 22 |
#include "screen.h" |
#include "screen.h" |
| 23 |
#include "str_process.h" |
#include "str_process.h" |
| 24 |
|
#include "user_info_update.h" |
| 25 |
#include "user_list.h" |
#include "user_list.h" |
| 26 |
#include "user_priv.h" |
#include "user_priv.h" |
| 27 |
#include <ctype.h> |
#include <ctype.h> |
| 28 |
#include <stdlib.h> |
#include <stdlib.h> |
| 29 |
#include <sys/param.h> |
#include <sys/param.h> |
| 30 |
|
|
| 31 |
|
enum bbs_user_sign_const_t |
| 32 |
|
{ |
| 33 |
|
BBS_user_sign_max_len = 4096, |
| 34 |
|
BBS_user_sign_max_line = 10, |
| 35 |
|
BBS_user_sign_cnt = 3, |
| 36 |
|
}; |
| 37 |
|
|
| 38 |
int user_intro_edit(int uid) |
int user_intro_edit(int uid) |
| 39 |
{ |
{ |
| 40 |
MYSQL *db = NULL; |
MYSQL *db = NULL; |
| 183 |
press_any_key(); |
press_any_key(); |
| 184 |
ret = 1; // Success |
ret = 1; // Success |
| 185 |
|
|
| 186 |
|
cleanup: |
| 187 |
|
mysql_free_result(rs); |
| 188 |
|
mysql_close(db); |
| 189 |
|
|
| 190 |
|
// Cleanup buffers |
| 191 |
|
editor_data_cleanup(p_editor_data); |
| 192 |
|
|
| 193 |
|
return ret; |
| 194 |
|
} |
| 195 |
|
|
| 196 |
|
int user_sign_edit(int uid) |
| 197 |
|
{ |
| 198 |
|
MYSQL *db = NULL; |
| 199 |
|
MYSQL_RES *rs = NULL; |
| 200 |
|
MYSQL_ROW row; |
| 201 |
|
char sql_sign[SQL_BUFFER_LEN + 2 * BBS_user_sign_max_len + 1]; |
| 202 |
|
EDITOR_DATA *p_editor_data = NULL; |
| 203 |
|
int ret = 0; |
| 204 |
|
int ch = 0; |
| 205 |
|
char sign[BBS_user_sign_max_len + 1]; |
| 206 |
|
char sign_f[BBS_user_sign_max_len * 2 + 1]; |
| 207 |
|
long len_sign = 0L; |
| 208 |
|
long line_offsets[BBS_user_sign_max_line + 1]; |
| 209 |
|
long lines = 0L; |
| 210 |
|
char buf[2] = ""; |
| 211 |
|
int sign_id = 0; |
| 212 |
|
|
| 213 |
|
clearscr(); |
| 214 |
|
get_data(1, 1, "请输入需要编辑的签名档编号(1-3): ", buf, sizeof(buf), 1); |
| 215 |
|
sign_id = atoi(buf); |
| 216 |
|
if (sign_id < 1 || sign_id > BBS_user_sign_cnt) |
| 217 |
|
{ |
| 218 |
|
ret = -1; |
| 219 |
|
goto cleanup; |
| 220 |
|
} |
| 221 |
|
|
| 222 |
|
db = db_open(); |
| 223 |
|
if (db == NULL) |
| 224 |
|
{ |
| 225 |
|
log_error("db_open() error: %s\n", mysql_error(db)); |
| 226 |
|
ret = -1; |
| 227 |
|
goto cleanup; |
| 228 |
|
} |
| 229 |
|
|
| 230 |
|
snprintf(sql_sign, sizeof(sql_sign), "SELECT sign_%d FROM user_pubinfo WHERE UID=%d", sign_id, uid); |
| 231 |
|
if (mysql_query(db, sql_sign) != 0) |
| 232 |
|
{ |
| 233 |
|
log_error("Query user_pubinfo error: %s\n", mysql_error(db)); |
| 234 |
|
ret = -2; |
| 235 |
|
goto cleanup; |
| 236 |
|
} |
| 237 |
|
if ((rs = mysql_store_result(db)) == NULL) |
| 238 |
|
{ |
| 239 |
|
log_error("Get user_sign data failed\n"); |
| 240 |
|
ret = -2; |
| 241 |
|
goto cleanup; |
| 242 |
|
} |
| 243 |
|
if ((row = mysql_fetch_row(rs))) |
| 244 |
|
{ |
| 245 |
|
p_editor_data = editor_data_load(row[0] ? row[0] : ""); |
| 246 |
|
} |
| 247 |
|
else |
| 248 |
|
{ |
| 249 |
|
log_error("mysql_fetch_row() failed\n"); |
| 250 |
|
ret = -2; |
| 251 |
|
goto cleanup; |
| 252 |
|
} |
| 253 |
|
mysql_free_result(rs); |
| 254 |
|
rs = NULL; |
| 255 |
|
|
| 256 |
|
mysql_close(db); |
| 257 |
|
db = NULL; |
| 258 |
|
|
| 259 |
|
for (ch = 'E'; !SYS_server_exit;) |
| 260 |
|
{ |
| 261 |
|
if (ch == 'E') |
| 262 |
|
{ |
| 263 |
|
editor_display(p_editor_data); |
| 264 |
|
} |
| 265 |
|
|
| 266 |
|
clearscr(); |
| 267 |
|
moveto(1, 1); |
| 268 |
|
prints("(S)保存, (C)取消 or (E)再编辑? [S]: "); |
| 269 |
|
iflush(); |
| 270 |
|
|
| 271 |
|
ch = igetch_t(BBS_max_user_idle_time); |
| 272 |
|
switch (toupper(ch)) |
| 273 |
|
{ |
| 274 |
|
case KEY_NULL: |
| 275 |
|
case KEY_TIMEOUT: |
| 276 |
|
goto cleanup; |
| 277 |
|
case CR: |
| 278 |
|
case 'S': |
| 279 |
|
len_sign = editor_data_save(p_editor_data, sign, BBS_user_sign_max_len); |
| 280 |
|
if (len_sign < 0) |
| 281 |
|
{ |
| 282 |
|
log_error("editor_data_save() error\n"); |
| 283 |
|
ret = -3; |
| 284 |
|
goto cleanup; |
| 285 |
|
} |
| 286 |
|
|
| 287 |
|
if (check_badwords(sign, '*') < 0) |
| 288 |
|
{ |
| 289 |
|
log_error("check_badwords(sign) error\n"); |
| 290 |
|
ret = -3; |
| 291 |
|
goto cleanup; |
| 292 |
|
} |
| 293 |
|
|
| 294 |
|
lml_render(sign, sign_f, sizeof(sign_f), SCREEN_COLS, 0); |
| 295 |
|
|
| 296 |
|
lines = split_data_lines(sign_f, SCREEN_COLS + 1, line_offsets, BBS_user_sign_max_line + 2, 1, NULL); |
| 297 |
|
if (lines > BBS_user_sign_max_line) |
| 298 |
|
{ |
| 299 |
|
clearscr(); |
| 300 |
|
moveto(1, 1); |
| 301 |
|
prints("签名档长度超过限制 (%d行),请返回修改", BBS_user_sign_max_line); |
| 302 |
|
press_any_key(); |
| 303 |
|
|
| 304 |
|
ch = 'E'; |
| 305 |
|
continue; |
| 306 |
|
} |
| 307 |
|
break; |
| 308 |
|
case 'C': |
| 309 |
|
clearscr(); |
| 310 |
|
moveto(1, 1); |
| 311 |
|
prints("取消更改..."); |
| 312 |
|
press_any_key(); |
| 313 |
|
goto cleanup; |
| 314 |
|
case 'E': |
| 315 |
|
ch = 'E'; |
| 316 |
|
continue; |
| 317 |
|
default: // Invalid selection |
| 318 |
|
continue; |
| 319 |
|
} |
| 320 |
|
|
| 321 |
|
break; |
| 322 |
|
} |
| 323 |
|
|
| 324 |
|
db = db_open(); |
| 325 |
|
if (db == NULL) |
| 326 |
|
{ |
| 327 |
|
log_error("db_open() error: %s\n", mysql_error(db)); |
| 328 |
|
ret = -1; |
| 329 |
|
goto cleanup; |
| 330 |
|
} |
| 331 |
|
|
| 332 |
|
// Secure SQL parameters |
| 333 |
|
mysql_real_escape_string(db, sign_f, sign, (unsigned long)len_sign); |
| 334 |
|
|
| 335 |
|
// Update user sign |
| 336 |
|
snprintf(sql_sign, sizeof(sql_sign), |
| 337 |
|
"UPDATE user_pubinfo SET sign_%d = '%s' WHERE UID=%d", |
| 338 |
|
sign_id, sign_f, uid); |
| 339 |
|
|
| 340 |
|
if (mysql_query(db, sql_sign) != 0) |
| 341 |
|
{ |
| 342 |
|
log_error("Update user_pubinfo error: %s\n", mysql_error(db)); |
| 343 |
|
ret = -2; |
| 344 |
|
goto cleanup; |
| 345 |
|
} |
| 346 |
|
|
| 347 |
|
mysql_close(db); |
| 348 |
|
db = NULL; |
| 349 |
|
|
| 350 |
|
clearscr(); |
| 351 |
|
moveto(1, 1); |
| 352 |
|
prints("签名档修改完成"); |
| 353 |
|
press_any_key(); |
| 354 |
|
ret = 1; // Success |
| 355 |
|
|
| 356 |
cleanup: |
cleanup: |
| 357 |
mysql_free_result(rs); |
mysql_free_result(rs); |
| 358 |
mysql_close(db); |
mysql_close(db); |