-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.cfg.php
84 lines (65 loc) · 2.64 KB
/
app.cfg.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
<?php
/**
* Copyright (c) Karl Austin - 2019, All Rights Reserved.
*/
/**
* Created by PhpStorm.
* User: karlaustin
* Date: 13/02/2019
* Time: 09:45
*/
define( 'APP_DIR', __DIR__ );
define( 'BACKUP_SUFFIX', '.bak' );
define( 'BLOCK_START', '#* DYNAMIC IPS -- START *#' );
define( 'BLOCK_END', '#* DYNAMIC IPS -- END *#' );
$cOptionsShort = 'h';
$cOptionsLong = array(
'hostnames:',
'ips:',
'htaccess:',
'backup',
'ipv6',
'compat',
'litespeed',
'help'
);
/**
* FILTER_VALIDATE_DOMAIN needs PHP7
*/
if( PHP_MAJOR_VERSION < 7 ) {
echo 'Error: You need PHP 7.0 or newer to run this tool';
exit(-1);
}
$cOptions = getopt( $cOptionsShort, $cOptionsLong );
if( !isset( $cOptions['hostnames'] )
|| !isset( $cOptions['htaccess'] )
|| isset($cOptions['h'] )
|| isset($cOptions['help'] )) {
echo <<<EOD
USAGE:
dynamic.php --htaccess <file> --hostnames <file> [--ipv6] [--backup] [--compat|--litespeed]
-h|--help This help message
--htaccess Path to the .htaccess file you'd like to put the IPs in
--hostnames Path to the file containing a list of dynamic hosts, one entry per line
--ipv6 Optional: Perform IPv6 lookup on each hostname as well
--backup Optional: Make a backup (default prefix .bak) of the .htaccess file
--compat Optional: Apache 2.2 syntax
--litespeed Optional: Same as --compat, enabling Apache 2.2 syntax for Litespeed Web Server
WARNING: Any new .htaccess file or backup file that is created, will be created as the user running this script.
Similarly, any new file created will be created with the system default umask.
EOD;
exit( -1 );
}
if( !file_exists( $cOptions['hostnames'] ) ) {
echo 'Error: The hostnames file does not exist' . "\n";
exit( -1 );
}
define( 'BACKUP', isset( $cOptions['backup'] ) ? true : false );
define( 'COMPAT', ( isset( $cOptions['compat'] ) || isset( $cOptions['litespeed'] ) ) ? true : false );
define( 'IPV6', isset( $cOptions['ipv6'] ) ? true : false );
define( 'FILE_HOSTNAMES', $cOptions['hostnames'] );
// define( 'FILE_IPS', $cOptions['ips'] );
define( 'FILE_HTACCESS', $cOptions['htaccess'] );
define( 'OUTPUT_PREFIX', COMPAT ? "Order Deny,Allow\nDeny from all" : '<RequireAny>' );
define( 'OUTPUT_SUFFIX', COMPAT ? '' : '</RequireAny>' );
define( 'OUTPUT_ENTRY_PREFIX', COMPAT ? 'Allow from' : 'Require ip' );