2022-09-11 16:18:55 +08:00
|
|
|
#include "stdafx.h"
|
2022-09-18 11:15:37 +08:00
|
|
|
#include "user_login.h"
|
|
|
|
#include "user_status.h"
|
|
|
|
#include "limit_speed.h"
|
|
|
|
|
|
|
|
static void do_status(const char* addr, acl::sslbase_conf& ssl_conf,
|
|
|
|
const char* user, const char* pass) {
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
acl::string stok;
|
|
|
|
user_login login(addr, ssl_conf, user, pass);
|
|
|
|
if (!login.start(stok)) {
|
|
|
|
logger_error("login failed, user=%s, pass=%s",
|
|
|
|
user, pass);
|
|
|
|
sleep(1);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
user_status status(addr, ssl_conf, stok);
|
|
|
|
status.start();
|
|
|
|
sleep(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void do_limit_speed(const char* addr, acl::sslbase_conf& ssl_conf,
|
|
|
|
const char* hostname, const char* user, const char* pass,
|
|
|
|
const char* mac, const char* ip, int up, int down) {
|
|
|
|
|
|
|
|
acl::string stok;
|
|
|
|
user_login login(addr, ssl_conf, user, pass);
|
|
|
|
if (!login.start(stok)) {
|
|
|
|
logger_error("login failed, user=%s, pass=%s", user, pass);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
limit_speed limit(addr, ssl_conf, stok, mac, ip);
|
|
|
|
limit.set_hostname(hostname);
|
|
|
|
limit.start(up, down);
|
|
|
|
}
|
2022-09-11 16:18:55 +08:00
|
|
|
|
|
|
|
static void usage(const char* procname) {
|
|
|
|
printf("usage: %s -h[help]\r\n"
|
|
|
|
" -s server_address\r\n"
|
2022-09-18 11:15:37 +08:00
|
|
|
" -a action[status|limit_speed]\r\n"
|
|
|
|
" -U up_limit[default: 15]\r\n"
|
|
|
|
" -D down_limit[default: 15]\r\n"
|
|
|
|
" -H hostname\r\n"
|
|
|
|
" -M mac\r\n"
|
|
|
|
" -I ip\r\n"
|
2022-09-11 16:18:55 +08:00
|
|
|
" -u username\r\n"
|
|
|
|
" -p password\r\n"
|
|
|
|
" -C path_to_crypto\r\n"
|
|
|
|
" -S path_to_ssl\r\n"
|
2022-09-11 16:24:01 +08:00
|
|
|
" -L logfile\r\n"
|
2022-09-11 16:18:55 +08:00
|
|
|
, procname);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char* argv[]) {
|
|
|
|
acl::string addr("192.168.1.65:443");
|
2022-09-18 11:15:37 +08:00
|
|
|
int ch, up = 15, down = 15;
|
2022-09-11 16:18:55 +08:00
|
|
|
acl::sslbase_conf* ssl_conf;
|
|
|
|
acl::string crypto_path = "/usr/local/lib/libcrypto.dylib";
|
|
|
|
acl::string ssl_path = "/usr/local/lib/libssl.dylib";
|
2022-09-18 11:15:37 +08:00
|
|
|
acl::string user, pass, logfile, action = "status";
|
|
|
|
acl::string mac, ip, hostname = "---";
|
2022-09-11 16:18:55 +08:00
|
|
|
|
2022-09-18 11:15:37 +08:00
|
|
|
while ((ch = getopt(argc, argv, "hs:a:C:S:u:p:L:U:D:M:I:H:")) > 0) {
|
2022-09-11 16:18:55 +08:00
|
|
|
switch (ch) {
|
|
|
|
case 'h':
|
|
|
|
usage(argv[0]);
|
|
|
|
return 0;
|
|
|
|
case 's':
|
|
|
|
addr = optarg;
|
|
|
|
break;
|
2022-09-18 11:15:37 +08:00
|
|
|
case 'a':
|
|
|
|
action = optarg;
|
|
|
|
break;
|
2022-09-11 16:18:55 +08:00
|
|
|
case 'C':
|
|
|
|
crypto_path = optarg;
|
|
|
|
break;
|
|
|
|
case 'S':
|
|
|
|
ssl_path = optarg;
|
|
|
|
break;
|
|
|
|
case 'u':
|
|
|
|
user = optarg;
|
|
|
|
break;
|
|
|
|
case 'p':
|
|
|
|
pass = optarg;
|
|
|
|
break;
|
2022-09-11 16:24:01 +08:00
|
|
|
case 'L':
|
|
|
|
logfile = optarg;
|
|
|
|
break;
|
2022-09-18 11:15:37 +08:00
|
|
|
case 'U':
|
|
|
|
up = atoi(optarg);
|
|
|
|
break;
|
|
|
|
case 'D':
|
|
|
|
down = atoi(optarg);
|
|
|
|
break;
|
|
|
|
case 'M':
|
|
|
|
mac = optarg;
|
|
|
|
break;
|
|
|
|
case 'I':
|
|
|
|
ip = optarg;
|
|
|
|
break;
|
|
|
|
case 'H':
|
|
|
|
hostname = optarg;
|
|
|
|
break;
|
2022-09-11 16:18:55 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (user.empty() || pass.empty()) {
|
|
|
|
usage(argv[0]);
|
|
|
|
printf("\r\nusername or password empty!\r\n\r\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2022-09-11 16:24:01 +08:00
|
|
|
if (logfile.empty()) {
|
|
|
|
acl::log::stdout_open(true);
|
|
|
|
} else {
|
|
|
|
acl::log::open(logfile, "status");
|
|
|
|
}
|
2022-09-11 16:18:55 +08:00
|
|
|
|
|
|
|
acl::openssl_conf::set_libpath(crypto_path, ssl_path);
|
|
|
|
|
|
|
|
if (!acl::openssl_conf::load()) {
|
2022-09-15 23:13:17 +08:00
|
|
|
logger_error("load ssl error, crypto=%s, ssl=%s",
|
2022-09-11 16:18:55 +08:00
|
|
|
crypto_path.c_str(), ssl_path.c_str());
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ssl_conf = new acl::openssl_conf(false);
|
2022-09-18 11:15:37 +08:00
|
|
|
|
|
|
|
if (action == "status") {
|
|
|
|
do_status(addr, *ssl_conf, user, pass);
|
|
|
|
} else if (action == "limit_speed") {
|
|
|
|
do_limit_speed(addr, *ssl_conf, hostname, user, pass, mac, ip, up, down);
|
|
|
|
} else {
|
|
|
|
printf("unknown action=%s\r\n", action.c_str());
|
|
|
|
}
|
2022-09-11 16:18:55 +08:00
|
|
|
|
|
|
|
printf("OVER!\n");
|
|
|
|
|
|
|
|
delete ssl_conf;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|