Skip to content

Commit b341bd6

Browse files
committed
+ catch to elephantIO functions, this allows use of the system without the feedserver running.
~ socket authentication. ~ updated readme.
1 parent 02243f7 commit b341bd6

File tree

6 files changed

+171
-105
lines changed

6 files changed

+171
-105
lines changed

README.md

Lines changed: 80 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,60 +12,106 @@ Take your business into the cloud with WallacePOS!
1212

1313
To find out more about WallacePOS, head over to [wallacepos.com](https://wallacepos.com)
1414

15-
## Server Requirements
15+
## Server Prerequisites
1616

1717
WallacePOS requires:
1818

19-
- A Lamp server with PHP>=5.4 and Apache module proxy_wstunnel installed & enabled.
19+
1. A Lamp server with PHP version>=5.4 and Apache version>=2.4.7 with modules rewrite and proxy_wstunnel.
2020

21-
- You can enable proxy_wstunnel by typing the following in your terminal
21+
- You can enable proxy_wstunnel & rewrite by typing the following in your terminal
2222

23-
```
24-
sudo a2enmod proxy_wstunnel
25-
```
23+
```
24+
sudo a2enmod proxy_wstunnel && a2enmod rewrite
25+
```
2626
27-
- The following snippet in your apache.conf or apache config dir
27+
- The following virtual host snippet in your apache config, replace %*% with your values and modify to your needs.
2828
29-
```
30-
ProxyRequests Off
31-
ProxyPreserveHost On
32-
<Proxy *>
33-
Order deny,allow
34-
Allow from all
35-
</Proxy>
36-
ProxyPass /socket.io/1/websocket/ ws://127.0.0.1:8080/socket.io/1/websocket/
37-
ProxyPassReverse /socket.io/1/websocket/ ws://127.0.0.1:8080/socket.io/1/websocket/
38-
ProxyPass /socket.io/ http://127.0.0.1:8080/socket.io/
39-
ProxyPassReverse /socket.io/ http://127.0.0.1:8080/socket.io/
40-
<Location /socket.io>
41-
Order allow,deny
42-
Allow from all
43-
</Location>
44-
```
4529
46-
- Node.js installed along with the socket.io library
30+
```
31+
<VirtualHost *:443>
32+
DocumentRoot %/your_install_dir%
33+
ServerName %your.server.fqdn%
34+
35+
ErrorLog ${APACHE_LOG_DIR}/error.log
36+
CustomLog ${APACHE_LOG_DIR}/access.log combined
37+
38+
SSLEngine on
39+
SSLCipherSuite !ADH:!DSS:!RC4:HIGH:+3DES:+RC4
40+
SSLProtocol all -SSLv2 -SSLv3
41+
SSLCertificateFile %certificate_location%
42+
SSLCertificateKeyFile %key_location%
43+
SSLCertificateChainFile %cert_chain_location%
44+
45+
<Directory %/your_install_dir%>
46+
AllowOverride all
47+
</Directory>
48+
49+
# WSPROXY CONF
50+
ProxyRequests Off
51+
ProxyPreserveHost On
52+
<Proxy *>
53+
Order deny,allow
54+
Allow from all
55+
</Proxy>
56+
ProxyPass /socket.io/1/websocket/ ws://localhost:8080/socket.io/1/websocket/
57+
ProxyPassReverse /socket.io/1/websocket/ ws://localhost:8080/socket.io/1/websocket
58+
ProxyPass /socket.io/ http://localhost:8080/socket.io/
59+
ProxyPassReverse /socket.io/ http://localhost:8080/socket.io/
60+
<Location /socket.io>
61+
Order allow,deny
62+
Allow from all
63+
</Location>
64+
</VirtualHost>
65+
```
66+
67+
Note: Using plain http is not recommended.
68+
69+
2. Node.js installed along with the socket.io library
70+
71+
For a Debian distro:
72+
73+
```
74+
sudo apt-get update
75+
sudo apt-get install nodejs && apt-get install npm
76+
cd %/your_install_dir%
77+
sudo npm install
78+
```
79+
80+
## Installation & Startup
81+
82+
1. Clone your chosen WallacePOS release to %your_install_dir% if you haven't done so already.
83+
84+
2. Configure the database by copying %your_install_dir%/library/wpos/dbconfig_template.php to %your_install_dir%/library/wpos/dbconfig.php and fill in your own values.
85+
86+
3. Install the database schema & templates:
87+
88+
1. Enable the /library/installer/index.php file by removing the die(); command at the start
89+
2. Access library/installer/?install from the web browser to install the database schema
90+
91+
OR
92+
93+
1. Manually install the database schema at %your_install_dir%/library/installer/schemas/install.sql using your favoured sql management method.
94+
2. Copy docs-template folder to docs, make sure it is writable by your apache user (eg. www-data)
95+
96+
4. Login to the admin dashboard at /admin using credentials admin:admin, from the menu go to Settings -> Utilities and click the Start button under Feed Server
97+
98+
5. Change default passwords in Settings -> Staff & Admins!
4799
48100
## Deploying using dokku
49101
50102
To deploy WallacePOS on dokku:
51103
52104
1. Install [dokku-buildpack-multi](https://github.com/pauldub/dokku-multi-buildpack) on your dokku host
53105
54-
2. Copy /library/wpos/dbconfig_template.php to dbconfig.php and fill in your own values
106+
2. Fork the WallacePOS to a PRIVATE repo (IMPORTANT), copy /library/wpos/dbconfig_template.php to dbconfig.php and fill in your own values
55107
56108
**OR**
57109
58-
Use my [dokku mysql plugin](https://github.com/micwallace/dokku-mysql-server-plugin) to create and link the database automatically
59-
60-
## Installation & Startup
61-
62-
### To install the database:
110+
Use my [dokku mysql plugin](https://github.com/micwallace/dokku-mysql-server-plugin) to create and link the database automagically
63111
64-
1. Enable the /library/installer/index.php file by removing the die(); command at the start
65-
2. Access library/installer/?install from the web browser to install the database schema
112+
3. Deploy in the usual manner.
66113
67-
### To run the feed server
114+
4. Login to the admin dashboard at /admin using credentials admin:admin & change the default passwords in Settings -> Staff & Admins!
68115
69-
- Run /api/server.js using node.js or login to the admin dashboard, go to settings -> utilities and click the start button under feed server.
70116
71117

api/server.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function wshandler(req, res) {
2323
var devices = {};
2424
var sessions = {};
2525

26-
var hashkey = "0798f20c2c513da7cad1af28ffa3012cdafd0e799e41912f006e6d46c8e99327"; // private key for php interaction
26+
var hashkey = "0798f20c2c513da7cad1af28ffa3012cdafd0e799e41912f006e6d46c8e99327"; // key for php interaction, provides extra security
2727

2828
io.sockets.on('connection', function (socket) {
2929
// START AUTHENTICATION
@@ -50,7 +50,7 @@ io.sockets.on('connection', function (socket) {
5050
// check for hashkey (for php authentication)
5151
if (cookies == null) {
5252
if (socket.handshake.query.hasOwnProperty('hashkey')) {
53-
if (hashkey == socket.handshake.query.hashkey) {
53+
if ((hashkey == socket.handshake.query.hashkey) && (socket.handshake.address.address=="127.0.0.1")) {
5454
authed = true;
5555
console.log("Authorised by hashkey: " + socket.handshake.query.hashkey);
5656
}

api/wpos.php

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -37,34 +37,31 @@
3737

3838
$auth = new Auth();
3939
// Check for auth request
40-
if ($_REQUEST['a'] == "auth") {
40+
if ($_REQUEST['a'] == "auth" || $_REQUEST['a'] == "authrenew") {
4141
$data = json_decode($_REQUEST['data']);
42-
if ($data !== false) {
43-
if (($authres = $auth->login($data->username, $data->password, isset($data->getsessiontokens))) === true) {
44-
$result['data'] = $auth->getUser();
45-
} else if ($authres == -1) {
46-
$result['errorCode'] = "authdenied";
47-
$result['error'] = "Your account has been disabled, please contact your system administrator!";
48-
} else {
49-
$result['errorCode'] = "authdenied";
50-
$result['error'] = "Access Denied!";
51-
}
42+
if ($_REQUEST['a'] == "auth"){
43+
$authres = $auth->login($data->username, $data->password, isset($data->getsessiontokens));
5244
} else {
53-
$result['errorCode'] = "jsondec";
54-
$result['error'] = "Error decoding the json request!";
45+
$authres = $auth->renewTokenSession($data->username, $data->auth_hash);
5546
}
56-
returnResult($result);
57-
} else if ($_REQUEST['a'] == "authrenew") {
58-
$data = json_decode($_REQUEST['data']);
5947
if ($data !== false) {
60-
if (($authres = $auth->renewTokenSession($data->username, $data->auth_hash)) === true) {
61-
$result['data'] = $auth->getUser();
62-
} else if ($authres == -1) {
63-
$result['errorCode'] = "authdenied";
64-
$result['error'] = "Your account has been disabled, please contact your system administrator!";
65-
} else {
66-
$result['errorCode'] = "authdenied";
67-
$result['error'] = "Failed to renew your session, please login again.";
48+
switch ($authres){
49+
// will be included when elephantIO is upgraded, no reliable exceptions in current version
50+
/*case -2: // user authenticated successfully, but could not be authenticated with the feed server, fall through to normal login
51+
$result['warning'] = "Warning: Feedserver authentication attempt failed.";*/
52+
case true:
53+
$result['data'] = $auth->getUser();
54+
break;
55+
56+
case -1:
57+
$result['errorCode'] = "authdenied";
58+
$result['error'] = "Your account has been disabled, please contact your system administrator!";
59+
break;
60+
61+
case false:
62+
default:
63+
$result['errorCode'] = "authdenied";
64+
$result['error'] = "Access Denied!";
6865
}
6966
} else {
7067
$result['errorCode'] = "jsondec";

library/wpos/Auth.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,15 @@ public function login($username, $password, $getToken=false){
193193
if ($getToken!==false)
194194
$this->setNewSessionToken($user['id'], $user['hash']);
195195

196-
// Send to node JS
197-
$socket = new WposSocketIO();
198-
$socket->sendSessionData(session_id());
199196
// log data
200197
Logger::write("Authentication successful for user:".$username, "AUTH");
201198

199+
// Send to node JS
200+
$socket = new WposSocketIO();
201+
$socket->sendSessionData(session_id());
202+
/*if (!$socket->sendSessionData(session_id())){
203+
return -2;
204+
}*/
202205
return true;
203206
} else{
204207
// log data
@@ -234,12 +237,15 @@ public function renewTokenSession($username, $auth_hash){
234237
$_SESSION['permissions'] = json_decode($user['permissions'], true);
235238
//$this->hash = $user['hash'];
236239
$this->setNewSessionToken($user['id'], $user['hash']);
240+
// log data
241+
Logger::write("Authentication successful for user:".$username, "AUTH");
237242

238243
// Send to node JS
239244
$socket = new WposSocketIO();
240245
$socket->sendSessionData(session_id());
241-
// log data
242-
Logger::write("Authentication successful for user:".$username, "AUTH");
246+
/*if (!$socket->sendSessionData(session_id())){
247+
return -2;
248+
}*/
243249
return true;
244250
} else {
245251
// log data

library/wpos/models/TestData.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ public function generateTestData(){
4242
}
4343

4444
public function resetDocuments(){
45-
exec("rm -R ".$_SERVER['DOCUMENT_ROOT'].$_SERVER['APP_ROOT']."docs/");
46-
exec("cp -R ".$_SERVER['DOCUMENT_ROOT'].$_SERVER['APP_ROOT']."docs-template ".$_SERVER['DOCUMENT_ROOT'].$_SERVER['APP_ROOT']."docs");
45+
exec("rm -r ".$_SERVER['DOCUMENT_ROOT'].$_SERVER['APP_ROOT']."docs/");
46+
exec("cp -rp ".$_SERVER['DOCUMENT_ROOT'].$_SERVER['APP_ROOT']."docs-template ".$_SERVER['DOCUMENT_ROOT'].$_SERVER['APP_ROOT']."docs");
4747
}
4848

4949
public function generate($numtransactions, $type='sale'){

0 commit comments

Comments
 (0)