sma-website /search/inc/core.inc.php

Language PHP Lines 298
MD5 Hash 3e1d3e82796d018082b235cebc96127d Estimated Cost $5,616 (why?)
Repository https://bitbucket.org/molusc/sma-website.git View Raw File
  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
<?php

/******************************************************************************
 * iSearch2 - website search engine                                           *
 *                                                                            *
 * Visit the iSearch homepage at http://www.iSearchTheNet.com/isearch         *
 *                                                                            *
 * Copyright (C) 2002-2007 Z-Host. All rights reserved.                       *
 *                                                                            *
 ******************************************************************************/

if ( !defined('IN_ISEARCH') )
{
    die('Hacking attempt');
}

/* Disable notice/warning errors */
error_reporting(E_ALL ^ (E_NOTICE | E_WARNING));

/* Include configuration options */
require_once "$isearch_path/inc/config.inc.php";

/* Import the list of supported languages */
require_once "$isearch_path/lang/config.inc.php";

$isearch_version = '2.18';

/* Die function - called on a fatal error */
function isearch_die( $error = 'unknown' )
{
    echo "<h1>iSearch Error: $error.</h1>";
    exit;
}


/* Open the iSearch component */
function isearch_open($readOnly = False)
{
    global $isearch_path;
    global $isearch_sql_server, $isearch_sql_username, $isearch_sql_password, $isearch_sql_database;
    global $isearch_sql_ro_username, $isearch_sql_ro_password;
    global $isearch_db, $isearch_ro_db;
    global $isearch_table_info, $isearch_table_urls;

    global $isearch_config;

    /* From language include file */
    global $isearch_lang;
    global $isearch_languageCode;
    global $isearch_lang_config;


    if ($readOnly)
    {
        if ($isearch_sql_ro_username == '')
        {
            $isearch_ro_db = mysql_connect($isearch_sql_server, $isearch_sql_username, $isearch_sql_password);
            $isearch_db = $isearch_ro_db;
        }
        else
        {
            $isearch_ro_db = mysql_connect($isearch_sql_server, $isearch_sql_ro_username, $isearch_sql_ro_password);
        }
    }
    else
    {
        $isearch_db = mysql_connect($isearch_sql_server, $isearch_sql_username, $isearch_sql_password);

        if ($isearch_sql_ro_username == '')
        {
            $isearch_ro_db = $isearch_db;
        }
        else
        {
            $isearch_ro_db = mysql_connect($isearch_sql_server, $isearch_sql_ro_username, $isearch_sql_ro_password);
        }

        if (!$isearch_db)
        {
            isearch_die('Unable to connect to MySQL. Please check your iSearch MySQL server, username and password configuration options in <i>isearch2/inc/config.inc.php</i>.');
        }
        mysql_select_db($isearch_sql_database, $isearch_db) or isearch_die('Unable to select the database. Please check your iSearch MySQL database configuration option in <i>isearch2/inc/config.inc.php</i>.');
    }

    if (!$isearch_ro_db)
    {
        isearch_die('Unable to connect to MySQL (readonly). Please check your iSearch MySQL server, username and password configuration options in <i>isearch2/inc/config.inc.php</i>.');
    }
    mysql_select_db($isearch_sql_database, $isearch_ro_db) or isearch_die('Unable to select the database (readonly). Please check your iSearch MySQL database configuration option in <i>isearch2/inc/config.inc.php</i>.');

    $resultInfo = mysql_query("SELECT * FROM $isearch_table_info", $isearch_ro_db);
    if (($resultInfo) && ($isearch_config = mysql_fetch_array($resultInfo, MYSQL_ASSOC)))
    {
        $explodeVars = array(
            'allowed_ext',
            'allowed_urls',
            'allowed_urls_beginning',
            'exclude_urls',
            'exclude_urls_beginning',
            'groups',
            'remove_get_vars',
            'start_urls',
            'stop_words',
            'strip_defaults',

            'robots_domains',
            'robots_excludes',
            );

        foreach ($explodeVars as $varname)
        {
            if ($isearch_config[$varname] == '')
            {
                $isearch_config[$varname] = array();
            }
            else
            {
                $isearch_config[$varname] = explode(' ', $isearch_config[$varname]);
            }
        }

        /* Check that language is valid */
        if (!in_array($isearch_config['lang_name'], $isearch_lang_config))
        {
            $isearch_config['lang_name'] = 'english';
        }

        include $isearch_path . '/lang/' . $isearch_config['lang_name'] . '.inc.php';

        /* Set maximum execution time */
        @ini_set('max_execution_time', $isearch_config['max_execution_time']);
        switch ($isearch_config['error_reporting'])
        {
            case 2:
                // Disable notices and warnings
                error_reporting(E_ALL ^ (E_NOTICE | E_WARNING));
                break;
            case 3:
                // Show all errors
                error_reporting(E_ALL);
                break;
            case 4:
                // Turn off all error reporting
                error_reporting(0);
                break;
            default:
                // Disable notices
                error_reporting(E_ALL ^ (E_NOTICE));
                break;
        }

        if ((time() - $isearch_config['update_last_checked']) > (7 * 86400))
        {
            isearch_check_for_update();
        }

        return True;
    }

    return False;
}


