| 14 |
* * |
* * |
| 15 |
***************************************************************************/ |
***************************************************************************/ |
| 16 |
|
|
|
#define _POSIX_C_SOURCE 200112L |
|
|
|
|
| 17 |
#include "common.h" |
#include "common.h" |
|
#include "log.h" |
|
|
#include "menu.h" |
|
|
#include <string.h> |
|
|
#include <time.h> |
|
|
#include <sys/types.h> |
|
|
|
|
|
// Version information |
|
|
char app_version[256] = "LBBS-devel version 1.0"; |
|
| 18 |
|
|
| 19 |
// File loader |
// File loader |
| 20 |
const char *data_files_load_startup[] = { |
const char *data_files_load_startup[] = { |
| 29 |
VAR_BBS_TOP}; |
VAR_BBS_TOP}; |
| 30 |
int data_files_load_startup_count = 9; // Count of data_files_load_startup[] |
int data_files_load_startup_count = 9; // Count of data_files_load_startup[] |
| 31 |
|
|
|
const char *data_files_load_timeval[] = { |
|
|
VAR_BBS_TOP}; |
|
|
int data_files_load_timeval_count = 1; // Count of data_files_load_timeval[] |
|
|
|
|
| 32 |
// Global declaration for sockets |
// Global declaration for sockets |
| 33 |
int socket_server; |
int socket_server[2]; |
| 34 |
int socket_client; |
int socket_client; |
| 35 |
char hostaddr_server[50]; |
char hostaddr_client[IP_ADDR_LEN]; |
|
char hostaddr_client[50]; |
|
|
int port_server; |
|
| 36 |
int port_client; |
int port_client; |
| 37 |
|
|
| 38 |
|
// SSHv2 |
| 39 |
|
int SSH_v2 = 0; |
| 40 |
|
ssh_bind sshbind; |
| 41 |
|
ssh_session SSH_session; |
| 42 |
|
ssh_channel SSH_channel; |
| 43 |
|
|
| 44 |
// Global declaration for system |
// Global declaration for system |
| 45 |
volatile int SYS_server_exit = 0; |
volatile int SYS_server_exit = 0; |
| 46 |
volatile int SYS_child_process_count = 0; |
volatile int SYS_child_process_count = 0; |
| 47 |
volatile int SYS_child_exit = 0; |
volatile int SYS_child_exit = 0; |
| 48 |
volatile int SYS_menu_reload = 0; |
volatile int SYS_conf_reload = 0; |
|
volatile int SYS_data_file_reload = 0; |
|
|
volatile int SYS_section_list_reload = 0; |
|
|
|
|
|
static const char *weekday[] = { |
|
|
"天", "一", "二", "三", "四", "五", "六"}; |
|
| 49 |
|
|
| 50 |
// Common function |
// Common function |
|
const char *get_time_str(char *s, size_t len) |
|
|
{ |
|
|
time_t curtime; |
|
|
struct tm local_tm; |
|
|
|
|
|
time(&curtime); |
|
|
localtime_r(&curtime, &local_tm); |
|
|
size_t j = strftime(s, len, "%Y年%m月%d日%H:%M:%S 星期", &local_tm); |
|
|
|
|
|
if (j == 0 || j + strlen(weekday[local_tm.tm_wday]) + 1 > len) |
|
|
{ |
|
|
return NULL; |
|
|
} |
|
|
|
|
|
strncat(s, weekday[local_tm.tm_wday], len - 1 - j); |
|
|
|
|
|
return s; |
|
|
} |
|
|
|
|
| 51 |
void sig_hup_handler(int i) |
void sig_hup_handler(int i) |
| 52 |
{ |
{ |
| 53 |
SYS_menu_reload = 1; |
SYS_conf_reload = 1; |
|
SYS_data_file_reload = 1; |
|
|
SYS_section_list_reload = 1; |
|
| 54 |
} |
} |
| 55 |
|
|
| 56 |
void sig_term_handler(int i) |
void sig_term_handler(int i) |
| 62 |
{ |
{ |
| 63 |
SYS_child_exit = 1; |
SYS_child_exit = 1; |
| 64 |
} |
} |
|
|
|
|
const char *ip_mask(char *s, int level, char mask) |
|
|
{ |
|
|
char *p = s; |
|
|
|
|
|
if (level <= 0) |
|
|
{ |
|
|
return s; |
|
|
} |
|
|
if (level > 4) |
|
|
{ |
|
|
level = 4; |
|
|
} |
|
|
|
|
|
for (int i = 0; i < 4 - level; i++) |
|
|
{ |
|
|
p = strchr(p, '.'); |
|
|
if (p == NULL) |
|
|
{ |
|
|
return s; |
|
|
} |
|
|
p++; |
|
|
} |
|
|
|
|
|
for (int i = 0; i < level; i++) |
|
|
{ |
|
|
*p = mask; |
|
|
p++; |
|
|
if (i < level - 1) |
|
|
{ |
|
|
*p = '.'; |
|
|
p++; |
|
|
} |
|
|
} |
|
|
*p = '\0'; |
|
|
|
|
|
return s; |
|
|
} |
|