Adjusted DB Installer to include comment field
[PHPCredLocker.git] / Install / index.php
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
<?php
/** PHPCredLocker Installer File
*
* Copyright (C) 2012 B Tasker
* Released under GNU GPL V2
* See LICENSE
*
*/
define('_CREDLOCK',"1");
 
 
 
// Prevent some of the required modules from bumming out
class notifications{
 
function RequireScript($script){
echo "<script src='../Resources/$script.js' type='text/javascript'></script>\n";
}
 
function RequireCSS($css){
echo "<link rel='stylesheet' type='text/css' href='../Resources/$css.css' />\n";
}
 
}
 
class Logging{
 
function LogEntry($cred,$action){
return;
}
 
}
 
/** Remove the installation directory
*
*/
function credlocker_install_stage_17(){
 
if (unlink(__FILE__) && rmdir(dirname(__FILE__))){
// Successfully removed
header('Location: ../index.php');
die;
}else{
 
echo "<div class='alert alert-error' title=\"The directory couldn't be removed - usually a permissions issue. Remove it manually to continue\">Unable to remove the Installation directory. Please remove <i>Install</i> manually</div>";
 
}
 
}
 
 
 
/** Inform the user of the final step
*
*/
function credlocker_install_stage_16(){
?>
<h1>System Configured</h1>
 
PHPCredLocker is installed and configured, all that remains is to remove the installation directory! 
 
To attempt to do this automatically, click the button below. Alternatively manually remove the directory <i>Install</i>. 
 
Once removed, you'll be able to log into the system with the details you just provided. Before you can add Credentials to the system, you'll need to create at least one Credential Type from the administration menu.
 
<form method="POST">
<input type="hidden" name="stage" value="17">
<input type="submit" class="btn btn-primary" value="Remove Installation Directory">
</form>
<?php
 
}
 
 
 
/** Create the admin user
*
*/
function credlocker_install_stage_15(){
require 'lib/auth.class.php';
 
$auth = new ProgAuth;
 
if ($auth->createUser($_POST['UserName'],$_POST['frmPass'],$_POST['RealName'], array("-1"))){
 
echo "<div class='alert alert-success'>Added User Successfully</div>";
 
}else{
echo "<div class='alert alert-error'>Could not add user, please try again</div>";
}
 
 
credlocker_install_stage_16();
}
 
 
/** Get the user to provide details necessary to create the admin user
*
*/
function credlocker_install_stage_14(){
notifications::RequireScript('passwordmeter');
notifications::RequireScript('main');
?>
<h1>Create Administrator Account</h1>
Next we'll create the Administrator account for this install
 
 
<form method="POST" onsubmit="return validateUserAdd();">
<input type="hidden" name="stage" value="15">
<input type="hidden" id="passScore" disabled="true">
<input type="hidden" id="minpassStrength" disabled="true" value="<?php echo BTMain::getConf()->minpassStrength;?>">
 
<table>
<tr><th>Username</th><td title="Your desired username, try to avoid 'admin' as it's a little easy for an attacker to guess"><input type="text" name="UserName" id="frmUsername"></td><td></td></tr>
<tr><th>Real Name</th><td title="Your real name (will be used in Logs)"><input type="text" name="RealName" id="frmRName"></td><td></td></tr>
<tr><th>Password</th><td title="Enter a password, minimum strength is whatever you selected earlier"><input type="password" name="frmPass" id="frmPass" autocomplete="off" onkeyup="testPassword(this.value);"></td><td><span id="passStrength"></span><div id="PassNoMatch" style="display: none;" class="alert alert-error"></div></td></tr>
<tr><th>Confirm Password</th><td title="Confirm your password"><input type="password" name="frmPassConf" autocomplete="off" id="frmPassConf"></td><td></td></tr>
</table>
<input type="submit" class="btn btn-primary" value="Create User">
</form>
 
<?php
 
}
 
 
 
 
 
 
/** Use the Entropy to create a key
*
*/
function credlocker_install_stage_13(){
 
writeCryptoKey("Groups","Groups");
credlocker_install_stage_14();
 
 
}
 
 
 