/* Close the iSearch component */
function isearch_close()
{
    global $isearch_db, $isearch_ro_db;

    mysql_close($isearch_ro_db);
    if (isset($isearch_db))
    {
        mysql_close($isearch_db);
    }
}


function isearch_getPostVar($var, $default='')
{
    if (isset($_REQUEST[$var]))
    {
        return $_REQUEST[$var];
    }

    return $default;
}


/* Check for an updated version of iSearch */
function isearch_check_for_update()
{
    global $isearch_table_info;
    global $isearch_db;
    global $isearch_config;
    global $isearch_version;

    if (isset($isearch_db))
    {
        $host='www.iSearchTheNet.com';
        $port=80;
        $path='/isearch/version.txt';

        $version = '';
        $msg = array();

        $sock = @fsockopen($host, $port, $errno, $errstr, 1.0);
        if ($sock)
        {
            $request  = "GET http://$host$path HTTP/1.0\r\n";

            $request .= "User-Agent: iSearchPro/$isearch_version\r\n";



            $request .= "Host: $host\r\n";
            $request .= "Referer: http://".$_SERVER['HTTP_HOST'].$isearch_config['base_url']."/\r\n";
            $request .= "Connection: Close\r\n";
            $request .= "\r\n";

            fputs($sock, $request);

            /* Read status line */
            $status = fgets($sock, 1024);

            while (!feof($sock))
            {
                $line = fgets($sock, 1024);
                if ($line == '\r\n')
                {
                    $version = fgets($sock, 1024);
                    $mailSubject = fgets($sock, 1024);
                    while (!feof($sock))
                    {
                        $msg[] = fgets($sock, 1024);
                    }
                    break;
                }
            }
            fclose($sock);
        }

        if ($version != '')
        {
            if ($version != $isearch_version)
            {
                $mailTo = $isearch_config['admin_email'];
                $mailHeaders = "From: " . $isearch_config['admin_email'] . "\n";
                $mailBody = explode("\n", $msg);
                $mailBody .= "\n";
                $mailBody .= "This email is automatically generated by iSearch. To prevent checking\n";
                $mailBody .= "for future updates, please untick the Update Notification setting in\n";
                $mailBody .= "your iSearch admin control panel.\n";
                $mailBody .= "\n";
                $mailBody .= "Visit the iSearch home page at http://www.iSearchTheNet.com/isearch\n";
                if (@mail($mailTo, $mailSubject, $mailBody, $mailHeaders))
                {
                    mysql_query("UPDATE $isearch_table_info SET search_log_last_emailed='$now'", $isearch_db);
                    $isearch_config['search_log_last_emailed'] = $now;
                    isearch_clearSearchLog();
                }
            }
        }

        mysql_query("UPDATE $isearch_table_info SET update_last_checked='" . time() . "' WHERE id='1'", $isearch_db);
    }
}

if (function_exists('mysql_real_escape_string'))
{
    function isearch_escape_string($str)
    {
        return mysql_real_escape_string($str);
    }
}
else
{
    function isearch_escape_string($str)
    {
        return mysql_escape_string($str);
    }
}


if (get_magic_quotes_gpc())
{
    function isearch_stripslashes($str)
    {
        return stripslashes($str);
    }
}
else
{
    function isearch_stripslashes($str)
    {
        return $str;
    }
}
?>
Back to Top