commit b0471c6ae66c06a7912930ce96ed85c1c2df5392
parent 980e3e4c195172780d89aedffbb4bd7633860802
Author: Marcello Stanisci <marcello.stanisci@inria.fr>
Date: Wed, 16 Nov 2016 01:31:29 +0100
Removing deadcode
Diffstat:
18 files changed, 0 insertions(+), 1387 deletions(-)
diff --git a/php/Makefile.am b/php/Makefile.am
@@ -1,3 +0,0 @@
-# This Makefile is in the public domain
-
-SUBDIRS = doc
diff --git a/php/blog/articles/article_images.php b/php/blog/articles/article_images.php
@@ -1,82 +0,0 @@
-<?php
- /**
- * Parse $html_filename and add an entry of the type
- * "$html_filename" => ("img1.png", "img2.png") for each
- * encountered 'img' tag having the 'src' attribute formatted
- * as "/essay/<article_filename>/data/img1.png", to the JSON which
- * associates any article with its images.
- * Note that <article_filename> has the final '.html' removed
- */
- function add_article($html_filename){
- $doc = new DOMDocument();
- $doc->loadHTMLFile($html_filename);
- $xpath = new DOMXPath($doc);
- $xpath->registerNamespace('php', 'http://php.net/xpath');
- $xpath->registerPhpFunctions('preg_match');
- $elements = $xpath->query('//img[php:functionString("preg_match", "@^/data/[^/]+/[^/]+@", @src) > 0]');
- $db_filename = "articles_images.json";
- $json_str;
- if (file_exists($db_filename))
- $json_str = file_get_contents($db_filename);
- else
- $json_str = "";
- $json_db = json_decode($json_str);
- $json_db->$html_filename = array();
- foreach($elements as $img){
- $value = $img->getAttributeNode("src")->value;
- array_push($json_db->$html_filename, basename($value));
- }
- file_put_contents($db_filename, json_encode($json_db));
- }
-
- /* suppress warnings due to parsing HTML5 */
- libxml_use_internal_errors(true);
-
- add_article("scrap1_10.html");
- add_article("scrap1_11.html");
- add_article("scrap1_12.html");
- add_article("scrap1_13.html");
- add_article("scrap1_14.html");
- add_article("scrap1_15.html");
- add_article("scrap1_16.html");
- add_article("scrap1_17.html");
- add_article("scrap1_18.html");
- add_article("scrap1_19.html");
- add_article("scrap1_1.html");
- add_article("scrap1_20.html");
- add_article("scrap1_21.html");
- add_article("scrap1_22.html");
- add_article("scrap1_23.html");
- add_article("scrap1_24.html");
- add_article("scrap1_25.html");
- add_article("scrap1_26.html");
- add_article("scrap1_27.html");
- add_article("scrap1_28.html");
- add_article("scrap1_29.html");
- add_article("scrap1_2.html");
- add_article("scrap1_30.html");
- add_article("scrap1_31.html");
- add_article("scrap1_32.html");
- add_article("scrap1_33.html");
- add_article("scrap1_34.html");
- add_article("scrap1_35.html");
- add_article("scrap1_36.html");
- add_article("scrap1_37.html");
- add_article("scrap1_38.html");
- add_article("scrap1_39.html");
- add_article("scrap1_3.html");
- add_article("scrap1_40.html");
- add_article("scrap1_41.html");
- add_article("scrap1_42.html");
- add_article("scrap1_43.html");
- add_article("scrap1_46.html");
- add_article("scrap1_47.html");
- add_article("scrap1_4.html");
- add_article("scrap1_5.html");
- add_article("scrap1_6.html");
- add_article("scrap1_7.html");
- add_article("scrap1_8.html");
- add_article("scrap1_9.html");
- add_article("scrap1_U.0.html");
- add_article("scrap1_U.1.html");
-?>
diff --git a/php/blog/blog_lib.php b/php/blog/blog_lib.php
@@ -1,53 +0,0 @@
-<?php
-/*
- This file is part of GNU TALER.
- Copyright (C) 2014, 2015, 2016 INRIA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU Lesser General Public License as published by the Free Software
- Foundation; either version 2.1, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License along with
- TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
-*/
-
- /**
- * Take a (article's) filename and return its
- * teaser. It has the articles folder hardcoded
- */
- function get_title($name){
- $content = file_get_contents("articles/$name.html");
- $doc = new DOMDocument();
- $doc->loadHTML($content);
- $finder = new DOMXPath($doc);
- $query_set = $finder->query("//h1[@class='chapter' or @class='unnumbered']");
- if (1 != $query_set->length)
- return "No title for this item";
- // assuming all the articles are well-formed..
- return $query_set->item(0)->nodeValue;
- }
-
- /**
- * Take a (article's) filename and return its
- * DOM. It has the articles folder hardcoded
- */
- function get_article($name){
- $raw_content = file_get_contents("articles/$name.html");
- return $raw_content;
- }
-
- /**
- * Fetch the page $page and return its
- * DOM.
- */
- function get_page($page){
- $content = file_get_contents($page);
- $doc = new DOMDocument();
- $doc->loadHTML($content);
- return $doc;
- }
-?>
diff --git a/php/blog/essay_cc-fulfillment.php b/php/blog/essay_cc-fulfillment.php
@@ -1,36 +0,0 @@
-<?php
-/*
- This file is part of GNU TALER.
- Copyright (C) 2014, 2015, 2016 INRIA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU Lesser General Public License as published by the Free Software
- Foundation; either version 2.1, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License along with
- TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
-
- @author Marcello Stanisci
-*/
-
- include '../../copylib/util.php';
- include './blog_lib.php';
-
- $article = get($_GET['article']);
- if (null == $article){
- http_response_code(400);
- echo "Bad request (no article specified)";
- return;
- }
-
- session_start();
- $payments = &pull($_SESSION, "payments", array());
- $payments[$article] = array("ispayed" => true);
- $fulfillment_url = url_rel("essay_fulfillment.php");
- header("Location: $fulfillment_url");
- die();
-?>
diff --git a/php/blog/essay_contract.php b/php/blog/essay_contract.php
@@ -1,72 +0,0 @@
-<?php
-/*
- This file is part of GNU TALER.
- Copyright (C) 2014, 2015, 2016 INRIA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU Lesser General Public License as published by the Free Software
- Foundation; either version 2.1, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License along with
- TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
-*/
-
- include("../../copylib/merchants.php");
- include("../../copylib/util.php");
- include("../../copylib/config.php");
- include("./blog_lib.php");
- $article = get($_GET['article']);
- if (null == $article){
- echo message_from_missing_param("article", "/");
- die();
- }
- // send contract
- $transaction_id = rand(0, 1001);
- $now = new DateTime('now');
- $teaser = get_title($article);
- $amount_value = 0;
- $amount_fraction = 50000;
- $teatax = array ();
- $transaction_id = rand(0, 1001);
- $fulfillment_url = url_rel("essay_fulfillment.php")
- . '×tamp=' . $now->getTimestamp()
- . '&tid=' . $transaction_id;
-
- $contract_json = generate_contract(array(
- "amount_value" => $amount_value,
- "amount_fraction" => $amount_fraction,
- "currency" => $MERCHANT_CURRENCY,
- "refund_delta" => $REFUND_DELTA,
- "transaction_id" => $transaction_id,
- "description" => trim($teaser),
- "merchant_name" => "Free Software Foundation (demo)",
- "product_id" => $article,
- "correlation_id" => $article,
- "taxes" => $teatax,
- "now" => $now,
- "fulfillment_url" => $fulfillment_url)
- );
- $resp = give_to_backend("backend/contract",
- $contract_json);
- $status_code = $resp->getResponseCode();
- http_response_code ($status_code);
- if ($status_code != 200){
- echo json_encode(array(
- 'error' => "internal error",
- 'hint' => "backend indicated error",
- 'detail' => $resp->body->toString()
- ), JSON_PRETTY_PRINT);
- }
- else {
- $got_json = json_decode($resp->body->toString(), true);
- $hc = $got_json["H_contract"];
- session_start();
- $payments = &pull($_SESSION, "payments", array());
- $payments[$article] = array("ispayed" => false);
- echo $resp->body->toString();
- }
-?>
diff --git a/php/blog/essay_fulfillment.php b/php/blog/essay_fulfillment.php
@@ -1,89 +0,0 @@
-<?php
-/*
- This file is part of GNU TALER.
- Copyright (C) 2014, 2015, 2016 INRIA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU Lesser General Public License as published by the Free Software
- Foundation; either version 2.1, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License along with
- TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
-*/
- include '../../copylib/util.php';
- include '../../copylib/merchants.php';
- include '../../copylib/config.php';
- include './blog_lib.php';
-
- $article = get($_GET['article']);
- if (null == $article){
- http_response_code(400);
- echo message_from_missing_param("article", "/");
- return;
- }
- session_start();
- //syslog($LOG_ERR, "merchant: official log system");
- $payments = &pull($_SESSION, 'payments', array());
- $my_payment = &pull($payments, $article, false);
-
- $pay_url = url_rel("essay_pay.php");
- $offering_url = url_rel("essay_fulfillment.php", true);
- $offering_url .= "?article=$article";
-
- // In PHP false == null
- if (null == get($payments[$article]['ispayed']) || false == $my_payment){
- $tid = get($_GET['tid']);
- $timestamp = get($_GET['timestamp']);
- // 1st time
- if (null == $tid || null == $timestamp){
- $js_code = "get_contract(\"$article\");";
- $cc_page = template("./essay_cc-form.html", array('article' => $article, 'jscode' => $js_code));
- echo $cc_page;
- return;
- }
- // using deeplink (whether 1st time or not)
- // restore contract
- $now = new DateTime();
- $now->setTimestamp(intval($timestamp));
-
- $contract_rec = generate_contract(array(
- "amount_value" => 0,
- "amount_fraction" => 50000,
- "currency" => $MERCHANT_CURRENCY,
- "refund_delta" => $REFUND_DELTA,
- "merchant_name" => "Free Software Foundation (demo)",
- "transaction_id" => intval($tid),
- "description" => trim(get_title($article)),
- "product_id" => $article,
- "correlation_id" => $article,
- "taxes" => array(),
- "now" => $now,
- "fulfillment_url" => get_full_uri())
- );
- $resp = give_to_backend("backend/contract",
- $contract_rec);
- if ($resp->getResponseCode() != 200){
- echo json_encode(array(
- 'error' => "internal error",
- 'hint' => "non hashable contract",
- 'detail' => $resp->body->toString()
- ), JSON_PRETTY_PRINT);
- die();
- }
- $hc = json_decode($resp->body->toString(), true)['H_contract'];
- $my_payment['hc'] = $hc;
- //syslog($LOG_INFO, "sending payment event");
- $js_code = "taler.executePayment(\"$hc\", \"$pay_url\", \"$offering_url\");";
- $cc_page = template("./essay_cc-form.html", array('article' => $article, 'jscode' => $js_code));
- echo $cc_page;
- return;
- }
- // control here == article payed
- //syslog($LOG_INFO, "showing article");
- $article = get_article($article);
- echo $article;
-?>
diff --git a/php/blog/essay_pay.php b/php/blog/essay_pay.php
@@ -1,77 +0,0 @@
-<?php
-/*
- This file is part of GNU TALER.
- Copyright (C) 2014, 2015, 2016 INRIA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU Lesser General Public License as published by the Free Software
- Foundation; either version 2.1, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License along with
- TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
-*/
-
- include("../../copylib/merchants.php");
- include("../../copylib/util.php");
- include("./blog_lib.php");
-
- /*FIXME: the following log gets annoyingly sent to _any_ open terminal */
- /*syslog($LOG_INFO, "paying");*/
-
- $article = get($_GET["article"]);
- if (empty($article)){
- http_response_code(400);
- echo json_encode(array(
- "error" => "missing parameter",
- "parameter" => "article"
- ));
- return;
- }
- $deposit_permission = file_get_contents('php://input');
- session_start();
- if (!isset($_SESSION["payments"])) {
- $json = json_encode(
- array(
- "error" => "no payments ongoing",
- "status" => 500,
- "detail" => "the shop has no state for any article"
- )
- );
- echo $json;
- die();
- }
- $payments = &pull($_SESSION, "payments", array());
- $dec_dep_perm = json_decode($deposit_permission, true);
- if ($dec_dep_perm['H_contract'] != $payments[$article]['hc']){
- $json = json_encode(
- array(
- "error" => "ill behaved wallet",
- "status" => 400,
- "detail" => "article payed differs from article to be shown"
- )
- );
- echo $json;
- die();
- }
-
- // with the article that's going to be payed
- $resp = give_to_backend("backend/pay",
- $deposit_permission);
- $status_code = $resp->getResponseCode();
- http_response_code ($status_code);
- if ($status_code != 200)
- {
- $json = json_encode(
- array(
- "error" => "backend error",
- "status" => $status_code,
- "detail" => $resp->body->toString()));
- echo $json;
- die();
- }
- $payments[$article]['ispayed'] = true;
-?>
diff --git a/php/blog/images.php b/php/blog/images.php
@@ -1,58 +0,0 @@
-<?php
-/*
- This file is part of GNU TALER.
- Copyright (C) 2014, 2015, 2016 INRIA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU Lesser General Public License as published by the Free Software
- Foundation; either version 2.1, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License along with
- TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
-*/
-
- include '../../copylib/util.php';
-
- $article = get($_GET['article']);
- $image = get($_GET['image']);
- session_start();
- $payments = &pull($_SESSION, 'payments', false);
- if (!$payments) {
- echo "No session active";
- return 400;
- }
- if (null == get($payments[$article]['ispayed'])) {
- echo "Article not payed";
- return 400;
- }
-
- $db_filename = "articles/articles_images.json";
- $json_str;
- if (file_exists($db_filename))
- $json_str = file_get_contents($db_filename);
- else {
- echo "Internal server error: data registry not found";
- return 500;
- }
- $db = json_decode($json_str, true);
- $article_images = get($db[$article . ".html"]);
- if (null == $article_images) {
- echo "This article has no images to sell";
- return 400;
- }
- if (false === array_search($image, $article_images)) {
- echo "Requested image does not belong to article '$article'";
- return 400;
- }
-
- $image_path = "data/" . $image;
- $fp = fopen($image_path, 'rb');
- header("Content-Type: image/png"); // fix image extension
- header("Content-Length: " . filesize($image_path));
- fpassthru($fp);
- exit;
-?>
diff --git a/php/copylib/config.php b/php/copylib/config.php
@@ -1,40 +0,0 @@
-<?php
-/*
- This file is part of GNU TALER.
- Copyright (C) 2014, 2015 INRIA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU Lesser General Public License as published by the Free Software
- Foundation; either version 2.1, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License along with
- TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
-*/
-
-$REFUND_DELTA = 'P3M';
-// set to false when done with local tests
-$explicit_currency = "PUDOS";
-$MERCHANT_CURRENCY = $explicit_currency;
-
-$host = $_SERVER["HTTP_HOST"];
-switch ($host) {
-case "blog.demo.taler.net":
-case "shop.demo.taler.net":
- $MERCHANT_CURRENCY = "KUDOS";
- break;
-case "blog.test.taler.net":
-case "shop.test.taler.net":
- $MERCHANT_CURRENCY = "PUDOS";
- break;
-default:
- if(false == $explicit_currency){
- http_response_code (500);
- echo "<p>Bank configuration error: No currency for domain $host</p>\n";
- die();
- }
-}
-?>
diff --git a/php/copylib/merchants.php b/php/copylib/merchants.php
@@ -1,105 +0,0 @@
-<?php
-/*
- This file is part of GNU TALER.
- Copyright (C) 2014, 2015 INRIA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU Lesser General Public License as published by the Free Software
- Foundation; either version 2.1, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License along with
- TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
-*/
-
-/**
- * Return a contract proposition to forward to the backend
- * Note that `teatax` is an associative array representing a
- * Taler-style amount (so it has the usual <amount,fration,currency>
- * triple). Moreover, `teatax` should be a *list* of taxes
- */
-function generate_contract($args){
- $contract = array ('amount' =>
- array ('value' => $args['amount_value'],
- 'fraction' => $args['amount_fraction'],
- 'currency' => $args['currency']),
- 'max_fee' =>
- array ('value' => 3,
- 'fraction' => 01010,
- 'currency' => $args['currency']),
- 'transaction_id' => $args['transaction_id'],
- 'products' => array (
- array ('description' => $args['description'],
- 'quantity' => 1,
- 'price' =>
- array ('value' => $args['amount_value'],
- 'fraction' => $args['amount_fraction'],
- 'currency' => $args['currency']),
- 'product_id' => $args['product_id'],
- 'taxes' => $args['taxes'],
- 'delivery_date' => "Some Date Format",
- 'delivery_location' => 'LNAME1')),
- 'timestamp' => "/Date(" . $args['now']->getTimestamp() . ")/",
- 'expiry' =>
- "/Date(" . $args['now']->add(new DateInterval('P2W'))->getTimestamp() . ")/",
- 'refund_deadline' =>
- "/Date(" . $args['now']->add(new DateInterval($args['refund_delta']))->getTimestamp() . ")/",
- 'repurchase_correlation_id' => $args['correlation_id'],
- 'fulfillment_url' => $args['fulfillment_url'],
- 'merchant' =>
- array ('address' => 'LNAME2',
- 'name' => $args['merchant_name'],
- 'jurisdiction' => 'LNAME3'),
- 'locations' =>
- array ('LNAME1' =>
- array ('country' => 'Test Country',
- 'city' => 'Test City',
- 'state' => 'Test State',
- 'region' => 'Test Region',
- 'province' => 'Test Province',
- 'ZIP code' => 4908,
- 'street' => 'test street',
- 'street number' => 20),
- 'LNAME2' =>
- array ('country' => 'Test Country',
- 'city' => 'Test City',
- 'state' => 'Test State',
- 'region' => 'Test Region',
- 'province' => 'Test Province',
- 'ZIP code' => 4908,
- 'street' => 'test street',
- 'street number' => 20),
- 'LNAME3' =>
- array ('country' => 'Test Country',
- 'city' => 'Test City',
- 'state' => 'Test State',
- 'region' => 'Test Region',
- 'province' => 'Test Province',
- 'ZIP code' => 4908)));
- $json = json_encode (array ('contract' => $contract), JSON_PRETTY_PRINT);
- return $json;
-}
-
-
-/**
- * Feed `$json` to the backend and return the "(pecl) http response object"
- * corresponding to the `$backend_relative_url` call
- */
-function give_to_backend($backend_relative_url, $json){
- $url = url_join("http://".$_SERVER["HTTP_HOST"], $backend_relative_url);
-
- $req = new http\Client\Request("POST",
- $url,
- array ("Content-Type" => "application/json"));
-
- $req->getBody()->append($json);
-
- // Execute the HTTP request
- $client = new http\Client;
- $client->enqueue($req)->send();
- return $client->getResponse();
-}
-?>
diff --git a/php/copylib/util.php b/php/copylib/util.php
@@ -1,88 +0,0 @@
-<?php
-/*
- This file is part of GNU TALER.
- Copyright (C) 2014, 2015 INRIA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU Lesser General Public License as published by the Free Software
- Foundation; either version 2.1, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License along with
- TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
-*/
-
-function get(&$var, $default=null) {
- return isset($var) ? $var : $default;
-}
-
-function &pull(&$arr, $idx, $default) {
- if (!isset($arr[$idx])) {
- $arr[$idx] = $default;
- }
- return $arr[$idx];
-}
-
-function message_from_missing_param($missing, $link, $link_name="home page"){
- return "<p>Bad request, no $missing given. Return to <a href=\"$link\">$link_name</a></p>";
-}
-
-function article_state_to_str($article_state){
- if(null == $article_state || !isset($article_state))
- return "undefined state";
- $str = "Is payed? ";
- $str .= $article_state['ispayed'] ? "true," : "false,";
- if(!isset($article_state['hc']))
- $str .= " no hashcode for this article";
- else $str .= " " . $article_state['hc'];
- return $str;
-}
-
-function log_string($str){
- file_put_contents("/tmp/frontend.dbg", $str . "\n", FILE_APPEND);
-}
-
-function get_full_uri(){
-
- return $_SERVER['REQUEST_SCHEME'] . '://'
- . $_SERVER['HTTP_HOST']
- . $_SERVER['REQUEST_URI'];
-}
-
-function url_join($base, $path, $strip=false) {
- $flags = $strip ? (http\Url::STRIP_PATH|http\URL::STRIP_QUERY) : 0;
- return (new http\URL($base, null, $flags))
- ->mod(array ("path" => $path), http\Url::JOIN_PATH|http\URL::SANITIZE_PATH)
- ->toString();
-}
-
-// Get a url with a path relative to the
-// current script's path.
-function url_rel($path, $strip=false) {
- return url_join(
- $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'],
- $path,
- $strip);
-}
-
-function template($file, $array) {
- if (file_exists($file)) {
- $output = file_get_contents($file);
- foreach ($array as $key => $val) {
- $replace = '{'.$key.'}';
- $output = str_replace($replace, $val, $output);
- }
- return $output;
- }
-}
-
-function str_to_dom($str){
- $doc = new DOMDocument();
- $doc->loadHTML($str);
- return $doc;
-
-}
-?>
diff --git a/php/doc/Makefile.am b/php/doc/Makefile.am
@@ -1,15 +0,0 @@
-# This Makefile is in the public domain
-
-all: manual.pdf manual.html
-
-manual.pdf: arch.pdf manual.texi
- texi2pdf manual.texi
-manual.html: arch.jpg manual.texi
- texi2html manual.texi
-arch.pdf: arch.dot
- dot -Tpdf arch.dot > arch.pdf
-arch.jpg: arch.dot
- dot -Tjpg arch.dot > arch.jpg
-
-info_TEXINFOS = manual.texi
-manual_TEXINFOS = version.texi
diff --git a/php/shop/checkout.php b/php/shop/checkout.php
@@ -1,183 +0,0 @@
-<!DOCTYPE html>
-<!--
- This file is aprt of GNU TALER
- Copyright (C) 2014,2015, 2016 INRIA
-
- TALER is free software: you can
- redistribute it and/or modify it under the terms of the GNU
- Lesser General Public License (GNU LGPL) as published by the
- Free Software
- Foundation, either version 3 of the License, or (at your option)
- any later version. The code is distributed WITHOUT ANY WARRANTY;
- without even the implied warranty of MERCHANTABILITY or FITNESS
- FOR A PARTICULAR PURPOSE. See the GNU LGPL for more details.
-
- As additional permission under GNU LGPL version 3 section 7, you
- may distribute non-source (e.g., minimized or compacted) forms of
- that code without the copy of the GNU LGPL normally required by
- section 4, provided you include this license notice and a URL
- through which recipients can access the Corresponding Source.
-
--->
-<html>
-<head>
- <title>Toy Store - Payment method - Taler Demo</title>
- <link rel="stylesheet" type="text/css" href="web-common/style.css">
- <script type="application/javascript" src="web-common/taler-presence.js"></script>
-</head>
-<body>
-
-<?php
- // get the donation information from form
- $donation_receiver = $_POST['donation_receiver'];
- $donation_amount = $_POST['donation_amount'];
- $donation_currency = $_POST['donation_currency'];
-
- // get frational part
- list ($donation_value, $donation_fraction) = explode (".", $donation_amount, 2);
- // create PHP session and store donation information in session
- $donation_fraction = (float) ("0." . $donation_fraction);
- session_start();
- $_SESSION['receiver'] = $donation_receiver;
- $_SESSION['amount_value'] = (int) $donation_amount;
- $_SESSION['amount_fraction'] = (int) ($donation_fraction * 1000000);
- $_SESSION['currency'] = $donation_currency;
-?>
-
- <header>
- <div id="logo">
- <svg height="100" width="100">
- <circle cx="50" cy="50" r="40" stroke="darkcyan" stroke-width="6" fill="white" />
- <text x="19" y="82" font-family="Verdana" font-size="90" fill="darkcyan">S</text>
- </svg>
- </div>
- <!--#include virtual="web-common/dropdown-navbar.html" -->
- <h1 class="nav">Toy Store - Select payment method</h1>
- </header>
-
- <aside class="sidebar" id="left">
- </aside>
-
- <section id="main">
- <article>
- <h1>Select your payment method</h1>
-
- <p>
- This is an example for a "checkout" page of a Web shop.
- On the previous page, you have created the shopping cart
- and decided which product to buy (i.e. which project to
- donate KUDOS to). Now in this page, you are asked to
- select a payment option. As Taler is not yet universally
- used, we expect merchants will offer various payment options.
- </p>
- <p>
- The page also demonstrates how to only enable (or show) the Taler
- option if Taler is actually supported by the browser. For example,
- if you disable the Taler extension now, the Taler payment option
- will be disabled in the page. Naturally, you could also trivially
- hide the Taler option entirely by changing the visibility instead.
- </p>
- <p>
- Note that you MUST select Taler here for the demo to continue,
- as the other payment options are just placeholders and not
- really working in the demonstration. Also, it is of course
- possible to ask the user to make this choice already on the
- previous page (with the shopping cart), we just separated the
- two steps to keep each step as simple as possible.
- </p>
-
- <form name="tform" action="" method="POST">
- <div id="opt-form" align="left"><br>
- <input type="radio" name="payment_system" value="lisa"
- id="lisa-radio-button-id">Lisa</input>
- <br/>
- <input type="radio" name="payment_system" value="ycard">You Card</input>
- <br/>
- <input type="radio" name="payment_system" value="cardme">Card Me</input>
- <br/>
- <input type="radio" name="payment_system" value="taler"
- checked
- id="taler-radio-button-id" class="taler-installed-enable">Taler</input>
- <br/>
- <input type="button" onclick="pay(this.form)" value="Ok"></input>
- </div>
- </form>
-
- </article>
- </section>
-
-<script type="text/javascript">
-
-/* This function is called from "taler_pay" after
- we downloaded the JSON contract from the merchant.
- We now need to pass it to the extension. */
-function handle_contract(contract_wrapper) {
- var cEvent = new CustomEvent('taler-confirm-contract', {
- detail: {
- contract_wrapper: contract_wrapper
- }
- });
- document.dispatchEvent(cEvent);
-};
-
-
-/* Trigger Taler contract generation on the server, and pass the
- contract to the extension once we got it. */
-function taler_pay(form) {
- var contract_request = new XMLHttpRequest();
-
- /* Note that the URL we give here is specific to the Demo-shop
- and not dictated by the protocol: each web shop can
- have its own way of generating and transmitting the
- contract, there just must be a way to get the contract
- and to pass it to the wallet when the user selects 'Pay'. */
- contract_request.open("GET", "generate_taler_contract.php", true);
- contract_request.onload = function (e) {
- if (contract_request.readyState == 4) {
- if (contract_request.status == 200) {
- /* display contract_requestificate (i.e. it sends the JSON string
- to the extension) alert (contract_request.responseText); */
- console.log("response text:", contract_request.responseText);
- var contract_wrapper = JSON.parse(contract_request.responseText);
- if (!contract_wrapper) {
- console.error("response text is invalid JSON");
- return;
- }
- handle_contract(contract_wrapper);
- } else {
- /* There was an error obtaining the contract from the merchant,
- obviously this should not happen. To keep it simple, we just
- alert the user to the error. */
- alert("Failure to download contract from merchant " +
- "(" + contract_request.status + "):\n" +
- contract_request.responseText);
- }
- }
- };
- contract_request.onerror = function (e) {
- /* There was an error obtaining the contract from the merchant,
- obviously this should not happen. To keep it simple, we just
- alert the user to the error. */
- alert("Failure requesting the contract:\n" + contract_request.statusText);
- };
- contract_request.send();
-}
-
-
-/* This function is called when the user presses the
- 'Ok' button. We are now supposed to trigger the
- "correct" payment system logic. For this demo, we
- only handle "taler". */
-function pay(form) {
- var choice = form.elements["payment_system"].value;
- if (choice == "taler") {
- taler_pay(form);
- }
- else {
- alert("You selected '" + choice + "', but we do not support this payment system in the demo.");
- }
-};
-
-</script>
-</body>
-</html>
diff --git a/php/shop/config.php b/php/shop/config.php
@@ -1,20 +0,0 @@
-<?php
-/* This file is in the public domain */
-
-$host = $_SERVER["HTTP_HOST"];
-
-switch ($host) {
-case "shop.demo.taler.net":
- $SHOP_CURRENCY = "KUDOS";
- break;
-case "shop.test.taler.net":
- $SHOP_CURRENCY = "PUDOS";
- break;
-default:
- http_response_code ($status_code);
- echo "<p>Configuration error: No currency for domain $host</p>\n";
- die();
- break;
-}
-
-?>
diff --git a/php/shop/fulfillment.php b/php/shop/fulfillment.php
@@ -1,134 +0,0 @@
-<!DOCTYPE html>
-<!--
- This file is part of GNU TALER.
- Copyright (C) 2014, 2015, 2016 INRIA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU Lesser General Public License as published by the Free Software
- Foundation; either version 2.1, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
--->
-<html lang="en">
-<head>
- <title>Taler's "Demo" Shop</title>
- <link rel="stylesheet" type="text/css" href="web-common/style.css">
- <script type="application/javascript" src="web-common/taler-wallet-lib.js"></script>
- <script type="application/javascript">
- function makeVisible() {
- function cb() {
- document.body.style.display = "";
- }
- document.addEventListener("DOMContentLoaded", cb, false);
- }
- </script>
-</head>
-<body style="display:none;">
- <header>
- <div id="logo">
- <svg height="100" width="100">
- <circle cx="50" cy="50" r="40" stroke="darkcyan" stroke-width="6" fill="white" />
- <text x="19" y="82" font-family="Verdana" font-size="90" fill="darkcyan">S</text>
- </svg>
- </div>
- <!--#include virtual="web-common/dropdown-navbar.html"-->
- <h1 class="nav">Toy Store - Product Page</h1>
- </header>
-
- <aside class="sidebar" id="left">
- </aside>
-
- <section id="main">
- <article>
-<?php
-
-include '../../copylib/util.php';
-include "../../copylib/merchants.php";
-
-$receiver = get($_GET["receiver"]);
-$now = new DateTime();
-$now->setTimestamp(intval(get($_GET["timestamp"])));
-
-if (empty($receiver)) {
- http_response_code(400);
- echo "<p>Bad request (UUID missing)</p>";
- return;
-}
-
-session_start();
-
-$payments = &pull($_SESSION, 'payments', array());
-$my_payment = &pull($payments, $receiver, array());
-
-// This will keep the query parameters.
-$pay_url = url_rel("pay.php");
-$offering_url = url_rel("index.php", true);
-
-if (array() === $my_payment || true !== get($my_payment["is_payed"], false)) {
- // restore contract
- $contract = generate_contract(array(
- "amount_value" => intval($_GET['aval']),
- "amount_fraction" => intval($_GET['afrac']),
- "currency" => $_GET['acurr'],
- "refund_delta" => 'P3M',
- "transaction_id" => intval($_GET['tid']),
- "description" => "Donation to " . $receiver,
- "product_id" => "unused",
- "correlation_id" => "",
- "merchant_name" => "Kudos Inc.",
- "taxes" => array(),
- "now" => $now,
- "fulfillment_url" => get_full_uri())
- );
-
- $resp = give_to_backend("backend/contract", $contract);
- if ($resp->getResponseCode() != 200){
- echo json_encode(array(
- 'error' => "internal error",
- 'hint' => "failed to regenerate contract",
- 'detail' => $resp->body->toString()
- ), JSON_PRETTY_PRINT);
- return;
- }
-
- $hc = json_decode($resp->body->toString(), true)['H_contract'];
- $my_payment['is_payed'] = false;
- $my_payment['hc'] = $hc;
- echo "<p>you have not payed for this contract: " . $hc . "</p>";
- echo "<p>Asking the wallet to re-execute it ... </p>";
- echo "<script>taler.executePayment('$hc', '$pay_url', '$offering_url');</script>";
- return;
-}
-
-$news = false;
-switch ($receiver) {
- case "Taler":
- $news = "https://taler.net/news";
- break;
- case "GNUnet":
- $news = "https://gnunet.org/";
- break;
- case "Tor":
- $news = "https://www.torproject.org/press/press.html.en";
- break;
-}
-
-$msg = "<p>Thanks for donating to " . $receiver . ".</p>";
-if ($news) {
- $msg .= "<p>Check our latest <a href=\"" . $news . "\">news!</a></p>";
-}
-
-echo $msg;
-
-echo "<script>makeVisible();</script>";
-
-?>
- </article>
- </section>
-</body>
-</html>
diff --git a/php/shop/generate_taler_contract.php b/php/shop/generate_taler_contract.php
@@ -1,92 +0,0 @@
-<?php
-/*
- This file is part of GNU TALER.
- Copyright (C) 2014-2016 INRIA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU Lesser General Public License as published by the Free Software
- Foundation; either version 2.1, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License along with
- TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
- */
-
-include '../../copylib/util.php';
-include "../../copylib/config.php";
-include "../../copylib/merchants.php";
-
-session_start();
-
-if (!isset($_SESSION['receiver']))
-{
- http_response_code(400);
- die();
-}
-
-$receiver = $_SESSION['receiver'];
-$amount_value = intval($_SESSION['amount_value']);
-$amount_fraction = intval($_SESSION['amount_fraction']);
-$currency = $_SESSION['currency'];
-
-// generate a front-end transaction id.
-// In production context, we might want to
-// record this value somewhere together
-// with the rest of the contract data.
-$transaction_id = rand(0, 2<<40);
-
-// Human-readable description of this deal
-$desc = "Donation to " . $receiver;
-
-// Take a timestamp
-$now = new DateTime('now');
-
-// Include all information so we can
-// restore the contract without storing it
-$fulfillment_url = url_rel("fulfillment.php")
- . '?timestamp=' . $now->getTimestamp()
- . '&receiver=' . urlencode($receiver)
- . '&aval=' . urlencode($amount_value)
- . '&afrac=' . urlencode($amount_fraction)
- . '&acurr=' . urlencode($currency)
- . '&tid=' . $transaction_id;
-
-$contract = generate_contract(array(
- "amount_value" => $amount_value,
- "amount_fraction" => $amount_fraction,
- "currency" => $currency,
- "refund_delta" => 'P3M',
- "transaction_id" => $transaction_id,
- "description" => $desc,
- "product_id" => "unused",
- "correlation_id" => "",
- "merchant_name" => "Kudos Inc.",
- "taxes" => array(),
- "now" => $now,
- "fulfillment_url" => $fulfillment_url)
-);
-
-$resp = give_to_backend("backend/contract", $contract);
-
-// Our response code is the same we got from the backend:
-http_response_code($resp->getResponseCode());
-
-// Now generate our body
-if ($resp->getResponseCode() != 200)
-{
- echo json_encode(array(
- 'error' => "internal error",
- 'hint' => "backend indicated error",
- 'detail' => $resp->body->toString()
- ), JSON_PRETTY_PRINT);
-}
-else
-{
- # no state here
- $got_json = json_decode($resp->body->toString(), true);
- echo json_encode ($got_json, JSON_PRETTY_PRINT);
-}
-?>
diff --git a/php/shop/index.php b/php/shop/index.php
@@ -1,139 +0,0 @@
-<!DOCTYPE html>
-<!--
- This file is part of GNU TALER.
- Copyright (C) 2014, 2015, 2016 INRIA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU Lesser General Public License as published by the Free Software
- Foundation; either version 2.1, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License along with
- TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
--->
-<?php
-require_once "../../copylib/config.php";
-session_destroy();
-?>
-<html lang="en">
-<head>
- <title>Taler Donation Demo</title>
- <link rel="stylesheet" type="text/css" href="web-common/style.css">
- <script src="web-common/taler-presence.js" type="text/javascript"></script>
-<script type="text/javascript">
-<?php
-echo "\tvar shop_currency = '$MERCHANT_CURRENCY';\n";
-?>
-
- function addOption(value, label) {
- var s = document.getElementById("taler-donation");
- var e = document.createElement("option");
- e.textContent = label ? label : ("".concat(value, " ", shop_currency));
- e.value = value;
- s.appendChild(e);
- }
-
- function init() {
- var e = document.getElementById("currency-input");
- e.value = shop_currency;
- addOption("0.1");
- addOption("1.0");
- addOption("6.0", "".concat(5, " ", shop_currency));
- addOption("10");
- }
-
- document.addEventListener("DOMContentLoaded", init);
-
-</script>
-</head>
-
-<body>
- <header>
- <div id="logo">
- <svg height="100" width="100">
- <circle cx="50" cy="50" r="40" stroke="darkcyan" stroke-width="6" fill="white" />
- <text x="19" y="82" font-family="Verdana" font-size="90" fill="darkcyan">S</text>
- </svg>
- </div>
- <!--#include virtual="web-common/dropdown-navbar.html" -->
- <h1 class="nav">Toy "Store" - Taler Demo</h1>
- </header>
-
- <aside class="sidebar" id="left">
- </aside>
-
- <section id="main">
- <article>
- <h1>Welcome to the Taler Donation "Shop" Demo</h1>
-
- <p>This "toy" website provides you with the ability to
- experience using the
- <a href="https://www.taler.net/">GNU Taler</a>
- payment system without using
- valuable currency. Instead, for the demonstrator we
- will be using a "toy" currency, KUDOS. However, please remember that
- Taler is designed to work with ordinary currencies, such
- as Dollars or Euros, not just toy currencies.
- <br>
- This page, <tt>shop.demo.taler.net</tt> models the behavior of a
- typical Web shop supporting Taler. The other pages of the demo,
- <tt>exchange.demo.taler.net</tt> and
- <tt>bank.demo.taler.net</tt>, correspond to a Taler exchange
- and bank with tight Taler integration respectively. You
- may also enjoy visiting the <tt>blog.demo.taler.net</tt>.
- </p>
- </article>
-
- <div class="taler-installed-hide">
- <h2>Installing the Taler wallet</h2>
- First, you need to install the Taler wallet browser extension.
- Install the wallet
- <span id="install-done" style="visibility: hidden">(done)</span>
- <ul>
- <li>from the app store for <a href="https://chrome.google.com/webstore/detail/gnu-taler-wallet/millncjiddlpgdmkklmhfadpacifaonc">Google
- Chrome and Chromium</a>
- </li>
- <li>By visiting our <a href="/landing">landing page</a>.
- </li>
- </ul>
- Wallets for other browsers will be provided in the near future.
- </div>
-
- <div class="taler-installed-show">
- <p>Please choose a project and the amount of KUDOS you
- wish to donate:</p>
-
- <form name="tform" action="checkout.php" method="POST">
- <div class="participation" id="fake-shop">
- <br>
- <input type="radio" name="donation_receiver" value="Taler" checked="true">GNU Taler</input>
- <br>
- <input type="radio" name="donation_receiver" value="Tor">Tor</input>
- <br>
- <input type="radio" name="donation_receiver" value="GNUnet">GNUnet</input>
- <br>
- <select id="taler-donation" name="donation_amount">
- <!-- options will be added dynamically -->
- </select>
- <input id="currency-input" type="hidden" name="donation_currency"/>
- <input type="submit" name="keyName" value="Donate!"/>
- <br>
- <br>
- </div>
- </form>
- <p>
- (*) To make it a bit more fun, the 5 KUDOS option
- is deliberately implemented with a fault: the merchant will try to
- make you donate 6 KUDOS instead of the 5 KUDOS you got to see. But do
- not worry, you will be given the opportunity to review the
- final offer from the merchant in a window secured
- by the Taler extension. That way, you can spot the
- error before committing to an incorrect contract.
- </p>
- </div>
- </section>
-</body>
-</html>
diff --git a/php/shop/pay.php b/php/shop/pay.php
@@ -1,101 +0,0 @@
-<?php
-/*
- This file is part of GNU TALER.
- Copyright (C) 2014, 2015, 2016 INRIA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU Lesser General Public License as published by the Free Software
- Foundation; either version 2.1, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License along with
- TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/licenses/>
-
-*/
-
-include '../../copylib/util.php';
-log_string("getting money");
-// so we won't generate a response for the wrong receiver.
-$receiver = get($_GET["receiver"]);
-if (empty($receiver))
-{
- http_response_code(400);
- echo json_encode(array(
- "error" => "missing parameter",
- "parameter" => "receiver"
- ));
- return;
-}
-
-session_start();
-$payments = &pull($_SESSION, "payments", array());
-
-if (!isset($payments[$receiver]))
-{
- http_response_code(400);
- echo json_encode(array(
- "error" => "no payment session active"
- ));
- return;
-}
-
-$post_body = file_get_contents('php://input');
-$deposit_permission = json_decode ($post_body, true);
-
-// Check if the receiver is actually *mentioned* in the contract
-if ($payments[$receiver]['hc'] != $deposit_permission['H_contract']) {
-
- $json = json_encode(
- array(
- "error" => "ill behaved wallet",
- "status" => 400,
- "detail" => "deposit permission mismatches with reconstructed contract"
- )
- );
- echo $json;
- die();
-}
-
-
-/* Craft the HTTP request, note that the backend
- could be on an entirely different machine if
- desired. */
-
-// Backend is relative to the shop site.
-$url = url_rel("backend/pay");
-
-$req = new http\Client\Request("POST",
- $url,
- array("Content-Type" => "application/json"));
-$req->getBody()->append (json_encode ($deposit_permission));
-
-// Execute the HTTP request to the backend
-$client = new http\Client;
-$client->enqueue($req)->send();
-
-// Fetch the response
-$resp = $client->getResponse();
-$status_code = $resp->getResponseCode();
-
-// Our response code is the same we got from the backend:
-http_response_code($status_code);
-
-// Now generate our body
-if ($status_code != 200)
-{
- $json = json_encode(
- array(
- "error" => "backend error",
- "status" => $status_code,
- "detail" => $resp->body->toString()));
- echo $json;
- die();
-}
-
-$payments = &pull($_SESSION, "payments", array());
-$payments[$receiver]['is_payed'] = true;
-
-?>