1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
|
#!/usr/bin/perl
#
# perl script to preview a spend
# from maintenance release e-gold system
# version 1.0
# free for use, modification, redistribution
#
#Disclaimer
#The Author [e-gold Ltd.] accepts no
#responsibility for damages to persons, property or data incurred
#through the use of this script(s). To the maximum extent permitted
#by law, in no event shall the Author [e-gold Ltd.] be
#liable for any damages whatsoever (including, without limitation,
#damages for loss of business profits, business interruption, loss of
#business information, or other pecuniary loss) arising out of the use
#or inability to use this software, even if the Author has been advised
#of the possibility of such damages.
#
#This product is supplied as-is, with no warranties express or implied.
#Use this software at your own risk.
#
# SECURITY NOTE:
# the curl system command spawned by this example will probably expose
# its arguments to any other user on the system that can run a 'ps'
# type command. the account passphrase would be visible in that situation.
# if you must use this script on a shared or untrusted box, which is really
# not a good idea, consider using the --data @foobar option to read curl
# arguments from file foobar.
#
if ($#ARGV < 4) {
&command_help;
}
# pick up account number we will be spending from...
$accountfrom = $ARGV[0];
shift;
# pick up account number we will be spending to...
$accountto = $ARGV[0];
shift;
# pick up amount
$amount = $ARGV[0];
shift;
# pick up units
$units = uc($ARGV[0]);
shift;
$unitsok = 0;
if(index($units,"USD") == 0){
$units = 1;
$unitsok = 1;
}
if(index($units,"OZ") == 0){
$units = 9999;
$unitsok = 1;
}
if(index($units,"G") == 0){
$units = 8888;
$unitsok = 1;
}
if(index($units,"CAD") == 0){
$units = 2;
$unitsok = 1;
}
if(index($units,"FFR") == 0){
$units = 33;
$unitsok = 1;
}
if(index($units,"CHF") == 0){
$units = 41;
$unitsok = 1;
}
if(index($units,"GBP") == 0){
$units = 44;
$unitsok = 1;
}
if(index($units,"DEM") == 0){
$units = 49;
$unitsok = 1;
}
if(index($units,"AUD") == 0){
$units = 61;
$unitsok = 1;
}
if(index($units,"JPY") == 0){
$units = 81;
$unitsok = 1;
}
if($unitsok == 0) {
die "$units is Invalid, choose oz, g, usd, gbp, aud, jpy, dem, cad, ffr, chr";
}
# pick up e-metal type
$metal = uc($ARGV[0]);
shift;
$metalok = 0;
if(index($metal,"GOLD") == 0){
$metal = "Gold";
$metalok = 1;
}
if(index($metal,"SILVER") == 0){
$metal = "Silver";
$metalok = 1;
}
if(index($metal,"PLATINUM") == 0){
$metal = "Platinum";
$metalok = 1;
}
if(index($metal,"PALLADIUM") == 0){
$metal = "Palladium";
$metalok = 1;
}
if($metalok == 0) {
die "$metal is invalid, choose gold, silver, platinum, or palladium";
}
sub command_help
{
print "Usage: $0 from to amount units metal\n";
print " units can be one of oz, g, usd, aud, cad, dem, gbp, jpy, chf, ffr\n";
print " metal can be one of gold, silver, platinum, palladium\n";
print "\nexample:\n";
print "$0 101574 100998 1 usd gold\n";
print "to preview a spend of 1 US dollar equivalent of gold from\n";
print " account 101574 to account 100998\n";
exit 1;
}
# prompt user for password
print "\nPassphrase for $accountfrom?";
if ( system('stty -echo') != 0) {
die "Error setting terminal to not echo\n";
}
$pp = "{password}";
chop($pp);
system('stty echo');
print "\n";
#build up the arguments for the preview command
$curlargs = "Payee_Account=$accountto";
$curlargs .= "&Amount=$amount";
$curlargs .= "&PAY_IN=$units";
$curlargs .= "&WORTH_OF=$metal";
$curlargs .= "&Memo=automatic spend";
$curlargs .= "&PassPhrase=$pp";
$curlargs .= "&AccountID=$accountfrom";
# print "\n$curlargs\n";
$sysstring = "curl -s -d ";
$sysstring .= '"';
$sysstring .= $curlargs;
$sysstring .= "&CURPAGE=0";
$sysstring .= '"';
$sysstring .= " https://www.e-gold.com/acct/verify.asp";
#print $sysstring;
# read everything into one buffer
undef $/;
open(foo, "$sysstring|");
while(<foo>){
# pull out the hidden fields...the pattern starts with "hidden name=" and
# ends with ">"
while( /hidden name=(.*?)>/gs ) {
# see if there was some kind of error
if(index($1, "ERROR") == 0) {
$errstring = $1;
$errstring =~ ( /value="(.*)"/ );
print "Error on preview is: $1\n";
exit -1;
}
# print out the information we care about from the preview
if(index($1, "ACTUAL_PAYMENT_OUNCES") == 0) {
$ozstring = $1;
$ozstring =~ ( /value="(.*)"/ );
print "Successful Preview.\n";
print "Weight of this payment would be: $1 oz.\n";
}
}
}
close foo;
# all done
print "\n"; |
Partager