|
|
@ -49,7 +49,7 @@ |
|
|
|
|
|
|
|
|
|
|
|
#define DB_VLOCK "1" |
|
|
|
#define DB_VLOCK "1" |
|
|
|
#define DB_VERSION "0.9.2" |
|
|
|
#define DB_VERSION "0.9.2" |
|
|
|
#define CKDB_VERSION DB_VERSION"-0.335" |
|
|
|
#define CKDB_VERSION DB_VERSION"-0.336" |
|
|
|
|
|
|
|
|
|
|
|
#define WHERE_FFL " - from %s %s() line %d" |
|
|
|
#define WHERE_FFL " - from %s %s() line %d" |
|
|
|
#define WHERE_FFL_HERE __FILE__, __func__, __LINE__ |
|
|
|
#define WHERE_FFL_HERE __FILE__, __func__, __LINE__ |
|
|
@ -807,6 +807,7 @@ enum cmd_values { |
|
|
|
CMD_NEWPASS, |
|
|
|
CMD_NEWPASS, |
|
|
|
CMD_CHKPASS, |
|
|
|
CMD_CHKPASS, |
|
|
|
CMD_USERSET, |
|
|
|
CMD_USERSET, |
|
|
|
|
|
|
|
CMD_WORKERSET, |
|
|
|
CMD_POOLSTAT, |
|
|
|
CMD_POOLSTAT, |
|
|
|
CMD_USERSTAT, |
|
|
|
CMD_USERSTAT, |
|
|
|
CMD_BLOCK, |
|
|
|
CMD_BLOCK, |
|
|
@ -3814,9 +3815,14 @@ unitem: |
|
|
|
return ret; |
|
|
|
return ret; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* The assumption is that the worker already exists in the DB
|
|
|
|
|
|
|
|
* and in the RAM tables and the item passed is already in the tree |
|
|
|
|
|
|
|
* Since there is no change to the key, there's no tree reorg required |
|
|
|
|
|
|
|
* check = false means just update it, ignore the passed char* vars */ |
|
|
|
static bool workers_update(PGconn *conn, K_ITEM *item, char *difficultydefault, |
|
|
|
static bool workers_update(PGconn *conn, K_ITEM *item, char *difficultydefault, |
|
|
|
char *idlenotificationenabled, char *idlenotificationtime, |
|
|
|
char *idlenotificationenabled, |
|
|
|
char *by, char *code, char *inet, tv_t *cd, K_TREE *trf_root) |
|
|
|
char *idlenotificationtime, char *by, char *code, |
|
|
|
|
|
|
|
char *inet, tv_t *cd, K_TREE *trf_root, bool check) |
|
|
|
{ |
|
|
|
{ |
|
|
|
ExecStatusType rescode; |
|
|
|
ExecStatusType rescode; |
|
|
|
bool conned = false; |
|
|
|
bool conned = false; |
|
|
@ -3834,42 +3840,49 @@ static bool workers_update(PGconn *conn, K_ITEM *item, char *difficultydefault, |
|
|
|
|
|
|
|
|
|
|
|
DATA_WORKERS(row, item); |
|
|
|
DATA_WORKERS(row, item); |
|
|
|
|
|
|
|
|
|
|
|
if (difficultydefault && *difficultydefault) { |
|
|
|
if (check) { |
|
|
|
diffdef = atoi(difficultydefault); |
|
|
|
if (difficultydefault && *difficultydefault) { |
|
|
|
if (diffdef < DIFFICULTYDEFAULT_MIN) |
|
|
|
diffdef = atoi(difficultydefault); |
|
|
|
diffdef = row->difficultydefault; |
|
|
|
if (diffdef < DIFFICULTYDEFAULT_MIN) |
|
|
|
if (diffdef > DIFFICULTYDEFAULT_MAX) |
|
|
|
diffdef = row->difficultydefault; |
|
|
|
|
|
|
|
if (diffdef > DIFFICULTYDEFAULT_MAX) |
|
|
|
|
|
|
|
diffdef = row->difficultydefault; |
|
|
|
|
|
|
|
} else |
|
|
|
diffdef = row->difficultydefault; |
|
|
|
diffdef = row->difficultydefault; |
|
|
|
} else |
|
|
|
|
|
|
|
diffdef = row->difficultydefault; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (idlenotificationenabled && *idlenotificationenabled) { |
|
|
|
|
|
|
|
if (tolower(*idlenotificationenabled) == IDLENOTIFICATIONENABLED[0]) |
|
|
|
|
|
|
|
idlenot = IDLENOTIFICATIONENABLED[0]; |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
idlenot = IDLENOTIFICATIONDISABLED[0]; |
|
|
|
|
|
|
|
} else |
|
|
|
|
|
|
|
idlenot = row->idlenotificationenabled[0]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (idlenotificationtime && *idlenotificationtime) { |
|
|
|
if (idlenotificationenabled && *idlenotificationenabled) { |
|
|
|
nottime = atoi(idlenotificationtime); |
|
|
|
if (tolower(*idlenotificationenabled) == IDLENOTIFICATIONENABLED[0]) |
|
|
|
if (nottime < IDLENOTIFICATIONTIME_MIN) |
|
|
|
idlenot = IDLENOTIFICATIONENABLED[0]; |
|
|
|
nottime = row->idlenotificationtime; |
|
|
|
else |
|
|
|
if (nottime > IDLENOTIFICATIONTIME_MAX) |
|
|
|
idlenot = IDLENOTIFICATIONDISABLED[0]; |
|
|
|
|
|
|
|
} else |
|
|
|
|
|
|
|
idlenot = row->idlenotificationenabled[0]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (idlenotificationtime && *idlenotificationtime) { |
|
|
|
|
|
|
|
nottime = atoi(idlenotificationtime); |
|
|
|
|
|
|
|
if (nottime < IDLENOTIFICATIONTIME_MIN) |
|
|
|
|
|
|
|
nottime = row->idlenotificationtime; |
|
|
|
|
|
|
|
if (nottime > IDLENOTIFICATIONTIME_MAX) |
|
|
|
|
|
|
|
nottime = row->idlenotificationtime; |
|
|
|
|
|
|
|
} else |
|
|
|
nottime = row->idlenotificationtime; |
|
|
|
nottime = row->idlenotificationtime; |
|
|
|
} else |
|
|
|
|
|
|
|
nottime = row->idlenotificationtime; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
HISTORYDATEINIT(row, cd, by, code, inet); |
|
|
|
if (diffdef == row->difficultydefault && |
|
|
|
HISTORYDATETRANSFER(trf_root, row); |
|
|
|
idlenot == row->idlenotificationenabled[0] && |
|
|
|
|
|
|
|
nottime == row->idlenotificationtime) { |
|
|
|
|
|
|
|
ok = true; |
|
|
|
|
|
|
|
goto early; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (diffdef == row->difficultydefault && |
|
|
|
row->difficultydefault = diffdef; |
|
|
|
idlenot == row->idlenotificationenabled[0] && |
|
|
|
row->idlenotificationenabled[0] = idlenot; |
|
|
|
nottime == row->idlenotificationtime) { |
|
|
|
row->idlenotificationenabled[1] = '\0'; |
|
|
|
ok = true; |
|
|
|
row->idlenotificationtime = nottime; |
|
|
|
goto early; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
HISTORYDATEINIT(row, cd, by, code, inet); |
|
|
|
|
|
|
|
HISTORYDATETRANSFER(trf_root, row); |
|
|
|
|
|
|
|
|
|
|
|
upd = "update workers set expirydate=$1 where workerid=$2 and expirydate=$3"; |
|
|
|
upd = "update workers set expirydate=$1 where workerid=$2 and expirydate=$3"; |
|
|
|
par = 0; |
|
|
|
par = 0; |
|
|
|
params[par++] = tv_to_buf(cd, NULL, 0); |
|
|
|
params[par++] = tv_to_buf(cd, NULL, 0); |
|
|
@ -3906,11 +3919,6 @@ static bool workers_update(PGconn *conn, K_ITEM *item, char *difficultydefault, |
|
|
|
"idlenotificationenabled,idlenotificationtime" |
|
|
|
"idlenotificationenabled,idlenotificationtime" |
|
|
|
HISTORYDATECONTROL ") values (" PQPARAM11 ")"; |
|
|
|
HISTORYDATECONTROL ") values (" PQPARAM11 ")"; |
|
|
|
|
|
|
|
|
|
|
|
row->difficultydefault = diffdef; |
|
|
|
|
|
|
|
row->idlenotificationenabled[0] = idlenot; |
|
|
|
|
|
|
|
row->idlenotificationenabled[1] = '\0'; |
|
|
|
|
|
|
|
row->idlenotificationtime = nottime; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
par = 0; |
|
|
|
par = 0; |
|
|
|
params[par++] = bigint_to_buf(row->workerid, NULL, 0); |
|
|
|
params[par++] = bigint_to_buf(row->workerid, NULL, 0); |
|
|
|
params[par++] = bigint_to_buf(row->userid, NULL, 0); |
|
|
|
params[par++] = bigint_to_buf(row->userid, NULL, 0); |
|
|
@ -3958,7 +3966,7 @@ static K_ITEM *new_worker(PGconn *conn, bool update, int64_t userid, char *worke |
|
|
|
if (!confirm_sharesummary && update) { |
|
|
|
if (!confirm_sharesummary && update) { |
|
|
|
workers_update(conn, item, diffdef, idlenotificationenabled, |
|
|
|
workers_update(conn, item, diffdef, idlenotificationenabled, |
|
|
|
idlenotificationtime, by, code, inet, cd, |
|
|
|
idlenotificationtime, by, code, inet, cd, |
|
|
|
trf_root); |
|
|
|
trf_root, true); |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
if (confirm_sharesummary) { |
|
|
|
if (confirm_sharesummary) { |
|
|
@ -9200,6 +9208,118 @@ struckout: |
|
|
|
return strdup(reply); |
|
|
|
return strdup(reply); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static char *cmd_workerset(PGconn *conn, char *cmd, char *id, tv_t *now, |
|
|
|
|
|
|
|
char *by, char *code, char *inet, |
|
|
|
|
|
|
|
__maybe_unused tv_t *notcd, K_TREE *trf_root) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
K_ITEM *i_username, *i_workername, *i_diffdef, *u_item, *w_item; |
|
|
|
|
|
|
|
char workername_buf[32]; // 'workername:' + digits
|
|
|
|
|
|
|
|
char diffdef_buf[32]; // 'difficultydefault:' + digits
|
|
|
|
|
|
|
|
char reply[1024] = ""; |
|
|
|
|
|
|
|
size_t siz = sizeof(reply); |
|
|
|
|
|
|
|
WORKERS *workers; |
|
|
|
|
|
|
|
USERS *users; |
|
|
|
|
|
|
|
int32_t difficultydefault; |
|
|
|
|
|
|
|
char *reason = NULL; |
|
|
|
|
|
|
|
char *answer = NULL; |
|
|
|
|
|
|
|
int workernum; |
|
|
|
|
|
|
|
bool ok; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LOGDEBUG("%s(): cmd '%s'", __func__, cmd); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
i_username = require_name(trf_root, "username", 3, (char *)userpatt, reply, siz); |
|
|
|
|
|
|
|
if (!i_username) { |
|
|
|
|
|
|
|
// For web this message is detailed enough
|
|
|
|
|
|
|
|
reason = "System error"; |
|
|
|
|
|
|
|
goto struckout; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
K_RLOCK(users_free); |
|
|
|
|
|
|
|
u_item = find_users(transfer_data(i_username)); |
|
|
|
|
|
|
|
K_RUNLOCK(users_free); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!u_item) { |
|
|
|
|
|
|
|
reason = "Unknown user"; |
|
|
|
|
|
|
|
goto struckout; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
DATA_USERS(users, u_item); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Default answer if no problems
|
|
|
|
|
|
|
|
answer = strdup("updated"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Loop through the list of workers and do any changes
|
|
|
|
|
|
|
|
for (workernum = 0; workernum < 9999; workernum++) { |
|
|
|
|
|
|
|
snprintf(workername_buf, sizeof(workername_buf), |
|
|
|
|
|
|
|
"workername:%d", workernum); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
i_workername = optional_name(trf_root, workername_buf, |
|
|
|
|
|
|
|
1, NULL, reply, siz); |
|
|
|
|
|
|
|
if (!i_workername) |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
w_item = find_workers(users->userid, |
|
|
|
|
|
|
|
transfer_data(i_workername)); |
|
|
|
|
|
|
|
// Abort if any dont exist
|
|
|
|
|
|
|
|
if (!w_item) { |
|
|
|
|
|
|
|
reason = "Unknown worker"; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DATA_WORKERS(workers, w_item); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
snprintf(diffdef_buf, sizeof(diffdef_buf), |
|
|
|
|
|
|
|
"difficultydefault:%d", workernum); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
i_diffdef = optional_name(trf_root, diffdef_buf, |
|
|
|
|
|
|
|
1, (char *)intpatt, |
|
|
|
|
|
|
|
reply, siz); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Abort if any are invalid
|
|
|
|
|
|
|
|
if (*reply) { |
|
|
|
|
|
|
|
reason = "Invalid diff"; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!i_diffdef) |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
difficultydefault = atoi(transfer_data(i_diffdef)); |
|
|
|
|
|
|
|
if (difficultydefault < DIFFICULTYDEFAULT_MIN) |
|
|
|
|
|
|
|
difficultydefault = DIFFICULTYDEFAULT_MIN; |
|
|
|
|
|
|
|
if (difficultydefault > DIFFICULTYDEFAULT_MAX) |
|
|
|
|
|
|
|
difficultydefault = DIFFICULTYDEFAULT_MAX; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (workers->difficultydefault != difficultydefault) { |
|
|
|
|
|
|
|
/* This uses a seperate txn per update
|
|
|
|
|
|
|
|
thus will update all up to a failure |
|
|
|
|
|
|
|
Since the web then re-gets the values, |
|
|
|
|
|
|
|
it will show what was updated */ |
|
|
|
|
|
|
|
workers->difficultydefault = difficultydefault; |
|
|
|
|
|
|
|
ok = workers_update(conn, w_item, NULL, NULL, |
|
|
|
|
|
|
|
NULL, by, code, inet, |
|
|
|
|
|
|
|
now, trf_root, false); |
|
|
|
|
|
|
|
if (!ok) { |
|
|
|
|
|
|
|
reason = "DB error"; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struckout: |
|
|
|
|
|
|
|
if (reason) { |
|
|
|
|
|
|
|
if (answer) |
|
|
|
|
|
|
|
free(answer); |
|
|
|
|
|
|
|
snprintf(reply, siz, "ERR.%s", reason); |
|
|
|
|
|
|
|
LOGERR("%s.%s.%s", cmd, id, reply); |
|
|
|
|
|
|
|
return strdup(reply); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
snprintf(reply, siz, "ok.%s", answer); |
|
|
|
|
|
|
|
LOGDEBUG("%s.%s", id, answer); |
|
|
|
|
|
|
|
free(answer); |
|
|
|
|
|
|
|
return strdup(reply); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static char *cmd_poolstats_do(PGconn *conn, char *cmd, char *id, char *by, |
|
|
|
static char *cmd_poolstats_do(PGconn *conn, char *cmd, char *id, char *by, |
|
|
|
char *code, char *inet, tv_t *cd, bool igndup, |
|
|
|
char *code, char *inet, tv_t *cd, bool igndup, |
|
|
|
K_TREE *trf_root) |
|
|
|
K_TREE *trf_root) |
|
|
@ -12170,6 +12290,7 @@ static struct CMDS { |
|
|
|
{ CMD_NEWPASS, "newpass", false, false, cmd_newpass, ACCESS_WEB }, |
|
|
|
{ CMD_NEWPASS, "newpass", false, false, cmd_newpass, ACCESS_WEB }, |
|
|
|
{ CMD_CHKPASS, "chkpass", false, false, cmd_chkpass, ACCESS_WEB }, |
|
|
|
{ CMD_CHKPASS, "chkpass", false, false, cmd_chkpass, ACCESS_WEB }, |
|
|
|
{ CMD_USERSET, "usersettings", false, false, cmd_userset, ACCESS_WEB }, |
|
|
|
{ CMD_USERSET, "usersettings", false, false, cmd_userset, ACCESS_WEB }, |
|
|
|
|
|
|
|
{ CMD_WORKERSET,"workerset", false, false, cmd_workerset, ACCESS_WEB }, |
|
|
|
{ CMD_POOLSTAT, "poolstats", false, true, cmd_poolstats, ACCESS_POOL }, |
|
|
|
{ CMD_POOLSTAT, "poolstats", false, true, cmd_poolstats, ACCESS_POOL }, |
|
|
|
{ CMD_USERSTAT, "userstats", false, true, cmd_userstats, ACCESS_POOL }, |
|
|
|
{ CMD_USERSTAT, "userstats", false, true, cmd_userstats, ACCESS_POOL }, |
|
|
|
{ CMD_BLOCK, "block", false, true, cmd_blocks, ACCESS_POOL }, |
|
|
|
{ CMD_BLOCK, "block", false, true, cmd_blocks, ACCESS_POOL }, |
|
|
@ -12852,6 +12973,7 @@ static void *socketer(__maybe_unused void *arg) |
|
|
|
char *last_adduser = NULL, *reply_adduser = NULL; |
|
|
|
char *last_adduser = NULL, *reply_adduser = NULL; |
|
|
|
char *last_newpass = NULL, *reply_newpass = NULL; |
|
|
|
char *last_newpass = NULL, *reply_newpass = NULL; |
|
|
|
char *last_userset = NULL, *reply_userset = NULL; |
|
|
|
char *last_userset = NULL, *reply_userset = NULL; |
|
|
|
|
|
|
|
char *last_workerset = NULL, *reply_workerset = NULL; |
|
|
|
char *last_newid = NULL, *reply_newid = NULL; |
|
|
|
char *last_newid = NULL, *reply_newid = NULL; |
|
|
|
char *last_setatts = NULL, *reply_setatts = NULL; |
|
|
|
char *last_setatts = NULL, *reply_setatts = NULL; |
|
|
|
char *last_setopts = NULL, *reply_setopts = NULL; |
|
|
|
char *last_setopts = NULL, *reply_setopts = NULL; |
|
|
@ -12947,6 +13069,9 @@ static void *socketer(__maybe_unused void *arg) |
|
|
|
} else if (last_userset && strcmp(last_userset, buf) == 0) { |
|
|
|
} else if (last_userset && strcmp(last_userset, buf) == 0) { |
|
|
|
reply_last = reply_userset; |
|
|
|
reply_last = reply_userset; |
|
|
|
dup = true; |
|
|
|
dup = true; |
|
|
|
|
|
|
|
} else if (last_workerset && strcmp(last_workerset, buf) == 0) { |
|
|
|
|
|
|
|
reply_last = reply_workerset; |
|
|
|
|
|
|
|
dup = true; |
|
|
|
} else if (last_setatts && strcmp(last_setatts, buf) == 0) { |
|
|
|
} else if (last_setatts && strcmp(last_setatts, buf) == 0) { |
|
|
|
reply_last = reply_setatts; |
|
|
|
reply_last = reply_setatts; |
|
|
|
dup = true; |
|
|
|
dup = true; |
|
|
@ -13044,6 +13169,7 @@ static void *socketer(__maybe_unused void *arg) |
|
|
|
case CMD_ADDUSER: |
|
|
|
case CMD_ADDUSER: |
|
|
|
case CMD_NEWPASS: |
|
|
|
case CMD_NEWPASS: |
|
|
|
case CMD_USERSET: |
|
|
|
case CMD_USERSET: |
|
|
|
|
|
|
|
case CMD_WORKERSET: |
|
|
|
case CMD_GETATTS: |
|
|
|
case CMD_GETATTS: |
|
|
|
case CMD_SETATTS: |
|
|
|
case CMD_SETATTS: |
|
|
|
case CMD_EXPATTS: |
|
|
|
case CMD_EXPATTS: |
|
|
@ -13082,6 +13208,9 @@ static void *socketer(__maybe_unused void *arg) |
|
|
|
case CMD_USERSET: |
|
|
|
case CMD_USERSET: |
|
|
|
STORELASTREPLY(userset); |
|
|
|
STORELASTREPLY(userset); |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
case CMD_WORKERSET: |
|
|
|
|
|
|
|
STORELASTREPLY(workerset); |
|
|
|
|
|
|
|
break; |
|
|
|
case CMD_NEWID: |
|
|
|
case CMD_NEWID: |
|
|
|
STORELASTREPLY(newid); |
|
|
|
STORELASTREPLY(newid); |
|
|
|
break; |
|
|
|
break; |
|
|
@ -13279,6 +13408,7 @@ static bool reload_line(PGconn *conn, char *filename, uint64_t count, char *buf) |
|
|
|
case CMD_NEWPASS: |
|
|
|
case CMD_NEWPASS: |
|
|
|
case CMD_CHKPASS: |
|
|
|
case CMD_CHKPASS: |
|
|
|
case CMD_USERSET: |
|
|
|
case CMD_USERSET: |
|
|
|
|
|
|
|
case CMD_WORKERSET: |
|
|
|
case CMD_BLOCKLIST: |
|
|
|
case CMD_BLOCKLIST: |
|
|
|
case CMD_BLOCKSTATUS: |
|
|
|
case CMD_BLOCKSTATUS: |
|
|
|
case CMD_NEWID: |
|
|
|
case CMD_NEWID: |
|
|
|