/** Generate a key for authentication
*
*/
function credlocker_install_stage_12(){
$notifications = new notifications;
?>
 
<h1>Create Group Key - Last One!</h1>
 
Now we're going to create an encryption key which will be used to secure all Group Data. To do so, we need to generate random data, so please move your mouse and click randomly in the box below until it turns green
<br/><br /><form method="POST">
<input type="hidden" name="stage" value="13">
<?php require 'lib/includes/gatherEntropy.php'; ?>
<input type="submit" class="btn btn-primary" value="Generate Key">
</form>
<?php
}
 
 
 
/** Use the Entropy to create a key
*
*/
function credlocker_install_stage_11(){
 
writeCryptoKey("Customer","Customer Data");
credlocker_install_stage_12();
 
 
}
 
 
 
/** Generate a key for authentication
*
*/
function credlocker_install_stage_10(){
$notifications = new notifications;
?>
 
<h1>Create Customer Key</h1>
 
Now we're going to create an encryption key which will be used to secure all Customer Data. To do so, we need to generate random data, so please move your mouse and click randomly in the box below until it turns green
<br/><br /><form method="POST">
<input type="hidden" name="stage" value="11">
<?php require 'lib/includes/gatherEntropy.php'; ?>
<input type="submit" class="btn btn-primary" value="Generate Key">
</form>
<?php
}
 
 
 
 
/** Use the Entropy to create a key
*
*/
function credlocker_install_stage_9(){
writeCryptoKey("CredType","Credential Types");
credlocker_install_stage_10();
 
 
}
 
 
 
/** Generate a key for authentication
*
*/
function credlocker_install_stage_8(){
$notifications = new notifications;
?>
 
<h1>Create CredType Key</h1>
 
Now we're going to create an encryption key which will be used to secure all Credential Categories. To do so, we need to generate random data, so please move your mouse and click randomly in the box below until it turns green
<br/><br /><form method="POST">
<input type="hidden" name="stage" value="9">
<?php require 'lib/includes/gatherEntropy.php'; ?>
<input type="submit" class="btn btn-primary" value="Generate Key">
</form>
<?php
}
 
 
 
 
 
 
/** Use the Entropy to create a key
*
*/
function credlocker_install_stage_7(){
writeCryptoKey("auth","Authentication");
credlocker_install_stage_8();
 
 
}
 
 
/** Generate a key for authentication
*
*/
function credlocker_install_stage_6(){
$notifications = new notifications;
?>
 
<h1>Create Authentication Key</h1>
 
Now we're going to create an encryption key which will be used to secure all user accounts. To do so, we need to generate random data, so please move your mouse and click randomly in the box below until it turns green
<br/><br /><form method="POST">
<input type="hidden" name="stage" value="7">
<?php require 'lib/includes/gatherEntropy.php'; ?>
<input type="submit" class="btn btn-primary" value="Generate Key">
</form>
<?php
}
 
 
 
