2 require_once "LoomClient.php";
3 require_once "LoomRandom.php";
4 require_once "bcbitwise.php";
5 //require_once "Diceware.php"; // required below only when used (it's big)
8 if (get_magic_quotes_gpc()) return stripslashes($x);
12 $page = mq($_GET['page']);
13 if ($page == '') $page = 'grid';
14 $common_type = mq($_POST['common_type']);
15 $default_server = 'https://loom.cc/';
16 $loom_server = mq($_REQUEST['loom_server']);
17 if ($loom_server == '') $loom_server = $default_server;
18 if (substr($loom_server, -1) != '/') $loom_server .= '/';
19 $buy_loc = mq($_POST['buy_loc']);
20 $buy_usage = mq($_POST['buy_usage']);
21 $issuer_orig = mq($_POST['issuer_orig']);
22 $issuer_dest = mq($_POST['issuer_dest']);
23 $touch_loc = mq($_POST['touch_loc']);
24 $look_hash = mq($_POST['look_hash']);
25 $move_qty = mq($_POST['move_qty']);
26 $move_orig = mq($_POST['move_orig']);
27 $move_dest = mq($_POST['move_dest']);
28 $content = mq($_POST['content']);
29 $id = mq($_POST['id']);
30 $passphrase = mq($_POST['passphrase']);
31 $idhash = mq($_POST['idhash']);
33 function maybe_echo_server($q) {
34 global $loom_server, $default_server;
35 if ($loom_server != $default_server) {
36 echo $q . 'loom_server=' . urlencode($loom_server);
42 <title
>Loom Grid
&
; Archive Tutorials in PHP
</title
>
43 <link rel
="shortcut icon" href
="krugerand.png"/>
44 <style type
="text/css">
45 body
{ font
-family
: verdana
, arial
, sans
-serif
; font
-size
: 10pt
}
46 div
{ font
-size
:10pt
}
53 li
{ padding
-bottom
: 7px
}
54 pre
{ font
-family
: verdana
, arial
, sans
-serif
; }
55 A
:link
, A
:visited
{ color
:blue
; text
-decoration
:none
}
56 A
:hover
{ color
:blue
; text
-decoration
:underline
}
57 A
:active
{ color
:#FAD805; text-decoration:underline }
58 .tt
{ font
-family
: Courier
; font
-size
:10pt
}
59 .mono
{ font
-family
: monospace
; font
-size
: 8pt
}
60 .large_mono
{ font
-family
: monospace
; font
-size
: 10pt
}
61 .giant_mono
{ font
-family
: monospace
; font
-size
: 14pt
}
62 .tiny_mono
{ font
-family
: monospace
; font
-size
: 6pt
}
63 .normal
{ font
-size
:10pt
}
64 .smaller
{ font
-size
:6pt
}
65 .small
{ font
-size
:8pt
}
66 .large
{ font
-size
:12pt
}
68 .focus_value
{ background
-color
:#DDDDDD }
69 .color_heading
{ margin
-top
:12px
; padding
:1px
; background
-color
:#DDDDDD; width:100% }
70 A
.label_link
{ font
-weight
:bold
; }
71 A
.highlight_link
{ font
-weight
:bold
; }
72 A
.cancel
{ background
-color
:#FFDDDD }
73 A
.plain
:link
, A
.plain
:visited
{ color
:black
; text
-decoration
:none
}
74 A
.plain
:hover
{ color
:blue
; text
-decoration
:underline
}
75 A
.plain
:active
{ color
:#FAD805; text-decoration:underline }
76 A
.name_dot
{ font
-size
:14pt
; font
-weight
:bold
; color
:green
; }
86 This is a PHP translation of the Loom
.cc
88 if ($page == 'grid') {
89 echo '<a href="https://loom.cc/?function=grid_tutorial&mode=advanced">grid tutorial</a>.';
90 } elseif ($page == 'archive') {
91 echo '<a href="https://loom.cc/?function=archive_tutorial&mode=advanced">archive tutorial</a>.';
93 echo 'Tools page (login required).';
96 Note that
if you enter any
real locations containing valuable assets in this page
, those locations are being transferred through my web site to loom
.cc
. All trasmissions are encrypted
, so it
's unlikely that anybody can steal your valuable information en-route, but you ARE trusting me to not snarf your locations with my PHP code. I promise that unless somebody hacks my site, the code that is running is the code I've posted at the link below
, which does NOT save your information anywhere
, just passes it on to loom
.cc
. But
if you don
't trust me, don't give away anything important
.
99 <a href
="../loomclient.tar.gz">loomclient
.tar
.gz
</a
>
102 <a href
="index.html">Loom Index
</a
> |
103 <a href
="grid-tutorial.php<? maybe_echo_server('?'); ?>">
105 if ($page == 'grid') {
110 <a href
="grid-tutorial.php?page=archive<? maybe_echo_server('&'); ?>">
112 if ($page == 'archive') {
113 echo '<b>Archive</b>';
114 } else echo 'Archive';
117 <a href
="grid-tutorial.php?page=tools<? maybe_echo_server('&'); ?>">
119 if ($page == 'tools') {
128 $client = new LoomClient($loom_server);
131 if ($page == 'grid') {
133 $issuer_message = '';
137 if ($_POST['buy'] != '') {
138 $res = $client->buy($common_type, $buy_loc, $buy_usage, &$url);
139 checkResult($res, 'usage_balance', 'error_loc', &$buy_message);
140 } elseif ($_POST['sell'] != '') {
141 $res = $client->sell($common_type, $buy_loc, $buy_usage, &$url);
142 checkResult($res, 'usage_balance', 'error_loc', &$buy_message);
143 } elseif ($_POST['issuer'] != '') {
144 $res = $client->issuer($common_type, $issuer_orig, $issuer_dest, &$url);
145 checkResult($res, 'status', 'status', &$issuer_message);
146 } elseif ($_POST['touch'] != '') {
147 $res = $client->touch($common_type, $touch_loc, &$url);
148 checkResult($res, 'value', 'error_loc', &$touch_message);
149 } elseif ($_POST['look'] != '') {
150 $res = $client->look($common_type, $look_hash, &$url);
151 checkResult($res, 'value', 'error_loc', &$look_message);
152 } elseif ($_POST['move'] != '') {
153 $res = $client->move($common_type, $move_qty, $move_orig, $move_dest, &$url);
154 checkResult($res, 'value_dest', 'error_qty', &$move_message);
155 } elseif ($_POST['move_back'] != '') {
156 $res = $client->move($common_type, $move_qty, $move_dest, $move_orig, &$url);
157 checkResult($res, 'value_orig', 'error_qty', &$move_message);
159 } else if ($page == 'archive') {
160 if ($_POST['look_archive'] != '') {
161 $res = $client->look_archive($look_hash, &$url);
162 if ($res != '') $content = htmlspecialchars($res['content']);
163 } elseif ($_POST['touch_archive'] != '') {
164 $res = $client->touch_archive($touch_loc, &$url);
166 $content = htmlspecialchars($res['content']);
167 if ($res['hash'] != '') $look_hash = $res['hash'];
169 } elseif ($_POST['buy_archive'] != '') {
170 $res = $client->buy_archive($touch_loc, $buy_usage, &$url);
171 } elseif ($_POST['sell_archive'] != '') {
172 $res = $client->sell_archive($touch_loc, $buy_usage, &$url);
173 } elseif ($_POST['write_archive'] != '') {
174 $res = $client->write_archive($touch_loc, $buy_usage, html_entity_decode($content), &$url);
175 if ($res['hash'] != '') $look_hash = $res['hash'];
178 if ($_POST['random_id'] != '') {
179 $random = new LoomRandom();
180 $id = $random->random_id();
183 } elseif ($_POST['id_hash'] != '') {
184 $idhash = $client->sha256($client->hex2bin($id));
185 } elseif ($_POST['random_passphrase'] != '') {
186 require_once "Diceware.php";
187 if (!isset($diceware)) $diceware = new Diceware();
188 $passphrase = $diceware->random_words(5);
191 } elseif ($_POST['hash_passphrase'] != '') {
192 $hash = $client->sha256($passphrase);
193 $id = $client->hash2location($hash);
198 if ($page == 'grid') print_grid();
199 else if ($page == 'archive') print_archive();
203 echo "<p><b>URL</b><p>$url<p><b>Result (in KV format)</b><p><pre>";
205 foreach ($res as $key => $value) {
206 echo ":" . htmlspecialchars($client->quote_cstring($key)) . "\n";
207 echo "=" . htmlspecialchars($client->quote_cstring($value)) . "\n";
218 function checkResult($res, $success_key, $fail_key, &$var) {
219 $status = $res['status'];
220 if ($status == 'success') $var = $res[$success_key];
221 else $var = $res[$fail_key];
222 if ($var == '') $var = $status;
225 function hsc($text) {
226 return htmlspecialchars($text);
229 function print_grid() {
230 global $common_type, $loom_server, $buy_loc, $buy_usage, $issuer_orig;
231 global $issuer_dest, $touch_loc, $look_hash, $move_qty, $move_orig, $move_dest;
232 global $buy_message, $issuer_message, $touch_message, $look_message, $move_message;
236 This is an interactive tutorial to help you set up
and test grid operations
.
237 Be careful using sensitive locations in this tutorial
, since they
do show
238 up in plain text on this screen
. The grid API is
<a href
="https://loom.cc/?function=help&topic=grid&mode=advanced">fully documented
</a
>.
241 <form method
=post action
="grid-tutorial.php" autocomplete
=off
>
242 <table border
=1 cellpadding
=10 style
='border-collapse:collapse'>
246 <table border
=0 style
='border-collapse:collapse'>
259 <input type
=text
class=tt name
=common_type size
=36 value
=<?
echo hsc($common_type); ?
>>
268 <input type
=text name
=loom_server size
=50 value
=<?
echo hsc($loom_server); ?
>>
279 <table border
=0 style
='border-collapse:collapse'>
288 <input type
=submit name
=buy value
="Buy">
289 <input type
=submit name
=sell value
="Sell">
293 Buy location
for one usage token
, or sell location
for refund
.
302 <input type
=text
class=tt name
=buy_loc size
=36 value
=<?
echo hsc($buy_loc); ?
>>
303 <?
echo $buy_message; ?
>
313 <input type
=text
class=tt name
=buy_usage size
=36 value
=<?
echo hsc($buy_usage); ?
>>
324 <table border
=0 style
='border-collapse:collapse'>
334 <input type
=submit name
=issuer value
="Issuer">
337 Change the issuer location
for a type
.
347 <input type
=text
class=tt name
=issuer_orig size
=36 value
=<?
echo hsc($issuer_orig);?
>>
348 <?
echo $issuer_message; ?
>
357 <input type
=text
class=tt name
=issuer_dest size
=36 value
=<?
echo hsc($issuer_dest); ?
>>
368 <table border
=0 style
='border-collapse:collapse'>
377 <input type
=submit name
=touch value
="Touch">
380 Touch a location directly to see its value
.
390 <input type
=text
class=tt name
=touch_loc size
=36 value
=<?
echo hsc($touch_loc); ?
>>
391 <?
echo $touch_message; ?
>
403 <table border
=0 style
='border-collapse:collapse'>
412 <input type
=submit name
=look value
="Look">
415 Look at a location by its hash
.
424 <input type
=text
class=tt name
=look_hash size
=72 value
=<?
echo hsc($look_hash); ?
>>
425 <?
echo $look_message; ?
>
436 <table border
=0 style
='border-collapse:collapse'>
446 <input type
=submit name
=move value
="Move">
447 <input type
=submit name
=move_back value
="Back">
450 Move units from one location to another
.
460 <input type
=text
class=tt name
=move_qty size
=45 value
=<?
echo hsc($move_qty); ?
>>
469 <input type
=text
class=tt name
=move_orig size
=36 value
=<?
echo hsc($move_orig); ?
>>
478 <input type
=text
class=tt name
=move_dest size
=36 value
=<?
echo hsc($move_dest); ?
>>
479 <?
echo $move_message; ?
>
494 function print_archive() {
495 global $loom_server, $look_hash, $touch_loc, $buy_usage, $content;
497 <form method
=post action
="grid-tutorial.php?page=archive" autocomplete
=off
>
500 This screen is a simple user
interface into the archive
function <a href
="https://loom.cc/?function=help&topic=archive&mode=advanced">documented here
</a
>.
501 It also serves
as a tutorial
, showing you the API url
and result
.
504 <table border
=0 style
='border-collapse:collapse'>
516 <input type
=text name
=loom_server size
=50 value
=<?
echo hsc($loom_server); ?
>>
524 <input type
=text
class=tt name
=look_hash size
=72 value
=<?
echo hsc($look_hash); ?
>>
525 <input type
=submit name
=look_archive value
="Look">
535 <input type
=text
class=tt name
=touch_loc size
=36 value
=<?
echo hsc($touch_loc); ?
>>
536 <input type
=submit name
=touch_archive value
="Touch">
537 <input type
=submit name
=buy_archive value
="Buy">
538 <input type
=submit name
=sell_archive value
="Sell">
548 <input type
=text
class=tt name
=buy_usage size
=36 value
=<?
echo hsc($buy_usage); ?
>>
557 <a href
="<? echo hsc($loom_server); ?>?function=view&hash=<? echo hsc($look_hash); ?>" title
="View as web page">View
</a
>
558 <input type
=submit name
=write_archive value
="Write">
564 <textarea name
=content rows
=20 cols
=120>
565 <?
echo hsc($content); ?
>
576 function print_tools() {
577 global $loom_server, $id, $passphrase, $idhash;
579 <form method
=post action
="grid-tutorial.php?page=tools" autocomplete
=off
>
583 Here is an assortment of tools which you may occasionally find useful
.
585 On this panel
, you may generate a
new random identifier
or random passphrase
.
586 You may also compute the
"hash" of a passphrase
, which converts a passphrase
587 into an identifier
. You may enter the passphrase manually
if you don
't want
590 <table border=0 cellpadding=5 style='border
-collapse
:collapse
'>
601 <input type=text name=loom_server size=50 value=<? echo hsc($loom_server); ?>>
608 <input type=text class=tt name=idhash size=72 value="<? echo hsc($idhash); ?>">
615 <input type=text class=tt name=id size=36 value="<? echo hsc($id); ?>">
616 <input type=submit name=random_id value="Random">
617 <input type=submit name=id_hash value="Hash">
624 <input type=text name=passphrase size=50 value="<? echo hsc($passphrase); ?>">
625 <input type=submit name=random_passphrase value="Random">
626 <input type=submit name=hash_passphrase value="Hash">
636 /* ***** BEGIN LICENSE BLOCK *****
637 * Version: MPL 1.1/GPL 2.0/LGPL 2.1/Apache 2.0
639 * The contents of this file are subject to the Mozilla Public License Version
640 * 1.1 (the "License"); you may not use this file except in compliance with
641 * the License. You may obtain a copy of the License at
642 * http://www.mozilla.org/MPL/
644 * Software distributed under the License is distributed on an "AS IS" basis,
645 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
646 * for the specific language governing rights and limitations under the
649 * The Original Code is LoomClient PHP library
651 * The Initial Developer of the Original Code is
653 * Portions created by the Initial Developer are Copyright (C) 2008
654 * the Initial Developer. All Rights Reserved.
657 * Bill St. Clair <bill@billstclair.com>
659 * Alternatively, the contents of this file may be used under the
660 * terms of the GNU General Public License Version 2 or later (the
661 * "GPL"), the GNU Lesser General Public License Version 2.1 or later
662 * (the "LGPL"), or The Apache License Version 2.0 (the "AL"), in
663 * which case the provisions of the GPL, LGPL, or AL are applicable
664 * instead of those above. If you wish to allow use of your version of
665 * this file only under the terms of the GPL, the LGPL, or the AL, and
666 * not to allow others to use your version of this file under the
667 * terms of the MPL, indicate your decision by deleting the provisions
668 * above and replace them with the notice and other provisions
669 * required by the GPL or the LGPL. If you do not delete the
670 * provisions above, a recipient may use your version of this file
671 * under the terms of any one of the MPL, the GPL the LGPL, or the AL.
672 ****** END LICENSE BLOCK ***** */