added example project

This commit is contained in:
Alexander Willner 2012-01-16 02:06:09 +01:00
parent ec7f0d9ee5
commit 14f45412c5
5 changed files with 210 additions and 0 deletions

View File

@ -4,8 +4,14 @@ help:
@echo "minify - makes JavaScript download and run faster"
@echo "lint - checks JavaScript files for style issues"
@echo "test - runs JavaScript unit tests"
@echo "example - creates a simple example"
@echo "ext-chr-gmail - creates the Google Chrome / Google Mail extension"
example:
@mkdir -p build
@rm -f build/example.zip
@zip -j build/example.zip resources/example.* resources/openpgp.min.js resources/jquery.min.js
ext-chr-gmail:
@./scripts/create_extension.sh

103
resources/example.css Normal file
View File

@ -0,0 +1,103 @@
html, body {
margin:0;
padding:0;
height:100%;
width:100%;
font: 0.86em/120% Tahoma, Arial, sans-serif;
color:#333;
background:transparent;
}
html {
background:#eee;
}
a:hover, a:active { outline: none; }
a, a:active, a:visited { color: #607890; text-decoration:none;}
a:hover { color: #036; }
h1, h2, h3 {
font-size: medium;
font-weight: normal;
margin:0;
padding:.5em;
}
p { padding-left:1.5em;}
h1 {
font-size:xx-large;
}
.block {
margin:0 auto;
margin-top:1em;
margin-bottom:1em;
padding:.5em;
max-width:70em;
background:#fff;
-webkit-box-shadow: 0px 2px 5px #aaa;
-moz-box-shadow: 0px 2px 5px #aaa;
box-shadow: 0px 2px 5px #aaa;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
border:1px solid #ccc;
}
#title {
background:#369;
color:#eee;
margin:0;
padding:.5em;
border-bottom:1px solid black;
-webkit-box-shadow: 0px 5px 5px #aaa;
-moz-box-shadow: 0px 5px 5px #aaa;
box-shadow: 0px 5px 5px #aaa;
}
#browsers {
width:90%;
margin:0 auto;
}
.logo {
height:8em;
width:8em;
}
input:invalid, textarea:invalid {
border-radius: 1px;
-moz-box-shadow: 0px 0px 5px red;
-webkit-box-shadow: 0px 0px 5px red;
box-shadow: 0px 0px 5px red;
}
input, textarea {
width:15em;
margin-top: 1em;
margin-bottom: 1em;
background-color: white;
color: #666;
border: 1px solid #C4C4C4;
border-right: 1px solid #E9E9E9;
border-bottom: 1px solid #E9E9E9;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
}
#mybutton {
background-color: #333;
color:#fff;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
}
textarea {
width:40em;
height:5em;
max-width:90%;
}

68
resources/example.html Normal file
View File

@ -0,0 +1,68 @@
<!doctype html>
<html>
<head>
<title>Example | OpenPGP.js</title>
<link rel="stylesheet" media="all" href="example.css">
</head>
<body>
<div id="title">
<h1>Example | OpenPGP.js</h1>
<p>This example page must run on a php enabled web space.</p>
</div>
<div class="block">
<h2>Send us an encrypted message</h2>
<form action="example.php" method="post" onsubmit="return encrypt();" name="myform" id="myform">
<ul>
<li><label>Your mail: </label><br/><input type="email" name="mail" id="mail" /></li>
<li><label>Your message: </label><br/><textarea name="message" id="message"></textarea></li>
</ul>
<input type="submit" name="mybutton" id="mybutton" />
</form>
</div>
<div class="block">
<h2>Our public key</h2>
<pre id="pubkey">
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG/MacGPG2 v2.0.18 (Darwin)
Comment: GPGTools - http://gpgtools.org
mQENBE8Tb1oBCADSFabWN+0j8Edt3b0s2/pf5C6oKY0SFgblPwSq//R0Cm6h2cOd
C1SqKPdv1BW8qWyBJ4P58+Fh4FNqWKUTsE4BHE8Sq2Go2tN1pROedubDcgYYuJ+c
VLY7Q0fqnHlm2wifVEvvv6rBRtwyFlBU9Elc3N7pN0kGtUI2nSEQZsmbsn9/jawt
CwSvz2KomJ54pAm2UlWMy62b+VS0yorHbe6WjO2FdisUa3EQxGcF5yTMdpNPGb/R
9tw0FMOL0D8mG4T24uFMd19xl+BjoQ7r+rVJr6+S2CgQ4cG+6PnvBfzFsamSiXvi
hkM2LgJEMeNavonbPKcd2zo4mUaFfvhtAEYBABEBAAG0HE9wZW5QR1AuanMgPGxp
c3RAb3BlbnBncC5qcz6JAT8EEwECACkFAk8Tb1oC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
KTENEv9ubqVJgH+u0kA052yzc8dWt1XBjcOF4voRZ/Iksn6QtCtpHB40hSSwL5I0
VEv9LeMbkzHb+ZhNCq9VFK2x0RrgGgDLOoSEUbrCJDyHnQfkCnVEl6eTVm1JfA34
VejDMU8F7GJ8RypWZKeTxqe2Wh2nB/9p1Ea0Q0f5BWfdulEMKhbkr6a0VrWQ/76M
wmgqFsiqGkU28gCiXJBJc1557FOYUquzGo1dRoEbl9nCVXkcfVjgGCiVBnQWhNk2
CTGA0lZ/Bzw0gZXjs32SRzTIUoaS7aJi7V324Q2ISjYJjJ3soijctVHCzi7JK43j
kg64fBx5DqXZGZaKESlcI1apmAo2O9GvoSusAzfg6h55dJh3526MRgN6ooB+Mlm+
d1znU1KJs+UvEXFkvlCo6Q8nhjKzUMWqXthoWcc3ZqFvc2Abvu3n/T4Malsq7kiC
z8jl9UymAkoTcsVWRVr5PKR0zsCxaNV3w5hv6j12+US7mEWe2kuD
=Lx12
-----END PGP PUBLIC KEY BLOCK-----
</pre>
</div>
<script src="./jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script src="./openpgp.min.js" type="text/javascript" charset="utf-8"></script>
<script src="./example.js" type="text/javascript" charset="utf-8"></script>
</body>
</html>

5
resources/example.js Normal file
View File

@ -0,0 +1,5 @@
function encrypt() {
openpgp.init();
var pub_key = openpgp.read_publicKey($('#pubkey').text());
$('#message').val(openpgp.write_encrypted_message(pub_key,$('#message').val()));
}

28
resources/example.php Normal file
View File

@ -0,0 +1,28 @@
<?php
// Author: Alex
// Description: OpenPGP.js message example
/* setup -------------------------------------------------------------------- */
define('SMALL_LIMIT',128);
define('LARGE_LIMIT',131072);
$subject="OpenPGP.js Example";
$to="alex@openpgpjs.org";
$headers = "From: OpenPGP.js Example <noreply@openpgpjs.org>\r\n";
$mail = "$message";
/* -------------------------------------------------------------------------- */
/* input -------------------------------------------------------------------- */
$user=substr(trim($_POST["mail"]), 0, SMALL_LIMIT);
$message=substr(trim($_POST["message"]), 0, LARGE_LIMIT);
/* -------------------------------------------------------------------------- */
/* send the request --------------------------------------------------------- */
if (filter_var($user, FILTER_VALIDATE_EMAIL)) {
$headers = "From: $user\r\n";
}
mail($to, $subject, $message, $headers);
/* Redirect browser */
header("Location: http://openpgpjs.org");
?>