diff --git a/admin.php b/admin.php index 9839bb1..a5fcabe 100644 --- a/admin.php +++ b/admin.php @@ -27,7 +27,7 @@ if($_SERVER['REQUEST_METHOD']==='HEAD'){ } include('common_config.php'); try{ - $db=new PDO('mysql:host=' . DBHOST . ';dbname=' . DBNAME, DBUSER, DBPASS, [PDO::ATTR_ERRMODE=>PDO::ERRMODE_WARNING, PDO::ATTR_PERSISTENT=>PERSISTENT]); + $db=new PDO('mysql:host=' . DBHOST . ';dbname=' . DBNAME . ';charset=utf8mb4', DBUSER, DBPASS, [PDO::ATTR_ERRMODE=>PDO::ERRMODE_WARNING, PDO::ATTR_PERSISTENT=>PERSISTENT]); }catch(PDOException $e){ die($I['nodb']); } diff --git a/background_tests.php b/background_tests.php index b7982ae..c6d6273 100644 --- a/background_tests.php +++ b/background_tests.php @@ -21,7 +21,7 @@ // Executed every 15 minutes via cron - up/down checks include('common_config.php'); try{ - $db=new PDO('mysql:host=' . DBHOST . ';dbname=' . DBNAME, DBUSER, DBPASS, [PDO::ATTR_ERRMODE=>PDO::ERRMODE_WARNING, PDO::ATTR_PERSISTENT=>PERSISTENT]); + $db=new PDO('mysql:host=' . DBHOST . ';dbname=' . DBNAME . ';charset=utf8mb4', DBUSER, DBPASS, [PDO::ATTR_ERRMODE=>PDO::ERRMODE_WARNING, PDO::ATTR_PERSISTENT=>PERSISTENT]); }catch(PDOException $e){ die($I['nodb']); } diff --git a/common_config.php b/common_config.php index 0cadbb9..34419bd 100644 --- a/common_config.php +++ b/common_config.php @@ -33,7 +33,7 @@ define('PROMOTEPRICE', 0.025); // Price to promote a site for PROMOTETIME long define('PROMOTETIME', 864000); // Time (in seconds) to promote a site payed with PROMOTEPRICE - 864000 equals 10 days define('PER_PAGE', 50); // Sites listed per page define('VERSION', '1'); // Script version -define('DBVERSION', 1); // Database layout version +define('DBVERSION', 2); // Database layout version //Categories - new links will always be put into the first one, leave it to Unsorted //once configured, only add new categories at the end or you have to manually adjust the database. $categories=['Unsorted', 'Adult/Porn', 'Communication/Social', 'Cryptocurrencies', 'Empty/Error/Unknown', 'Forums', 'Hacking', 'Hosting', 'Libraries/Wikis', 'Link Lists', 'Market/Shop/Store', 'Other', 'Personal Sites/Blogs', 'Scam', 'Security/Privacy', 'Whistleblowing']; diff --git a/onions.php b/onions.php index 468e84f..1c1de3e 100644 --- a/onions.php +++ b/onions.php @@ -23,7 +23,7 @@ if($_SERVER['REQUEST_METHOD']==='HEAD'){ } include('common_config.php'); try{ - $db=new PDO('mysql:host=' . DBHOST . ';dbname=' . DBNAME, DBUSER, DBPASS, [PDO::ATTR_ERRMODE=>PDO::ERRMODE_WARNING, PDO::ATTR_PERSISTENT=>PERSISTENT]); + $db=new PDO('mysql:host=' . DBHOST . ';dbname=' . DBNAME . ';charset=utf8mb4', DBUSER, DBPASS, [PDO::ATTR_ERRMODE=>PDO::ERRMODE_WARNING, PDO::ATTR_PERSISTENT=>PERSISTENT]); }catch(PDOException $e){ } date_default_timezone_set('UTC'); diff --git a/phishing_tests.php b/phishing_tests.php index bb5c7bc..f983544 100644 --- a/phishing_tests.php +++ b/phishing_tests.php @@ -22,7 +22,7 @@ date_default_timezone_set('UTC'); include('common_config.php'); try{ - $db=new PDO('mysql:host=' . DBHOST . ';dbname=' . DBNAME, DBUSER, DBPASS, [PDO::ATTR_ERRMODE=>PDO::ERRMODE_WARNING, PDO::ATTR_PERSISTENT=>PERSISTENT]); + $db=new PDO('mysql:host=' . DBHOST . ';dbname=' . DBNAME . ';charset=utf8mb4', DBUSER, DBPASS, [PDO::ATTR_ERRMODE=>PDO::ERRMODE_WARNING, PDO::ATTR_PERSISTENT=>PERSISTENT]); }catch(PDOException $e){ die($I['nodb']); } diff --git a/setup.php b/setup.php index 1fb13d4..2e2b868 100644 --- a/setup.php +++ b/setup.php @@ -28,20 +28,20 @@ if(!extension_loaded('pcre')){ if(!extension_loaded('json')){ die($I['jsonextrequired']); } -if(!extension_loaded('json')){ +if(!extension_loaded('curl')){ die($I['curlextrequired']); } if(!extension_loaded('date')){ die($I['dateextrequired']); } try{ - $db=new PDO('mysql:host=' . DBHOST . ';dbname=' . DBNAME, DBUSER, DBPASS, [PDO::ATTR_ERRMODE=>PDO::ERRMODE_WARNING, PDO::ATTR_PERSISTENT=>PERSISTENT]); + $db=new PDO('mysql:host=' . DBHOST . ';dbname=' . DBNAME . ';charset=utf8mb4', DBUSER, DBPASS, [PDO::ATTR_ERRMODE=>PDO::ERRMODE_WARNING, PDO::ATTR_PERSISTENT=>PERSISTENT]); }catch(PDOException $e){ try{ //Attempt to create database - $db=new PDO('mysql:host=' . DBHOST, DBUSER, DBPASS, $options); + $db=new PDO('mysql:host=' . DBHOST . ';charset=utf8mb4', DBUSER, DBPASS, [PDO::ATTR_ERRMODE=>PDO::ERRMODE_WARNING, PDO::ATTR_PERSISTENT=>PERSISTENT]); if(false!==$db->exec('CREATE DATABASE ' . DBNAME)){ - $db=new PDO('mysql:host=' . DBHOST . ';dbname=' . DBNAME, DBUSER, DBPASS, [PDO::ATTR_ERRMODE=>PDO::ERRMODE_WARNING, PDO::ATTR_PERSISTENT=>PERSISTENT]); + $db=new PDO('mysql:host=' . DBHOST . ';dbname=' . DBNAME . ';charset=utf8mb4', DBUSER, DBPASS, [PDO::ATTR_ERRMODE=>PDO::ERRMODE_WARNING, PDO::ATTR_PERSISTENT=>PERSISTENT]); }else{ die($I['nodb']); } @@ -51,12 +51,36 @@ try{ } if(!@$db->query('SELECT * FROM ' . PREFIX . 'settings LIMIT 1;')){ //create tables - $db->exec('CREATE TABLE ' . PREFIX . 'onions (id int(10) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT, address varchar(16) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL, md5sum binary(16) NOT NULL UNIQUE, lasttest int(10) UNSIGNED NOT NULL, lastup int(10) UNSIGNED NOT NULL, timediff int(10) UNSIGNED NOT NULL, timeadded int(10) UNSIGNED NOT NULL, description varchar(20000) CHARACTER SET utf8 NOT NULL, category smallint(6) NOT NULL, locked smallint(6) NOT NULL, special int(10) UNSIGNED NOT NULL, INDEX(address), INDEX(lasttest), INDEX(timediff), INDEX(category), INDEX(special));'); - $db->exec('CREATE TABLE ' . PREFIX . 'phishing (id int(11) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT, onion_id int(10) UNSIGNED NOT NULL UNIQUE, original varchar(16) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL, FOREIGN KEY (onion_id) REFERENCES onions(id) ON DELETE CASCADE ON UPDATE CASCADE);'); + $db->exec('CREATE TABLE ' . PREFIX . 'onions (id int(10) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT, address varchar(16) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL, md5sum binary(16) NOT NULL UNIQUE, lasttest int(10) UNSIGNED NOT NULL, lastup int(10) UNSIGNED NOT NULL, timediff int(10) UNSIGNED NOT NULL, timeadded int(10) UNSIGNED NOT NULL, description text CHARACTER SET utf8mb4 NOT NULL, category smallint(6) NOT NULL, locked smallint(6) NOT NULL, special int(10) UNSIGNED NOT NULL, INDEX(address), INDEX(lasttest), INDEX(timediff), INDEX(category), INDEX(special));'); + $db->exec('CREATE TABLE ' . PREFIX . 'phishing (onion_id int(10) UNSIGNED NOT NULL PRIMARY_KEY, original varchar(16) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL, FOREIGN KEY (onion_id) REFERENCES onions(id) ON DELETE CASCADE ON UPDATE CASCADE);'); $db->exec('CREATE TABLE ' . PREFIX . 'settings (setting varchar(50) NOT NULL PRIMARY KEY, value varchar(20000) NOT NULL);'); - $db->exec('INSERT INTO ' . PREFIX . "settings (setting, value) VALUES ('version', '1');"); + $stmt=$db->prepare('INSERT INTO ' . PREFIX . "settings (setting, value) VALUES ('version', ?);"); + $stmt->execute([DBVERSION]); echo "$I[succdbcreate]\n"; }else{ + $res=$db->query('SELECT value FROM ' . PREFIX . "settings WHERE setting='version';"); + $version=$res->fetch(PDO::FETCH_NUM)[0]; + if($version<2){ + $olddb=new PDO('mysql:host=' . DBHOST . ';dbname=' . DBNAME, DBUSER, DBPASS, [PDO::ATTR_ERRMODE=>PDO::ERRMODE_WARNING, PDO::ATTR_PERSISTENT=>PERSISTENT]); + $stmt=$olddb->query('SELECT onion_id, original FROM ' . PREFIX . 'phishing;'); + $phishings=$stmt->fetchAll(PDO::FETCH_NUM); + $stmt=$olddb->query('SELECT id, address, md5sum, lasttest, lastup, timediff, timeadded, description, category, locked, special FROM ' . PREFIX . 'onions;'); + $onions=$stmt->fetchAll(PDO::FETCH_NUM); + $db->exec('DROP TABLE ' . PREFIX . 'phishing;'); + $db->exec('DROP TABLE ' . PREFIX . 'onions;'); + $db->exec('CREATE TABLE ' . PREFIX . 'onions (id int(10) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT, address varchar(16) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL, md5sum binary(16) NOT NULL UNIQUE, lasttest int(10) UNSIGNED NOT NULL, lastup int(10) UNSIGNED NOT NULL, timediff int(10) UNSIGNED NOT NULL, timeadded int(10) UNSIGNED NOT NULL, description text CHARACTER SET utf8mb4 NOT NULL, category smallint(6) NOT NULL, locked smallint(6) NOT NULL, special int(10) UNSIGNED NOT NULL, INDEX(address), INDEX(lasttest), INDEX(timediff), INDEX(category), INDEX(special));'); + $db->exec('CREATE TABLE ' . PREFIX . 'phishing (onion_id int(10) UNSIGNED NOT NULL PRIMARY KEY, original varchar(16) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL, FOREIGN KEY (onion_id) REFERENCES onions(id) ON DELETE CASCADE ON UPDATE CASCADE);'); + $stmt=$db->prepare('INSERT INTO ' . PREFIX . 'onions (id, address, md5sum, lasttest, lastup, timediff, timeadded, description, category, locked, special) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'); + foreach($onions as $onion){ + $stmt->execute($onion); + } + $stmt=$db->prepare('INSERT INTO ' . PREFIX . 'phishing (onion_id, original) VALUES (?, ?);'); + foreach($phishings as $phishing){ + $stmt->execute($phishing); + } + } + $stmt=$db->prepare('UPDATE ' . PREFIX . "settings SET value=? WHERE setting='version';"); + $stmt->execute([DBVERSION]); echo "$I[statusok]\n"; } ?> diff --git a/test.php b/test.php index ce33895..9ae29bb 100644 --- a/test.php +++ b/test.php @@ -47,7 +47,7 @@ if(!empty($_REQUEST['addr'])){ ob_end_flush(); } try{ - $db=new PDO('mysql:host=' . DBHOST . ';dbname=' . DBNAME, DBUSER, DBPASS, [PDO::ATTR_ERRMODE=>PDO::ERRMODE_WARNING, PDO::ATTR_PERSISTENT=>PERSISTENT]); + $db=new PDO('mysql:host=' . DBHOST . ';dbname=' . DBNAME . ';charset=utf8mb4', DBUSER, DBPASS, [PDO::ATTR_ERRMODE=>PDO::ERRMODE_WARNING, PDO::ATTR_PERSISTENT=>PERSISTENT]); }catch(PDOException $e){ } if(!preg_match('~(^(https?://)?([a-z0-9]*\.)?([a-z2-7]{16})(\.onion(/.*)?)?$)~i', trim($_REQUEST['addr']), $addr)){ diff --git a/update.php b/update.php index a2edb6e..f3d3541 100644 --- a/update.php +++ b/update.php @@ -21,7 +21,7 @@ // Executed every 24 hours via cron - checks for new sites. include('common_config.php'); try{ - $db=new PDO('mysql:host=' . DBHOST . ';dbname=' . DBNAME, DBUSER, DBPASS, [PDO::ATTR_ERRMODE=>PDO::ERRMODE_WARNING, PDO::ATTR_PERSISTENT=>PERSISTENT]); + $db=new PDO('mysql:host=' . DBHOST . ';dbname=' . DBNAME . ';charset=utf8mb4', DBUSER, DBPASS, [PDO::ATTR_ERRMODE=>PDO::ERRMODE_WARNING, PDO::ATTR_PERSISTENT=>PERSISTENT]); }catch(PDOException $e){ die($I['nodb']); }