ban-met-htaccess

Gesponsorde koppelingen

PHP script bestanden

  1. ban-met-htaccess

« Lees de omschrijving en reacties

Code (php)
PHP script in nieuw venster Selecteer het PHP script
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
<?php
session_start();
/***************************************************************/
//Some vars you can adjust//
/***************************************************************/

$file = '.htaccess';
$login = 'Dark';
$pass = 'passwoord';
$page = $_SERVER['PHP_SELF'];
$login_code=md5($login.$pass);
/***************************************************************/
//Controll if your logged in//
/***************************************************************/

if(isset($_POST['login']) && isset($_POST['password'])){
$_SESSION['code']=md5($_POST['login'].$_POST['password']);
header('Location: '.$page);
}

if(isset($_POST['logout'])){
$_SESSION['code']='';
header('Location: '.$page);
}

if(isset($_SESSION['code'])){
$code=$_SESSION['code'];
}

else{
$code='';
}

if($code!=$login_code){
echo '<table width="500" cellspacing="0" cellpadding="2" border="1" align="center">';
echo '<form action="'.$page.'" method="POST">';
echo '<tr><td colspan="2"><h1>Login</h1></td></tr>';
if($code!=''){
echo '<tr><td colspan="2">Wrong login/password.</td></tr>';    
}

echo '<tr><td>Login:</td><td><input type="text" name="login"></td></tr>';
echo '<tr><td>Password:</td><td><input type="password" name="password"></td></tr>';
echo '<tr><td colspan="2" align="center"><input type="submit" name="submit" value="Login"></td></tr>';
echo '</form>';
echo '</table>';
exit();
}

/***************************************************************/
//Function read opens a page and reads its source (in this case .htaccess)//
/***************************************************************/

function read($site){
$contents='';
$handle = @fopen ($site, "r");
if($handle){
while (!feof ($handle)) {
$buffer = fgets($handle, 4096);
$contents=$contents.$buffer;
}

fclose ($handle);
return $contents;
}
}

/***************************************************************/
//Check of a .htaccess excist, if not create one//
/***************************************************************/

if(!file_exists($file)){
$handle=fopen($file, "w");
fwrite($handle, 'allow from all');    
}

/***************************************************************/
//open .htaccess//
/***************************************************************/

$file_content=strtolower(read($file));
/***************************************************************/
//Update .htaccess//
/***************************************************************/

if(isset($_GET['d']) && isset($_GET['t'])){
    if(substr_count($file_content, $_GET['d'])==1){
        if($_GET['t']=='a'){
            $string='allow from '.$_GET['d'];
        }

        else{
            $string='deny from '.$_GET['d'];
        }

        $file_content=str_replace($string, '',$file_content);
        $handle=fopen($file, "w");
        fwrite($handle, $file_content);
    }
}

elseif(isset($_POST['submit'])){
$add='';
    if(isset($_POST['status'])){
        if(substr_count($file_content, 'deny from all')==1){
        $status='deny';    
        }

        elseif(substr_count($file_content, 'allow from all')==1){
        $status='allow';    
        }

        else{
        $status='empty';
        }

         if($_POST['status']=='allow' && $status!='allow'){
             $string='deny from all';
            $file_content=str_replace($string, '',$file_content);
            $file_content="allow from all\n".$file_content;
            $handle=fopen($file, "w");
            fwrite($handle, trim($file_content));
         }

         elseif($status=='empty'){
             $file_content="allow from all\n".$file_content;
            $handle=fopen($file, "w");
            fwrite($handle, trim($file_content));
        }

         else{
             $string='allow from all';
            $file_content=str_replace($string, '',$file_content);
            $file_content="deny from all\n".$file_content;
            $handle=fopen($file, "w");
            fwrite($handle, trim($file_content));
        }
    }

    if(isset($_POST['allow'])){
        if($_POST['allow']!=''){    
            if(substr_count($file_content, $_POST['allow'])==0){
                $add="\nallow from ".$_POST['allow'];
            }
        }
    }

    if(isset($_POST['deny'])){
        if($_POST['deny']!=''){
            if(substr_count($file_content, $_POST['deny'])==0){
                $add.="\ndeny from ".$_POST['deny'];
            }    
        }
    }

    if(isset($add)){
    $handle=fopen($file, "a");
    fwrite($handle, $add);
    }
}