/** Set Crypto settings then have the user generate entropy so we can create keys
*
*/
function credlocker_install_stage_5(){
 
if (!$fh = fopen(dirname(__FILE__)."/../conf/crypto.php",'w')){
echo "<div class='alert alert-error'>Unable to create Cryptographic config file, please check permissions and try again</div>";
return;
 
}
 
 
 
// Create the file header
$str = "<?php\n/** Crypto Keys\n*\n*KEEP THIS FILE SECRET!\n*\n* Copyright (C) 2012 B Tasker\n* Released under GNU GPL V2\n* See LICENSE\n*\n*/\ndefined('_CREDLOCK') or die;\n\n";
 
fwrite($fh,$str);
 
 
$str = "\t\t /** General Settings **/\n\$cipher->Engine = '{$_POST['Engine']}';\n\$cipher->keyLength='{$_POST['keyLength']}';\n\n";
 
if (is_array($_POST['MCrypt'])){
$str .= "\t\t /** MCrypt Specific **/\n\$cipher->MCrypt->Encryption = '{$_POST['MCrypt']['Encryption']}';\n\$cipher->MCrypt->mode = '{$_POST['MCrypt']['mode']}';\n\n";
}
 
if (is_array($_POST['openssl'])){
$str .= "\t\t/** OpenSSL Specific **/\n\$cipher->OpenSSL->Cipher = '{$_POST['openssl']['cipher']}';\n\n";
}
 
$str .= "\n\n \t\t /** KEYS FOLLOW **/\n\n";
 
fwrite($fh,$str);
fclose($fh);
 
echo "<div class='alert alert-success'>Cryptographic Settings Saved</div>";
 
credlocker_install_stage_6();
}
 
 
/** Set up Crypto
*
*/
function credlocker_install_stage_4(){
 
?><h1>CryptoGraphic Settings</h1>
 
Before we generate keys, we need to set which engine and cipher will be used
 
<form method="POST">
<input type="hidden" name="stage" value="5">
 
<table>
<tr><td colspan="2"><h2>Crypto Settings</h2></td></tr>
 
<tr>
<td>Encryption Engine</td>
<td title="The Encryption engine to use, OpenSSL is generally recommended - if you have it (requires PHP 5.3)">
<select name="Engine">
<?php
 
$ssl = function_exists('openssl_encrypt');
$mcrypt = function_exists('mcrypt_encrypt');
 
if ($ssl){
echo "<option value='OpenSSL' selected>OpenSSL</option>\n";
}
 
if ($mcrypt){
echo "<option value='MCrypt'>MCrypt</option>\n";
}
 
?>
</select>
</td></tr>
 
<tr>
<td>Key Length</td>
<td title="The length of encryption key to use. Higher is generally more secure but may have a performance impact"><input type="text" name="keyLength" value="2048"></td>
</tr>
 
 
 
        <?php if ($ssl):?>
          <tr>
                <td>&nbsp;</td><td>&nbsp;</td>
          </tr>
          <tr>
            <td colspan="2"><h2>OpenSSL Specific Settings</h2></td>
          </tr>
 
          <tr>
            <td>Algorithm</td><td title="The OpenSSL algorithm to use. PHPCredLocker has been most heavily tested with des-cbc"><select name="openssl[cipher]">
                <?php foreach (openssl_get_cipher_methods() as $cipher) {?>
                      <option value='<?php echo $cipher; ?>'><?php echo $cipher; ?></option>
                <?php }?>
            </select></td>
          </tr>
        <?php endif; ?>
 
        <?php if ($mcrypt):?>
          <tr>
                <td>&nbsp;</td><td>&nbsp;</td>
          </tr>
 
          <tr>
            <td colspan="2"><h2>MCrypt Specific Settings</h2></td>
          </tr>
 
          <tr>
            <td>Algorithm</td><td title="The MCrypt Algorithm to use"><select name="MCrypt[Encryption]">
                <?php foreach (mcrypt_list_algorithms() as $cipher) {?>
                      <option value='<?php echo $cipher; ?>'><?php echo $cipher; ?></option>
                <?php }?>
            </select></td>
          </tr>
          <tr>
            <td>Mode</td><td title="The Mcrypt Mode to use"><select name="MCrypt[mode]">
                <?php foreach (mcrypt_list_modes() as $cipher) {?>
                      <option value='<?php echo $cipher; ?>'><?php echo $cipher; ?></option>
                <?php }?>
            </select></td>
          </tr>
            
        <?php endif; ?>
 
</table>
 <input type="submit" class="btn btn-primary" value="Proceed to Key Generation">
  </form>
 
 
 
<?php
 
}
 
