From 8a034edf2909136b0959eeb523b49721ae0106e6 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Sat, 24 Dec 2016 01:09:38 +0100 Subject: [PATCH] triggers: handle rpc commands move the text query parser used in web console in the wallet rpc class --- web/yaamp/core/backend/notify.php | 32 ++++++++++ web/yaamp/core/rpc/wallet-rpc.php | 59 +++++++++++++++++++ web/yaamp/modules/site/coin_console.php | 54 ++--------------- web/yaamp/modules/site/coin_triggers.php | 4 +- .../modules/site/results/wallet_results.php | 4 +- 5 files changed, 100 insertions(+), 53 deletions(-) diff --git a/web/yaamp/core/backend/notify.php b/web/yaamp/core/backend/notify.php index cceef5f..89e8c63 100644 --- a/web/yaamp/core/backend/notify.php +++ b/web/yaamp/core/backend/notify.php @@ -77,6 +77,16 @@ function NotifyCheckRules() $message .= "Field: {$field}\n"; $message .= "Value: {$value} at ".strftime("%Y-%m-%d %T %z", $time)."\n"; + // replace some possible vars in message (description) + $message = str_replace('$X', $value, $message); + $message = str_replace('$F', $field, $message); + $message = str_replace('$T', $conditiontype, $message); + $message = str_replace('$V', $conditionvalue, $message); + $message = str_replace('$N', $coin->name, $message); + $message = str_replace('$SYM', $coin->symbol, $message); + $message = str_replace('$S2', $coin->symbol2, $message); + $message = str_replace('$A', $coin->master_wallet, $message); + $dest = YAAMP_ADMIN_EMAIL; if (!empty($rule->notifycmd) && strstr($notifycmd, "@")) { $dest = $rule->notifycmd; @@ -87,6 +97,27 @@ function NotifyCheckRules() debuglog("notify: unable to send mail to {$dest}!"); break; + case 'rpc': + + $command = $rule->notifycmd; + + // replace some possible vars in user command + $command = str_replace('$X', $value, $command); + $command = str_replace('$F', $field, $command); + $command = str_replace('$T', $conditiontype, $command); + $command = str_replace('$V', $conditionvalue, $command); + $command = str_replace('$N', $coin->name, $command); + $command = str_replace('$SYM', $coin->symbol, $command); + $command = str_replace('$S2', $coin->symbol2, $command); + $command = str_replace('$A', $coin->master_wallet, $command); + + $remote = new WalletRPC($coin); + + $res = $remote->execute($command); + if ($res === false) + debuglog("notify: rpc error {$coin->symbol} {$command}"); + break; + case 'system': $command = $rule->notifycmd; @@ -99,6 +130,7 @@ function NotifyCheckRules() $command = str_replace('$N', $coin->name, $command); $command = str_replace('$SYM', $coin->symbol, $command); $command = str_replace('$S2', $coin->symbol2, $command); + $command = str_replace('$A', $coin->master_wallet, $command); $res = system($command); if ($res === false) diff --git a/web/yaamp/core/rpc/wallet-rpc.php b/web/yaamp/core/rpc/wallet-rpc.php index 5bf1f0f..5a304bd 100644 --- a/web/yaamp/core/rpc/wallet-rpc.php +++ b/web/yaamp/core/rpc/wallet-rpc.php @@ -324,4 +324,63 @@ class WalletRPC { $this->rpc->$prop = $value; } + function execute($query) + { + $result = ''; + + if (!empty($query)) try { + $params = explode(' ', trim($query)); + $command = array_shift($params); + + $p = array(); + foreach ($params as $param) { + if ($param === 'true' || $param === 'false') { + $param = $param === 'true' ? true : false; + } + else if (strpos($param, '0x') === 0) + $param = "$param"; // eth hex crap + else + $param = (is_numeric($param)) ? 0 + $param : trim($param,'"'); + $p[] = $param; + } + + switch (count($params)) { + case 0: + $result = $this->$command(); + break; + case 1: + $result = $this->$command($p[0]); + break; + case 2: + $result = $this->$command($p[0], $p[1]); + break; + case 3: + $result = $this->$command($p[0], $p[1], $p[2]); + break; + case 4: + $result = $this->$command($p[0], $p[1], $p[2], $p[3]); + break; + case 5: + $result = $this->$command($p[0], $p[1], $p[2], $p[3], $p[4]); + break; + case 6: + $result = $this->$command($p[0], $p[1], $p[2], $p[3], $p[4], $p[5]); + break; + case 7: + $result = $this->$command($p[0], $p[1], $p[2], $p[3], $p[4], $p[5], $p[6]); + break; + case 8: + $result = $this->$command($p[0], $p[1], $p[2], $p[3], $p[4], $p[5], $p[6], $p[7]); + break; + default: + $result = 'error: too much parameters'; + } + + } catch (Exception $e) { + $result = false; + } + + return $result; + } + } diff --git a/web/yaamp/modules/site/coin_console.php b/web/yaamp/modules/site/coin_console.php index 7e4518b..47ddfbf 100644 --- a/web/yaamp/modules/site/coin_console.php +++ b/web/yaamp/modules/site/coin_console.php @@ -118,57 +118,11 @@ div.terminal { color: silver; background: black; min-height: 180px; margin-left: end; $result = ''; - -if (!empty($query)) try { - $params = explode(' ', trim($query)); - $command = array_shift($params); - - $p = array(); - foreach ($params as $param) { - if ($param === 'true' || $param === 'false') { - $param = $param === 'true' ? true : false; - } - else if (strpos($param, '0x') === 0) - $param = "$param"; // eth hex crap - else - $param = (is_numeric($param)) ? 0 + $param : trim($param,'"'); - $p[] = $param; +if (!empty($query)) { + $result = $remote->execute($query); + if ($result === false) { + $result = $remote->error; } - - switch (count($params)) { - case 0: - $result = $remote->$command(); - break; - case 1: - $result = $remote->$command($p[0]); - break; - case 2: - $result = $remote->$command($p[0], $p[1]); - break; - case 3: - $result = $remote->$command($p[0], $p[1], $p[2]); - break; - case 4: - $result = $remote->$command($p[0], $p[1], $p[2], $p[3]); - break; - case 5: - $result = $remote->$command($p[0], $p[1], $p[2], $p[3], $p[4]); - break; - case 6: - $result = $remote->$command($p[0], $p[1], $p[2], $p[3], $p[4], $p[5]); - break; - case 7: - $result = $remote->$command($p[0], $p[1], $p[2], $p[3], $p[4], $p[5], $p[6]); - break; - case 8: - $result = $remote->$command($p[0], $p[1], $p[2], $p[3], $p[4], $p[5], $p[6], $p[7]); - break; - default: - $result = 'error: too much parameters'; - } - -} catch (Exception $e) { - $result = $remote->error; } if (!empty($remote->error) && $remote->error != $result) { diff --git a/web/yaamp/modules/site/coin_triggers.php b/web/yaamp/modules/site/coin_triggers.php index c39820e..bce9c93 100644 --- a/web/yaamp/modules/site/coin_triggers.php +++ b/web/yaamp/modules/site/coin_triggers.php @@ -93,9 +93,10 @@ echo <<Type

- +

@@ -113,6 +114,7 @@ echo <<\$SYM coin symbol
  • \$S2 coin symbol2
  • \$N coin name
  • +
  • \$A wallet address
  • diff --git a/web/yaamp/modules/site/results/wallet_results.php b/web/yaamp/modules/site/results/wallet_results.php index 0113b84..ebbeba0 100644 --- a/web/yaamp/modules/site/results/wallet_results.php +++ b/web/yaamp/modules/site/results/wallet_results.php @@ -276,8 +276,8 @@ if (!empty($list_extra)) { - Some wallets (LYB) have a problem and don't confirm a transaction in the requested time.
    - Please be honest and continue mining to handle these extra transactions sent to you.
    + Some wallets (UFO,LYB) have a problem and don't always confirm a transaction in the requested time.
    +