Skip to content

Commit 4a4e276

Browse files
committed
Merge pull request #2033 from MPOS/development
UPDATE : Development to Master - NO VERSION
2 parents e45a29c + a70d6af commit 4a4e276

File tree

214 files changed

+22948
-164
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

214 files changed

+22948
-164
lines changed

public/include/admin_checks.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,18 @@
9898

9999
// poke stratum using gettingstarted details -> enotice
100100
if (function_exists('socket_create')) {
101-
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
102-
if ($socket !== false) {
103-
$address = @gethostbyname($config['gettingstarted']['stratumurl']);
104-
$result = @socket_connect($socket, $address, $config['gettingstarted']['stratumport']);
105-
if ($result !== true) {
106-
$enotice[] = 'We tried to poke your Stratum server using your $config[\'gettingstarted\'] settings but it didn\'t respond';
107-
}
108-
$close = @socket_close($socket);
101+
$host = @gethostbyname($config['gettingstarted']['stratumurl']);
102+
$port = $config['gettingstarted']['stratumport'];
103+
104+
if (isset($host) and
105+
isset($port) and
106+
($socket=socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) and
107+
(socket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO, array('sec' => 3, 'usec' => 0))) and
108+
(@socket_connect($socket, $host, $port)))
109+
{
110+
socket_close($socket);
111+
} else {
112+
$enotice[] = 'We tried to poke your Stratum server using your $config[\'gettingstarted\'] settings but it didn\'t respond - ' . socket_strerror(socket_last_error());
109113
}
110114
} else {
111115
// Connect via fsockopen as fallback

public/include/autoloader.inc.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
die('Unable to load your coins class definition for ' . $config['algorithm']);
2828
}
2929

