Ejemplo n.º 1
1
 /** @return object */
 public static function getSwarmUAIndex()
 {
     // Lazy-init and cache
     if (self::$swarmUaIndex === null) {
         global $swarmInstallDir;
         // Convert from array with string values
         // to an object with boolean values
         $swarmUaIndex = new stdClass();
         $rawIndex = parse_ini_file("{$swarmInstallDir}/config/useragents.ini", true);
         foreach ($rawIndex as $uaID => $uaItem) {
             if (is_array($uaItem)) {
                 $uaItem2 = $uaItem;
                 foreach ($uaItem2 as $uaDataKey => $uaDataVal) {
                     if ($uaDataKey !== "displaytitle" && $uaDataKey !== "displayicon") {
                         $uaItem[$uaDataKey] = (bool) trim($uaDataVal);
                     } else {
                         $uaItem[$uaDataKey] = trim($uaDataVal);
                     }
                 }
                 if (!isset($uaItem["displaytitle"]) || !$uaItem["displaytitle"]) {
                     throw new SwarmException("User agent `{$uaID}` is missing a displaytitle property.");
                 }
                 if (!isset($uaItem["displayicon"]) || !$uaItem["displayicon"]) {
                     throw new SwarmException("User agent `{$uaID}` is missing a displayicon property.");
                 }
                 $swarmUaIndex->{$uaID} = (object) $uaItem;
             }
         }
         self::$swarmUaIndex = $swarmUaIndex;
     }
     return self::$swarmUaIndex;
 }
Ejemplo n.º 2
1
function makeLoginPage($user = false)
{
    // We need global Variables.
    global $VERSION;
    global $SITENAME;
    global $IGB;
    global $IS_DEMO;
    global $IS_BETA;
    global $DB;
    global $IGB_VISUAL;
    if ($IGB && $IGB_VISUAL) {
        $login = new table(3, true);
    } else {
        $login = new table(3, true, "width=\"400\"", "align=\"center\"");
    }
    $peeps = $DB->getCol("SELECT COUNT(id) FROM users");
    if ($peeps[0] == 0) {
        header("Location: index.php?auth=requestaccount&admin=true");
    }
    $login->addHeader(">> Welcome to {$VERSION}.");
    $login->addRow("#060622");
    $login->addCol($SITENAME, array("colspan" => 3, "align" => "center", "bold" => true));
    if ($user) {
        if ($user == "__invalidchar") {
            $login->addRow("redish");
            $login->addCol("Only characters a-z, A-Z and 0-9 are allowed. " . array("bold" => "true", "colspan" => 3));
        } else {
            if (isset($_SESSION['testauth'])) {
                $login->addRow();
                $login->addCol("Please select the character you wish to login as.", array("colspan" => 3));
            } else {
                $login->addRow("redish");
                $login->addCol("Your supplied credentials are invalid, please check and try again. " . "If you cannot remember your password use the Password Recovery link below.", array("bold" => "true", "colspan" => 3));
            }
        }
    }
    // Show login info for demo.
    if ($IS_DEMO) {
        $login->addRow("#006600");
        $login->addCol("This installation of MiningBuddy runs in demo mode. Login with username demo, password demo. If you get kicked out, someone else logged in with the same account.", array("colspan" => 3, "align" => "center", "bold" => true));
    }
    global $BLESSED;
    if ($BLESSED == true) {
        $login->addRow("#330000");
        $login->addCol("Using a superior hosted slot.", array("colspan" => 3, "align" => "center", "bold" => true));
    }
    // Beta Warning
    if ($IS_BETA) {
        $login->addRow("#904000");
        $login->addCol("-beta version-", array("colspan" => 3, "align" => "center", "bold" => true));
    }
    // User has logged in, but we need a character name.
    if (!isset($_SESSION[testauth])) {
        $login->addRow();
        $login->addCol("Username:"******"<input type=\"text\" name=\"username\" value=\"{$EVE_Charname}\" maxlength=\"30\">");
        } else {
            $login->addCol("<input type=\"text\" name=\"username\" value=\"" . stripcslashes($user) . "\" maxlength=\"30\">");
        }
        $login->addCol("<img src=\"./images/keys.png\">", array("rowspan" => "2"));
        $login->addRow();
        $login->addCol("Password:"******"<input type=\"password\" name=\"password\" maxlength=\"80\">", array("colspan" => "2"));
        $login->addRow("#060622");
        $login->addCol("Please login with your credentials. If you are in need of an account, request an account below and ask your CEO to activate it for you.", array("colspan" => "3", "align" => "center"));
    } else {
        $login->addRow();
        $login->addCol("Character:");
        global $TEST_AUTH;
        $eveApiProxyUrl = "https://auth.pleaseignore.com/api/1.0/eveapi/?apikey={$TEST_AUTH}&userid=" . $_SESSION[testauth][id];
        $return = file_get_contents($eveApiProxyUrl);
        $obj = json_decode($return, TRUE);
        $count = 0;
        $select = "<select name=\"username\" >";
        $array = array();
        foreach ($obj[keys] as $key) {
            $eveApiProxyUrl = "https://auth.pleaseignore.com/api/1.0/eveapi/account/Characters.xml.aspx?apikey={$TEST_AUTH}&userid=" . $key[api_user_id];
            $return = file_get_contents($eveApiProxyUrl);
            try {
                $chars = new SimpleXMLElement($return);
            } catch (Exception $ex) {
                continue;
            }
            foreach ($chars->result[0]->rowset[0] as $row) {
                $character = (string) $row[name];
                if ($row['corporationName'] != "B0rthole" || in_array($character, $array)) {
                    continue;
                }
                if ($character == $user) {
                    $selected = "selected";
                }
                $select .= "<option {$selected} value='{$character}'>{$character}</option>";
                $array[] = $character;
                $count++;
            }
        }
        //var_dump($array);
        $select .= "</select>";
        $login->addCol($select, array("colspan" => "2"));
        if ($count == 0) {
            session_destroy();
            makenotice("You do not belong here. Leave at once!", "warning", "ACCESS DENIED");
            die;
        }
        //file_put_contents($_SESSION[testauth][id].".xml",print_r($list,true));
    }
    if ($IGB && $IGB_VISUAL) {
        $login->addHeaderCentered("<input type=\"submit\" name=\"login\" value=\"login\">");
    } else {
        $login->addHeaderCentered("<input type=\"image\" name=\"login\" value=\"login\" src=\"./images/login.png\">");
    }
    $login->addRow("#060622");
    $login->addCol("<a href=\"index.php?auth=lostpass\">lost password</a>");
    /*
    $login->addCol("<a href=\"index.php?auth=requestaccount\">request account</a>", array (
    	"align" => "right",
    	"colspan" => "2"
    ));
    */
    $login->addCol("", array("colspan" => "2"));
    $page = "<br><br><br>";
    if (strstr($_SERVER[QUERY_STRING], "switch")) {
        $page .= "<form action=\"index.php?\" method=\"post\">";
    } else {
        $page .= "<form action=\"index.php?{$_SERVER['QUERY_STRING']}\" method=\"post\">";
    }
    // Add special hidden forms for stupid browsers.
    $browserinfo = new BrowserInfo();
    if (ereg("MSIE", $_SERVER[HTTP_USER_AGENT]) or $browserinfo->getBrowser() == BrowserInfo::BROWSER_FIREFOX && $browserinfo->getVersion() >= 4) {
        $page .= "<input type=\"hidden\" name=\"login\" value=\"login\">";
    }
    $page .= $login->flush();
    //$page .= "<input type='hidden' name='redirect' value='$_SERVER[QUERY_STRING]'";
    $page .= "</form><br><br><br>";
    $html = new html();
    $html->addBody($page);
    die($html->flush());
}
Ejemplo n.º 3
0
 protected function initContent()
 {
     $this->setTitle('Client');
     $error = $this->getAction()->getError();
     $data = $this->getAction()->getData();
     $html = '';
     if ($error) {
         $html .= html_tag('div', array('class' => 'alert alert-error'), $error['info']);
     }
     if (!isset($data['info'])) {
         return $html;
     }
     $info = $data['info'];
     $displayInfo = $info['uaData']['displayInfo'];
     $this->setSubTitle('#' . $info['id']);
     $html .= '<h3>Information</h3>' . '<div class="row">' . '<div class="span2">' . BrowserInfo::buildIconHtml($displayInfo) . '</div>' . '<div class="span10">' . '<table class="table table-striped">' . '<tbody>' . '<tr><th>Name</th><td>' . html_tag('a', array('href' => $info['viewUrl']), $info['name']) . '</td></tr>' . '<tr><th>UA ID</th><td>' . '<code>' . htmlspecialchars($info['uaID']) . '</code>' . '<tr><th>User-Agent</th><td>' . '<tt>' . htmlspecialchars($info['uaRaw']) . '</tt>' . '</td></tr>' . '<tr><th>Session age</th><td>' . number_format(intval($info['sessionAge'])) . 's' . '</td></tr>' . '<tr><th>Connected</th><td>' . self::getPrettyDateHtml($info, 'connected') . '</td></tr>' . '<tr><th>Last ping</th><td>' . self::getPrettyDateHtml($info, 'pinged') . '</td></tr>' . '</tbody></table>' . '</div>' . '</div>';
     $html .= '<h3>Log</h3>';
     if (!$data['results']) {
         $html .= '<div class="alert alert-info">Client has no run log.</div>';
     } else {
         $html .= '<table class="table table-striped">' . '<thead><tr><th>Result</th><th>Project</th></th><th>Run</th><th>Status</th>' . '<tbody>';
         foreach ($data['results'] as $run) {
             $html .= '<tr>' . '<td>' . html_tag('a', array('href' => $run['viewUrl']), '#' . $run['id']) . '</td>' . '<td>' . ($run['project'] ? html_tag('a', array('href' => $run['project']['viewUrl']), $run['project']['display_title']) : '-') . '</td>' . '<td>' . ($run['job'] && $run['run'] ? html_tag('a', array('href' => $run['job']['viewUrl']), $run['job']['nameText'] . ' / ' . $run['run']['name']) : '<em>Job has been deleted</em>') . '</td>' . JobPage::getJobStatusHtmlCell($run['status']) . '</tr>';
         }
         $html .= '</tbody></table>';
     }
     return $html;
 }