/***************************************************************/
//open .htaccess//
/***************************************************************/

$file_content=strtolower(read($file));
$file_split=explode("\n", $file_content);
$count=count($file_split);
/***************************************************************/
$allowall = 0;
$denyall = 0;
$denies = array();
$allows = array();
for($i=0;$i<$count;$i++){
$this_var=$file_split[$i];
    if(substr_count($this_var, 'allow from all')>0){
        $allowall=1;
    }

    elseif(substr_count($this_var, 'deny from all')>0){
        $denyall=1;
    }

    elseif(substr_count($this_var, 'deny from')>0){
        $denies[$i]=trim(str_replace('deny from', '', $this_var));
    }

    elseif(substr_count($this_var, 'allow from')>0){
        $allows[$i]=trim(str_replace('allow from', '', $this_var));
    }
}

/***************************************************************/
echo '<table width="500" cellspacing="0" cellpadding="2" border="1" align="center">';
echo '<tr><td colspan="2"><h1>Htaccess Banner</h1></td></tr>';
echo '<tr><td colspan="2"><b>Status:</b> ';
if($denyall==0){
echo 'everybody is allowed.';
}

else{
echo 'everybody is banned.';
}

echo '</td></tr>';
$allows=implode("\n",$allows);
$allows=explode("\n",$allows);
$denies=implode("\n",$denies);
$denies=explode("\n",$denies);
if($denies[0]==""){
$denies=array();
}

if($allows[0]==""){
$allows=array();
}

if(count($denies)>0){
    echo '<tr><td colspan="2"><h3><b>» Banned</b></h3></td></tr>';
    for($i=0;$i<count($denies);$i++){
        echo '<tr><td>'.$denies[$i].' [<a href="'.$page.'?d='.$denies[$i].'&t=b">Del</a>]</td>';
        $i++;
        if(empty($denies[$i])){
            echo '<td>&nbsp;</td></tr>';
        }

        else{
            echo '<td>'.$denies[$i].' [<a href="'.$page.'?d='.$denies[$i].'&t=b">Del</a>]</td></tr>';
        }
    }
}

if(count($allows)>0){
    echo '<tr><td colspan="2"><h3><b>» Allowed</b></h3></td></tr>';
    for($i=0;$i<count($allows);$i++){
        echo '<tr><td>'.$allows[$i].' [<a href="'.$page.'?d='.$allows[$i].'&t=a">Del</a>]</td>';
        $i++;
        if(empty($allows[$i])){
            echo '<td>&nbsp;</td></tr>';
        }

        else{
            echo '<td>'.$allows[$i].' [<a href="'.$page.'?d='.$allows[$i].'&t=a">Del</a>]</td></tr>';
        }
    }
}

if(isset($_POST['allow'])){
    $allow=$_POST['allow'];
}

else{
    $allow='';
}

if(isset($_POST['deny'])){
    $deny=$_POST['deny'];
}

else{
    $deny='';
}

$one='';
$two='';
if($denyall==0){
$one=' checked';
}

else{
$tow=' checked';
}

echo '<tr><td colspan="2"><h3><b>» Edit</b></h3></td></tr>';
echo '<form action="'.$page.'" method="POST">';
echo '<tr><td width="50%"><b>Allow:</b></td><td width="50%"><input type="text" name="allow" value="'.$allow.'"></td></tr>';
echo '<tr><td><b>Ban:</b></td><td><input type="text" name="deny" value="'.$deny.'"></td></tr>';
echo '<tr><td><input type="radio" name="status" value="allow"'.$one.'> Allow from all</td>';
echo '<td><input type="radio" name="status" value="deny"'.$two.'> Deny from all</td></tr>';
echo '<tr><td align="center" colspan="2"><input type="submit" value="Update" name="submit">';
echo '<input type="submit" value="Logout" name="logout"></td></tr>';
echo '</form>';
echo '</table>';
?>

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.