ip-blocker-met-admin-panel

Gesponsorde koppelingen

PHP script bestanden

  1. ip-blocker-met-admin-panel

« 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
<?php
    #######################################
    #      made by nano and ronald        #
    #      created 16 August, 2004        #
    #######################################

    

    $host = "localhost";
    $name = "";
    $pass = "";
    $db   = "";
    
    @
mysql_connect ($host,$name,$pass) or die (mysql_error());
    mysql_select_db ($db) or die (mysql_error());
?>


=====================================

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
<?php
    #######################################
    #                                     #
    #         --- main page ---           #
    #                                     #
    #      made by nano and ronald        #
    #      created 16 August, 2004        #
    #######################################


    session_start();
    
    require ("config/connect.php");
    require ("includes/functions.php");

    $ip = $_SERVER['REMOTE_ADDR'];
    $date = time();


    //===    kijken of IP in db bestaat
    
    if (!isset($_SESSION['db_updated'])) {
        if (check_ip($ip)) {
            if (!update($ip, $date))
                echo "er ging ergens iets niet goed (updaten)";
        }

        else {
            if (!new_entry($ip, $date))
                echo "er ging ergens iets niet goed (new entry)";
        }
    }


//    effe denken wat ie eerst moet gaan doen..

    //===    kijken of IP gebloked is

    if (check_block($ip))
        echo 'massel lozer.. je bent gebloked van deze site';
    else
        require("includes/site.php");
?>


=====================================

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
<?php
    #######################################
    #                                     #
    #     --- main fuctions page ---      #
    #                                     #
    #      made by nano and ronald        #
    #      created 16 August, 2004        #
    #######################################
    
    
    //===    check ip in db     ===//

    function check_ip ($ip) {
        $sql = "SELECT * FROM `ip_block` WHERE `ip` = '$ip'";
        $result = mysql_query ($sql) or die (mysql_error());
        $rows = mysql_num_rows($result);

        if ($rows == 1)
            return true;
    }

    
    
    //==    update existing       ===//
    function update($ip, $date) {
        $sql = "SELECT `visits` FROM `ip_block` WHERE `ip` = '$ip'";
        $result = mysql_query($sql) or die(mysql_error());
        $visits = mysql_result($result,0);
        $visits ++;
        
        $sql = "UPDATE `ip_block` SET `date_last` = '$date', `visits` = '$visits'  WHERE `ip` = '$ip'";
        $result = mysql_query($sql) or die (mysql_error());
        $rows = mysql_affected_rows();
        
        if ($rows == 1) {
            $_SESSION['db_updated'] = "yep";
            return true;
        }
    }

    
    
    //===    new entery    ===//
    function new_entry($ip, $date) {
        $sql = "INSERT INTO `ip_block` SET `ip` = '$ip', `date_last` = '$date', `visits` = '1', `block` = 'off', `naam` = 'Guest'";
        $result = mysql_query($sql) or die (mysql_error());
        $rows = mysql_affected_rows();

        if ($rows != 0) {
            $_SESSION['db_updated'] = "yep";        
            return true;
        }
    }

    
    
    //===    check if ip is blocked    ===//
    function check_block($ip) {
        $sql = "SELECT `block` FROM `ip_block` WHERE `ip` = '$ip'";
        $result = mysql_query($sql) or die (mysql_error());
        $block = mysql_result($result,0);
        
        if ($block == "on")
            return true;
    }

?>


