Browse Source

Frist

tags/1.0beta
Skylar Ittner 2 years ago
commit
b16da81513
10 changed files with 892 additions and 0 deletions
  1. 4
    0
      .gitignore
  2. 3
    0
      account.php
  3. 16
    0
      composer.json
  4. 575
    0
      composer.lock
  5. BIN
      database.mwb
  6. 17
    0
      index.php
  7. 7
    0
      nbproject/project.properties
  8. 9
    0
      nbproject/project.xml
  9. 231
    0
      required.php
  10. 30
    0
      settings.template.php

+ 4
- 0
.gitignore View File

@@ -0,0 +1,4 @@
1
+/settings.php
2
+/vendor
3
+/database.mwb.bak
4
+/nbproject/private

+ 3
- 0
account.php View File

@@ -0,0 +1,3 @@
1
+<?php
2
+
3
+require __DIR__ . "/required.php";

+ 16
- 0
composer.json View File

@@ -0,0 +1,16 @@
1
+{
2
+    "name": "netsyms/business-sso",
3
+    "description": "Single-sign-on system and accounts database for Netsyms small business apps",
4
+    "type": "project",
5
+    "require": {
6
+        "catfan/medoo": "^1.2",
7
+        "spomky-labs/otphp": "^8.3",
8
+        "endroid/qrcode": "^1.9"
9
+    },
10
+    "authors": [
11
+        {
12
+            "name": "Skylar Ittner",
13
+            "email": "admin@netsyms.com"
14
+        }
15
+    ]
16
+}

+ 575
- 0
composer.lock View File

