示例#1
0
function processcustompage($pagename, $sections, $sum, $ext, $namemap)
{
    global $sectionmap;
    global $miner, $port;
    global $rigs, $error;
    global $warnfont, $warnoff;
    global $dfmt;
    global $readonly, $showndate;
    $cmds = array();
    $errors = array();
    foreach ($sections as $section => $fields) {
        $all = explode('+', $section);
        foreach ($all as $section) {
            if (isset($sectionmap[$section])) {
                $cmd = $sectionmap[$section];
                if (!isset($cmds[$cmd])) {
                    $cmds[$cmd] = 1;
                }
            } else {
                if ($section != 'DATE') {
                    $errors[] = "Error: unknown section '{$section}' in custom summary page '{$pagename}'";
                }
            }
        }
    }
    $results = array();
    foreach ($rigs as $num => $rig) {
        $parts = explode(':', $rig, 3);
        if (count($parts) >= 1) {
            $miner = $parts[0];
            if (count($parts) >= 2) {
                $port = $parts[1];
            } else {
                $port = '';
            }
            if (count($parts) > 2) {
                $name = $parts[2];
            } else {
                $name = $rig;
            }
            foreach ($cmds as $cmd => $one) {
                $process = api($name, $cmd);
                if ($error != null) {
                    $errors[] = "Error getting {$cmd} for {$name} {$warnfont}{$error}{$warnoff}";
                    break;
                } else {
                    $results[$cmd][$num] = $process;
                }
            }
        } else {
            otherrow('<td class=bad>Bad "$rigs" array</td>');
        }
    }
    // Show API errors at the top
    if (count($errors) > 0) {
        foreach ($errors as $err) {
            otherrow("<td colspan=100>{$err}</td>");
        }
        $errors = array();
    }
    $shownsomething = false;
    if (count($results) > 0) {
        list($results, $errors) = joinsections($sections, $results, $errors);
        $first = true;
        foreach ($sections as $section => $fields) {
            if ($section === 'DATE') {
                if ($shownsomething) {
                    otherrow('<td>&nbsp;</td>');
                }
                newtable();
                showdatetime();
                endtable();
                // On top of the next table
                $shownsomething = false;
                continue;
            }
            if ($section === 'RIGS') {
                if ($shownsomething) {
                    otherrow('<td>&nbsp;</td>');
                }
                newtable();
                showrigs($results['version'], 'Rig', '');
                endtable();
                $shownsomething = true;
                continue;
            }
            if (isset($results[$sectionmap[$section]])) {
                if (isset($ext[$section]['fmt'])) {
                    $cf = $ext[$section]['fmt'];
                } else {
                    $cf = NULL;
                }
                $rigresults = processext($ext, $section, $results[$sectionmap[$section]], $fields);
                $showfields = array();
                $showhead = array();
                foreach ($fields as $field) {
                    foreach ($rigresults as $result) {
                        foreach ($result as $sec => $row) {
                            $secname = preg_replace('/\\d/', '', $sec);
                            if (secmatch($section, $secname)) {
                                if ($field === '*') {
                                    foreach ($row as $f => $v) {
                                        $showfields[$f] = 1;
                                        $map = $section . '.' . $f;
                                        if (isset($namemap[$map])) {
                                            $showhead[$namemap[$map]] = 1;
                                        } else {
                                            $showhead[$f] = 1;
                                        }
                                    }
                                } elseif ($field === '#') {
                                    $showfields[$field] = 1;
                                    $showhead[$field] = 1;
                                } elseif (isset($row[$field])) {
                                    $showfields[$field] = 1;
                                    $map = $section . '.' . $field;
                                    if (isset($namemap[$map])) {
                                        $showhead[$namemap[$map]] = 1;
                                    } else {
                                        $showhead[$field] = 1;
                                    }
                                }
                            }
                        }
                    }
                }
                if (count($showfields) > 0) {
                    if ($shownsomething) {
                        otherrow('<td>&nbsp;</td>');
                    }
                    newtable();
                    if (count($rigresults) == 1 && isset($rigresults[''])) {
                        $ri = array('' => 1) + $showhead;
                    } else {
                        $ri = array('Rig' => 1) + $showhead;
                    }
                    showhead('', $ri, true);
                    $total = array();
                    $add = array('total' => array());
                    foreach ($rigresults as $num => $result) {
                        $total = customset($showfields, $sum, $section, $num, true, $result, $total, $cf);
                    }
                    if (count($total) > 0) {
                        customset($showfields, $sum, $section, '&Sigma;', false, $add, $total, $cf);
                    }
                    $first = false;
                    endtable();
                    $shownsomething = true;
                }
            }
        }
    }
    if (count($errors) > 0) {
        if (count($results) > 0) {
            otherrow('<td>&nbsp;</td>');
        }
        foreach ($errors as $err) {
            otherrow("<td colspan=100>{$err}</td>");
        }
    }
}
示例#2
0
function display()
{
    global $miner, $port;
    global $mcast, $mcastexpect;
    global $readonly, $notify, $rigs;
    global $ignorerefresh, $autorefresh;
    global $allowcustompages, $customsummarypages;
    global $placebuttons;
    global $userlist, $ses;
    $pagesonly = checklogin();
    if ($pagesonly === 'login') {
        return;
    }
    $mcerr = '';
    if ($rigs == null or count($rigs) == 0) {
        if ($mcast === true) {
            $action = 'found';
        } else {
            $action = 'defined';
        }
        minhead();
        otherrow("<td class=bad>No rigs {$action}</td>");
        return;
    } else {
        if ($mcast === true && count($rigs) < $mcastexpect) {
            $mcerr = othrow('<td class=bad>Found ' . count($rigs) . " rigs but expected at least {$mcastexpect}</td>");
        }
    }
    if ($ignorerefresh == false) {
        $ref = trim(getparam('ref', true));
        if ($ref != null && $ref != '') {
            $autorefresh = intval($ref);
        }
    }
    if ($pagesonly !== true) {
        $rig = trim(getparam('rig', true));
        $arg = trim(getparam('arg', true));
        $preprocess = null;
        if ($arg != null and $arg != '') {
            if ($rig != null and $rig != '' and $rig >= 0 and $rig < count($rigs)) {
                $parts = explode(':', $rigs[$rig], 3);
                if (count($parts) >= 2) {
                    $miner = $parts[0];
                    $port = $parts[1];
                    if ($readonly !== true) {
                        $preprocess = $arg;
                    }
                }
            }
        }
    }
    if ($allowcustompages === true) {
        $pg = trim(getparam('pg', true));
        if ($pagesonly === true) {
            if ($pg !== null && $pg !== '') {
                if ($userlist !== null && isset($userlist['def']) && !in_array($pg, $userlist['def'])) {
                    $pg = null;
                }
            } else {
                if ($userlist !== null && isset($userlist['def'])) {
                    foreach ($userlist['def'] as $pglook) {
                        if (isset($customsummarypages[$pglook])) {
                            $pg = $pglook;
                            break;
                        }
                    }
                }
            }
        }
        if ($pg !== null && $pg !== '') {
            htmlhead($mcerr, false, null, $pg);
            showcustompage($pg, $mcerr);
            return;
        }
    }
    if ($pagesonly === true) {
        onlylogin();
        return;
    }
    if (count($rigs) == 1) {
        $parts = explode(':', $rigs[0], 3);
        if (count($parts) >= 2) {
            $miner = $parts[0];
            $port = $parts[1];
            htmlhead($mcerr, true, 0);
            doOne(0, $preprocess);
        } else {
            minhead($mcerr);
            otherrow('<td class=bad>Invalid "$rigs" array</td>');
        }
        return;
    }
    if ($rig != null and $rig != '' and $rig >= 0 and $rig < count($rigs)) {
        $parts = explode(':', $rigs[$rig], 3);
        if (count($parts) >= 2) {
            $miner = $parts[0];
            $port = $parts[1];
            htmlhead($mcerr, true, 0);
            doOne($rig, $preprocess);
        } else {
            minhead($mcerr);
            otherrow('<td class=bad>Invalid "$rigs" array</td>');
        }
        return;
    }
    htmlhead($mcerr, false, null);
    if ($placebuttons == 'top' || $placebuttons == 'both') {
        pagebuttons(null, null);
    }
    if ($preprocess != null) {
        process(array($preprocess => $preprocess), $rig);
    }
    newtable();
    doforeach('version', 'rig summary', array(), array(), true);
    $sum = array('MHS av', 'Getworks', 'Found Blocks', 'Accepted', 'Rejected', 'Discarded', 'Stale', 'Utility', 'Local Work', 'Total MH', 'Work Utility', 'Diff1 Shares', 'Diff1 Work', 'Difficulty Accepted', 'Difficulty Rejected', 'Difficulty Stale');
    doforeach('summary', 'summary information', $sum, array(), false);
    endtable();
    otherrow('<td><br><br></td>');
    newtable();
    doforeach('devs', 'device list', $sum, array('' => '', 'ID' => '', 'Name' => ''), false);
    endtable();
    otherrow('<td><br><br></td>');
    newtable();
    doforeach('pools', 'pool list', $sum, array('' => ''), false);
    endtable();
    if ($placebuttons == 'bot' || $placebuttons == 'both') {
        pagebuttons(null, null);
    }
}
示例#3
0
文件: miner.php 项目: nushor/cgminer
function display()
{
    global $miner, $port;
    global $readonly, $notify, $rigs;
    global $ignorerefresh, $autorefresh;
    global $allowcustompages;
    global $placebuttons;
    if ($ignorerefresh == false) {
        $ref = trim(getparam('ref', true));
        if ($ref != null && $ref != '') {
            $autorefresh = intval($ref);
        }
    }
    $rig = trim(getparam('rig', true));
    $arg = trim(getparam('arg', true));
    $preprocess = null;
    if ($arg != null and $arg != '') {
        $num = null;
        if ($rig != null and $rig != '') {
            if ($rig >= 0 and $rig < count($rigs)) {
                $num = $rig;
            }
        } else {
            if (count($rigs) == 0) {
                $num = 0;
            }
        }
        if ($num != null) {
            $parts = explode(':', $rigs[$num], 3);
            if (count($parts) >= 2) {
                $miner = $parts[0];
                $port = $parts[1];
                $preprocess = $arg;
            }
        }
    }
    if ($rigs == null or count($rigs) == 0) {
        otherrow("<td>No rigs defined</td>");
        return;
    }
    if ($allowcustompages === true) {
        $pg = trim(getparam('pg', true));
        if ($pg != null && $pg != '') {
            showcustompage($pg);
            return;
        }
    }
    if (count($rigs) == 1) {
        $parts = explode(':', $rigs[0], 3);
        if (count($parts) >= 2) {
            $miner = $parts[0];
            $port = $parts[1];
            doOne(0, $preprocess);
        } else {
            otherrow('<td>Invalid "$rigs" array</td>');
        }
        return;
    }
    if ($rig != null and $rig != '' and $rig >= 0 and $rig < count($rigs)) {
        $parts = explode(':', $rigs[$rig], 3);
        if (count($parts) >= 2) {
            $miner = $parts[0];
            $port = $parts[1];
            doOne($rig, $preprocess);
        } else {
            otherrow('<td>Invalid "$rigs" array</td>');
        }
        return;
    }
    htmlhead(false, null);
    if ($placebuttons == 'top' || $placebuttons == 'both') {
        pagebuttons(null, null);
    }
    if ($preprocess != null) {
        process(array($preprocess => $preprocess), $rig);
    }
    newtable();
    doforeach('version', 'rig summary', array(), array(), true);
    $sum = array('MHS av', 'Getworks', 'Found Blocks', 'Accepted', 'Rejected', 'Discarded', 'Stale', 'Utility', 'Local Work', 'Total MH');
    doforeach('summary', 'summary information', $sum, array(), false);
    endtable();
    otherrow('<td><br><br></td>');
    newtable();
    doforeach('devs', 'device list', $sum, array('' => '', 'ID' => '', 'Name' => ''), false);
    endtable();
    otherrow('<td><br><br></td>');
    newtable();
    doforeach('pools', 'pool list', $sum, array('' => ''), false);
    endtable();
    if ($placebuttons == 'bot' || $placebuttons == 'both') {
        pagebuttons(null, null);
    }
}