Browse Source

ckdb/php - add worker diff management

master
kanoi 10 years ago
parent
commit
64db53c390
  1. 14
      pool/db.php
  2. 89
      pool/page_workmgt.php
  3. 5
      pool/prime.php
  4. 154
      src/ckdb.c

14
pool/db.php

@ -188,6 +188,16 @@ function userSettings($user, $email = null, $addr = null, $pass = null)
return repDecode($rep); return repDecode($rep);
} }
# #
function workerSet($user, $settings)
{
$flds = array_merge(array('username' => $user), $settings);
$msg = msgEncode('workerset', 'workerset', $flds, $user);
$rep = sendsockreply('workerSet', $msg);
if (!$rep)
dbdown();
return repDecode($rep);
}
#
function getAllUsers($user) function getAllUsers($user)
{ {
$flds = array(); $flds = array();
@ -198,11 +208,11 @@ function getAllUsers($user)
return repDecode($rep); return repDecode($rep);
} }
# #
function getWorkers($user) function getWorkers($user, $stats = 'Y')
{ {
if ($user == false) if ($user == false)
showIndex(); showIndex();
$flds = array('username' => $user, 'stats' => 'Y'); $flds = array('username' => $user, 'stats' => $stats);
$msg = msgEncode('workers', 'work', $flds, $user); $msg = msgEncode('workers', 'work', $flds, $user);
$rep = sendsockreply('getWorkers', $msg); $rep = sendsockreply('getWorkers', $msg);
if (!$rep) if (!$rep)

89
pool/page_workmgt.php

@ -0,0 +1,89 @@
<?php
#
function workmgtuser($data, $user, $err)
{
$pg = '<h1>Worker Management</h1>';
if ($err != '')
$pg .= "<span class=err>$err<br><br></span>";
$pg .= makeForm('workmgt');
$pg .= "<table callpadding=0 cellspacing=0 border=0>\n";
$pg .= '<tr class=title>';
$pg .= '<td class=dl>Worker Name</td>';
$pg .= '<td class=dr>Minimum Diff</td>';
$pg .= '</tr>';
$ans = getWorkers($user, 'N');
$offset = 0;
if ($ans['STATUS'] == 'ok')
{
$count = $ans['rows'];
for ($i = 0; $i < $count; $i++)
{
if ((($offset) % 2) == 0)
$row = 'even';
else
$row = 'odd';
$pg .= "<tr class=$row>";
$wn = $ans['workername:'.$i];
$pg .= '<td class=dl>';
$pg .= "<input type=hidden name='workername:$i' value='$wn'>";
$pg .= $wn.'</td>';
$md = $ans['difficultydefault:'.$i];
$pg .= '<td class=dr>';
$pg .= "<input type=text size=6 name='difficultydefault:$i' value='$md'>";
$pg .= "<input type=submit name=OK value=OK>";
$pg .= "</td>";
$pg .= "</tr>\n";
$offset++;
}
}
$pg .= "</table><input type=hidden name=rows value=$count></form>\n";
return $pg;
}
#
function doworkmgt($data, $user)
{
$err = '';
$OK = getparam('OK', false);
$count = getparam('rows', false);
if ($OK == 'OK' && !nuem($count))
{
if ($count > 0 && $count < 9999)
{
$settings = array();
for ($i = 0; $i < $count; $i++)
{
$wn = getparam('workername:'.$i, false);
$md = getparam('difficultydefault:'.$i, false);
if (!nuem($wn) && !nuem($md))
{
$settings['workername:'.$i] = $wn;
$settings['difficultydefault:'.$i] = $md;
}
}
$ans = workerSet($user, $settings);
if ($ans['STATUS'] != 'ok')
$err = $ans['ERROR'];
}
}
$pg = workmgtuser($data, $user, $err);
return $pg;
}
#
function show_workmgt($page, $menu, $name, $user)
{
gopage(NULL, 'doworkmgt', $page, $menu, $name, $user);
}
#
?>

5
pool/prime.php

@ -49,11 +49,14 @@ function check()
'Home' => '' 'Home' => ''
), ),
'Account' => array( 'Account' => array(
'Workers' => 'workers',
'Payments' => 'payments', 'Payments' => 'payments',
'Settings' => 'settings', 'Settings' => 'settings',
'User Settings' => 'userset' 'User Settings' => 'userset'
), ),
'Workers' => array(
'Workers ' => 'workers',
'Management' => 'workmgt',
),
'Pool' => array( 'Pool' => array(
'Stats' => 'stats', 'Stats' => 'stats',
'Blocks' => 'blocks' 'Blocks' => 'blocks'

154
src/ckdb.c

@ -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,6 +3840,7 @@ static bool workers_update(PGconn *conn, K_ITEM *item, char *difficultydefault,
DATA_WORKERS(row, item); DATA_WORKERS(row, item);
if (check) {
if (difficultydefault && *difficultydefault) { if (difficultydefault && *difficultydefault) {
diffdef = atoi(difficultydefault); diffdef = atoi(difficultydefault);
if (diffdef < DIFFICULTYDEFAULT_MIN) if (diffdef < DIFFICULTYDEFAULT_MIN)
@ -3860,9 +3867,6 @@ static bool workers_update(PGconn *conn, K_ITEM *item, char *difficultydefault,
} else } else
nottime = row->idlenotificationtime; nottime = row->idlenotificationtime;
HISTORYDATEINIT(row, cd, by, code, inet);
HISTORYDATETRANSFER(trf_root, row);
if (diffdef == row->difficultydefault && if (diffdef == row->difficultydefault &&
idlenot == row->idlenotificationenabled[0] && idlenot == row->idlenotificationenabled[0] &&
nottime == row->idlenotificationtime) { nottime == row->idlenotificationtime) {
@ -3870,6 +3874,15 @@ static bool workers_update(PGconn *conn, K_ITEM *item, char *difficultydefault,
goto early; goto early;
} }
row->difficultydefault = diffdef;
row->idlenotificationenabled[0] = idlenot;
row->idlenotificationenabled[1] = '\0';
row->idlenotificationtime = nottime;
}
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:

Loading…
Cancel
Save