30+
// Swiftmailer
31+
require_once(INCLUDE_DIR . '/lib/swiftmailer/swift_required.php');
32+
3033
// Detect device
3134
if ( PHP_SAPI == 'cli') {
3235
// Create a new compile folder just for crons
@@ -70,4 +73,4 @@
7073
require_once(INCLUDE_DIR . '/lib/Michelf/Markdown.php');
7174
require_once(INCLUDE_DIR . '/lib/scrypt.php');
7275

73-
?>
76+
?>

public/include/classes/mail.class.php

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,26 +46,50 @@ public function contactform($senderName, $senderEmail, $senderSubject, $senderMe
4646
}
4747

4848
/**
49-
* Send a mail with templating via Smarty
49+
* Send a mail with templating via Smarty and Siftmailer
5050
* @param template string Template name within the mail folder, no extension
5151
* @param aData array Data array with some required fields
52-
* SUBJECT : Mail Subject
52+
* subject : Mail Subject
5353
* email : Destination address
5454
**/
5555
public function sendMail($template, $aData) {
56-
// Make sure we don't load a cached filed
56+
// Prepare SMTP transport and mailer
57+
$transport_type = $this->config['swiftmailer']['type'];
58+
if ($transport_type == 'sendmail') {
59+
$transport = Swift_SendmailTransport::newInstance($this->config['swiftmailer'][$transport_type]['path'] . ' ' . $this->config['swiftmailer'][$transport_type]['options']);
60+
} else if ($this->config['swiftmailer']['type'] == 'smtp') {
61+
$transport = Swift_SmtpTransport::newInstance($this->config['switfmailer']['smtp']['host'], $this->config['switfmailer']['smtp']['port'], $this->config['switfmailer']['smtp']['encryption']);
62+
if (!empty($this->config['switfmailer']['smtp']['username']) && !empty($this->config['switfmailer']['smtp']['password'])) {
63+
$transport->setUsername($this->config['switfmailer']['smtp']['username']);
64+
$transport->setPassword($this->config['switfmailer']['smtp']['password']);
65+
}
66+
}
67+
$mailer = Swift_Mailer::newInstance($transport);
68+
// Prepare the smarty templates used
5769
$this->smarty->clearCache(BASEPATH . 'templates/mail/' . $template . '.tpl');
5870
$this->smarty->clearCache(BASEPATH . 'templates/mail/subject.tpl');
5971
$this->smarty->assign('WEBSITENAME', $this->setting->getValue('website_name'));
6072
$this->smarty->assign('SUBJECT', $aData['subject']);
6173
$this->smarty->assign('DATA', $aData);
62-
$headers = 'From: ' . $this->setting->getValue('website_name') . '<' . $this->setting->getValue('website_email') . ">\n";
63-
$headers .= "MIME-Version: 1.0\n";
64-
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
74+
75+
// Create new message for Swiftmailer
76+
$message = Swift_Message::newInstance()
77+
->setSubject($this->smarty->fetch(BASEPATH . 'templates/mail/subject.tpl'))
78+
->setFrom(array( $this->setting->getValue('website_email') => $this->setting->getValue('website_name')))
79+
->setTo($aData['email'])
80+
->setSender($this->setting->getValue('website_email'))
81+
->setReturnPath($this->setting->getValue('website_email'))
82+
->setBody($this->smarty->fetch(BASEPATH . 'templates/mail/' . $template . '.tpl'), 'text/html');
6583
if (strlen(@$aData['senderName']) > 0 && @strlen($aData['senderEmail']) > 0 )
66-
$headers .= 'Reply-To: ' . $aData['senderName'] . ' <' . $aData['senderEmail'] . ">\n";
67-
if (mail($aData['email'], $this->smarty->fetch(BASEPATH . 'templates/mail/subject.tpl'), $this->smarty->fetch(BASEPATH . 'templates/mail/' . $template . '.tpl'), $headers, '-f ' . $this->setting->getValue('website_email')))
68-
return true;
84+
$message->setReplyTo(array($aData['senderEmail'] => $aData['senderName']));
85+
86+
// Send message out with configured transport
87+
try {
88+
if ($mailer->send($message)) return true;
89+
} catch (Exception $e) {
90+
$this->setErrorMessage($e->getMessage());
91+
return false;
92+
}
6993
$this->setErrorMessage($this->sqlError('E0031'));
7094
return false;
7195
}

public/include/classes/monitoring.class.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,8 @@ public function getStatus($name) {
7070
if ($query && $query->bind_param('s', $name) && $query->execute() && $result = $query->get_result()) {
7171
return $result->fetch_assoc();
7272
} else {
73-
$this->sqlError();
73+
return $this->sqlError();
7474
}
75-
return $value;
7675
}
7776

7877
/**

public/include/classes/setting.class.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ public function createCache() {
1919
return false;
2020
}
2121

22+
/**
23+
* Flush our local cache, may be required for upgrades
24+
* or other places where we need live data
25+
**/
26+
public function flushCache() {
27+
$this->cache = array();
28+
return true;
29+
}
30+
2231
/**
2332
* Fetch a value from our table
2433
* @param name string Setting name

public/include/classes/share.class.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,6 @@ public function getSharesForAccounts($previous_upstream=0, $current_upstream) {
112112
return $this->sqlError();
113113
}
114114

115-
/**
116-
* Fetch the highest available share ID
117-
**/
118-
function getMaxShareId() {
119-
$stmt = $this->mysqli->prepare("SELECT MAX(id) AS id FROM $this->table");
120-
if ($this->checkStmt($stmt) && $stmt->execute() && $result = $stmt->get_result())
121-
return $result->fetch_object()->id;
122-
return $this->sqlError();
123-
}
124-
125115
/**
126116
* Fetch the highest available share ID from archive
127117
**/

public/include/classes/statistics.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ public function getAllUserShares() {
344344
$data['data'][$row['id']]['is_anonymous'] = $row['is_anonymous'];
345345
}
346346
}
347-
$data['share_id'] = $this->share->getMaxShareId();
347+
$data['share_id'] = $this->share->getLastInsertedShareId();
348348
return $this->memcache->setCache(STATISTICS_ALL_USER_SHARES, $data);
349349
}
350350
return $this->sqlError();