/** Write the config file and create the database
*
*/
function credlocker_install_stage_3(){
unset($_POST['stage']);
 
 
if (!$fh = fopen(dirname(__FILE__)."/../conf/config.php",'w')){
echo "<div class='alert alert-error'>Unable to create config file, please check permissions and try again</div>";
return;
 
}
 
 
 
// Create the file header
$str = "<?php\n/** System Configuration\n*\n* Copyright (C) 2012 B Tasker\n* Released under GNU GPL V2\n* See LICENSE\n*\n*/\ndefined('_CREDLOCK') or die;\n\n";
 
fwrite($fh,$str);
  foreach ($_POST as $key=>$value){
 
      if ($value == 'true' || $value == 'false'){
        $val = $value;
      }else{
        $val = "'$value'";
      }
 
    $str = "\$conf->$key = $val;\n";
    fwrite($fh,$str);
  }
 
fwrite($fh,"\n\n?>");
fclose($fh);
 
echo "<div class='alert alert-success'>Config file created</div>";
 
unset($fh);
 
 
// Create the plugins obfuscation string and write to the config file
// For some reason this always returns false, so not using a test and hoping for the best!
$fh = fopen(dirname(__FILE__)."/../conf/plugins.php",'a+');
 
$obfus = sha1(mt_rand(0,90000) . date('s') . mt_rand(500,9999999) . mt_rand(1000,50000));
 
if (rename(dirname(__FILE__)."/../plugins/Blargle", dirname(__FILE__)."/../plugins/$obfus")){
 
$str = "\n\n defined(\"CREDLOCK_PLUGIN__PATH\") or define('CREDLOCK_PLUGIN__PATH','plugins/$obfus');\n";
fwrite($fh,$str);
fclose($fh);
}else{
echo "<div class='alert alert-error'>Could not Obfuscate Plugin path, you will need to do this manually</div>";
}
 
 
 
$sqls = array(
'DROP TABLE IF EXISTS `#__Audit`;',
 
'CREATE TABLE `#__Audit` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `date` datetime NOT NULL,
  `User` varchar(150) DEFAULT NULL,
  `Cust` varchar(150) DEFAULT NULL,
  `Action` tinyint(4) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;',
 
'DROP TABLE IF EXISTS `#__Cred`;',
 
'CREATE TABLE `#__Cred` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `cust` int(11) NOT NULL,
  `Added` datetime NOT NULL,
  `Group` int(11) NOT NULL,
  `Hash` blob,
  `CredType` int(11) NOT NULL,
  `Clicky` tinyint(1) unsigned NOT NULL DEFAULT \'0\',
  `Address` blob,
  `UName` blob,
  `Custom` blob,
  `hidden` tinyint(1) DEFAULT 0,
  `comment` blob DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `idx_Cred_Group` (`Group`),
  KEY `idx_cred_cust` (`cust`)
) ENGINE=MyISAM AUTO_INCREMENT=11 DEFAULT CHARSET=latin1;',
 
'DROP TABLE IF EXISTS `#__CredTypes`;',
 
'CREATE TABLE `#__CredTypes` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `Name` blob,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=12 DEFAULT CHARSET=latin1;',
 
'DROP TABLE IF EXISTS `#__Cust`;',
 
'CREATE TABLE `#__Cust` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `Name` blob,
  `Group` int(11) NOT NULL,
  `ContactName` blob,
  `ContactSurname` blob,
  `Email` blob,
  UNIQUE KEY `id` (`id`),
  UNIQUE KEY `idx_Customers` (`Name`(255)),
  KEY `idx_Cust_Group` (`Group`)
) ENGINE=MyISAM AUTO_INCREMENT=20 DEFAULT CHARSET=latin1;',
 
'DROP TABLE IF EXISTS `#__Groups`;',
 
'CREATE TABLE `#__Groups` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `Name` blob,
  `Parent` int(11) NOT NULL DEFAULT 0,
  `OwnCrypt` tinyint(1) NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`),
  KEY `idx_grp_parents` (`Parent`)
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;',
 
'DROP TABLE IF EXISTS `#__Sessions`;',
 
