Add worker montioring to template and worker class
* Add configurable monitoring for workers into template * Store monitoring status in DB First commit for #116
This commit is contained in:
parent
207f59dc80
commit
c69fbe4fc4
@ -43,17 +43,19 @@ class Worker {
|
||||
public function updateWorkers($account_id, $data) {
|
||||
$this->debug->append("STA " . __METHOD__, 4);
|
||||
$username = $this->user->getUserName($account_id);
|
||||
$iFailed = 0;
|
||||
foreach ($data as $key => $value) {
|
||||
// Prefix the WebUser to Worker name
|
||||
$value['username'] = "$username." . $value['username'];
|
||||
$stmt = $this->mysqli->prepare("UPDATE $this->table SET password = ?, username = ? WHERE account_id = ? AND id = ?");
|
||||
if ($this->checkStmt($stmt)) {
|
||||
if (!$stmt->bind_param('ssii', $value['password'], $value['username'], $account_id, $key)) return false;
|
||||
if (!$stmt->execute()) return false;
|
||||
$stmt->close();
|
||||
}
|
||||
$stmt = $this->mysqli->prepare("UPDATE $this->table SET password = ?, username = ?, monitor = ? WHERE account_id = ? AND id = ?");
|
||||
if ( ! ( $this->checkStmt($stmt) && $stmt->bind_param('ssiii', $value['password'], $value['username'], $value['monitor'], $account_id, $key) && $stmt->execute()) )
|
||||
$iFailed++;
|
||||
}
|
||||
return true;
|
||||
if ($iFailed == 0)
|
||||
return true;
|
||||
// Catchall
|
||||
$this->setErrorMessage('Failed to update ' . $iFailed . ' worker.');
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -64,7 +66,7 @@ class Worker {
|
||||
public function getWorkers($account_id) {
|
||||
$this->debug->append("STA " . __METHOD__, 4);
|
||||
$stmt = $this->mysqli->prepare("
|
||||
SELECT id, username, password,
|
||||
SELECT id, username, password, monitor,
|
||||
( SELECT SIGN(COUNT(id)) FROM " . $this->share->getTableName() . " WHERE username = $this->table.username AND time > DATE_SUB(now(), INTERVAL 10 MINUTE)) AS active,
|
||||
( SELECT ROUND(COUNT(id) * POW(2, " . $this->config['difficulty'] . ")/600/1000) FROM " . $this->share->getTableName() . " WHERE username = $this->table.username AND time > DATE_SUB(now(), INTERVAL 10 MINUTE)) AS hashrate
|
||||
FROM $this->table
|
||||
|
||||
@ -10,6 +10,7 @@
|
||||
<td>Worker Name</td>
|
||||
<td>Password</td>
|
||||
<td class="center">Active</td>
|
||||
<td class="center">Monitor</td>
|
||||
<td class="right">Khash/s</td>
|
||||
<td> </td>
|
||||
<td> </td>
|
||||
@ -20,6 +21,7 @@
|
||||
<td{if $WORKERS[worker].active} style="color: orange"{/if}>{$username.0|escape}.<input name="data[{$WORKERS[worker].id}][username]" value="{$username.1|escape}" size="10" /></td>
|
||||
<td><input type="text" name="data[{$WORKERS[worker].id}][password]" value="{$WORKERS[worker].password|escape}" size="10"></td>
|
||||
<td class="center"><img src="{$PATH}/images/{if $WORKERS[worker].active}success{else}error{/if}.gif" /></td>
|
||||
<td class="center"><input type="checkbox" name="data[{$WORKERS[worker].id}][monitor]" value="1" {if $WORKERS[worker].monitor}checked{/if} /></td>
|
||||
<td class="right">{$WORKERS[worker].hashrate|number_format}</td>
|
||||
<td align="right"><a href="{$smarty.server.PHP_SELF}?page={$smarty.request.page|escape}&action={$smarty.request.action|escape}&do=delete&id={$WORKERS[worker].id|escape}"><button style="padding:5px" type="button">Delete</button></a></td>
|
||||
</tr>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user