@@ -0,0 +1,575 @@
1
+{
2
+    "_readme": [
3
+        "This file locks the dependencies of your project to a known state",
4
+        "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
5
+        "This file is @generated automatically"
6
+    ],
7
+    "content-hash": "3d5a548f8a7cbbd0c911987b1fab33a5",
8
+    "packages": [
9
+        {
10
+            "name": "beberlei/assert",
11
+            "version": "v2.7.4",
12
+            "source": {
13
+                "type": "git",
14
+                "url": "https://github.com/beberlei/assert.git",
15
+                "reference": "3ee3bc468a3ce4bbfc3d74f53c6cdb5242d39d1a"
16
+            },
17
+            "dist": {
18
+                "type": "zip",
19
+                "url": "https://api.github.com/repos/beberlei/assert/zipball/3ee3bc468a3ce4bbfc3d74f53c6cdb5242d39d1a",
20
+                "reference": "3ee3bc468a3ce4bbfc3d74f53c6cdb5242d39d1a",
21
+                "shasum": ""
22
+            },
23
+            "require": {
24
+                "ext-mbstring": "*",
25
+                "php": ">=5.3"
26
+            },
27
+            "require-dev": {
28
+                "friendsofphp/php-cs-fixer": "^2.1.1",
29
+                "phpunit/phpunit": "^4|^5"
30
+            },
31
+            "type": "library",
32
+            "autoload": {
33
+                "psr-4": {
34
+                    "Assert\\": "lib/Assert"
35
+                },
36
+                "files": [
37
+                    "lib/Assert/functions.php"
38
+                ]
39
+            },
40
+            "notification-url": "https://packagist.org/downloads/",
41
+            "license": [
42
+                "BSD-2-Clause"
43
+            ],
44
+            "authors": [
45
+                {
46
+                    "name": "Benjamin Eberlei",
47
+                    "email": "kontakt@beberlei.de",
48
+                    "role": "Lead Developer"
49
+                },
50
+                {
51
+                    "name": "Richard Quadling",
52
+                    "email": "rquadling@gmail.com",
53
+                    "role": "Collaborator"
54
+                }
55
+            ],
56
+            "description": "Thin assertion library for input validation in business models.",
57
+            "keywords": [
58
+                "assert",
59
+                "assertion",
60
+                "validation"
61
+            ],
62
+            "time": "2017-03-14T18:06:52+00:00"
63
+        },
64
+        {
65
+            "name": "catfan/medoo",
66
+            "version": "v1.2.1",
67
+            "source": {
68
+                "type": "git",
69
+                "url": "https://github.com/catfan/Medoo.git",
70
+                "reference": "b5a788c90c44db0f978512c890cb6962af4685e8"
71
+            },
72
+            "dist": {
73
+                "type": "zip",
74
+                "url": "https://api.github.com/repos/catfan/Medoo/zipball/b5a788c90c44db0f978512c890cb6962af4685e8",
75
+                "reference": "b5a788c90c44db0f978512c890cb6962af4685e8",
76
+                "shasum": ""
77
+            },
78
+            "require": {
79
+                "ext-pdo": "*",
80
+                "php": ">=5.4"
81
+            },
82
+            "suggest": {
83
+                "ext-pdo_dblib": "For MSSQL or Sybase databases on Linux/UNIX platform",
84
+                "ext-pdo_mysql": "For MySQL or MariaDB databases",
85
+                "ext-pdo_oci": "For Oracle databases",
86
+                "ext-pdo_pqsql": "For PostgreSQL databases",
87
+                "ext-pdo_sqlite": "For SQLite databases",
88
+                "ext-pdo_sqlsrv": "For MSSQL databases on Windows platform"
89
+            },
90
+            "type": "framework",
91
+            "autoload": {
92
+                "psr-4": {
93
+                    "Medoo\\": "/src"
94
+                }
95
+            },
96
+            "notification-url": "https://packagist.org/downloads/",
97
+            "license": [
98
+                "MIT"
99
+            ],
100
+            "authors": [
101
+                {
102
+                    "name": "Angel Lai",
103
+                    "email": "angel@catfan.me"
104
+                }
105
+            ],
106
+            "description": "The Lightest PHP database framework to accelerate development",
107
+            "homepage": "http://medoo.in",
108
+            "keywords": [
109
+                "database",
110
+                "lightweight",
111
+                "mssql",
112
+                "mysql",
113
+                "php framework",
114
+                "sql",
115
+                "sqlite"
116
+            ],
117
+            "time": "2017-02-17T16:05:35+00:00"
118
+        },
119
+        {
120
+            "name": "christian-riesen/base32",
121
+            "version": "1.3.1",
122
+            "source": {
123
+                "type": "git",
124
+                "url": "https://github.com/ChristianRiesen/base32.git",
125
+                "reference": "0a31e50c0fa9b1692d077c86ac188eecdcbaf7fa"
126
+            },
127
+            "dist": {
128
+                "type": "zip",
129
+                "url": "https://api.github.com/repos/ChristianRiesen/base32/zipball/0a31e50c0fa9b1692d077c86ac188eecdcbaf7fa",
130
+                "reference": "0a31e50c0fa9b1692d077c86ac188eecdcbaf7fa",
131
+                "shasum": ""
132
+            },
133
+            "require": {
134
+                "php": ">=5.3.0"
135
+            },
136
+            "require-dev": {
137
+                "phpunit/phpunit": "4.*",
138
+                "satooshi/php-coveralls": "0.*"
139
+            },
140
+            "type": "library",
141
+            "extra": {
142
+                "branch-alias": {
143
+                    "dev-master": "1.1.x-dev"
144
+                }
145
+            },
146
+            "autoload": {
147
+                "psr-4": {
148
+                    "Base32\\": "src/"
149
+                }
150
+            },
151
+            "notification-url": "https://packagist.org/downloads/",
152
+            "license": [
153
+                "MIT"
154
+            ],
155
+            "authors": [
156
+                {
157
+                    "name": "Christian Riesen",
158
+                    "email": "chris.riesen@gmail.com",
159
+                    "homepage": "http://christianriesen.com",
160
+                    "role": "Developer"
161
+                }
162
+            ],
163
+            "description": "Base32 encoder/decoder according to RFC 4648",
164
+            "homepage": "https://github.com/ChristianRiesen/base32",
165
+            "keywords": [
166
+                "base32",
167
+                "decode",
168
+                "encode",
169
+                "rfc4648"
170
+            ],
171
+            "time": "2016-05-05T11:49:03+00:00"
172
+        },
173
+        {
174
+            "name": "endroid/qrcode",
175
+            "version": "1.9.3",
176
+            "source": {
177
+                "type": "git",
178
+                "url": "https://github.com/endroid/QrCode.git",
179
+                "reference": "c9644bec2a9cc9318e98d1437de3c628dcd1ef93"
180
+            },
181
+            "dist": {
182
+                "type": "zip",
183
+                "url": "https://api.github.com/repos/endroid/QrCode/zipball/c9644bec2a9cc9318e98d1437de3c628dcd1ef93",
184
+                "reference": "c9644bec2a9cc9318e98d1437de3c628dcd1ef93",
185
+                "shasum": ""
186
+            },
187
+            "require": {
188
+                "ext-gd": "*",
189
+                "php": ">=5.4",
190
+                "symfony/options-resolver": "^2.3|^3.0"
191
+            },
192
+            "require-dev": {
193
+                "phpunit/phpunit": "^4.0|^5.0",
194
+                "sensio/framework-extra-bundle": "^3.0",
195
+                "symfony/browser-kit": "^2.3|^3.0",
196
+                "symfony/framework-bundle": "^2.3|^3.0",
197
+                "symfony/http-kernel": "^2.3|^3.0"
198
+            },
199
+            "type": "library",
200
+            "extra": {
201
+                "branch-alias": {
202
+                    "dev-master": "1.x-dev"
203
+                }
204
+            },
205
+            "autoload": {
206
+                "psr-4": {
207
+                    "Endroid\\QrCode\\": "src/"
208
+                }
209
+            },
210
+            "notification-url": "https://packagist.org/downloads/",
211
+            "license": [
212
+                "MIT"
213
+            ],
214
+            "authors": [
215
+                {
216
+                    "name": "Jeroen van den Enden",
217
+                    "email": "info@endroid.nl",
218
+                    "homepage": "http://endroid.nl/"
219
+                }
220
+            ],
221
+            "description": "Endroid QR Code",
222
+            "homepage": "https://github.com/endroid/QrCode",
223
+            "keywords": [
224
+                "bundle",
225
+                "code",
226
+                "endroid",
227
+                "qr",
228
+                "qrcode",
229
+                "symfony"
230
+            ],
231
+            "time": "2017-04-08T09:13:59+00:00"
232
+        },
233
+        {
234
+            "name": "paragonie/random_compat",
235
+            "version": "v2.0.10",
236
+            "source": {
237
+                "type": "git",
238
+                "url": "https://github.com/paragonie/random_compat.git",
239
+                "reference": "634bae8e911eefa89c1abfbf1b66da679ac8f54d"
240
+            },
241
+            "dist": {
242
+                "type": "zip",
243
+                "url": "https://api.github.com/repos/paragonie/random_compat/zipball/634bae8e911eefa89c1abfbf1b66da679ac8f54d",
244
+                "reference": "634bae8e911eefa89c1abfbf1b66da679ac8f54d",
245
+                "shasum": ""
246
+            },
247
+            "require": {
248
+                "php": ">=5.2.0"
249
+            },
250
+            "require-dev": {
251
+                "phpunit/phpunit": "4.*|5.*"
252
+            },
253
+            "suggest": {
254
+                "ext-libsodium": "Provides a modern crypto API that can be used to generate random bytes."
255
+            },
256
+            "type": "library",
257
+            "autoload": {
258
+                "files": [
259
+                    "lib/random.php"
260
+                ]
261
+            },
262
+            "notification-url": "https://packagist.org/downloads/",
263
+            "license": [
264
+                "MIT"
265
+            ],
266
+            "authors": [
267
+                {
268
+                    "name": "Paragon Initiative Enterprises",
269
+                    "email": "security@paragonie.com",
270
+                    "homepage": "https://paragonie.com"
271
+                }
272
+            ],
273
+            "description": "PHP 5.x polyfill for random_bytes() and random_int() from PHP 7",
274
+            "keywords": [
275
+                "csprng",
276
+                "pseudorandom",
277
+                "random"
278
+            ],
279
+            "time": "2017-03-13T16:27:32+00:00"
280
+        },
281
+        {
282
+            "name": "spomky-labs/otphp",
283
+            "version": "v8.3.0",
284
+            "source": {
285
+                "type": "git",
286
+                "url": "https://github.com/Spomky-Labs/otphp.git",
287
+                "reference": "8c90e16ba48fe7c306832611e22c5bad2d663a98"
288
+            },
289
+            "dist": {
290
+                "type": "zip",
291
+                "url": "https://api.github.com/repos/Spomky-Labs/otphp/zipball/8c90e16ba48fe7c306832611e22c5bad2d663a98",
292
+                "reference": "8c90e16ba48fe7c306832611e22c5bad2d663a98",
293
+                "shasum": ""
294
+            },
295
+            "require": {
296
+                "beberlei/assert": "^2.4",
297
+                "christian-riesen/base32": "^1.1",
298
+                "paragonie/random_compat": "^2.0",
299
+                "php": "^5.5|^7.0",
300
+                "symfony/polyfill-mbstring": "^1.1",
301
+                "symfony/polyfill-php56": "^1.1"
302
+            },
303
+            "require-dev": {
304
+                "phpunit/phpunit": "~4.0|^5.0",
305
+                "satooshi/php-coveralls": "^1.0"
306
+            },
307
+            "type": "library",
308
+            "extra": {
309
+                "branch-alias": {
310
+                    "dev-master": "8.2.x-dev"
311
+                }
312
+            },
313
+            "autoload": {
314
+                "psr-4": {
315
+                    "OTPHP\\": "src/"
316
+                }
317
+            },
318
+            "notification-url": "https://packagist.org/downloads/",
319
+            "license": [
320
+                "MIT"
321
+            ],
322
+            "authors": [
323
+                {
324
+                    "name": "Florent Morselli",
325
+                    "homepage": "https://github.com/Spomky"
326
+                },
327
+                {
328
+                    "name": "All contributors",
329
+                    "homepage": "https://github.com/Spomky-Labs/otphp/contributors"
330
+                }
331
+            ],
332
+            "description": "A PHP library for generating one time passwords according to RFC 4226 (HOTP Algorithm) and the RFC 6238 (TOTP Algorithm) and compatible with Google Authenticator",
333
+            "homepage": "https://github.com/Spomky-Labs/otphp",
334
+            "keywords": [
335
+                "FreeOTP",
336
+                "RFC 4226",
337
+                "RFC 6238",
338
+                "google authenticator",
339
+                "hotp",
340
+                "otp",
341
+                "totp"
342
+            ],
343
+            "time": "2016-12-08T10:46:02+00:00"
344
+        },
345
+        {
346
+            "name": "symfony/options-resolver",
347
+            "version": "v3.2.7",
348
+            "source": {
349
+                "type": "git",
350
+                "url": "https://github.com/symfony/options-resolver.git",
351
+                "reference": "6a19be85237fe8bbd4975f86942b4763bb0da6ca"
352
+            },
353
+            "dist": {
354
+                "type": "zip",
355
+                "url": "https://api.github.com/repos/symfony/options-resolver/zipball/6a19be85237fe8bbd4975f86942b4763bb0da6ca",
356
+                "reference": "6a19be85237fe8bbd4975f86942b4763bb0da6ca",
357
+                "shasum": ""
358
+            },
359
+            "require": {
360
+                "php": ">=5.5.9"
361
+            },
362
+            "type": "library",
363
+            "extra": {
364
+                "branch-alias": {
365
+                    "dev-master": "3.2-dev"
366
+                }
367
+            },
368
+            "autoload": {
369
+                "psr-4": {
370
+                    "Symfony\\Component\\OptionsResolver\\": ""
371
+                },
372
+                "exclude-from-classmap": [
373
+                    "/Tests/"
374
+                ]
375
+            },
376
+            "notification-url": "https://packagist.org/downloads/",
377
+            "license": [
378
+                "MIT"
379
+            ],
380
+            "authors": [
381
+                {
382
+                    "name": "Fabien Potencier",
383
+                    "email": "fabien@symfony.com"
384
+                },
385
+                {
386
+                    "name": "Symfony Community",
387
+                    "homepage": "https://symfony.com/contributors"
388
+                }
389
+            ],
390
+            "description": "Symfony OptionsResolver Component",
391
+            "homepage": "https://symfony.com",
392
+            "keywords": [
393
+                "config",
394
+                "configuration",
395
+                "options"
396
+            ],
397
+            "time": "2017-03-21T21:44:32+00:00"
398
+        },
399
+        {
400
+            "name": "symfony/polyfill-mbstring",
401
+            "version": "v1.3.0",
402
+            "source": {
403
+                "type": "git",
404
+                "url": "https://github.com/symfony/polyfill-mbstring.git",
405
+                "reference": "e79d363049d1c2128f133a2667e4f4190904f7f4"
406
+            },
407
+            "dist": {
408
+                "type": "zip",
409
+                "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/e79d363049d1c2128f133a2667e4f4190904f7f4",
410
+                "reference": "e79d363049d1c2128f133a2667e4f4190904f7f4",
411
+                "shasum": ""
412
+            },
413
+            "require": {
414
+                "php": ">=5.3.3"
415
+            },
416
+            "suggest": {
417
+                "ext-mbstring": "For best performance"
418
+            },
419
+            "type": "library",
420
+            "extra": {
421
+                "branch-alias": {
422
+                    "dev-master": "1.3-dev"
423
+                }
424
+            },
425
+            "autoload": {
426
+                "psr-4": {
427
+                    "Symfony\\Polyfill\\Mbstring\\": ""
428
+                },
429
+                "files": [
430
+                    "bootstrap.php"
431
+                ]
432
+            },
433
+            "notification-url": "https://packagist.org/downloads/",
434
+            "license": [
435
+                "MIT"
436
+            ],
437
+            "authors": [
438
+                {
439
+                    "name": "Nicolas Grekas",
440
+                    "email": "p@tchwork.com"
441
+                },
442
+                {
443
+                    "name": "Symfony Community",
444
+                    "homepage": "https://symfony.com/contributors"
445
+                }
446
+            ],
447
+            "description": "Symfony polyfill for the Mbstring extension",
448
+            "homepage": "https://symfony.com",
449
+            "keywords": [
450
+                "compatibility",
451
+                "mbstring",
452
+                "polyfill",
453
+                "portable",
454
+                "shim"
455
+            ],
456
+            "time": "2016-11-14T01:06:16+00:00"
457
+        },
458
+        {
459
+            "name": "symfony/polyfill-php56",
460
+            "version": "v1.3.0",
461
+            "source": {
462
+                "type": "git",
463
+                "url": "https://github.com/symfony/polyfill-php56.git",
464
+                "reference": "1dd42b9b89556f18092f3d1ada22cb05ac85383c"
465
+            },
466
+            "dist": {
467
+                "type": "zip",
468
+                "url": "https://api.github.com/repos/symfony/polyfill-php56/zipball/1dd42b9b89556f18092f3d1ada22cb05ac85383c",
469
+                "reference": "1dd42b9b89556f18092f3d1ada22cb05ac85383c",
470
+                "shasum": ""
471
+            },
472
+            "require": {
473
+                "php": ">=5.3.3",
474
+                "symfony/polyfill-util": "~1.0"
475
+            },
476
+            "type": "library",
477
+            "extra": {
478
+                "branch-alias": {
479
+                    "dev-master": "1.3-dev"
480
+                }
481
+            },
482
+            "autoload": {
483
+                "psr-4": {
484
+                    "Symfony\\Polyfill\\Php56\\": ""
485
+                },
486
+                "files": [
487
+                    "bootstrap.php"
488
+                ]
489
+            },
490
+            "notification-url": "https://packagist.org/downloads/",
491
+            "license": [
492
+                "MIT"
493
+            ],
494
+            "authors": [
495
+                {
496
+                    "name": "Nicolas Grekas",
497
+                    "email": "p@tchwork.com"
498
+                },
499
+                {
500
+                    "name": "Symfony Community",
501
+                    "homepage": "https://symfony.com/contributors"
502
+                }
503
+            ],
504
+            "description": "Symfony polyfill backporting some PHP 5.6+ features to lower PHP versions",
505
+            "homepage": "https://symfony.com",
506
+            "keywords": [
507
+                "compatibility",
508
+                "polyfill",
509
+                "portable",
510
+                "shim"
511
+            ],
512
+            "time": "2016-11-14T01:06:16+00:00"
513
+        },
514
+        {
515
+            "name": "symfony/polyfill-util",
516
+            "version": "v1.3.0",
517
+            "source": {
518
+                "type": "git",
519
+                "url": "https://github.com/symfony/polyfill-util.git",
520
+                "reference": "746bce0fca664ac0a575e465f65c6643faddf7fb"
521
+            },
522
+            "dist": {
523
+                "type": "zip",
524
+                "url": "https://api.github.com/repos/symfony/polyfill-util/zipball/746bce0fca664ac0a575e465f65c6643faddf7fb",
525
+                "reference": "746bce0fca664ac0a575e465f65c6643faddf7fb",
526
+                "shasum": ""
527
+            },
528
+            "require": {
529
+                "php": ">=5.3.3"
530
+            },
531
+            "type": "library",
532
+            "extra": {
533
+                "branch-alias": {
534
+                    "dev-master": "1.3-dev"
535
+                }
536
+            },
537
+            "autoload": {
538
+                "psr-4": {
539
+                    "Symfony\\Polyfill\\Util\\": ""
540
+                }
541
+            },
542
+            "notification-url": "https://packagist.org/downloads/",
543
+            "license": [
544
+                "MIT"
545
+            ],
546
+            "authors": [
547
+                {
548
+                    "name": "Nicolas Grekas",
549
+                    "email": "p@tchwork.com"
550
+                },
551
+                {
552
+                    "name": "Symfony Community",
553
+                    "homepage": "https://symfony.com/contributors"
554
+                }
555
+            ],
556
+            "description": "Symfony utilities for portability of PHP codes",
557
+            "homepage": "https://symfony.com",
558
+            "keywords": [
559
+                "compat",
560
+                "compatibility",
561
+                "polyfill",
562
+                "shim"
563
+            ],
564
+            "time": "2016-11-14T01:06:16+00:00"
565
+        }
566
+    ],
567
+    "packages-dev": [],
568
+    "aliases": [],
569
+    "minimum-stability": "stable",
570
+    "stability-flags": [],
571
+    "prefer-stable": false,
572
+    "prefer-lowest": false,
573
+    "platform": [],
574
+    "platform-dev": []
575
+}