'CREATE TABLE `#__Sessions` (
  `SessionID` varchar(150) NOT NULL,
  `Created` datetime NOT NULL,
  `User` varchar(150) NOT NULL,
  `Expires` datetime NOT NULL,
  `ClientIP` varchar(100) NOT NULL,
  `SessKey` varchar(255) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL,
  PRIMARY KEY (`SessionID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;',
 
'DROP TABLE IF EXISTS `#__Users`;',
 
'CREATE TABLE `#__Users` (
  `username` varchar(150) NOT NULL,
  `pass` blob NOT NULL,
  `Name` varchar(255) NOT NULL,
  `membergroup` longtext,
  `Usergroup` int(11) NOT NULL DEFAULT \'0\',
  PRIMARY KEY (`username`,`Usergroup`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;',
 
'DROP TABLE IF EXISTS `#__bannedIPs`;',
 
'CREATE TABLE `#__bannedIPs` (
  `IP` varchar(255) NOT NULL,
  `Expiry` datetime NOT NULL,
  PRIMARY KEY (`IP`),
  KEY `idx_ban_expiry` (`Expiry`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;',
 
'DROP TABLE IF EXISTS `#__FailedLogins`;',
 
'CREATE TABLE `#__FailedLogins` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(150) NOT NULL,
  `FailedAttempts` int(11) NOT NULL,
  `LastAttempt` datetime NOT NULL,
  `FailedIP` varchar(255) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `idx_failed_user_ip` (`username`,`FailedIP`),
  KEY `idx_failedips` (`FailedIP`)
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;',
 
'CREATE TABLE #__CustPortal( `id` INT NOT NULL, `email` TEXT, `pass` TEXT, `active` TINYINT(1), PRIMARY KEY (`id`));',
'CREATE UNIQUE INDEX idx_portal_logins ON #__CustPortal(`email`(100));',
'CREATE INDEX ifdx_active_portal ON #__CustPortal(`active`);,'
 
);
 
 
 
 
 
 
 
 
$db = new BTDB;
foreach ($sqls as $sql){
 
 
$db->setQuery($sql);
    if (!$db->runQuery()){
        echo "<div class='alert alert-error'>Database Creation Failed. Please try again</div>";
        return;
 
     }
}
echo "<div class='alert alert-success'>Database Tables Created</div>";
credlocker_install_stage_4();
 
 
 
}
 
 
/** Stage 2 - Set up the Config File including MySQL connection
*
*/
function credlocker_install_stage_2(){
 
?>
<form method="POST">
<input type="hidden" name="stage" value="3">
<input type="hidden" name="template" value="EstDeus">
<input type="hidden" name="JSMinName" value=".min">
<input type="hidden" name="forceSSL" value="false">
 
<table>
<tr>
<td colspan="2"><h2>Application Configuration</h2></td>
</tr>
<tr>
<td>Application Name</td><td title="The application name you want displayed in the Interface"><input type="text" name="ProgName" value="PHPCredLocker"></td>
</tr>
 
<tr>
<td>&nbsp;</td><td>&nbsp;</td>
</tr>
 
 
<tr>
<td colspan="2"><h2>Security Options</h2></td>
</tr>
<tr>
<td >Display Credentials for</td><td title="How long should credentials be displayed for when a user requests them? Should really be set to a low value" ><input type="text" name="CredDisplay" value="30" length="3"> seconds</td>
</tr>
<tr>
<td >Minimum Password Strength</td>
<td title="The weakest element of the system is usually going to be authentication. Any security measures taken in PHPCredLocker are wasted if you allow users to set obvious passwords!"><select name="minpassStrength">
<option value="0-16">Very Weak</option>
<option value="15-25">Weak</option>
<option value="24-35">Mediocre</option>
<option value="34-45" selected>Strong</option>
<option value="45+">Very Strong</option>
</td>
</tr>
<tr>
<td >Expire Sessions after</td><td title="Regardless of activity, sessions will expire after this interval. A lowish setting is recommended"><input type="text" name="sessionexpiry" value="15"> minutes</td>
</tr>
<tr>
<td >Internal Audit Logging Enabled</td><td title="All actions are usually logged. If you don't want this to happen, turn this off"><input type="checkbox" checked="checked" name="loggingenabled" value="true"></td>
</tr>
<tr>
<td >Force SSL</td><td title="Redirect http connections to https ones, generally a good idea to have switched on - do you really want to store your passwords securely and then send over the Internet in cleartext?"><input type="checkbox" name="forceSSL" checked="checked" value="true"></td>
</tr>
<tr>
<td >SSL URL</td><td title="The URL to use for https connections. Would normally be https://yourdomain but may be different if you're on shared hosting"><input type="text" name="SSLURL" value="<?php
 
 
$str = "https://".$_SERVER['SERVER_NAME'];
 
 
$req = explode("/",$_SERVER['REQUEST_URI']);
$len = count($req) - 1;
unset($req[$len]);   
unset($req[$len -1]);
 
$str .= implode("/",$req);
echo $str;
?>"></td>
 
<tr>
<td >Cron Password:</td><td title="A password used simply to prevent unauthorised users from running the cronjobs. Default is randomly generated, but you can change if you want"><input type="text" name="cronPass" value="<?php echo base_convert(rand(10e16, 10e20),10,36).mt_rand(0,500);?>"></td>
</tr>
 
 
<tr>
<td>IP Ban Threshold</td>
<td title="Number of permitted authentication failures before an IP is banned"><input type="text" name="banThresh" value="4"></td>
</tr>
 
<tr>
<td>IP Ban Check</td>
<td title="Time period (hours) to examine when considering whether to ban an IP"><input type="text" name="banProximity" value="24"></td>
</tr>
 
 
<tr>
<td>IP Ban Period</td>
<td title="Time period (hours) for which the IP will be banned"><input type="text" name="banLength" value="24"></td>
</tr>
 
 
 
</tr>
 
<tr>
<td>&nbsp;</td><td>&nbsp;</td>
</tr>
 
 
<tr>
<td colspan="2"><h2>Database Options</h2></td>
</tr>
 
<tr>
<td >Database Host</td><td title="The host name or IP address of the server hosting your MySQL Database"><input type="text" name="dbhost" value="localhost"></td>
</tr>
 
<tr>
<td >Database Name</td><td title="The name of the database that PHPCredLocker will be using. Must already exist"><input type="text" name="dbname" value="PHPCredLocker_<?php echo mt_rand(0,90000); ?>"></td>
</tr>
 
<tr>
<td >Database User</td><td title="The database username. Good practice dictates one user per database"><input type="text" name="dbuser" value=""></td>
</tr>
 
<tr>
<td >Database Password</td><td title="The database password"><input type="text" name="dbpass" value=""></td>
</tr>
 
<tr>
<td >Table Prefix</td><td title="Having a random table prefix helps reduce the effectiveness of SQLi attempts, though it's far from a panacea">
<input type="text" name="tblprefix" value="<?php echo chr(mt_rand(97,124)) . chr(mt_rand(97,124)) . chr(mt_rand(97,124)) . chr(mt_rand(97,124));?>_"></td>
</tr>
 
 
<tr>
<td >Display SQL Errors</td><td title="Display any SQL errors that are encountered. Should usually be off!"><input type="checkbox" name="showDBErrors" value="true"></td>
</tr>
 
</table>
 
<input type="submit" class="btn btn-primary" value="Save Configuration">
</form>
<?php
return;
}
 
 
 
 
 
 
 
 
 
 
 
/** Very first stage of install
*
*/
function first_install_stage(){
$fail = 0;
?>
Welcome to the PHPCredLocker Installation script. In a few simple steps we'll create the database, set up encryption keys and create a Superadministrator. <br/><br />
 
<h2>System Tests</h2>
<table class="table table-hover">
<tr>
<th >Crypto Functions</th>
<td title="Cryptographic libraries are required so that stored credentials can be encrypted. Storing in cleartext is a <b>really</b> bad idea and is entirely unsupported" class="test<?php
 
if (function_exists("openssl_encrypt")){
echo 'Pass">Pass - You have OpenSSL';
 
}elseif(function_exists("mcrypt_encrypt")){
echo 'Pass">Pass - You have MCrypt';
 
}else{
echo 'Fail">Fail - Neither the OpenSSL or the MCrypt libraries appear to be available';
$fail = 1;
}
?>
</td>
</tr>
 
 
<tr>
<th >Configuration Writable</th>
<td title='PHPCredLocker needs to be able to write to your configuration files, especially for the install!' class='test<?php
 
 
// is_writable doesn't seem to want to play nice here, writing a file instead
$path = dirname(__FILE__)."/../conf/test.txt";
 
$rm = file_exists($path);
    $f = @fopen($path, 'a');
    if ($f===false){
        echo "Fail'>Fail - Please check directory permissions";
        $fail = 1;
    }else{
    fclose($f);
    if (!$rm){
        unlink($path);
        echo "Pass'>Pass";
        }
}
 
 
 
 
 
 
 
 
?>
</td>
</tr>
 
<tr>
<th>Configuration Protection</th>
<td title='Your configuration directory should only be readable by Owner and group - Other users should be denied access (e.g. 660 or 650 permissions)' class='test<?php
 
$perms = sprintf('%o', fileperms(dirname(__FILE__)."/../conf/"));
 
$allperms = substr($perms,strlen($perms) - 1,1);
 
if ( $allperms != 0 ){
echo "Fail'>Fail - All users have read permissions on configuration directory. This could compromise your encryption keys.";
$fail = 1;
 
}else{
echo "Pass'>Pass";
}
 
 
?>
 
 
 
</tr>
 
<tr>
<th>Database Libraries</th>
<td title="To interact with the database, you'll need the relevant PHP libraries installed" class='test<?php
 
if (function_exists('mysql_query')){
 
echo "Pass'>Pass";
}else{
echo "Fail'>Fail - Could not find MySQL Libraries";
$fail = 1;
}?>
</td></tr>
</table>
 
 
<?php if ($fail == 0):?>
<form method="POST">
<input type="hidden" name="stage" value="2">
<input type="submit" class="btn btn-primary" value="Proceed with Install">
</form>
<?php else: ?>
 
Please address the issues listed above before continuing
 
<?php
endif;
}
 
 
/** Write the specified Crypto Key to the crypto config
*
* @arg key - The KeyName
* @arg text - The text to display to the user
*
*
*/
function writeCryptoKey($keyname,$text){
 
$submitted=1;
require 'lib/includes/gatherEntropy.php';
 
 
if (!$fh = fopen(dirname(__FILE__)."/../conf/crypto.php",'a')){
echo "<div class='alert alert-error'>Unable to append to Cryptographic config file, please check permissions and try again</div>";
return;
 
}
 
$str = "\$crypt->$keyname = '$newkey';\n";
fwrite($fh,$str);
 
fclose($fh);
 
echo "<div class='alert alert-success'>Created Cryptographic key for $text</div>";
 
 
}
 
 
?> 
<html>
<head>
<title>Install PHPCredLocker</title>
 
<link rel="stylesheet" type="text/css" href="../Resources/bootstrap/css/bootstrap-responsive.css" />
<link rel="stylesheet" type="text/css" href="../Resources/bootstrap/css/bootstrap.css" />
<link rel="stylesheet" type="text/css" href="../templates/EstDeus/css/EstDeus.css" />
<link rel="stylesheet" type="text/css" href="../Resources/jquery.tooltip.css" />
<script type="text/javascript" src="../Resources/jquery.min.js"></script>
<script type="text/javascript" src="../Resources/jquery.tooltip.min.js"></script>
<script type="text/javascript" src="../Resources/bootstrap/js/bootstrap.js"></script>
 
 
 
<Style type="text/css">
 
li.stage<?php echo $_POST['stage'];?> {font-weight: bold;}
#BreadCrumbs {width: 80% !important; margin: auto;}
</style>
</head>
<body>
<!-- Main PageWrap begins -->
<div id='all' class='PageWrap pgbackground'>
 
<!-- Navbar Begins -->
<div id='Nav' class='navbar row'>
    <div class='navbar-inner'>
    <div class="span12" style="width: 100%;">
        <a class="brand" href="index.php">PHPCredLocker</a>
          <ul class="nav">
            <li class="divider-vertical"></li>
            <li class="nav"><a id="Inst" href="#">Install</a></li>
          </ul>
    </div>
    </div>
</div>
<div id='FFContainer'>
<div class='contentArea pgbackground' id='contentArea'>
<div class='content' id='ContentWrap'>
 
 
<div class='BreadCrumbs' id='BreadCrumbs'>
 
  <ul class="breadcrumb">
 
    <li class="stage">Introduction</li>
    <li class="stage2"><span class="divider">/</span>Configuration</li>
    <li class="stage3"><span class="divider">/</span>CryptoGraphic Settings</li>
    <li class="stage5"><span class="divider">/</span>Authentication Key</li>
    <li class="stage7"><span class="divider">/</span>Credential Type Key</li>
    <li class="stage9"><span class="divider">/</span>Customer Key</li>
    <li class="stage11"><span class="divider">/</span>Group Key</li>
    <li class="stage13"><span class="divider">/</span>Administrator Account</li>
    <li class="stage15"><span class="divider">/</span>Remove Install Directory</li>
    <li class="stage17"><span class="divider">/</span>Complete!</li>
 
  </ul>
 
</div>
 
 
 
<div class='content'>
<?php
 
 
if (!isset($_POST['stage'])){
first_install_stage();
}else{
 
 
 
 
// Change working dir otherwise our includes will break
chdir(dirname(__FILE__)."/../");
require_once 'lib/Framework/main.php';
 
if (((($_POST['stage'] >= '5') && ($_POST['stage'] <= '13')) || ($_POST['stage'] == 15))) {
require_once 'lib/crypto.php';
 
}
 
 
$fn = "credlocker_install_stage_".$_POST['stage'];
$fn();
}
 
 
 
 
 
 
 
 
 
 
?>
</div>
 
 
</div>
 
</div>
 
</div>
</div>
<script type="text/javascript">
$('#ContentWrap *').tooltip({track: true, fade: 250});
</script>
</body>
</html>