Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f8d065b09e | ||
|
|
2f2e64ae31 | ||
|
|
a4812dd596 | ||
|
|
2e420e921c | ||
|
|
99972f257a | ||
|
|
8e4ca75d36 | ||
|
|
360019d1a4 | ||
|
|
204c086a03 | ||
|
|
316834ffd0 | ||
|
|
aefbd2e062 | ||
|
|
ff6f60f079 |
@@ -39,6 +39,7 @@
|
||||
#include "commandline.h"
|
||||
#include "debug.h"
|
||||
#include "version.h"
|
||||
#include "utils.h"
|
||||
|
||||
typedef void signal_func (int);
|
||||
|
||||
@@ -122,6 +123,7 @@ usage(const char *appname)
|
||||
fprintf(stdout, " -d <level> Debug level\n");
|
||||
fprintf(stdout, " -h Print usage\n");
|
||||
fprintf(stdout, " -v Print version information\n");
|
||||
fprintf(stdout, " -r Print run id of client\n");
|
||||
fprintf(stdout, "\n");
|
||||
}
|
||||
|
||||
@@ -134,7 +136,7 @@ parse_commandline(int argc, char **argv)
|
||||
int c;
|
||||
int flag = 0;
|
||||
|
||||
while (-1 != (c = getopt(argc, argv, "c:hfd:sw:vx:i:a:"))) {
|
||||
while (-1 != (c = getopt(argc, argv, "c:hfd:sw:vrx:i:a:"))) {
|
||||
|
||||
|
||||
switch (c) {
|
||||
@@ -168,7 +170,25 @@ parse_commandline(int argc, char **argv)
|
||||
fprintf(stdout, "version: " VERSION "\n");
|
||||
exit(1);
|
||||
break;
|
||||
|
||||
case 'r':
|
||||
{
|
||||
char ifname[16] = {0};
|
||||
if(get_net_ifname(ifname, 16)){
|
||||
debug(LOG_ERR, "error: get device sign ifname failed!");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
char if_mac[64] = {0};
|
||||
if(get_net_mac(ifname, if_mac, sizeof(if_mac))) {
|
||||
debug(LOG_ERR, "error: Hard ware MAC address of [%s] get failed!", ifname);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
fprintf(stdout, "run ID:%s\n", if_mac);
|
||||
exit(1);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
usage(argv[0]);
|
||||
exit(1);
|
||||
|
||||
13
config.c
13
config.c
@@ -311,8 +311,13 @@ static int common_handler(void *user, const char *section, const char *name, con
|
||||
#define MATCH(s, n) strcmp(section, s) == 0 && strcmp(name, n) == 0
|
||||
if (MATCH("common", "server_addr")) {
|
||||
SAFE_FREE(config->server_addr);
|
||||
config->server_addr = strdup(value);
|
||||
int addr_len = strlen(value) + 1;
|
||||
config->server_addr = (char *)calloc(1, addr_len);
|
||||
assert(config->server_addr);
|
||||
if(dns_unified(value, config->server_addr, addr_len)) {
|
||||
debug(LOG_ERR, "error: server_addr [%s] is invalid!", value);
|
||||
exit(0);
|
||||
}
|
||||
} else if (MATCH("common", "server_port")) {
|
||||
config->server_port = atoi(value);
|
||||
} else if (MATCH("common", "http_proxy")) {
|
||||
@@ -375,6 +380,7 @@ static void init_common_conf(struct common_conf *config)
|
||||
config->tcp_mux = 0;
|
||||
config->user = NULL;
|
||||
config->server_ip = NULL;
|
||||
config->is_router = 0;
|
||||
}
|
||||
|
||||
// it should be free after using
|
||||
@@ -425,3 +431,8 @@ void load_config(const char *confile)
|
||||
|
||||
dump_all_ps();
|
||||
}
|
||||
|
||||
int is_running_in_router()
|
||||
{
|
||||
return c_conf->is_router;
|
||||
}
|
||||
|
||||
16
config.h
16
config.h
@@ -45,20 +45,23 @@ struct base_conf{
|
||||
|
||||
// common config
|
||||
struct common_conf {
|
||||
char *server_addr; /* default 0.0.0.0 */
|
||||
char *server_addr; /* default 0.0.0.0 */
|
||||
char *server_ip;
|
||||
int server_port; /* default 7000 */
|
||||
int server_port; /* default 7000 */
|
||||
char *http_proxy;
|
||||
char *log_file; /* default consol */
|
||||
char *log_way; /* default console */
|
||||
char *log_level; /* default info */
|
||||
char *log_file; /* default consol */
|
||||
char *log_way; /* default console */
|
||||
char *log_level; /* default info */
|
||||
int log_max_days; /* default 3 */
|
||||
char *privilege_token;
|
||||
char *auth_token;
|
||||
int heartbeat_interval; /* default 10 */
|
||||
int heartbeat_timeout; /* default 30 */
|
||||
int tcp_mux; /* default 0 */
|
||||
int tcp_mux; /* default 0 */
|
||||
char *user;
|
||||
|
||||
/* private fields */
|
||||
int is_router; // to sign router (Openwrt/LEDE) or not
|
||||
};
|
||||
|
||||
struct common_conf *get_common_config();
|
||||
@@ -73,5 +76,6 @@ struct proxy_client *get_all_pc();
|
||||
void load_config(const char *confile);
|
||||
char *get_ftp_data_proxy_name(const char *ftp_proxy_name);
|
||||
void set_common_server_ip(const char *ip);
|
||||
int is_running_in_router();
|
||||
|
||||
#endif //_CONFIG_H_
|
||||
|
||||
5
login.c
5
login.c
@@ -73,6 +73,11 @@ void init_login()
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if (strcmp(ifname, "br-lan") == 0) {
|
||||
c_conf->is_router = 1;
|
||||
debug(LOG_DEBUG, "working in router");
|
||||
}
|
||||
|
||||
char if_mac[64] = {0};
|
||||
if(get_net_mac(ifname, if_mac, sizeof(if_mac))) {
|
||||
debug(LOG_ERR, "error: Hard ware MAC address of [%s] get failed!", ifname);
|
||||
|
||||
17
msg.c
17
msg.c
@@ -42,6 +42,7 @@
|
||||
#include "common.h"
|
||||
#include "login.h"
|
||||
#include "client.h"
|
||||
#include "utils.h"
|
||||
|
||||
#define JSON_MARSHAL_TYPE(jobj,key,jtype,item) \
|
||||
json_object_object_add(jobj, key, json_object_new_##jtype((item)));
|
||||
@@ -80,7 +81,14 @@ static void fill_custom_domains(struct json_object *j_ctl_req, const char *custo
|
||||
char *tok = tmp, *end = tmp;
|
||||
while (tok != NULL) {
|
||||
strsep(&end, ",");
|
||||
json_object_array_add(jarray_cdomains, json_object_new_string(tok));
|
||||
|
||||
int dname_len = strlen(tok) + 1;
|
||||
char *dname_buf = (char *)calloc(1, dname_len);
|
||||
assert(dname_buf);
|
||||
dns_unified(tok, dname_buf, dname_len);
|
||||
json_object_array_add(jarray_cdomains, json_object_new_string(dname_buf));
|
||||
|
||||
free(dname_buf);
|
||||
tok = end;
|
||||
}
|
||||
SAFE_FREE(tmp);
|
||||
@@ -172,7 +180,6 @@ int new_proxy_service_marshal(const struct proxy_service *np_req, char **msg)
|
||||
JSON_MARSHAL_TYPE(j_np_req, "proxy_type", string, np_req->proxy_type);
|
||||
JSON_MARSHAL_TYPE(j_np_req, "use_encryption", boolean, np_req->use_encryption);
|
||||
JSON_MARSHAL_TYPE(j_np_req, "use_compression", boolean, np_req->use_compression);
|
||||
JSON_MARSHAL_TYPE(j_np_req, "remote_port", int, np_req->remote_port);
|
||||
|
||||
if (is_ftp_proxy(np_req)) {
|
||||
JSON_MARSHAL_TYPE(j_np_req, "remote_data_port", int, np_req->remote_data_port);
|
||||
@@ -180,8 +187,14 @@ int new_proxy_service_marshal(const struct proxy_service *np_req, char **msg)
|
||||
|
||||
if (np_req->custom_domains) {
|
||||
fill_custom_domains(j_np_req, np_req->custom_domains);
|
||||
json_object_object_add(j_np_req, "remote_port", NULL);
|
||||
} else {
|
||||
json_object_object_add(j_np_req, "custom_domains", NULL);
|
||||
if (np_req->remote_port != -1) {
|
||||
JSON_MARSHAL_TYPE(j_np_req, "remote_port", int, np_req->remote_port);
|
||||
} else {
|
||||
json_object_object_add(j_np_req, "remote_port", NULL);
|
||||
}
|
||||
}
|
||||
|
||||
JSON_MARSHAL_TYPE(j_np_req, "subdomain", string, SAFE_JSON_STRING(np_req->subdomain));
|
||||
|
||||
27
utils.c
27
utils.c
@@ -7,6 +7,7 @@
|
||||
#include <sys/time.h>
|
||||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include <net/if.h>
|
||||
#include <sys/ioctl.h>
|
||||
@@ -180,4 +181,30 @@ int get_net_ifname(char *if_buf, int blen)
|
||||
|
||||
freeifaddrs(ifaddr);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// e.g. wWw.Baidu.com/China will be trans into www.baidu.com/China
|
||||
// return: 0:check and trant succeed, 1:failed or domain name is invalid
|
||||
int dns_unified(const char *dname, char *udname_buf, int udname_buf_len)
|
||||
{
|
||||
if (! dname || ! udname_buf || udname_buf_len < strlen(dname)+1)
|
||||
return 1;
|
||||
|
||||
int has_dot = 0;
|
||||
int dlen = strlen(dname);
|
||||
int i = 0;
|
||||
for(i=0; i<dlen; i++) {
|
||||
if(dname[i] == '/')
|
||||
break;
|
||||
|
||||
if (dname[i] == '.' && i != dlen-1)
|
||||
has_dot = 1;
|
||||
|
||||
udname_buf[i] = tolower(dname[i]);
|
||||
}
|
||||
|
||||
if (! has_dot) //domain name should have 1 dot leastly
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
1
utils.h
1
utils.h
@@ -9,5 +9,6 @@ int is_valid_ip_address(const char *ip_address);
|
||||
int show_net_ifname();
|
||||
int get_net_ifname(char *if_buf, int blen);
|
||||
int get_net_mac(char *net_if_name, char *mac, int mac_len);
|
||||
int dns_unified(const char *dname, char *udname_buf, int udname_buf_len);
|
||||
|
||||
#endif //_UTILS_H_
|
||||
|
||||
Reference in New Issue
Block a user