BIN
database.mwb View File


+ 17
- 0
index.php View File

@@ -0,0 +1,17 @@
1
+<!DOCTYPE html>
2
+<!--
3
+To change this license header, choose License Headers in Project Properties.
4
+To change this template file, choose Tools | Templates
5
+and open the template in the editor.
6
+-->
7
+<html>
8
+    <head>
9
+        <meta charset="UTF-8">
10
+        <title></title>
11
+    </head>
12
+    <body>
13
+        <?php
14
+        // put your code here
15
+        ?>
16
+    </body>
17
+</html>

+ 7
- 0
nbproject/project.properties View File

@@ -0,0 +1,7 @@
1
+include.path=${php.global.include.path}
2
+php.version=PHP_70
3
+source.encoding=UTF-8
4
+src.dir=.
5
+tags.asp=false
6
+tags.short=false
7
+web.root=.

+ 9
- 0
nbproject/project.xml View File

@@ -0,0 +1,9 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project xmlns="http://www.netbeans.org/ns/project/1">
3
+    <type>org.netbeans.modules.php.project</type>
4
+    <configuration>
5
+        <data xmlns="http://www.netbeans.org/ns/php-project/1">
6
+            <name>NetsymsBusinessSSO</name>
7
+        </data>
8
+    </configuration>
9
+</project>