Ejemplo n.º 4
0
    /**
     * @param string|bool $name
     */
    protected function getActiveClients($name = false)
    {
        $context = $this->getContext();
        $db = $context->getDB();
        $nameQuery = $name ? 'AND name = \'' . $db->strEncode($name) . '\'' : '';
        $results = array();
        $rows = $db->getRows(str_queryf("SELECT\n\t\t\t\tid,\n\t\t\t\tname,\n\t\t\t\tuseragent,\n\t\t\t\tupdated,\n\t\t\t\tcreated\n\t\t\tFROM\n\t\t\t\tclients\n\t\t\tWHERE updated >= %s\n\t\t\t{$nameQuery}\n\t\t\tORDER BY created DESC;", swarmdb_dateformat(Client::getMaxAge($context))));
        if ($rows) {
            foreach ($rows as $row) {
                $bi = BrowserInfo::newFromContext($this->getContext(), $row->useragent);
                $resultRow = $db->getRow(str_queryf('SELECT
						id,
						run_id,
						client_id,
						status,
						total,
						fail,
						error,
						updated,
						created
					FROM runresults
					WHERE client_id = %u
					ORDER BY created DESC
					LIMIT 1;', $row->id));
                $client = array('id' => $row->id, 'name' => $row->name, 'uaID' => $bi->getSwarmUaID(), 'uaRaw' => $bi->getRawUA(), 'uaData' => $bi->getUaData(), 'viewUrl' => swarmpath("client/{$row->id}"), 'lastResult' => !$resultRow ? null : array('id' => intval($resultRow->id), 'viewUrl' => swarmpath("result/{$resultRow->id}"), 'status' => JobAction::getRunresultsStatus($resultRow)));
                self::addTimestampsTo($client, $row->created, 'connected');
                self::addTimestampsTo($client, $row->updated, 'pinged');
                $results[$row->id] = $client;
            }
        }
        return $results;
    }
Ejemplo n.º 5
0
 /**
  * @requestParam browserSet string: Show useragents from a specific
  * browserset only.
  * @requestParam onlyactive bool: If true, only user agents that
  * have online clients and/or pending runs are included.
  * If both "browserSet" and "onlyactive" are used, the overlaping
  * subset will be output.
  */
 public function doAction()
 {
     $conf = $this->getContext()->getConf();
     $db = $this->getContext()->getDB();
     $request = $this->getContext()->getRequest();
     $showOnlyactive = $request->hasKey("onlyactive");
     $filterBrowserSet = $request->getVal("browserSet", false);
     $data = array("userAgents" => array());
     $uaIndex = BrowserInfo::getSwarmUAIndex();
     foreach ($uaIndex as $uaID => $uaData) {
         if ($filterBrowserSet && isset($conf->browserSets->{$filterBrowserSet}) && !in_array($uaID, $conf->browserSets->{$filterBrowserSet})) {
             continue;
         }
         // Count online clients with this UA
         $clients = $db->getOne(str_queryf("SELECT\n\t\t\t\t\tCOUNT(id)\n\t\t\t\tFROM clients\n\t\t\t\tWHERE useragent_id = %s\n\t\t\t\tAND   updated > %s", $uaID, swarmdb_dateformat(strtotime('1 minute ago'))));
         $clients = intval($clients);
         // Count pending runs for this UA
         $pendingRuns = $db->getOne(str_queryf("SELECT\n\t\t\t\t\tCOUNT(*)\n\t\t\t\tFROM run_useragent\n\t\t\t\tWHERE useragent_id = %s\n\t\t\t\tAND   status = 0;", $uaID));
         $pendingRuns = intval($pendingRuns);
         // Count past runs that can still be re-run to
         // possibly fix non-passing results
         $pendingReRuns = $db->getOne(str_queryf("SELECT\n\t\t\t\t\tCOUNT(*)\n\t\t\t\tFROM run_useragent\n\t\t\t\tWHERE useragent_id = %s\n\t\t\t\tAND   runs < max\n\t\t\t\tAND   completed > 0;", $uaID));
         $pendingReRuns = intval($pendingReRuns);
         if ($showOnlyactive && !$clients && !$pendingRuns && !$pendingReRuns) {
             continue;
         }
         $data["userAgents"][$uaID] = array("data" => $uaData, "stats" => array("onlineClients" => $clients, "pendingRuns" => $pendingRuns, "pendingReRuns" => $pendingReRuns));
     }
     $this->setData($data);
 }
Ejemplo n.º 6
0
 public function getBrowserInfo()
 {
     if ($this->browserInfo === null) {
         $ua = isset($_SERVER["HTTP_USER_AGENT"]) ? $_SERVER["HTTP_USER_AGENT"] : "";
         $this->browserInfo = BrowserInfo::newFromContext($this, $ua);
     }
     return $this->browserInfo;
 }
Ejemplo n.º 7
0
 public function executeRequest()
 {
     $this->initializeDatabase();
     Session::init();
     Flash::__load_from_session();
     BrowserInfo::fetch();
     RouteMap::init();
     //sanitize environment
     $this->renderResult();
     Flash::__save_to_session();
     Session::save();
     $this->disposeDatabase();
 }
Ejemplo n.º 8
0
    /**
     * @requestParam browserSet string: Show useragents from a specific
     * browserset only.
     * @requestParam onlyactive bool: If true, only user agents that
     * have online clients and/or pending runs are included.
     * If both "browserSet" and "onlyactive" are used, the overlaping
     * subset will be output.
     */
    public function doAction()
    {
        $conf = $this->getContext()->getConf();
        $db = $this->getContext()->getDB();
        $request = $this->getContext()->getRequest();
        $showOnlyactive = $request->getBool('onlyactive');
        $filterBrowserSet = $request->getVal('browserSet', false);
        $data = array('userAgents' => array());
        $uaIndex = BrowserInfo::getSwarmUAIndex();
        foreach ($uaIndex as $uaID => $uaData) {
            if ($filterBrowserSet && isset($conf->browserSets->{$filterBrowserSet}) && !in_array($uaID, $conf->browserSets->{$filterBrowserSet})) {
                continue;
            }
            // Count online clients with this UA
            $clients = $db->getOne(str_queryf('SELECT
					COUNT(id)
				FROM clients
				WHERE useragent_id = %s
				AND   updated > %s', $uaID, swarmdb_dateformat(time() - ($conf->client->pingTime + $conf->client->pingTimeMargin))));
            $clients = intval($clients);
            // Count active runs for this UA
            $activeRuns = $db->getOne(str_queryf('SELECT
					COUNT(*)
				FROM run_useragent
				WHERE useragent_id = %s
				AND   status = 1;', $uaID));
            $activeRuns = intval($activeRuns);
            // Count pending runs for this UA
            $pendingRuns = $db->getOne(str_queryf('SELECT
					COUNT(*)
				FROM run_useragent
				WHERE useragent_id = %s
				AND   status = 0
				AND   completed = 0;', $uaID));
            $pendingRuns = intval($pendingRuns);
            // Count past runs that can still be re-run to
            // possibly fix non-passing results
            $pendingReRuns = $db->getOne(str_queryf('SELECT
					COUNT(*)
				FROM run_useragent
				WHERE useragent_id = %s
				AND   status = 0
				AND   completed > 0;', $uaID));
            $pendingReRuns = intval($pendingReRuns);
            if ($showOnlyactive && !$clients && !$activeRuns && !$pendingRuns && !$pendingReRuns) {
                continue;
            }
            $data['userAgents'][$uaID] = array('data' => $uaData, 'stats' => array('onlineClients' => $clients, 'activeRuns' => $activeRuns, 'pendingRuns' => $pendingRuns, 'pendingReRuns' => $pendingReRuns));
        }
        $this->setData($data);
    }
Ejemplo n.º 9
0
 protected function execute()
 {
     $conf = $this->getContext()->getConf();
     $browserIndex = BrowserInfo::getBrowserIndex();
     // Output
     $set = $this->getOption('set');
     if ($set) {
         if (isset($conf->browserSets->{$set})) {
             $this->out("{$set}:\n* " . implode("\n* ", $conf->browserSets->{$set}));
         } else {
             $this->error("Browser set `{$set}` does not exist.");
         }
     } else {
         foreach ($conf->browserSets as $set => $browsers) {
             $this->out("\n{$set}:\n* " . implode("\n* ", $browsers));
         }
         $this->out("\n(everything):\n* " . implode("\n* ", array_keys((array) $browserIndex)));
     }
 }
Ejemplo n.º 10
0
 /** @return object */
 public static function getBrowserIndex()
 {
     // Lazy-init and cache
     if (self::$browserIndex === null) {
         global $swarmInstallDir, $swarmContext;
         // Convert from array with string values
         // to an object with boolean values
         $browserIndex = new stdClass();
         $userAgents = $swarmContext->getConf()->userAgents;
         foreach ($userAgents as $uaID => $uaData) {
             $keys = array_keys(get_object_vars($swarmContext->getBrowserInfo()->getUaData()));
             $data = new stdClass();
             // Filter out unwanted properties, and set missing properties.
             foreach ($keys as $key) {
                 $data->{$key} = isset($uaData->{$key}) ? $uaData->{$key} : '';
             }
             $data->displayInfo = self::getDisplayInfo($data);
             $browserIndex->{$uaID} = $data;
         }
         self::$browserIndex = $browserIndex;
     }
     return self::$browserIndex;
 }
Ejemplo n.º 11
0
    protected function getAddjobFormHtml()
    {
        $conf = $this->getContext()->getConf();
        $request = $this->getContext()->getRequest();
        $swarmUaIndex = BrowserInfo::getSwarmUAIndex();
        $addjobPageUrl = htmlspecialchars(swarmpath("addjob"));
        $userName = $request->getSessionData("username") && $request->getSessionData("auth") == "yes" ? htmlspecialchars($request->getSessionData("username")) : "";
        $formHtml = <<<HTML
<form action="{$addjobPageUrl}" method="post" class="form-horizontal">

\t<fieldset>
\t\t<legend>Authentication</legend>

\t\t<div class="control-group">
\t\t\t<label class="control-label" for="form-authUsername">User name:</label>
\t\t\t<div class="controls">
\t\t\t\t<input type="text" name="authUsername" value="{$userName}" id="form-authUsername">
\t\t\t</div>
\t\t</div>
\t\t<div class="control-group">
\t\t\t<label class="control-label" for="form-authToken">Auth token:</label>
\t\t\t<div class="controls">
\t\t\t\t<input type="text" name="authToken" id="form-authToken" class="input-xlarge">
\t\t\t</div>
\t\t</div>
\t</fieldset>

\t<fieldset>
\t\t<legend>Job information</legend>

\t\t<div class="control-group">
\t\t\t<label class="control-label" for="form-jobName">Job name:</label>
\t\t\t<div class="controls">
\t\t\t\t<input type="text" name="jobName" id="form-jobName" class="input-xlarge" maxlength="255">
\t\t\t\t<span class="help-inline">HTML, up to 255 characters</span>
\t\t\t</div>
\t\t</div>
\t\t<div class="control-group">
\t\t\t<label class="control-label" for="form-runMax">Run max:</label>
\t\t\t<div class="controls">
\t\t\t\t<input type="number" size="5" name="runMax" id="form-runMax" value="2" min="1" max="99">
\t\t\t\t<p class="help-block">This is the maximum number of times a run is ran in a user agent. If a run passes
\t\t\t\twithout failures then it is only ran once. If it does not pass, TestSwarm will re-try the run
\t\t\t\t(up to "Run max" times) for that useragent to avoid error pollution due to time-outs, slow
\t\t\t\tcomputers or other unrelated conditions that can cause the server to not receive a success report.</p>
\t\t\t</div>
\t\t</div>
\t</fieldset>

\t<fieldset>
\t\t<legend>Browsers</legend>

\t\t<p>Choose which groups of user agents this job should be ran in. Some of the groups may
\t\toverlap each other, TestSwarm will detect and remove duplicate entries in the resulting set.</p>

HTML;
        foreach ($conf->browserSets as $set => $browsers) {
            $set = htmlspecialchars($set);
            $browsersHtml = '';
            $last = count($browsers) - 1;
            foreach ($browsers as $i => $browser) {
                if ($i !== 0) {
                    $browsersHtml .= $i === $last ? '<br> and ' : ',<br>';
                } else {
                    $browsersHtml .= '<br>';
                }
                $browsersHtml .= htmlspecialchars($swarmUaIndex->{$browser}->displaytitle);
            }
            $formHtml .= <<<HTML
\t\t<div class="control-group">
\t\t\t<label class="checkbox" for="form-browserset-{$set}">
\t\t\t\t<input type="checkbox" name="browserSets[]" value="{$set}" id="form-browserset-{$set}">
\t\t\t\t<strong>{$set}</strong>: {$browsersHtml}.
\t\t\t</label>
\t\t</div>
HTML;
        }
        $formHtml .= <<<HTML
\t</fieldset>

\t<fieldset>
\t\t<legend>Runs</legend>

\t\t<p>Each job consists of several runs. Every run has a name and a url to where that test suite can be ran. All the test suites should probably have the same common code base or some other grouping characteristic, where each run is part of the larger test suite. As example, for a QUnit test suite the <code>filter</code> url parameter can be used to only run one of the "modules" so every run would be the name of that module and the URL to the testsuite with <code>?filter=modulename</code> appended to it.</p>

\t\t<div id="runs-container" class="well">
\t\t\t<fieldset>
\t\t\t\t<legend>Run 1</legend>

\t\t\t\t<label for="form-runNames1">Run name:</label>
\t\t\t\t<input type="text" name="runNames[]" id="form-runNames1" maxlength="255">
\t\t\t\t<br>
\t\t\t\t<label for="form-runUrls1">Run URL:</label>
\t\t\t\t<input type="text" name="runUrls[]" placeholder="http://" class="input-xlarge"id="form-runUrls1">
\t\t\t</fieldset>
\t\t\t<fieldset>
\t\t\t\t<legend>Run 2</legend>

\t\t\t\t<label for="form-runNames2">Run name:</label>
\t\t\t\t<input type="text" name="runNames[]" id="form-runNames2" maxlength="255">
\t\t\t\t<br>
\t\t\t\t<label for="form-runUrls2">Run URL:</label>
\t\t\t\t<input type="text" name="runUrls[]" placeholder="http://" class="input-xlarge"id="form-runUrls2">
\t\t\t</fieldset>
\t\t\t<fieldset>
\t\t\t\t<legend>Run 3</legend>

\t\t\t\t<label for="form-runNames3">Run name:</label>
\t\t\t\t<input type="text" name="runNames[]" id="form-runNames3" maxlength="255">
\t\t\t\t<br>
\t\t\t\t<label for="form-runUrls3">Run URL:</label>
\t\t\t\t<input type="text" name="runUrls[]" placeholder="http://" class="input-xlarge"id="form-runUrls3">
\t\t\t</fieldset>
\t\t</div>
\t</fieldset>

\t<div class="form-actions">
\t\t<input type="submit" value="Create job" class="btn btn-primary btn-large">
\t</div>
</form>
HTML;
        return $formHtml;
    }
Ejemplo n.º 12
0
    protected function getAddjobFormHtml()
    {
        $conf = $this->getContext()->getConf();
        $request = $this->getContext()->getRequest();
        $swarmUaIndex = BrowserInfo::getSwarmUAIndex();
        $addjobPageUrl = htmlspecialchars(swarmpath("adddevboxjob"));
        $userName = $request->getSessionData("username") && $request->getSessionData("auth") == "yes" ? htmlspecialchars($request->getSessionData("username")) : "";
        // fields to be taken from the querystring:
        $jobName = $request->getVal('jobName');
        $runMax = $request->getVal('runMax') ?: 3;
        $runNames = $request->getArray('runNames');
        $runUrls = $request->getArray('runUrls');
        $selectedBrowsers = $request->getArray('browsers');
        if ($runNames && !$runUrls || !$runNames && $runUrls || $runNames && $runUrls && count($runNames) != count($runUrls)) {
            throw new SwarmException("runNames and runUrls must have the same number of elements in the array");
            return;
        }
        $formHtml = <<<HTML
\t\t\t
<form action="{$addjobPageUrl}" method="post" class="form-horizontal">
\t<div class="row">
\t\t<div class="span6">
HTML;
        $formHtml .= $this->getBrowsers($conf, $swarmUaIndex, $selectedBrowsers);
        $formHtml .= <<<HTML
\t\t</div>
\t\t<div class="span6">
\t\t\t
HTML;
        $formHtml .= <<<HTML

\t\t\t<fieldset>
\t\t\t\t<legend>Runs <i class="icon-question-sign po" data-title="Runs" data-content='Each job consists of several runs. Every run has a name and a url to where that test suite can be ran. All the test suites should probably have the same common code base or some other grouping characteristic, where each run is part of the larger test suite. As example, for a QUnit test suite the <code>filter</code> url parameter can be used to only run one of the "modules" so every run would be the name of that module and the URL to the testsuite with <code>?filter=modulename</code> appended to it.'></i></legend>

\t\t\t\t<label class="control-label" for="button-TickRuns">Ticked runs: &nbsp;</label>

\t\t\t\t<div class="btn-group" data-toggle="buttons-radio" id="button-TickRuns">
\t\t\t\t\t<button class="btn all" type="button">all</button>
\t\t\t\t\t<button class="btn none" type="button">none</button>
\t\t\t\t\t<button class="btn same" type="button">same as last time</button>
\t\t\t\t\t<i class="icon-question-sign po" data-title="Same as last time" data-content='Restores runMax, browserSets and runNames fields from the cookie. runMax value is put into the form field. browserSets are ticked. Runs from the cookie are matched against runs in the html form value.'></i>
\t\t\t\t</div>
\t\t\t\t<div id="runs-container" class="well">
HTML;
        if ($runNames && count($runNames) > 0) {
            for ($i = 0; $i < count($runNames); $i++) {
                $formHtml .= $this->getRun($i + 1, $runNames[$i], $runUrls[$i]);
            }
        } else {
            for ($i = 0; $i < 3; $i++) {
                $formHtml .= $this->getRun($i + 1, $runNames[$i], $runUrls[$i]);
            }
        }
        $formHtml .= <<<HTML
\t\t\t\t</div>
\t\t\t</fieldset>
\t\t\t
\t\t\t<button class="btn" id="btnOtherInformation" type="button">Other information</button>
\t\t\t
\t\t\t<div class="well hide" id="otherInformation">
\t\t\t\t<fieldset>
\t\t\t\t\t<legend>Other information</legend>

\t\t\t\t\t<div class="control-group">
\t\t\t\t\t\t<label class="control-label" for="form-authUsername">User name:</label>
\t\t\t\t\t\t<div class="controls">
\t\t\t\t\t\t\t<input type="text" value="{$userName}" id="form-authUsername" disabled="disabled">
\t\t\t\t\t\t</div>
\t\t\t\t\t</div>
\t\t\t\t\t<div class="control-group">
\t\t\t\t\t\t<label class="control-label" for="form-runMax">Run max:</label>
\t\t\t\t\t\t<div class="controls">
\t\t\t\t\t\t\t<input type="number" size="5" name="runMax" id="form-runMax" value="{$runMax}" min="1" max="99">
\t\t\t\t\t\t\t<i class="icon-question-sign po" data-title="Run max" data-content='This is the maximum number of times a run is ran in a user agent. If a run passes
\t\t\t\t\t\t\twithout failures then it is only ran once. If it does not pass, TestSwarm will re-try the run
\t\t\t\t\t\t\t(up to "Run max" times) for that useragent to avoid error pollution due to time-outs, slow
\t\t\t\t\t\t\tcomputers or other unrelated conditions that can cause the server to not receive a success report.'></i>
\t\t\t\t\t\t</div>
\t\t\t\t\t</div>
\t\t\t\t</fieldset>
\t\t\t\t<input type="hidden" name="jobName" id="form-jobName" maxlength="255" value="{$jobName}">
\t\t\t</div>
\t\t</div>
\t</div>
\t
\t<div class="form-actions">
\t\t<input type="submit" value="Create job" class="btn btn-primary btn-large">
\t</div>
</form>
HTML;
        return $formHtml;
    }
Ejemplo n.º 13
0
 public function doAction()
 {
     $db = $this->getContext()->getDB();
     $request = $this->getContext()->getRequest();
     $userName = $request->getVal("item");
     if (!$userName) {
         $this->setError("missing-parameters");
         return;
     }
     $userID = $db->getOne(str_queryf("SELECT id FROM users WHERE name = %s;", $userName));
     $userID = intval($userID);
     if (!$userID) {
         $this->setError("invalid-input", "User does not exist");
         return;
     }
     $uaIndex = BrowserInfo::getSwarmUAIndex();
     // Active clients
     $activeClients = array();
     $clientRows = $db->getRows(str_queryf("SELECT\n\t\t\t\tuseragent_id,\n\t\t\t\tuseragent,\n\t\t\t\tcreated\n\t\t\tFROM\n\t\t\t\tclients\n\t\t\tWHERE user_id = %u\n\t\t\tAND   updated > %s\n\t\t\tORDER BY created DESC;", $userID, swarmdb_dateformat(strtotime("1 minutes ago"))));
     if ($clientRows) {
         foreach ($clientRows as $clientRow) {
             $bi = BrowserInfo::newFromContext($this->getContext(), $clientRow->useragent);
             $activeClient = array("uaID" => $clientRow->useragent_id, "uaRaw" => $bi->getRawUA(), "uaData" => $bi->getSwarmUaItem(), "uaBrowscap" => $bi->getBrowscap());
             self::addTimestampsTo($activeClient, $clientRow->created, "connected");
             $activeClients[] = $activeClient;
         }
     }
     // Recent jobs
     $recentJobs = array();
     // List of all user agents used in recent jobs
     // This is as helper allow creating proper gaps when iterating
     // over jobs.
     $userAgents = array();
     $jobRows = $db->getRows(str_queryf("SELECT\n\t\t\t\tid,\n\t\t\t\tname\n\t\t\tFROM\n\t\t\t\tjobs\n\t\t\tWHERE jobs.user_id = %u\n\t\t\tORDER BY jobs.created DESC\n\t\t\tLIMIT 15;", $userID));
     if ($jobRows) {
         $uaRunStatusStrength = array_flip(array("passed", "new", "progress", "failed", "timedout", "error"));
         foreach ($jobRows as $jobRow) {
             $jobID = intval($jobRow->id);
             $jobActionContext = $this->getContext()->createDerivedRequestContext(array("action" => "job", "item" => $jobID), "GET");
             $jobAction = JobAction::newFromContext($jobActionContext);
             $jobAction->doAction();
             if ($jobAction->getError()) {
                 $this->setError($jobAction->getError());
                 return;
             }
             $jobActionData = $jobAction->getData();
             // Add user agents array of this job to the overal user agents list.
             // php array+ automatically fixes clashing keys. The values are always the same
             // so it doesn't matter whether or not it overwrites.
             $userAgents += $jobActionData["userAgents"];
             // The summerized status for each user agent run
             // of this job. e.g. if all are new except one,
             // then it will be on "progress", if all are complete
             // then the worst failure is put in the summary
             $uaSummary = array();
             $uaNotNew = array();
             $uaHasIncomplete = array();
             $uaStrongestStatus = array();
             foreach ($jobActionData["runs"] as $run) {
                 foreach ($run["uaRuns"] as $uaID => $uaRun) {
                     if ($uaRun["runStatus"] !== "new" && !in_array($uaID, $uaNotNew)) {
                         $uaNotNew[] = $uaID;
                     }
                     if ($uaRun["runStatus"] === "new" || $uaRun["runStatus"] === "progress") {
                         if (!in_array($uaID, $uaHasIncomplete)) {
                             $uaHasIncomplete[] = $uaID;
                         }
                     }
                     if (!isset($uaStrongestStatus[$uaID]) || $uaRunStatusStrength[$uaRun["runStatus"]] > $uaRunStatusStrength[$uaStrongestStatus[$uaID]]) {
                         $uaStrongestStatus[$uaID] = $uaRun["runStatus"];
                     }
                     $uaSummary[$uaID] = !in_array($uaID, $uaNotNew) ? "new" : (in_array($uaID, $uaHasIncomplete) ? "progress" : $uaStrongestStatus[$uaID]);
                 }
             }
             $recentJobs[] = array("id" => $jobID, "name" => $jobRow->name, "url" => swarmpath("job/{$jobID}", "fullurl"), "uaSummary" => $uaSummary);
         }
     }
     natcaseksort($userAgents);
     $this->setData(array("userName" => $userName, "activeClients" => $activeClients, "recentJobs" => $recentJobs, "uasInJobs" => $userAgents));
 }
Ejemplo n.º 14
0
    /**
     * Iterate over all run rows and aggregate the runs and user agents.
     * @return Array List of runs and userAgents.
     */
    public static function getDataFromRunRows(TestSwarmContext $context, $runRows)
    {
        $db = $context->getDB();
        $userAgentIDs = array();
        $runs = array();
        foreach ($runRows as $runRow) {
            $runInfo = array('id' => $runRow->id, 'name' => $runRow->name, 'url' => $runRow->url);
            $runUaRuns = array();
            // Get list of useragents that this run is scheduled for
            $runUaRows = $db->getRows(str_queryf('SELECT
					status,
					useragent_id,
					results_id
				FROM
					run_useragent
				WHERE run_useragent.run_id = %u;', $runRow->id));
            if ($runUaRows) {
                foreach ($runUaRows as $runUaRow) {
                    // Add UA ID to the list. After we've collected
                    // all the UA IDs we'll perform one query for all of them
                    // to gather the info from the useragents table
                    $userAgentIDs[] = $runUaRow->useragent_id;
                    if (!$runUaRow->results_id) {
                        $runUaRuns[$runUaRow->useragent_id] = array('runStatus' => 'new');
                    } else {
                        $runresultsRow = $db->getRow(str_queryf('SELECT
								id,
								client_id,
								status,
								total,
								fail,
								error
							FROM runresults
							WHERE id = %u;', $runUaRow->results_id));
                        if (!$runresultsRow) {
                            $this->setError('data-corrupt');
                            return;
                        }
                        $runUaRuns[$runUaRow->useragent_id] = array('useragentID' => $runUaRow->useragent_id, 'clientID' => $runresultsRow->client_id, 'failedTests' => $runresultsRow->fail, 'totalTests' => $runresultsRow->total, 'errors' => $runresultsRow->error, 'runStatus' => self::getRunresultsStatus($runresultsRow), 'runResultsUrl' => swarmpath('result/' . $runUaRow->results_id), 'runResultsLabel' => $runresultsRow->status != ResultAction::$STATE_FINISHED ? '' : ($runresultsRow->error > 0 ? $runresultsRow->error : ($runresultsRow->fail > 0 ? $runresultsRow->fail : $runresultsRow->total)));
                    }
                }
                uksort($runUaRuns, array($context->getBrowserInfo(), 'sortUaId'));
                $runs[] = array('info' => $runInfo, 'uaRuns' => $runUaRuns);
            }
        }
        // Get information for all encounted useragents
        $browserIndex = BrowserInfo::getBrowserIndex();
        $userAgents = array();
        foreach ($userAgentIDs as $uaID) {
            if (!isset($browserIndex->{$uaID})) {
                // If it isn't in the index anymore, it means it has been removed from the browserSets
                // configuration. Use a generic fallback object;
                $userAgents[$uaID] = BrowserInfo::makeGenericUaData($uaID);
            } else {
                $userAgents[$uaID] = (array) $browserIndex->{$uaID};
            }
        }
        uasort($userAgents, 'BrowserInfo::sortUaData');
        return array('runs' => $runs, 'userAgents' => $userAgents);
    }
Ejemplo n.º 15
0
    /**
     * @actionParam string item: Client id.
     */
    public function doAction()
    {
        $context = $this->getContext();
        $db = $context->getDB();
        $request = $context->getRequest();
        $item = $request->getInt('item');
        if (!$item) {
            $this->setError('missing-parameters');
            return;
        }
        // Client information
        $row = $db->getRow(str_queryf('SELECT
				id,
				name,
				useragent,
				updated,
				created
			FROM
				clients
			WHERE id = %u;', $item));
        if (!$row) {
            $this->setError('invalid-input', 'Client not found');
            return;
        }
        $bi = BrowserInfo::newFromContext($context, $row->useragent);
        $info = array('id' => intval($row->id), 'name' => $row->name, 'viewUrl' => swarmpath("clients/{$row->name}"), 'uaID' => $bi->getSwarmUaID(), 'uaRaw' => $bi->getRawUA(), 'uaData' => $bi->getUaData(), 'sessionAge' => gmstrtotime($row->updated) - gmstrtotime($row->created));
        self::addTimestampsTo($info, $row->created, 'connected');
        self::addTimestampsTo($info, $row->updated, 'pinged');
        // Run results
        $results = array();
        $rows = $db->getRows(str_queryf('SELECT
				id,
				run_id,
				client_id,
				status,
				total,
				fail,
				error,
				updated,
				created
			FROM runresults
			WHERE client_id = %u
			ORDER BY created DESC;', $item));
        if ($rows) {
            foreach ($rows as $row) {
                $runRow = $jobRow = false;
                $result = array('id' => intval($row->id), 'viewUrl' => swarmpath("result/{$row->id}"), 'status' => JobAction::getRunresultsStatus($row));
                $runRow = $db->getRow(str_queryf('SELECT
						name,
						job_id
					FROM runs
					WHERE id = %u;', $row->run_id));
                if ($runRow) {
                    $jobRow = $db->getRow(str_queryf('SELECT
							id,
							name,
							project_id
						FROM
							jobs
						WHERE id = %u', $runRow->job_id));
                    if ($jobRow) {
                        $projectRow = $db->getRow(str_queryf('SELECT
								display_title
							FROM projects
							WHERE id = %s;', $jobRow->project_id));
                        $result['job'] = array('nameText' => strip_tags($jobRow->name), 'viewUrl' => swarmpath("job/{$jobRow->id}"));
                        $result['run'] = array('name' => $runRow->name);
                        $result['project'] = array('id' => $jobRow->project_id, 'display_title' => $projectRow->display_title, 'viewUrl' => swarmpath("project/{$jobRow->project_id}"));
                    }
                }
                // Runs and jobs could be deleted, results are preserved.
                if (!$jobRow) {
                    $result['job'] = null;
                    $result['run'] = null;
                    $result['project'] = null;
                }
                $results[] = $result;
            }
        }
        $this->setData(array('info' => $info, 'results' => $results));
    }
Ejemplo n.º 16
0
 protected function findUnknown($table, $batchSize, $interactive)
 {
     $db = $this->getContext()->getDB();
     $browserIndex = BrowserInfo::getBrowserIndex();
     $uaIDs = array_keys((array) $browserIndex);
     $start = $db->getOne("SELECT MIN(id) FROM {$table};");
     $end = $db->getOne("SELECT MAX(id) FROM {$table};");
     if (!$start || !$end) {
         $this->error("The {$table} table appears empty.");
     }
     $found = array();
     $end += $batchSize - 1;
     // Do remaining chunk
     $blockStart = $start;
     $blockEnd = min($start + $batchSize - 1, $end);
     while ($blockEnd <= $end) {
         $this->out("...scanning {$table}.id {$blockStart} to {$blockEnd}");
         $rows = $db->getRows(str_queryf("SELECT DISTINCT(useragent_id) FROM {$table}\n\t\t\t\tWHERE id BETWEEN {$blockStart} AND {$blockEnd}\n\t\t\t\tAND useragent_id NOT IN %l;\n\t\t\t\t", $uaIDs));
         $blockStart += $batchSize;
         $blockEnd += $batchSize;
         // Optimise for continuing a batch, don't wait if this chunk didn't
         // affect any rows. This way we fast-forward to the next affectable chunk.
         if ($rows) {
             foreach ($rows as $row) {
                 // Don't list the same one twice.
                 if (in_array($row->useragent_id, $found)) {
                     continue;
                 }
                 $found[] = $row->useragent_id;
                 $this->out('* ' . $row->useragent_id);
                 if ($interactive) {
                     $this->out('Enter replacement uaID (or leave blank to skip):');
                     // Input should either be empty (to skip) or be a valid uaID,
                     // otherwise, repeat the question.
                     while (($input = $this->cliInput()) && !isset($browserIndex->{$input})) {
                         $this->out('The entered uaID was not found. Try again.');
                     }
                     if ($input) {
                         $this->runBatch($row->useragent_id, $input, $batchSize);
                     }
                 }
             }
         }
     }
     return $found;
 }
Ejemplo n.º 17
0
}
$defaultSettings = json_decode(file_get_contents($defaultSettingsFile));
$localSettings = json_decode(file_get_contents($localSettingsFile));
if (!$defaultSettings) {
    echo "<b>TestSwarm Fatal:</b> Default settings file contains invalid JSON.\n";
    exit;
}
if (!$localSettings) {
    echo "<b>TestSwarm Fatal:</b> Local settings file contains invalid JSON.\n";
    exit;
}
$swarmConfig = object_merge($defaultSettings, $localSettings);
unset($defaultSettingsFile, $localSettingsFile, $defaultSettings, $localSettings);
// Validate browserSets
// Must be after AutoLoad
$swarmUaIndex = BrowserInfo::getSwarmUAIndex();
foreach ($swarmConfig->browserSets as $set => $browsers) {
    foreach ($browsers as $browser) {
        if (!isset($swarmUaIndex->{$browser})) {
            echo "<b>TestSwarm Fatal</b>: Invalid browser ID \"<code>{$browser}</code>\" in browser set \"<code>{$set}</code>\" !\n";
            exit;
        }
    }
}
// Timezone
date_default_timezone_set($swarmConfig->general->timezone);
// Auto-populate web.server
if ($swarmConfig->web->server === null) {
    $server = isset($_SERVER['HTTPS']) ? 'https://' : 'http://';
    if (isset($_SERVER["HTTP_HOST"])) {
        $server .= $_SERVER["HTTP_HOST"];
Ejemplo n.º 18
0
 /**
  * @actionMethod POST: Required.
  * @actionParam jobName string: May contain HTML.
  * @actionParam runMax int
  * @actionParam runNames array
  * @actionParam runUrls array
  * @actionParam browserSets array
  * @actionParam string authUsername
  * @actionParam string authToken
  * @actionAuth: Yes.
  */
 public function doAction()
 {
     $conf = $this->getContext()->getConf();
     $db = $this->getContext()->getDB();
     $request = $this->getContext()->getRequest();
     $userId = $this->doRequireAuth();
     if (!$userId) {
         return;
     }
     $jobName = $request->getVal("jobName");
     $runMax = $request->getInt("runMax");
     $runNames = $request->getArray("runNames");
     $runUrls = $request->getArray("runUrls");
     $browserSets = $request->getArray("browserSets");
     if (!$jobName || !$runNames || !count($runNames) || !$runUrls || !count($runUrls) || !$browserSets || !count($browserSets)) {
         $this->setError("missing-parameters");
         return;
     }
     if ($runMax < 1 || $runMax > 99) {
         $this->setError("invalid-input", "runMax must be a number between 1 and 99.");
         return;
     }
     $runs = array();
     // Loop through runNames / runUrls to validate them ahead of time,
     // and filter out empty ones from the AddjobPage.
     foreach ($runNames as $runNr => $runName) {
         if (!isset($runUrls[$runNr])) {
             $this->setError("invalid-input", "One or more runs is missing a URL.");
             return;
         }
         $runUrl = $runUrls[$runNr];
         // Filter out empty submissions,
         // AddjobPage may submit more input fields then filled in
         if ($runUrl == '' && $runName == '') {
             continue;
         }
         if ($runUrl == '' || $runName == '') {
             $this->setError("invalid-input", "Run names and urls must be non-empty.");
             return;
         }
         if (strlen($runName) > 255) {
             $formRunNr = $runNr + 1;
             // offset 0
             $this->setError("invalid-input", "Run #{$formRunNr} name was too long (up to 255 characters).");
             return;
         }
         $runs[] = array("name" => $runName, "url" => $runUrl);
     }
     if (!count($runs)) {
         $this->setError('missing-parameters', 'Job must have atleast 1 run.');
         return;
     }
     // Generate a list of user agent IDs based on the selected browser sets
     $browserSetsCnt = count($browserSets);
     $browserSets = array_unique($browserSets);
     if ($browserSetsCnt !== count($browserSets)) {
         $this->setError("invalid-input", "Duplicate entries in browserSets parameter.");
         return;
     }
     $swarmUaIndex = BrowserInfo::getSwarmUAIndex();
     $uaIDs = array();
     foreach ($browserSets as $browserSet) {
         if (!isset($conf->browserSets->{$browserSet})) {
             $this->setError("invalid-input", "Unknown browser set: {$browserSet}.");
             return;
         }
         // Merge the arrays, and re-index with unique (also prevents duplicate entries)
         $uaIDs = array_unique(array_merge($uaIDs, $conf->browserSets->{$browserSet}));
     }
     if (!count($uaIDs)) {
         $this->setError("data-corrupt", "No user agents matched the generated browserset filter.");
         return;
     }
     // Verify job name maxlength (otherwise MySQL will crop it, which might
     // result in incomplete html, screwing up the JobPage).
     if (strlen($jobName) > 255) {
         $this->setError("invalid-input", "Job name too long (up to 255 characters).");
     }
     // Create job
     $isInserted = $db->query(str_queryf("INSERT INTO jobs (user_id, name, created)\n\t\t\tVALUES (%u, %s, %s);", $userId, $jobName, swarmdb_dateformat(SWARM_NOW)));
     $newJobId = $db->getInsertId();
     if (!$isInserted || !$newJobId) {
         $this->setError("internal-error", "Insertion of job into database failed.");
         return;
     }
     // Create all runs and schedule them for the wanted browsersets in run_useragent
     foreach ($runs as $run) {
         // Create this run
         $isInserted = $db->query(str_queryf("INSERT INTO runs (job_id, name, url, created)\n\t\t\t\tVALUES(%u, %s, %s, %s);", $newJobId, $run['name'], $run['url'], swarmdb_dateformat(SWARM_NOW)));
         $newRunId = $db->getInsertId();
         if (!$isInserted || !$newRunId) {
             $this->setError("internal-error", "Insertion of job into database failed.");
             return;
         }
         // Schedule run_useragent entries for all user agents matching
         // the browerset(s) for this job.
         foreach ($uaIDs as $uaID) {
             $isInserted = $db->query(str_queryf("INSERT INTO run_useragent (run_id, useragent_id, max, updated, created)\n\t\t\t\t\tVALUES(%u, %s, %u, %s, %s);", $newRunId, $uaID, $runMax, swarmdb_dateformat(SWARM_NOW), swarmdb_dateformat(SWARM_NOW)));
         }
     }
     $this->setData(array("id" => $newJobId, "runTotal" => count($runs), "uaTotal" => count($uaIDs)));
 }
Ejemplo n.º 19
0
function event_load_html($list, $options)
{
  ?>
  <h3>
    Document <?php echo $list[0]->getWebId(); ?>
  </h3>
  <p>
    Total events: <?php echo count($list); ?>
  </p>
  <?php echo printArray($options); ?>
  <p>Results:</p>
  <ol>
  <?
  $event = count($list);
  for($i = 0; $i < count($list); $i++)
  { 
    $item = $list[$i];
    $event--;
    $host = $item->getRemoteHost();
    $browser = new BrowserInfo($item->getUserAgent());
    ?>
      <li>
        <?php 
          echo "[" . date("Y-d-m H:i:s", $item->getRequestedAt()); 

          if($item->getEvent() == "page_view") {
            echo " (" . $item->getDuration() . " s)";
          }
          echo "] ";
          echo '"' . $item->getEvent() . '"';
          echo " on page ".  $item->getPage(); 
          echo " (value: " . $item->getValue() .  ")";
          echo ' - <a href="' . $item->getReferer() . '">URL</a> - ';
          echo ' Remote host: <a href="location.php?ip=' . $host . '">' . $host . "</a> - ";
          echo $browser->getName() . " " . $browser->getVersion();
          ?>
      </li>
    <?php
  } 
  echo "</ol>";
}
Ejemplo n.º 20
0
 /**
  * @actionParam item int: Job ID.
  */
 public function doAction()
 {
     $db = $this->getContext()->getDB();
     $request = $this->getContext()->getRequest();
     $jobID = $request->getInt("item");
     if (!$jobID) {
         $this->setError("missing-parameters");
         return;
     }
     // Get job information
     $jobRow = $db->getRow(str_queryf("SELECT\n\t\t\t\tjobs.id as job_id,\n\t\t\t\tjobs.name as job_name,\n\t\t\t\tjobs.created as job_created,\n\t\t\t\tusers.name as user_name\n\t\t\tFROM\n\t\t\t\tjobs, users\n\t\t\tWHERE jobs.id = %u\n\t\t\tAND   users.id = jobs.user_id;", $jobID));
     if (!$jobRow) {
         $this->setError("invalid-input", "Job not found");
         return;
     }
     if (!$jobRow->job_id || !$jobRow->job_name || !$jobRow->user_name) {
         $this->setError("data-corrupt");
         return;
     }
     // Get runs for this job
     $runRows = $db->getRows(str_queryf("SELECT\n\t\t\t\truns.id as run_id,\n\t\t\t\truns.url as run_url,\n\t\t\t\truns.name as run_name\n\t\t\tFROM\n\t\t\t\truns\n\t\t\tWHERE runs.job_id = %u\n\t\t\tORDER BY run_id;", $jobID));
     // Start of response data
     $respData = array("jobInfo" => array("id" => $jobID, "name" => $jobRow->job_name, "ownerName" => $jobRow->user_name, "creationTimestamp" => $jobRow->job_created), "runs" => array(), "userAgents" => array());
     $userAgentIDs = array();
     foreach ($runRows as $runRow) {
         $runInfo = array("id" => $runRow->run_id, "name" => $runRow->run_name, "url" => $runRow->run_url);
         $runUaRuns = array();
         // Get list of useragents that this run is scheduled for
         $runUaRows = $db->getRows(str_queryf("SELECT\n\t\t\t\t\truns,\n\t\t\t\t\tmax,\n\t\t\t\t\tstatus,\n\t\t\t\t\tuseragent_id\n\t\t\t\tFROM\n\t\t\t\t\trun_useragent\n\t\t\t\tWHERE run_useragent.run_id = %u;", $runRow->run_id));
         if ($runUaRows) {
             foreach ($runUaRows as $runUaRow) {
                 // Create array for this ua run,
                 // If it has been run or is currently running,
                 // this array will be re-created in the loop over $clientRunRows
                 $runUaRuns[$runUaRow->useragent_id] = array("runStatus" => self::resolveStatusID((int) $runUaRow->status), "runRuns" => (int) $runUaRow->runs, "runMax" => (int) $runUaRow->max);
                 // Add UA ID to the list. After we've collected
                 // all the UA IDs we'll perform one query for all of them
                 // to gather the info from the useragents table
                 $userAgentIDs[] = $runUaRow->useragent_id;
             }
         }
         // Get client results for this run
         $clientRunRows = $db->getRows(str_queryf("SELECT\n\t\t\t\t\trun_client.client_id as client_id,\n\t\t\t\t\trun_client.status as status,\n\t\t\t\t\trun_client.fail as fail,\n\t\t\t\t\trun_client.error as error,\n\t\t\t\t\trun_client.total as total,\n\t\t\t\t\tclients.useragent_id as useragent_id\n\t\t\t\tFROM\n\t\t\t\t\trun_client, clients\n\t\t\t\tWHERE run_client.run_id = %u\n\t\t\t\tAND   run_client.client_id = clients.id\n\t\t\t\tORDER BY useragent_id;", $runRow->run_id));
         if ($clientRunRows) {
             foreach ($clientRunRows as $clientRunRow) {
                 $runUaRuns[$clientRunRow->useragent_id] = array_merge($runUaRuns[$clientRunRow->useragent_id], array("useragentID" => $clientRunRow->useragent_id, "clientID" => $clientRunRow->client_id, "failedTests" => $clientRunRow->fail, "totalTests" => $clientRunRow->total, "errors" => $clientRunRow->error, "runStatus" => self::getStatusFromClientRunRow($clientRunRow), "runResultsUrl" => swarmpath("index.php", "fullurl") . "?" . http_build_query(array("action" => "runresults", "run_id" => $runRow->run_id, "client_id" => $clientRunRow->client_id)), "runResultsLabel" => $clientRunRow->status < 2 ? "" : ($clientRunRow->total < 0 ? "" : ($clientRunRow->error > 0 ? $clientRunRow->error : ($clientRunRow->fail > 0 ? $clientRunRow->fail : $clientRunRow->total)))));
             }
             natcaseksort($runUaRuns);
         }
         $respData["runs"][] = array("info" => $runInfo, "uaRuns" => $runUaRuns);
     }
     // Get information for all encounted useragents
     $swarmUaIndex = BrowserInfo::getSwarmUAIndex();
     foreach ($userAgentIDs as $userAgentID) {
         if (!isset($swarmUaIndex->{$userAgentID})) {
             throw new SwarmException("Job {$jobID} has runs for unknown brower ID `{$userAgentID}`.");
         } else {
             $respData["userAgents"][$userAgentID] = (array) $swarmUaIndex->{$userAgentID};
         }
     }
     natcaseksort($respData["userAgents"]);
     // Save data
     $this->setData($respData);
 }
Ejemplo n.º 21
0
 /**
  * @param Array $data Details data from ClientsAction
  * @return string: HTML
  */
 protected function showDetails($data)
 {
     $html = '<div class="row">';
     foreach ($data['clients'] as $client) {
         $displayInfo = $client['uaData']['displayInfo'];
         $html .= '<div class="span4 swarm-client"><div class="well">' . '<div class="swarm-client-icon">' . BrowserInfo::buildIconHtml($displayInfo, array('wrap' => false)) . '</div>' . '<div class="swarm-client-info">' . '<p class="swarm-client-title">' . htmlspecialchars($displayInfo['title']) . '</p>' . '<table class="table table-condensed">' . '<tbody>' . '<tr><th>Last ping</th><td>' . self::getPrettyDateHtml($client, 'pinged') . '</td></tr>' . '<tr><th>Run</th>' . (!$client['lastResult'] ? '<td><span class="muted">Waiting for runs...</span></td>' : '<td class="swarm-status-' . $client['lastResult']['status'] . '">' . html_tag_open('a', array('href' => $client['lastResult']['viewUrl'])) . htmlspecialchars("#{$client['lastResult']['id']}") . ' ' . JobPage::getStatusIconHtml($client['lastResult']['status']) . '</a></td>') . '</tr>' . '<tr><th>Connected</th><td>' . self::getPrettyDateHtml($client, 'connected') . '</td></tr>' . '</tbody>' . '</table>' . '</div>' . '<div class="clearfix"><a href="' . htmlspecialchars($client['viewUrl']) . '" class="pull-right">Details &raquo;</a></div>' . '</div></div>';
     }
     return $html . '</div>';
 }
Ejemplo n.º 22
0
    /**
     * @actionParam string browserSet: Show useragents from a specific
     *  browserset only.
     * @actionParam bool onlyactive: If true, only user agents that
     *  have online clients and/or pending runs are included.
     *  If both "browserSet" and "onlyactive" are used, the overlaping
     *  subset will be output.
     */
    public function doAction()
    {
        $context = $this->getContext();
        $conf = $context->getConf();
        $db = $context->getDB();
        $request = $context->getRequest();
        $showOnlyactive = $request->getBool('onlyactive');
        $filterBrowserSet = $request->getVal('browserSet', false);
        $data = array('userAgents' => array());
        $browserIndex = BrowserInfo::getBrowserIndex();
        $browserSetByUaId = array();
        foreach ($conf->browserSets as $browserSet => $browsers) {
            foreach ($browsers as $browser) {
                $browserSetByUaId[$browser] = $browserSet;
            }
        }
        foreach ($browserIndex as $uaID => $uaData) {
            if ($filterBrowserSet && $browserSetByUaId[$uaID] !== $filterBrowserSet) {
                continue;
            }
            // Count online clients with this UA
            $clients = $db->getOne(str_queryf('SELECT
					COUNT(id)
				FROM clients
				WHERE useragent_id = %s
				AND   updated >= %s', $uaID, swarmdb_dateformat(Client::getMaxAge($context))));
            $clients = intval($clients);
            // Count active runs for this UA
            $activeRuns = $db->getOne(str_queryf('SELECT
					COUNT(*)
				FROM run_useragent
				WHERE useragent_id = %s
				AND   status = 1;', $uaID));
            $activeRuns = intval($activeRuns);
            // Count pending runs for this UA
            $pendingRuns = $db->getOne(str_queryf('SELECT
					COUNT(*)
				FROM run_useragent
				WHERE useragent_id = %s
				AND   status = 0
				AND   completed = 0;', $uaID));
            $pendingRuns = intval($pendingRuns);
            // Count past runs that can still be re-run to
            // possibly fix non-passing results
            $pendingReRuns = $db->getOne(str_queryf('SELECT
					COUNT(*)
				FROM run_useragent
				WHERE useragent_id = %s
				AND   status = 0
				AND   completed > 0;', $uaID));
            $pendingReRuns = intval($pendingReRuns);
            if (!$clients && !$activeRuns && !$pendingRuns && !$pendingReRuns) {
                if ($showOnlyactive || !isset($browserSetByUaId[$uaID])) {
                    continue;
                }
            }
            $data['userAgents'][$uaID] = array('data' => $uaData, 'stats' => array('onlineClients' => $clients, 'activeRuns' => $activeRuns, 'pendingRuns' => $pendingRuns, 'pendingReRuns' => $pendingReRuns));
        }
        // Make sure they are sorted nicely
        uasort($data['userAgents'], function ($a, $b) {
            return strnatcasecmp($a['data']->displayInfo['title'], $b['data']->displayInfo['title']);
        });
        $this->setData($data);
    }
Ejemplo n.º 23
0
    /**
     * @param Database $db
     * @param array $runRows: one or more rows from the `runs` table.
     * @return array with properties 'runs' and 'userAgents'
     */
    public static function getDataFromRunRows(Database $db, $runRows)
    {
        $userAgentIDs = array();
        $runs = array();
        foreach ($runRows as $runRow) {
            $runInfo = array('id' => $runRow->id, 'name' => $runRow->name, 'url' => $runRow->url);
            $runUaRuns = array();
            // Get list of useragents that this run is scheduled for
            $runUaRows = $db->getRows(str_queryf('SELECT
					status,
					useragent_id,
					results_id
				FROM
					run_useragent
				WHERE run_useragent.run_id = %u;', $runRow->id));
            if ($runUaRows) {
                foreach ($runUaRows as $runUaRow) {
                    // Add UA ID to the list. After we've collected
                    // all the UA IDs we'll perform one query for all of them
                    // to gather the info from the useragents table
                    $userAgentIDs[] = $runUaRow->useragent_id;
                    if (!$runUaRow->results_id) {
                        $runUaRuns[$runUaRow->useragent_id] = array('runStatus' => 'new');
                    } else {
                        $runresultsRow = $db->getRow(str_queryf('SELECT
								client_id,
								status,
								total,
								fail,
								error
							FROM runresults
							WHERE id = %u;', $runUaRow->results_id));
                        if (!$runresultsRow) {
                            $this->setError('data-corrupt');
                            return;
                        }
                        $runUaRuns[$runUaRow->useragent_id] = array('useragentID' => $runUaRow->useragent_id, 'clientID' => $runresultsRow->client_id, 'failedTests' => $runresultsRow->fail, 'totalTests' => $runresultsRow->total, 'errors' => $runresultsRow->error, 'runStatus' => self::getRunresultsStatus($runresultsRow), 'runResultsUrl' => swarmpath('result/' . $runUaRow->results_id), 'runResultsLabel' => $runresultsRow->status != ResultAction::$STATE_FINISHED ? '' : ($runresultsRow->error > 0 ? $runresultsRow->error : ($runresultsRow->fail > 0 ? $runresultsRow->fail : $runresultsRow->total)));
                    }
                }
                natcaseksort($runUaRuns);
                $runs[] = array('info' => $runInfo, 'uaRuns' => $runUaRuns);
            }
        }
        // Get information for all encounted useragents
        $swarmUaIndex = BrowserInfo::getSwarmUAIndex();
        $userAgents = array();
        foreach ($userAgentIDs as $userAgentID) {
            if (!isset($swarmUaIndex->{$userAgentID})) {
                throw new SwarmException("Job {$jobID} has runs for unknown brower ID `{$userAgentID}`.");
            } else {
                $userAgents[$userAgentID] = (array) $swarmUaIndex->{$userAgentID};
            }
        }
        natcaseksort($userAgents);
        return array('runs' => $runs, 'userAgents' => $userAgents);
    }
Ejemplo n.º 24
0
<?php

/* This software is released under the BSD license. Full text at project root -> license.txt */
require_once "../../../init.php";
BrowserInfo::set_screen_width($_GET["screen_width"]);
BrowserInfo::set_screen_height($_GET["screen_height"]);
BrowserInfo::set_as_fetched();