Exemplo n.º 1
0
$extval = $_REQUEST['ext'];
// test - one I have
// $urival = "ni:///sha-256;zxGpiG2_HXy3dHY9HZ3RJqsrhhVmWTsedpFnBTXN9us";
// $msgidval = 100;
// $extval = "";
// test - one I don't have (and is invalid)
// $urival = "ni:///sha-256;xxxxxoQ-h1bb0Ovu99EJUVQqyarpRQ4EQ0bCmJgY";
// $msgidval = 100;
// $extval = "";
// extract hashalg and hash and check for file, if it exists print it, otherwise 404
$hstr = "";
$algfound = false;
$hashval = "";
$ni_err = false;
$ni_errno = 0;
if (getAlg($urival, $algfound, $hstr, $hashval) === false) {
    $ni_err = true;
    $ni_errno = 490;
    $ni_errstr = "Bummer: {$ni_errno} I don't have {$urival} \nBad algorithm, no good alg found.";
    retErr($ni_errno, $ni_errstr);
    exit(1);
}
if (!$algfound) {
    $ni_err = true;
    $ni_errno = 491;
    $ni_errstr = "Bummer:  {$ni_errno}  I don't have {$urival} \nBad algorithm, no good alg found.";
    retErr($ni_errno, $ni_errstr);
    exit(1);
}
// TODO: see if we have that file elsewhere (netinffs)
// Check if we have NDO metadata
Exemplo n.º 2
0
 $results[$resind] = array();
 $results[$resind]['text'] = $item->Text;
 $results[$resind]['loc'] = $item->Url;
 $results[$resind]['desc'] = $item->Description;
 // grab a copy to a temp place
 $tfname = tempnam("/tmp", "ni-wiki-");
 // download, might be slow, optimise later (don't do it if I have copy)
 $rv = copy($item->Url, $tfname);
 // figure out ni name (fixed alg for now)
 $nresults = array();
 $niclcmd = $GLOBALS["cfg_nicl"] . " -g -n 'ni://wikipedia.org/sha-256;' -f " . $tfname;
 exec($niclcmd, $nresults);
 $nistr = $nresults[0];
 $results[$resind]['ni'] = $nistr;
 // cache a copy, make the .well-known link, store the meta-data
 getAlg($nistr, $algfound, $hstr, $hashval);
 $filename = $GLOBALS["cfg_cache"] . "/" . $hstr . ";" . $hashval;
 rename($tfname, $filename);
 $results[$resind]['file'] = $filename;
 // make a link
 $wlname = $GLOBALS["cfg_wkd"] . "/{$hstr}/{$hashval}";
 $rv = symlink($filename, $wlname);
 $results[$resind]['wku'] = $wlname;
 $wku = $GLOBALS["cfg_site"] . "/.well-known/ni/" . $hstr . "/" . $hashval;
 // make meta-data file
 $extrameta = "{ \"search\" : \"{$tokens}\"}";
 storeMeta($hstr, $hashval, $nistr, $item->Url, $wku, $extrameta);
 // some output please
 if ($rform == "html") {
     print "<li>";
     print "<a href=\"{$wku}\">{$nistr}</a>";