From 9ee496ccee210d22816dd41e56ec1ca46185da4f Mon Sep 17 00:00:00 2001 From: s22-tech Date: Sat, 25 May 2024 19:32:42 -0700 Subject: [PATCH] Install files --- bookmarks/new_bookmark.php | 22 +- cron/remove_stray_favicons.php | 53 ++++ docs/SQL.sql | 58 ++++ install/SQL.sql | 58 ++++ install/install.php | 528 +++++++++++++++++++++++++++++++++ 5 files changed, 707 insertions(+), 12 deletions(-) create mode 100644 cron/remove_stray_favicons.php create mode 100644 docs/SQL.sql create mode 100644 install/SQL.sql create mode 100644 install/install.php diff --git a/bookmarks/new_bookmark.php b/bookmarks/new_bookmark.php index ef168b7..b1e3b83 100644 --- a/bookmarks/new_bookmark.php +++ b/bookmarks/new_bookmark.php @@ -1,9 +1,6 @@ get_path_to_root($post_childof)) . '&folderid=' . $post_childof; @@ -32,7 +29,7 @@ if ($post_url != '') { $url = $post_url; } - else if ($get_url != '') { + elseif ($get_url != '') { $url = $get_url; } else { @@ -77,15 +74,16 @@ escape($username), $mysql->escape($post_title), $mysql->escape($post_url), $mysql->escape($post_description), $mysql->escape($post_childof), - $mysql->escape($post_public) + $mysql->escape($post_public), + date('Y-m-d H:i:s') ); if ($mysql->query($query)) { echo 'Bookmark successfully created.
' . PHP_EOL; @@ -108,7 +106,7 @@ // since the favicon is not as important. /////////////////////////// if ($settings['show_bookmark_icon']) { - require_once(DOC_ROOT . '/favicon.php'); + require_once(realpath(DOC_ROOT . '/favicon.php')); $favicon = new Favicon($post_url); debug_logger(variable:print_r($favicon, true), name:'favicon-object', file:__FILE__, function:__FUNCTION__); @@ -148,5 +146,5 @@ echo ''; } } - require_once(DOC_ROOT . '/footer.php'); + require_once(realpath(DOC_ROOT . '/footer.php')); ?> \ No newline at end of file diff --git a/cron/remove_stray_favicons.php b/cron/remove_stray_favicons.php new file mode 100644 index 0000000..c50a399 --- /dev/null +++ b/cron/remove_stray_favicons.php @@ -0,0 +1,53 @@ +#!/usr/local/bin/php += 1; + "; + + if ($mysql->query($query)) { + $favicons_sql = []; + while ($row = mysqli_fetch_assoc($mysql->result)) { + if (!empty($row['favicon'])) { + $favicons_sql[$row['id']] = $row['favicon']; + } + } +// print_r($favicons_sql); //:debug + } + + +////////////////////////////////// +// Delete favicons from the server. +////////////////////////////////// + $favicons = []; + $icons_path = realpath(DOC_ROOT . '/icons/'); + foreach (glob($icons_path . '/*') as $filename) { + if (!in_array(basename($filename), $favicons_sql)) { + $favicons[] = $filename; + unlink($filename); + } + } + + +////////////////////////////////// +// Print results. +////////////////////////////////// + if ($param !== 'cron') { + $deleted_icons = implode(PHP_EOL, $favicons); + echo 'Deleted favicons:' . PHP_EOL; + echo $deleted_icons . PHP_EOL; + } + +__halt_compiler(); +This script will delete all unsused favicons on the server as often as it's run either manually or scheduled via cron. Helps to keep the icon footprint as small as possible. \ No newline at end of file diff --git a/docs/SQL.sql b/docs/SQL.sql new file mode 100644 index 0000000..b887a86 --- /dev/null +++ b/docs/SQL.sql @@ -0,0 +1,58 @@ +CREATE TABLE `obm_bookmarks` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `childof` int(11) NOT NULL DEFAULT 0, + `user` char(20) NOT NULL DEFAULT '', + `title` varchar(200) NOT NULL DEFAULT '', + `url` varchar(512) NOT NULL DEFAULT '', + `description` longtext DEFAULT NULL, + `deleted` enum('0','1') NOT NULL DEFAULT '0', + `favicon` varchar(1048) DEFAULT NULL, + `private` enum('0','1') DEFAULT NULL, + `public` enum('0','1') NOT NULL DEFAULT '0', + `last_visit` datetime DEFAULT NULL, + `date` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), + `date_created` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', + PRIMARY KEY (`id`), + FULLTEXT KEY `title` (`title`,`url`,`description`) +) ENGINE=Aria AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci PAGE_CHECKSUM=1; + + +CREATE TABLE `obm_folders` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `childof` int(11) NOT NULL DEFAULT 0, + `name` char(70) NOT NULL DEFAULT '', + `user` char(20) NOT NULL DEFAULT '', + `deleted` enum('0','1') NOT NULL DEFAULT '0', + `public` enum('0','1') NOT NULL DEFAULT '0', + UNIQUE KEY `id` (`id`) +) ENGINE=Aria AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci PAGE_CHECKSUM=1; + + +CREATE TABLE `obm_users` ( + `username` char(50) NOT NULL DEFAULT '', + `password` char(50) NOT NULL DEFAULT '', + `theme` varchar(50) NOT NULL DEFAULT '', + `admin` enum('0','1') NOT NULL DEFAULT '0', + `language` char(20) NOT NULL DEFAULT '', + `root_folder_name` char(50) NOT NULL DEFAULT 'My Bookmarks', + `column_width_folder` smallint(3) NOT NULL DEFAULT 0, + `column_width_bookmark` smallint(3) NOT NULL DEFAULT 0, + `table_height` smallint(3) NOT NULL DEFAULT 0, + `confirm_delete` enum('0','1') NOT NULL DEFAULT '1', + `open_new_window` enum('0','1') NOT NULL DEFAULT '1', + `show_bookmark_description` enum('0','1') NOT NULL DEFAULT '1', + `show_bookmark_icon` enum('0','1') NOT NULL DEFAULT '1', + `show_column_date` enum('0','1') NOT NULL DEFAULT '1', + `date_format` smallint(6) NOT NULL DEFAULT 0, + `show_column_edit` enum('0','1') NOT NULL DEFAULT '1', + `show_column_move` enum('0','1') NOT NULL DEFAULT '1', + `show_column_delete` enum('0','1') NOT NULL DEFAULT '1', + `fast_folder_minus` enum('0','1') NOT NULL DEFAULT '1', + `fast_folder_plus` enum('0','1') NOT NULL DEFAULT '1', + `fast_symbol` enum('0','1') NOT NULL DEFAULT '1', + `simple_tree_mode` enum('0','1') NOT NULL DEFAULT '0', + `show_public` enum('0','1') NOT NULL DEFAULT '1', + `private_mode` enum('0','1') NOT NULL DEFAULT '1', + `notes` varchar(512) DEFAULT NULL, + UNIQUE KEY `id` (`username`) +) ENGINE=Aria DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci PAGE_CHECKSUM=1; diff --git a/install/SQL.sql b/install/SQL.sql new file mode 100644 index 0000000..b887a86 --- /dev/null +++ b/install/SQL.sql @@ -0,0 +1,58 @@ +CREATE TABLE `obm_bookmarks` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `childof` int(11) NOT NULL DEFAULT 0, + `user` char(20) NOT NULL DEFAULT '', + `title` varchar(200) NOT NULL DEFAULT '', + `url` varchar(512) NOT NULL DEFAULT '', + `description` longtext DEFAULT NULL, + `deleted` enum('0','1') NOT NULL DEFAULT '0', + `favicon` varchar(1048) DEFAULT NULL, + `private` enum('0','1') DEFAULT NULL, + `public` enum('0','1') NOT NULL DEFAULT '0', + `last_visit` datetime DEFAULT NULL, + `date` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), + `date_created` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', + PRIMARY KEY (`id`), + FULLTEXT KEY `title` (`title`,`url`,`description`) +) ENGINE=Aria AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci PAGE_CHECKSUM=1; + + +CREATE TABLE `obm_folders` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `childof` int(11) NOT NULL DEFAULT 0, + `name` char(70) NOT NULL DEFAULT '', + `user` char(20) NOT NULL DEFAULT '', + `deleted` enum('0','1') NOT NULL DEFAULT '0', + `public` enum('0','1') NOT NULL DEFAULT '0', + UNIQUE KEY `id` (`id`) +) ENGINE=Aria AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci PAGE_CHECKSUM=1; + + +CREATE TABLE `obm_users` ( + `username` char(50) NOT NULL DEFAULT '', + `password` char(50) NOT NULL DEFAULT '', + `theme` varchar(50) NOT NULL DEFAULT '', + `admin` enum('0','1') NOT NULL DEFAULT '0', + `language` char(20) NOT NULL DEFAULT '', + `root_folder_name` char(50) NOT NULL DEFAULT 'My Bookmarks', + `column_width_folder` smallint(3) NOT NULL DEFAULT 0, + `column_width_bookmark` smallint(3) NOT NULL DEFAULT 0, + `table_height` smallint(3) NOT NULL DEFAULT 0, + `confirm_delete` enum('0','1') NOT NULL DEFAULT '1', + `open_new_window` enum('0','1') NOT NULL DEFAULT '1', + `show_bookmark_description` enum('0','1') NOT NULL DEFAULT '1', + `show_bookmark_icon` enum('0','1') NOT NULL DEFAULT '1', + `show_column_date` enum('0','1') NOT NULL DEFAULT '1', + `date_format` smallint(6) NOT NULL DEFAULT 0, + `show_column_edit` enum('0','1') NOT NULL DEFAULT '1', + `show_column_move` enum('0','1') NOT NULL DEFAULT '1', + `show_column_delete` enum('0','1') NOT NULL DEFAULT '1', + `fast_folder_minus` enum('0','1') NOT NULL DEFAULT '1', + `fast_folder_plus` enum('0','1') NOT NULL DEFAULT '1', + `fast_symbol` enum('0','1') NOT NULL DEFAULT '1', + `simple_tree_mode` enum('0','1') NOT NULL DEFAULT '0', + `show_public` enum('0','1') NOT NULL DEFAULT '1', + `private_mode` enum('0','1') NOT NULL DEFAULT '1', + `notes` varchar(512) DEFAULT NULL, + UNIQUE KEY `id` (`username`) +) ENGINE=Aria DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci PAGE_CHECKSUM=1; diff --git a/install/install.php b/install/install.php new file mode 100644 index 0000000..a2b1191 --- /dev/null +++ b/install/install.php @@ -0,0 +1,528 @@ + + + + + + OpenBookmark + + + + +' . $message . '' . "\n"; + } + + function check_table_version($table, $field) { + $query = "DESC $table"; + $return = false; + if ($result = mysql_query($query)) { + while ($row = mysql_fetch_row ($result)) { + if ($row[0] == $field) { + $return = true; + break; + } + } + } + return $return; + } + + function upgrade_table($table, $field, $query) { + if (check_table_version ($table, $field)) { + print_msg("Table $table contains '$field' field, good.", 'success'); + } + else { + print_msg("Table $table does not contain $field field, attempting to upgrade", 'notice'); + if (mysql_query($query)) { + print_msg("Table $table altered, $field added.", 'success'); + } + else { + print_msg("Failure! Table $table was not changed.", 'error'); + } + } + } + + + ############## html stuff ############## + + function html_db() { + global $mysql_hostname, + $mysql_db_name, + $mysql_db_username, + $mysql_db_su_username, + $cookie_name, + $cookie_domain, + $cookie_path, + $cookie_seed, + $cookie_expire; +?> + +

Database connection:

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Database hostname:
Database name:
Database username:
Database password:
Create new database:
using Superuser account:
Superuser password:

Cookie settings:

Cookie name:
Cookie domain:
Cookie path:
Cookie seed:Just some random junk.
Cookie expire:Set an amount of seconds when the cookie will expire.
+
+ + $mysql_db_username, + 'db_password' => $mysql_db_password, + 'db_hostname' => $mysql_hostname, + 'db_name' => $mysql_db_name, + ]; + + if (!mysql_connect ($dsn['db_hostname'], $dsn['db_username'], $dsn['db_password'])) { + html_db(); + print_msg(mysql_error(), 'error'); + } + else { + if (!mysql_select_db($dsn['db_name'])) { + html_db(); + print_msg(mysql_error(), 'error'); + } + else { + ############## DB support ############## + print_msg("DB connection succeeded", 'success'); + + $query = "SHOW TABLES"; + $tables = []; + $result = mysql_query($query); + + while ($row = mysql_fetch_row($result)) { + array_push($tables, $row[0]); + } + + # The bookmark table. + if (!in_array('bookmark', $tables)) { + if (create_table_bookmark()) { + print_msg('Table bookmark created', 'success'); + } + else { + print_msg(mysql_error(), 'error'); + } + } + else { + print_msg("Table bookmark exists, checking for version:", 'notice'); + + # Check for favicon support. + upgrade_table('obm_bookmarks', 'favicon', "ALTER TABLE `obm_bookmarks` ADD COLUMN favicon varchar(200)"); + + # Check for public field in table. + upgrade_table('obm_bookmarks', "public", "ALTER TABLE `obm_bookmarks` ADD COLUMN public ENUM('0','1') DEFAULT 0 NOT NULL"); + } + + # The folder table. + if (!in_array('folder', $tables)) { + if (create_table_folder()) { + print_msg('Table folder created', 'success'); + } + else { + print_msg(mysql_error(), 'error'); + } + } + else { + print_msg("Table folder exists, checking for version:", 'notice'); + + # Check for public field in table. + upgrade_table('obm_folders', 'public', "ALTER TABLE `obm_folders` ADD COLUMN public ENUM('0','1') DEFAULT 0 NOT NULL"); + } + + + + # the user table + if (!in_array("user", $tables)) { + if (create_table_user ()) { + print_msg('Table user created', 'success'); + if (create_admin_user()) { + print_msg("Admin user created (see below)", 'success'); + $admin_message = 'Initial user created. Login with username "admin" and password "admin"'; + } + } + else { + print_msg(mysql_error(), 'error'); + } + } + else { + print_msg('Table user exists, checking for version:', 'notice'); + + # Check for date_format field in table. + upgrade_table('obm_users', 'date_format', "ALTER TABLE `obm_users` ADD COLUMN date_format SMALLINT(6) NOT NULL DEFAULT '0' AFTER show_column_date"); + + # Check for show_public field in table. + upgrade_table('obm_users', 'show_public', "ALTER TABLE `obm_users` ADD COLUMN show_public ENUM('0','1') DEFAULT 1 NOT NULL"); + + # Check for admin field in table. + upgrade_table('obm_users', 'admin', "ALTER TABLE `obm_users` ADD COLUMN admin ENUM('0','1') DEFAULT 0 NOT NULL AFTER password"); + + # Check for theme field in table. + upgrade_table('obm_users', 'theme', "ALTER TABLE `obm_users` ADD COLUMN theme varchar(5) DEFAULT '' NOT NULL AFTER password"); + } + + ############## favicon support ############## + + if ($convert = exec('which convert')) { + $convert_favicons = 'true'; + print_msg("ImageMagick convert found: $convert", 'success'); + } + else { + $convert = ''; + $convert_favicons = 'false'; + print_msg("ImageMagick convert not found. Make sure ImageMagick is installed and specify location of convert manually or set \$convert_favicons to false.", 'error'); + } + + if ($identify = exec('which identify')) { + $convert_favicons = 'true'; + print_msg("ImageMagick identify found: $identify", 'success'); + } + else { + $identify = ''; + $convert_favicons = 'false'; + print_msg("ImageMagick identify not found. Make sure ImageMagick is installed and specify location of identify manually or set \$convert_favicons to false.", 'error'); + } + + if (is_writable ("./favicons/")) { + print_msg("./favicons directory is writable by the webserver, good.", 'success'); + } + else { + print_msg("./favicons directory is not writable by the webserver. Adjust permissions manually.", 'error'); + } + + + $config = ' + <?php + if (basename ($_SERVER[\'SCRIPT_NAME\']) == basename (__FILE__)) { + die ("no direct access allowed"); + } + + $dsn = array( + \'username\' => \'' . $mysql_db_username . '\', + \'password\' => \'' . $mysql_db_password . '\', + \'hostspec\' => \'' . $mysql_hostname . '\', + \'database\' => \'' . $mysql_db_name . '\', + ); + + $cookie = array ( + \'name\' => \'' . $cookie_name . '\', + \'domain\' => \'' . $cookie_domain . '\', + \'path\' => \'' . $cookie_path . '\', + \'seed\' => \'' . $cookie_seed . '\', + \'expire\' => time() + ' . $cookie_expire . ', + ); + + # Feel free to add values to this list as you like + # according to the PHP documentation + # http://www.php.net/manual/en/function.date.php + $date_formats = array ( + \'d/m/Y\', + \'Y-m-d\', + \'m/d/Y\', + \'d.m.Y\', + \'F j, Y\', + \'dS \o\f F Y\', + \'dS F Y\', + \'d F Y\', + \'d. M Y\', + \'Y F d\', + \'F d, Y\', + \'M. d, Y\', + \'m/d/Y\', + \'m-d-Y\', + \'m.d.Y\', + \'m.d.y\', + ); + + $convert_favicons = ' . $convert_favicons . '; + $convert = \'' . $convert . '\'; + $identify = \'' . $identify . '\'; + $timeout = 5; + $folder_closed = \'<img src="./images/folder.gif" alt="">\'; + $folder_opened = \'<img src="./images/folder_open.gif" alt="">\'; + $folder_closed_public = \'<img src="./images/folder_red.gif" alt="">\'; + $folder_opened_public = \'<img src="./images/folder_open_red.gif" alt="">\'; + $bookmark_image = \'<img src="./images/bookmark_image.gif" alt="">\'; + $plus = \'<img src="./images/plus.gif" alt=""> \'; + $minus = \'<img src="./images/minus.gif" alt=""> \'; + $neutral = \'<img src="./images/spacer.gif" width="13" height="1" alt=""> \'; + $edit_image = \'<img src="./images/edit.gif" title="%s" alt="">\'; + $move_image = \'<img src="./images/move.gif" title="%s" alt="">\'; + $delete_image = \'<img src="./images/delete.gif" title="%s" alt="">\'; + $delimiter = "/"; + ?>'; + + echo '

Paste the configuration shown below in the configuration file ./config/config.php

' . "\n"; + if ($admin_message != '') { + echo $admin_message; + } + print_msg("

IMPORTANT! Do not forget to remove this install.php script.

"); + echo '
';
+				echo $config;
+				echo "
\n"; + echo 'Now go Bookmark...'; + } + } + } + else { + html_db(); + } + + require_once($_SERVER['DOCUMENT_ROOT'] .'/'. basename(__DIR__) . '/footer.php'); +?>