public/include/classes/transaction.class.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,37 +109,42 @@ public function getTransactionSummary($account_id=NULL) {
109109
public function getTransactionTypebyTime($account_id=NULL) {
110110
$this->debug->append("STA " . __METHOD__, 4);
111111
if ($data = $this->memcache->get(__FUNCTION__)) return $data;
112-
$stmt = $this->mysqli->prepare("
113-
SELECT
112+
$stmt = $this->mysqli->prepare("
113+
SELECT
114114
IFNULL(SUM(IF(t.type = 'Credit' AND timestamp >= DATE_SUB(now(), INTERVAL 3600 SECOND), t.amount, 0)), 0) AS 1HourCredit,
115+
IFNULL(SUM(IF(t.type = 'Bonus' AND timestamp >= DATE_SUB(now(), INTERVAL 3600 SECOND), t.amount, 0)), 0) AS 1HourBonus,
115116
IFNULL(SUM(IF(t.type = 'Debit_MP' AND timestamp >= DATE_SUB(now(), INTERVAL 3600 SECOND), t.amount, 0)), 0) AS 1HourDebitMP,
116117
IFNULL(SUM(IF(t.type = 'Debit_AP' AND timestamp >= DATE_SUB(now(), INTERVAL 3600 SECOND), t.amount, 0)), 0) AS 1HourDebitAP,
117118
IFNULL(SUM(IF(t.type = 'TXFee' AND timestamp >= DATE_SUB(now(), INTERVAL 3600 SECOND), t.amount, 0)), 0) AS 1HourTXFee,
118119
IFNULL(SUM(IF(t.type = 'Fee' AND timestamp >= DATE_SUB(now(), INTERVAL 3600 SECOND), t.amount, 0)), 0) AS 1HourFee,
119120
IFNULL(SUM(IF(t.type = 'Donation' AND timestamp >= DATE_SUB(now(), INTERVAL 3600 SECOND), t.amount, 0)), 0) AS 1HourDonation,
120-
121+
121122
IFNULL(SUM(IF(t.type = 'Credit' AND timestamp >= DATE_SUB(now(), INTERVAL 86400 SECOND), t.amount, 0)), 0) AS 24HourCredit,
123+
IFNULL(SUM(IF(t.type = 'Bonus' AND timestamp >= DATE_SUB(now(), INTERVAL 86400 SECOND), t.amount, 0)), 0) AS 24HourBonus,
122124
IFNULL(SUM(IF(t.type = 'Debit_MP' AND timestamp >= DATE_SUB(now(), INTERVAL 86400 SECOND), t.amount, 0)), 0) AS 24HourDebitMP,
123125
IFNULL(SUM(IF(t.type = 'Debit_AP' AND timestamp >= DATE_SUB(now(), INTERVAL 86400 SECOND), t.amount, 0)), 0) AS 24HourDebitAP,
124126
IFNULL(SUM(IF(t.type = 'TXFee' AND timestamp >= DATE_SUB(now(), INTERVAL 86400 SECOND), t.amount, 0)), 0) AS 24HourTXFee,
125127
IFNULL(SUM(IF(t.type = 'Fee' AND timestamp >= DATE_SUB(now(), INTERVAL 86400 SECOND), t.amount, 0)), 0) AS 24HourFee,
126128
IFNULL(SUM(IF(t.type = 'Donation' AND timestamp >= DATE_SUB(now(), INTERVAL 86400 SECOND), t.amount, 0)), 0) AS 24HourDonation,
127129
128130
IFNULL(SUM(IF(t.type = 'Credit' AND timestamp >= DATE_SUB(now(), INTERVAL 604800 SECOND), t.amount, 0)), 0) AS 1WeekCredit,
131+
IFNULL(SUM(IF(t.type = 'Bonus' AND timestamp >= DATE_SUB(now(), INTERVAL 604800 SECOND), t.amount, 0)), 0) AS 1WeekBonus,
129132
IFNULL(SUM(IF(t.type = 'Debit_MP' AND timestamp >= DATE_SUB(now(), INTERVAL 604800 SECOND), t.amount, 0)), 0) AS 1WeekDebitMP,
130133
IFNULL(SUM(IF(t.type = 'Debit_AP' AND timestamp >= DATE_SUB(now(), INTERVAL 604800 SECOND), t.amount, 0)), 0) AS 1WeekDebitAP,
131134
IFNULL(SUM(IF(t.type = 'TXFee' AND timestamp >= DATE_SUB(now(), INTERVAL 604800 SECOND), t.amount, 0)), 0) AS 1WeekTXFee,
132135
IFNULL(SUM(IF(t.type = 'Fee' AND timestamp >= DATE_SUB(now(), INTERVAL 604800 SECOND), t.amount, 0)), 0) AS 1WeekFee,
133136
IFNULL(SUM(IF(t.type = 'Donation' AND timestamp >= DATE_SUB(now(), INTERVAL 604800 SECOND), t.amount, 0)), 0) AS 1WeekDonation,
134137
135138
IFNULL(SUM(IF(t.type = 'Credit' AND timestamp >= DATE_SUB(now(), INTERVAL 2419200 SECOND), t.amount, 0)), 0) AS 1MonthCredit,
139+
IFNULL(SUM(IF(t.type = 'Bonus' AND timestamp >= DATE_SUB(now(), INTERVAL 2419200 SECOND), t.amount, 0)), 0) AS 1MonthBonus,
136140
IFNULL(SUM(IF(t.type = 'Debit_MP' AND timestamp >= DATE_SUB(now(), INTERVAL 2419200 SECOND), t.amount, 0)), 0) AS 1MonthDebitMP,
137141
IFNULL(SUM(IF(t.type = 'Debit_AP' AND timestamp >= DATE_SUB(now(), INTERVAL 2419200 SECOND), t.amount, 0)), 0) AS 1MonthDebitAP,
138142
IFNULL(SUM(IF(t.type = 'TXFee' AND timestamp >= DATE_SUB(now(), INTERVAL 2419200 SECOND), t.amount, 0)), 0) AS 1MonthTXFee,
139143
IFNULL(SUM(IF(t.type = 'Fee' AND timestamp >= DATE_SUB(now(), INTERVAL 2419200 SECOND), t.amount, 0)), 0) AS 1MonthFee,
140144
IFNULL(SUM(IF(t.type = 'Donation' AND timestamp >= DATE_SUB(now(), INTERVAL 2419200 SECOND), t.amount, 0)), 0) AS 1MonthDonation,
141-
145+
142146
IFNULL(SUM(IF(t.type = 'Credit' AND timestamp >= DATE_SUB(now(), INTERVAL 31536000 SECOND), t.amount, 0)), 0) AS 1YearCredit,
147+
IFNULL(SUM(IF(t.type = 'Bonus' AND timestamp >= DATE_SUB(now(), INTERVAL 31536000 SECOND), t.amount, 0)), 0) AS 1YearBonus,
143148
IFNULL(SUM(IF(t.type = 'Debit_MP' AND timestamp >= DATE_SUB(now(), INTERVAL 31536000 SECOND), t.amount, 0)), 0) AS 1YearDebitMP,
144149
IFNULL(SUM(IF(t.type = 'Debit_AP' AND timestamp >= DATE_SUB(now(), INTERVAL 31536000 SECOND), t.amount, 0)), 0) AS 1YearDebitAP,
145150
IFNULL(SUM(IF(t.type = 'TXFee' AND timestamp >= DATE_SUB(now(), INTERVAL 31536000 SECOND), t.amount, 0)), 0) AS 1YearTXFee,

public/include/config/global.inc.dist.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,20 @@
5757
$config['wallet']['username'] = 'testnet';
5858
$config['wallet']['password'] = 'testnet';
5959

60+
/**
61+
* Swiftmailer configuration
62+
* Configure your way to send mails
63+
* https://github.com/MPOS/php-mpos/wiki/Config-Setup#wiki-swiftmailer
64+
**/
65+
$config['swiftmailer']['type'] = 'sendmail';
66+
$config['swiftmailer']['sendmail']['path'] = '/usr/sbin/sendmail';
67+
$config['swiftmailer']['sendmail']['options'] = '-bs';
68+
$config['switfmailer']['smtp']['host'] = 'your.mail-relay.com';
69+
$config['switfmailer']['smtp']['port'] = '587';
70+
$config['switfmailer']['smtp']['encryption'] = 'tls';
71+
$config['switfmailer']['smtp']['username'] = '';
72+
$config['switfmailer']['smtp']['password'] = '';
73+
6074
/**
6175
* Getting Started Config
6276
* Shown to users in the 'Getting Started' section
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
3+
/*
4+
* This file is part of SwiftMailer.
5+
* (c) 2004-2009 Chris Corbyn
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
11+
/**
12+
* General utility class in Swift Mailer, not to be instantiated.
13+
*
14+
* @package Swift
15+
*
16+
* @author Chris Corbyn
17+
*/
18+
abstract class Swift
19+
{
20+
public static $initialized = false;
21+
public static $inits = array();
22+
23+
/** Swift Mailer Version number generated during dist release process */
24+
const VERSION = '5.1.0';
25+
26+
/**
27+
* Registers an initializer callable that will be called the first time
28+
* a SwiftMailer class is autoloaded.
29+
*
30+
* This enables you to tweak the default configuration in a lazy way.
31+
*
32+
* @param mixed $callable A valid PHP callable that will be called when autoloading the first Swift class
33+
*/
34+
public static function init($callable)
35+
{
36+
self::$inits[] = $callable;
37+
}
38+
39+
/**
40+
* Internal autoloader for spl_autoload_register().
41+
*
42+
* @param string $class
43+
*/
44+
public static function autoload($class)
45+
{
46+
// Don't interfere with other autoloaders
47+
if (0 !== strpos($class, 'Swift_')) {
48+
return;
49+
}
50+
51+
$path = dirname(__FILE__).'/'.str_replace('_', '/', $class).'.php';
52+
53+
if (!file_exists($path)) {
54+
return;
55+
}
56+
57+
require $path;
58+
59+
if (self::$inits && !self::$initialized) {
60+
self::$initialized = true;
61+
foreach (self::$inits as $init) {
62+
call_user_func($init);
63+
}
64+
}
65+
}
66+
67+
/**
68+
* Configure autoloading using Swift Mailer.
69+
*
70+
* This is designed to play nicely with other autoloaders.
71+
*
72+
* @param mixed $callable A valid PHP callable that will be called when autoloading the first Swift class
73+
*/
74+
public static function registerAutoload($callable = null)
75+
{
76+
if (null !== $callable) {
77+
self::$inits[] = $callable;
78+
}
79+
spl_autoload_register(array('Swift', 'autoload'));
80+
}
81+
}

0 commit comments

Comments
 (0)