Podpis na forum pokazujący prace w toku

Zaczęty przez SzaMoT🍀, 01 Wrzesień 2019, 18:20

SzaMoT🍀

Od kilku dni próbuję uruchomić skrypt pokazujący pracę BOINC, znajduje się pod tym adresem
https://boinc.berkeley.edu/addon_item.php?platform=web&item=b-sig.zip
Udało się uruchomić ale pokazuje tylko praca w toku, nie pokazuje postępu i projektu. ( Zmieniłem adres w skrypcie na obecne liczony projekt)
Umieściłem go na VPS'e gdzie działa BOINC.
Po zatrzymaniu BOINC Praca w toku znika, po wznowienu BM powraca praca w toku
Wstawię cały skrypt, proszę ekspertów o wypowiedź czy ten skrypt będzie pokazywał postęp zadań w toku i projekt
Najlepiej jakby go ktoś przetestował siebie.

<?php
/**
 * "BOINC monitor" forum signature.
 *
 * @author Nicolas Alvarez <nicolas.alvarez@gmail.com>
 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License v3
 */

class RPC {
private $c;
public function __construct($ip='127.0.0.1'$port=31416) {
$this->fsockopen($ip$port);
}
public function __destruct() {
fclose($this->c);
}
public function getResults() {
$req $this->createRequest();
$req->documentElement->appendChild($req->createElement('get_results'));

list($reply$xpath) = $this->sendAndGet($req);

$results_nl $xpath->query('/boinc_gui_rpc_reply/results[1]/result');
//[active_task/active_task_state=1]
$results = array();
foreach ($results_nl as $result_el) {
$results[] = self::parseResult($result_el);
}
return $results;
}

private static function parseResult(DOMElement $result_el) {
$result = array();
foreach ($result_el->childNodes as $property_el) {
if ($property_el->nodeType != XML_ELEMENT_NODE) continue;
$tagname $property_el->tagName;
switch ($tagname) {
case 'name':
case 'wu_name':
case 'project_url':
$result[$tagname] = (string)$property_el->textContent;
break;
case 'final_cpu_time':
case 'report_deadline':
case 'estimated_cpu_time_remaining':
$result[$tagname] = (float)$property_el->textContent;
break;
case 'state':
case 'exit_status':
$result[$tagname] = (int)$property_el->textContent;
break;
case 'active_task':
$result[$tagname] = self::parseActiveTask($property_el);
break;
}
}
return $result;
}
private static function parseActiveTask(DOMElement $activetask_el) {
$active_task = array();
foreach ($activetask_el->childNodes as $property_el) {
if ($property_el->nodeType != XML_ELEMENT_NODE) continue;
$tagname $property_el->tagName;
switch ($tagname) {
case 'checkpoint_cpu_time':
case 'fraction_done':
case 'current_cpu_time':
case 'swap_size':
case 'working_set_size':
case 'working_set_size_smoothed':
case 'page_fault_rate':
$active_task[$tagname] = (float)$property_el->textContent;
break;
case 'active_task_state':
case 'app_version_num':
case 'slot':
case 'scheduler_state':
$active_task[$tagname] = (int)$property_el->textContent;
break;
}
}
return $active_task;
}
public function auth($password) {
$nonce $this->getNonce();
$this->auth2($nonce$password);
}
private function getNonce() {
$req $this->createRequest();
$req->documentElement->appendChild($req->createElement('auth1'));

list($reply$xpath) = $this->sendAndGet($req);
if ($xpath->evaluate('count(/boinc_gui_rpc_reply/nonce) = 1')) {
return $xpath->evaluate('string(/boinc_gui_rpc_reply/nonce)');
} else {
throw new Exception("Invalid reply\n".$reply->saveXML());
}
}
private function auth2($nonce$password) {
$req $this->createRequest();
$auth2 $req->createElement('auth2');
$nonce_hash $req->createElement('nonce_hash'md5($nonce.$password));
$auth2->appendChild($nonce_hash);
$req->documentElement->appendChild($auth2);

list($reply$xpath) = $this->sendAndGet($req);
if ($xpath->evaluate('count(/boinc_gui_rpc_reply/authorized) = 1')) {
return true;
} else {
return false;
}
}
private function createRequest() {
$doc = new DOMDocument();
$req $doc->appendChild($doc->createElement('boinc_gui_rpc_request'));
return $doc;
}
private function sendAndGet(DOMDocument $d) {
$this->sendXML($d);
$reply $this->recvReply();
$r = new DOMDocument();
$r->loadXML($reply);
if ($r->documentElement->tagName == 'boinc_gui_rpc_reply') {
return array($r, new DOMXPath($r));
} else {
die($r->documentElement->tagName " the hell?");
}
}
private function sendXML(DOMDocument $d) {
fwrite($this->c$d->saveXML()."\003");
fflush($this->c);
}
private function recvReply() {
$reply '';
$idx 0;
//Stupid thing doesn't work in blocking mode; it blocks even when there 
//is *some* data. It should return even with 1 byte.
stream_set_blocking($this->c0);
while (!feof($this->c)) {
$chunk fread($this->c1024);

//avoid busy loops in non-blocking mode
if (strlen($chunk) == 0usleep(1e5);

//$idx is an optimization: only search for the terminator on new 
//data, skip what has been already searched.
$idx strlen($reply);

$reply .= $chunk;
$p strpos($reply"\003"$idx);
if ($p !== FALSE) {
$leftover substr($reply$p+1);
$reply substr($reply0$p-1);
return $reply;
}
}
throw new Exception("EOF");
}
}

$boinc = new RPC('127.0.0.1',31416);
//$boinc->auth('password');
$results $boinc->getResults();

$im imagecreate(220,50);

//colors
if(isset($_GET['white'])) {
$background_color imagecolorallocate($im255,255,255);
imagecolortransparent($im$background_color);
$wuname_color imagecolorallocate($im0x000x330x99);
$progress_color imagecolorallocate($im0x000x660xcc);
} else {
$background_color imagecolorallocate($im000);
$wuname_color imagecolorallocate($im0x000xcc0x99);
$progress_color imagecolorallocate($im0x000x990xff);
}

//title
imagestring($im3403"BOINC Work in progress"$wuname_color);

//task list
$y=17;
foreach (
$results as $r) {
if(isset($r['active_task']) && $r['active_task']['active_task_state'] == 1) {
$progress $r['active_task']['fraction_done']*100;
$progressfmt number_format($progress2'.''') . '%';
$name $r['name'];
if($r['project_url'] == 'http://boinc.bio.wzw.tum.de/boincsimap/') {
$name "$name (SIMAP)";
}

imagestring($im25,   $y$name$wuname_color);
imagestring($im2175$y$progressfmt$progress_color);
$y+=12;
}
}

//send it back!
header('Content-Type: image/png');
imagepng($im);
imagedestroy($im);
?>



SzaMoT🍀

#2
Proszę chociaż spojrzeć na skrypt i napisać czy ten skrypt ma pokazywać postęp zadań. Z tego co ja widzę to powinien to robić ale ja nie mam pojęcia o skryptach i mogę się mylić. Może jak był pisany 2007 to stara wersja BM była i z nowszymi nie działa?
Edit:
Napisałem do twórcy scryptu może on coś poradzi