Esempio n. 1
0
            $msg_arr[] = ">>> Added Universign.eu as RFC 3161 TSA for team #" . $team['team_id'];
        } else {
            die($die_msg);
        }
    }
}
// if Universign was used either globally or on a per team level, correct the recorded dates for the timestamps in the database
if ($old_timestamping_global || $old_timestamping_teams) {
    // check if we have timestamped experiments
    $sql = "SELECT * FROM experiments";
    $req = $pdo->prepare($sql);
    $req->execute();
    while ($show = $req->fetch()) {
        if ($show['timestamped'] === '1') {
            $ts = new Elabftw\Elabftw\TrustedTimestamps(null, null, ELAB_ROOT . 'uploads/' . $show['timestamptoken']);
            $date = $ts->getResponseTime();
            if ($show['timestampedwhen'] !== $date) {
                $sql_update = "UPDATE experiments SET timestampedwhen = :date WHERE id = :id";
                $req_update = $pdo->prepare($sql_update);
                $res_update = $req_update->execute(array('date' => $date, 'id' => $show['id']));
                if ($res_update) {
                    $msg_arr[] = ">>> Corrected timestamp data for experiment #" . $show['id'];
                } else {
                    die($die_msg);
                }
            }
        }
    }
}
// if Universign.eu was not used, a database update might still be needed; check for that
if (!$old_timestamping_global) {
Esempio n. 2
0
$longname = hash("sha512", uniqid(rand(), true)) . ".asn1";
$file_path = ELAB_ROOT . 'uploads/' . $longname;
// save the timestamptoken
try {
    file_put_contents($file_path, $token);
} catch (Exception $e) {
    dblog('Error', $_SESSION['userid'], $e->getMessage());
    $msg_arr[] = _('There was an error with the timestamping. Experiment is NOT timestamped. Error has been logged.');
    $_SESSION['errors'] = $msg_arr;
    header("Location: ../experiments.php?mode=view&id=" . $id);
    exit;
}
// SQL
$sql = "UPDATE `experiments` SET `timestamped` = 1, `timestampedby` = :userid, `timestampedwhen` = :timestampedwhen, `timestamptoken` = :longname WHERE `id` = :id;";
$req = $pdo->prepare($sql);
$req->bindParam(':timestampedwhen', $trusted_timestamp->getResponseTime());
// the date recorded in the db has to match the creation time of the timestamp token
$req->bindParam(':longname', $longname);
$req->bindParam(':userid', $_SESSION['userid']);
$req->bindParam(':id', $id);
$res1 = $req->execute();
// unset $trusted_timestamp to delete associated temporary files
unset($trusted_timestamp);
// add also our pdf to the attached files of the experiment, this way it is kept safely :)
// I had this idea when realizing that if you comment an experiment, the hash won't be good anymore. Because the pdf will contain the new comments.
// Keeping the pdf here is the best way to go, as this leaves room to leave comments.
// this sql is to get the elabid which will be the real_name of the PDF
$sql = "SELECT elabid FROM experiments WHERE id = :id";
$req = $pdo->prepare($sql);
$req->bindParam(':id', $id);
$res2 = $req->execute();