+ 231
- 0
required.php View File

@@ -0,0 +1,231 @@
1
+<?php
2
+
3
+/**
4
+ * This file contains global settings and utility functions.
5
+ */
6
+ob_start();
7
+session_start();
8
+
9
+header('Content-Type: text/html; charset=utf-8');
10
+
11
+// Composer
12
+require __DIR__ . '/vendor/autoload.php';
13
+// Settings file
14
+require __DIR__ . '/settings.php';
15
+
16
+function sendError($error) {
17
+    die("<!DOCTYPE html><html><head><title>Error</title></head><body><h1 style='color: red; font-family: sans-serif; font-size:100%;'>" . htmlspecialchars($error) . "</h1></body></html>");
18
+}
19
+
20
+date_default_timezone_set(TIMEZONE);
21
+
22
+// Database settings
23
+// Also inits database and stuff
24
+use Medoo\Medoo;
25
+
26
+$database;
27
+try {
28
+    $database = new Medoo([
29
+        'database_type' => DB_TYPE,
30
+        'database_name' => DB_NAME,
31
+        'server' => DB_SERVER,
32
+        'username' => DB_USER,
33
+        'password' => DB_PASS,
34
+        'charset' => DB_CHARSET
35
+    ]);
36
+} catch (Exception $ex) {
37
+    //header('HTTP/1.1 500 Internal Server Error');
38
+    sendError("Database error.  Try again later.  $ex");
39
+}
40
+
41
+
42
+if (!DEBUG) {
43
+    error_reporting(0);
44
+} else {
45
+    error_reporting(E_ALL);
46
+    ini_set('display_errors', 'On');
47
+}
48
+
49
+
50
+$VARS;
51
+if ($_SERVER['REQUEST_METHOD'] === 'POST') {
52
+    $VARS = $_POST;
53
+    define("GET", false);
54
+} else {
55
+    $VARS = $_GET;
56
+    define("GET", true);
57
+}
58
+
59
+/**
60
+ * Checks if a string or whatever is empty.
61
+ * @param $str The thingy to check
62
+ * @return boolean True if it's empty or whatever.
63
+ */
64
+function is_empty($str) {
65
+    return (is_null($str) || !isset($str) || $str == '');
66
+}
67
+
68
+/**
69
+ * Add a user to the system.  /!\ Assumes input is OK /!\
70
+ * @param string $username Username, saved in lowercase.
71
+ * @param string $password Password, will be hashed before saving.
72
+ * @param string $realname User's real legal name
73
+ * @param string $email User's email address.
74
+ * @return int The new user's ID number in the database.
75
+ */
76
+function adduser($username, $password, $realname, $email = "NOEMAIL@EXAMPLE.COM", $phone1 = "", $phone2 = "") {
77
+    global $database;
78
+    $database->insert('accounts', [
79
+        'username' => strtolower($username),
80
+        'password' => encryptPassword($password),
81
+        'realname' => $realname,
82
+        'email' => $email,
83
+        'phone1' => $phone1,
84
+        'phone2' => $phone2
85
+    ]);
86
+    return $database->id();
87
+}
88
+
89
+/**
90
+ * Checks if an email address is valid.
91
+ * @param string $email Email to check
92
+ * @return boolean True if email passes validation, else false.
93
+ */
94
+function isValidEmail($email) {
95
+    return filter_var($email, FILTER_VALIDATE_EMAIL);
96
+}
97
+
98
+/**
99
+ * Check if an email exists in the database.
100
+ * @param String $email
101
+ */
102
+function email_exists($email) {
103
+    global $database;
104
+    return $database->has('accounts', ['email' => $email, "LIMIT" => QUERY_LIMIT]);
105
+}
106
+
107
+/**
108
+ * Check if a username exists in the database.
109
+ * @param String $username
110
+ */
111
+function user_exists($username) {
112
+    global $database;
113
+    return $database->has('accounts', ['username' => $username, "LIMIT" => QUERY_LIMIT]);
114
+}
115
+
116
+/**
117
+ * Checks the given credentials to see if they're legit.
118
+ * @param string $username
119
+ * @param string $password
120
+ * @return boolean True if OK, else false
121
+ */
122
+function authenticate_user_ldap($username, $password) {
123
+    $ds = ldap_connect(LDAP_SERVER);
124
+    if ($ds) {
125
+        $sr = ldap_search($ds, LDAP_BASEDN, "(|(uid=" . $username . ")(mail=" . $username . "))", ['cn', 'uid', 'mail']);
126
+        if (ldap_count_entries($ds, $sr) == 1) {
127
+            $info = ldap_get_entries($ds, $sr);
128
+            $name = $info[0]["cn"][0];
129
+            $uid = $info[0]["uid"][0];
130
+            $mail = $info[0]["mail"][0];
131
+            $_SESSION['uid'] = $uid;
132
+            $_SESSION['name'] = $name;
133
+            $_SESSION['mail'] = $mail;
134
+            return true;
135
+        } else if (ldap_count_entries($ds, $sr) > 1) {
136
+            sendError("Multiple users matched search criteria.  Unsure which one you are.");
137
+        } else {
138
+            return false;
139
+        }
140
+    } else {
141
+        sendError("Login server offline.");
142
+    }
143
+}
144
+
145
+/**
146
+ * Hashes the given plaintext password
147
+ * @param String $password
148
+ * @return String the hash, using bcrypt
149
+ */
150
+function encryptPassword($password) {
151
+    return password_hash($password, PASSWORD_BCRYPT);
152
+}
153
+
154
+/**
155
+ * Securely verify a password and its hash
156
+ * @param String $password
157
+ * @param String $hash the hash to compare to
158
+ * @return boolean True if password OK, else false
159
+ */
160
+function comparePassword($password, $hash) {
161
+    return password_verify($password, $hash);
162
+}
163
+
164
+function dieifnotloggedin() {
165
+    if ($_SESSION['loggedin'] != true) {
166
+        sendError("Session expired.  Please log out and log in again.");
167
+    }
168
+}
169
+
170
+/**
171
+ * Check if the previous database action had a problem.
172
+ * @param array $specials int=>string array with special response messages for SQL errors
173
+ */
174
+function checkDBError($specials = []) {
175
+    global $database;
176
+    $errors = $database->error();
177
+    if (!is_null($errors[1])) {
178
+        foreach ($specials as $code => $text) {
179
+            if ($errors[1] == $code) {
180
+                sendError($text);
181
+            }
182
+        }
183
+        sendError("A database error occurred:<br /><code>" . $errors[2] . "</code>");
184
+    }
185
+}
186
+
187
+/*
188
+ * http://stackoverflow.com/a/20075147/2534036
189
+ */
190
+if (!function_exists('base_url')) {
191
+
192
+    function base_url($atRoot = FALSE, $atCore = FALSE, $parse = FALSE) {
193
+        if (isset($_SERVER['HTTP_HOST'])) {
194
+            $http = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off' ? 'https' : 'http';
195
+            $hostname = $_SERVER['HTTP_HOST'];
196
+            $dir = str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);
197
+
198
+            $core = preg_split('@/@', str_replace($_SERVER['DOCUMENT_ROOT'], '', realpath(dirname(__FILE__))), NULL, PREG_SPLIT_NO_EMPTY);
199
+            $core = $core[0];
200
+
201
+            $tmplt = $atRoot ? ($atCore ? "%s://%s/%s/" : "%s://%s/") : ($atCore ? "%s://%s/%s/" : "%s://%s%s");
202
+            $end = $atRoot ? ($atCore ? $core : $hostname) : ($atCore ? $core : $dir);
203
+            $base_url = sprintf($tmplt, $http, $hostname, $end);
204
+        } else
205
+            $base_url = 'http://localhost/';
206
+
207
+        if ($parse) {
208
+            $base_url = parse_url($base_url);
209
+            if (isset($base_url['path']))
210
+                if ($base_url['path'] == '/')
211
+                    $base_url['path'] = '';
212
+        }
213
+
214
+        return $base_url;
215
+    }
216
+
217
+}
218
+
219
+function redirectToPageId($id, $args, $dontdie) {
220
+    header('Location: ' . URL . '?id=' . $id . $args);
221
+    if (is_null($dontdie)) {
222
+        die("Please go to " . URL . '?id=' . $id . $args);
223
+    }
224
+}
225
+
226
+function redirectIfNotLoggedIn() {
227
+    if ($_SESSION['loggedin'] !== TRUE) {
228
+        header('Location: ' . URL . '/login.php');
229
+        die();
230
+    }
231
+}