=====================================

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
<?php
    #######################################
    #                                     #
    #        --- admin page ---           #
    #                                     #
    #      made by nano and ronald        #
    #      created 16 August, 2004        #
    #######################################


    session_start();

    require ("../config/connect.php");
    require ("includes/admin_funcions.php");

    $user = "admin";
    $pass = "admin_pass";

    $messagePerPage = 30;
    $page = isset($_GET['page']) ? $_GET['page'] : 1;
    $offset = ($page - 1) * $messagePerPage;

    if (!check_auth($user, $pass)) {
        header( 'WWW-Authenticate: Basic realm="admin section"' );
        header( 'HTTP/1.0 401 Unauthorized' );
        
        include("includes/auth_failed.inc");
        exit;
    }



    include("includes/html_top.inc");

    if (!isset($_POST['submit'])) {
        $sql = "SELECT * FROM `ip_block` ORDER BY `id` DESC LIMIT ".$offset.",".$messagePerPage;    //===    LIMIT (start offset), (num records)

        echo '<p><a href="../index.php" title="back to the site">terug naar de site</a></p>';                
        echo show_search_box();
        echo page_numbers($messagePerPage, $page);
        echo show_form($sql);
        
    }

    else {
        switch ($_POST['submit']) {
            case
"update":
                echo update();
                break;
                
            case
"search":
                echo '<a href="index.php" title="escape">escape</a><br><br>';

                $search_str = str_replace("*", "%", $_POST['search']);;
                $sql = "SELECT * FROM `ip_block` WHERE `ip` LIKE '$search_str' OR `naam` LIKE '$search_str' OR `block` LIKE '$search_str' ORDER BY `id` DESC ";
                echo search($sql);
                break;
        }
    }

    echo "<p><small>Scripted by NaNo and Ronald 2004<small></p></body></html>";
?>