+ 30
- 0
settings.template.php View File

@@ -0,0 +1,30 @@
1
+<?php
2
+
3
+// Whether to show debugging data in output.
4
+// DO NOT SET TO TRUE IN PRODUCTION!!!
5
+define("DEBUG", false);
6
+
7
+// Database connection settings
8
+// See http://medoo.in/api/new for info
9
+define("DB_TYPE", "mysql");
10
+define("DB_NAME", "sso");
11
+define("DB_SERVER", "localhost");
12
+define("DB_USER", "sso");
13
+define("DB_PASS", "");
14
+define("DB_CHARSET", "utf8");
15
+
16
+define("LDAP_SERVER", "example.com");
17
+define("LDAP_BASEDN", "ou=users,dc=example,dc=com");
18
+
19
+define("SITE_TITLE", "Netsyms Business Apps :: Single Sign On");
20
+
21
+define("COPYRIGHT_NAME", "Netsyms Technologies");
22
+
23
+// For supported values, see http://php.net/manual/en/timezones.php
24
+define("TIMEZONE", "America/Denver");
25
+
26
+// Base URL for site links.
27
+define('URL', 'http://localhost:8000/');
28
+
29
+// Maximum number of rows to get in a query.
30
+define("QUERY_LIMIT", 1000);

Loading…
Cancel
Save