=====================================

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
<?php
    #######################################
    #                                     #
    #     --- admin fuctions page ---     #
    #                                     #
    #      made by nano and ronald        #
    #      created 16 August, 2004        #
    #######################################


    //===    kijken of de header authentication klopt met de ingevoerde username en wachtwoord

    function check_auth($user, $pass) {
        if (isset( $_SERVER['PHP_AUTH_USER'] ) && isset($_SERVER['PHP_AUTH_PW'])) {
            if (( $_SERVER['PHP_AUTH_USER'] == $user ) && ($_SERVER['PHP_AUTH_PW'] == $pass))
                return true;
        }
    }



    //===    functie voor het echo'en van de search_box
    function show_search_box() {
        $search_box = '<form action="index.php" method="post" enctype="multipart/form-data">

            <input type="text" name="search">
            <input type="submit" name="submit" value="search"> &nbsp; Search can be perfomed on <span class="search">name</span>, <span class="search">ip</span>, block <span class="search">on</span> / <span class="search">off</span><br>
            <small>You can use a wildcard with the search like : 192.168.*</small>
                            </form>'
;
        return $search_box;
    }




    //===    echo-en van de page-nummers van de admin panel
    function page_numbers($messagePerPage, $page) {
        $sql = mysql_query("SELECT count(*) FROM `ip_block`");
        $total_inputs = mysql_result($sql, 0 ,0);
        $page_nummers = ceil($total_inputs / $messagePerPage);

        if($page_nummers > 1) {
            $show_page_nummers = '<small>';
            for ($i = 1; $i <= $page_nummers; $i++) {
                if ($i == $page)
                    $show_page_nummers .= ' | <b><u>'.$i.'</u></b>';
                else
                    $show_page_nummers .= ' | <a href="index.php?page='.$i.'" title="go to page '.$i.'">'.$i.'</a>';
            }

            $show_page_nummers .= ' |</small><br><br>';
            return $show_page_nummers;
        }

        else
            return "no page numbers yet";
    }

    
    

    //===    functie voor het echo'en van de resultaten uit de database    
    function show_form($sql) {

        $result = mysql_query($sql);

        $block_array = array ("off", "on");
        $bg_color_1 = 'bgcolor="#C4CFDE"';
        
        $show_forum = '<div style="border:1px solid #000000; width:700px"><table border="0" cellpadding="4" cellspacing="0" width="700">
                        <tr>
                        <td '
.$bg_color_1.'>&nbsp;</td>
                        <td '
.$bg_color_1.'>naam / nick</td>
                        <td '
.$bg_color_1.'>IP Adress</td>
                        <td '
.$bg_color_1.'>Block</td>
                        <td '
.$bg_color_1.'>Date Last of Visited</td>
                        <td '
.$bg_color_1.'>Total Vistits</td>
                        <td '
.$bg_color_1.'>Block / Un-block</td>
                        </tr>'
;
        $i = 0;
        
        //=== suggested by Robby Town ( assoc ipv object )                     
        while ($record = mysql_fetch_assoc($result)) {    

            $id     = $record['id'];                
            $ip     = $record ['ip'];
            $block  = $record['block'];
            $name   = $record['naam'];
            $visits = $record['visits'];
            $datum  = $record['date_last'];
            
            if ($i % 2) {    $bg_color = 'bgcolor="#E7E8EF"';    }
            else         {    $bg_color = 'bgcolor="#F9F9F9"';    }
                
            $show_forum .= '<form action="index.php" method="post" enctype="multipart/form-data"><tr>
                <td '
.$bg_color.'><img src="../images/'.$block.'.gif" alt="block is '.$block.'"</td>
                <td '
.$bg_color.'><input type="text" name="name" value="'.$name.'"></td>
                <td '
.$bg_color.'>'.$ip.'</td>
                <td '
.$bg_color.'><select class="input" name="block">';
                
                foreach($block_array as $option) {
                    $show_forum .= '<option value="'.$option.'" ';
                    if ($option == $block)    {
                        $show_forum .= 'selected';
                    }

                    $show_forum .= '>'.$option.'</option>';
                }

            $show_forum .= '</select></td>
                <td '
.$bg_color.'>'.date("d/m/Y - H:i a", $datum).'</td>
                <td '
.$bg_color.'>'.$visits.'</td>
                <td '
.$bg_color.'><input type="submit" name="submit" value="update">
                <input type="hidden" name="id" value="'
.$id.'">
                </td>
                </tr></form>'
;
            $i++;
        }

        $show_forum .= '</table></div>';
        return $show_forum;
    }



    //===    funtie voor het updaten van de record
    function update() {
        $sql = "UPDATE `ip_block` SET `block` = '$_POST[block]', `naam` = '$_POST[name]' WHERE `id` = '$_POST[id]'";
        $result = mysql_query ($sql) or die (mysql_error());
        $rows = mysql_affected_rows();
        
        if ($rows != 0) {
            $update_result = '<p><h3>updated succesfull</h3>
                              block is set to <b>"'
.$_POST['block'].'"</b><br>
                              name is set to <b>"'
.$_POST['name'].'"</b></p>
                              <p><a href="index.php" title="go back">back</a></p>'
;
        }

        else {
            $update_result = '<p>no changes made</p>';
        }

        return $update_result;
    }

    
    
    //===    funtie zoeken naar naam, ip, of block on / off in de DB
    function search($sql) {
        if($_POST['search'] !== "") {
            $result = mysql_query($sql) or die (mysql_error());
            $rows = mysql_num_rows($result);

            if ($rows != 0)
                $search_result = show_form($sql);
            else
                $search_result = 'zoek resultaat heeft niets opgeleverd';
                
            return $search_result;
        }

        else {
            return "je moet natuurlijk wel wat invullen om naar te zoeken";
        }
    }

?>


=====================================

<!-- auth_failed.inc -->

<html>
<head>
<title>Authetication Failed</title>
<meta http-equiv="Refresh" content="2; URL=index.php">
</head>
<body>
<center>
<h1>Authentication failed</h1>
<p>Username and Password required.</p>
<br>
<br>
<p></i><small>this section of the site is for the Webmaster only...</small></i></p>
</center>
</body>
</html>

=====================================

<!-- html_top.inc -->

<html>
<head>
<title>admin page van de ip blocker</title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>

=====================================

<!-- en dan netuurlijk de site zelf die ingeladen gaat worden -->

<html>
<head>
<title>hier naam van site</title>
<style type="text/css">
body { font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:11px;}
a { text-decoration:none;}
a:hover { text-decoration:underline;}
</style>
</head>

<body>
<h3>welkom</h3>

<p>
hier je shit die je allemaal wil neerzetten met layout enz
</p>
<p>
<a href="admin/index.php" title="go admin">admin</a>
</p>
</body>
</html>

 
 

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.