123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522 |
- <?php
- define ("ABSOLUTE_PATH", dirname (__FILE__) . "/");
- require_once (ABSOLUTE_PATH . "lib/webstart.php");
- require_once (ABSOLUTE_PATH . "lib/lib.php");
- ?>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
- <html>
- <head>
- <title>Online-Bookmarks</title>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
- </head>
- <body>
- <?php
- $mysql_hostname = set_post_string_var ('mysql_hostname', 'localhost');
- $mysql_db_name = set_post_string_var ('mysql_db_name', 'bookmarks');
- $mysql_db_username = set_post_string_var ('mysql_db_username', 'bookmarkmgr');
- $mysql_db_password = set_post_string_var ('mysql_db_password');
- $mysql_db_create = set_post_bool_var ('mysql_db_create', false);
- $mysql_db_su_username = set_post_string_var ('mysql_db_su_username', 'root');
- $mysql_db_su_password = set_post_string_var ('mysql_db_su_password');
- $cookie_name = set_post_string_var ('cookie_name', 'ob_cookie');
- $cookie_domain = set_post_string_var ('cookie_domain', '');
- $cookie_path = set_post_string_var ('cookie_path', '/');
- $cookie_seed = set_post_string_var ('cookie_seed', random_string ());
- $cookie_expire = set_post_string_var ('cookie_expire', '31536000');
- $submit = set_post_bool_var ('submit', false);
- $admin_message = '';
- if (intval(str_replace('.', '', phpversion())) < 430) {
- print_msg ('You are running PHP version '.PHP_VERSION.'. Online-Bookmarks requires at least PHP 4.3.0 to run properly. You must upgrade your PHP installation before you can continue.', "error");
- }
- ############## database control ##############
- function create_table_bookmark($link) {
- $query = "CREATE TABLE bookmark (
- user char(20) NOT NULL default '',
- title char(70) NOT NULL default '',
- url char(200) NOT NULL default '',
- description mediumtext default NULL,
- private enum('0','1') default NULL,
- date timestamp(6) NOT NULL,
- childof int(11) NOT NULL default '0',
- id int(11) NOT NULL auto_increment,
- deleted enum('0','1') NOT NULL default '0',
- favicon varchar(200),
- public enum('0','1') NOT NULL default '0',
- PRIMARY KEY (id),
- FULLTEXT KEY title (title,url,description)
- )";
- if (mysqli_query($link, $query)) {
- return true;
- }
- else {
- return false;
- }
- }
- function create_table_folder($link) {
- $query = "CREATE TABLE folder (
- 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)
- )";
- if (mysqli_query($link, $query)) {
- return true;
- }
- else {
- return false;
- }
- }
- function create_table_user($link) {
- $query = "CREATE TABLE user (
- username char(50) NOT NULL default '',
- password char(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 '400',
- column_width_bookmark smallint(3) NOT NULL default '0',
- table_height smallint(3) NOT NULL default '400',
- 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',
- UNIQUE KEY id (username)
- )";
- if (mysqli_query($link, $query)) {
- return true;
- }
- else {
- return false;
- }
- }
- function create_admin_user($link) {
- $query = "INSERT INTO user (username, password, admin)
- VALUES ('admin', MD5('admin'), '1');";
- if (mysqli_query($link, $query)) {
- return true;
- }
- else {
- return false;
- }
- }
- function random_string ($max = 14){ # TODO: definitely replace this with some built in std function
- $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_";
- $string = '';
- for($i = 0; $i < $max; $i++){
- $rand_key = mt_rand (0, strlen($chars));
- $string .= substr ($chars, $rand_key, 1);
- }
- return str_shuffle ($string);
- }
- function print_msg ($message, $type = "") {
- if ($type == "success") {
- $color = "green";
- }
- else if ($type == "error") {
- $color = "red";
- }
- else if ($type == "notice") {
- $color = "orange";
- }
- else {
- $color = "black";
- }
- echo '<div style="font:bold 12pt Times; color: ' . $color . '">' . $message . '</div>' . "\n";
- }
- function check_table_version ($link, $table, $field) {
- $query = "DESC $table";
- $return = false;
- if ($result = mysqli_query ($link, $query)) {
- while ($row = mysqli_fetch_row ($result)) {
- if ($row[0] == $field) {
- $return = true;
- break;
- }
- }
- }
- return $return;
- }
- function upgrade_table ($link, $table, $field, $query) {
- if (check_table_version ($link, $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 (mysqli_query ($link, $query)) {
- print_msg ("Table $table altered, $field added.", "success");
- }
- else {
- print_msg ("Failure! Table $table 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;
- ?>
-
- <h3>Database connection:</h3>
- <form method="POST" action="<?php echo $_SERVER['SCRIPT_NAME']; ?>">
- <table>
- <tr>
- <td>Database hostname:</td>
- <td><input type="text" name="mysql_hostname" value="<?php echo $mysql_hostname; ?>"></td>
- <td></td>
- </tr>
- <tr>
- <td>Database name:</td>
- <td><input type="text" name="mysql_db_name" value="<?php echo $mysql_db_name; ?>"></td>
- <td></td>
- </tr>
- <tr>
- <td>Database username:</td>
- <td><input type="text" name="mysql_db_username" value="<?php echo $mysql_db_username; ?>"></td>
- <td></td>
- </tr>
- <tr>
- <td>Database password:</td>
- <td><input type="password" name="mysql_db_password" value=""></td>
- <td></td>
- </tr>
- <tr>
- <td>Create new database:</td>
- <td><input type="checkbox" name="mysql_db_create"></td>
- <td></td>
- </tr>
- <tr>
- <td>using Superuser account:</td>
- <td><input type="text" name="mysql_db_su_username" value="<?php echo $mysql_db_su_username; ?>"></td>
- <td></td>
- </tr>
- <tr>
- <td>Superuser password:</td>
- <td><input type="password" name="mysql_db_su_password" value=""></td>
- <td></td>
- </tr>
- <tr>
- <td><h3>Cookie settings:</h3></td>
- <td></td>
- <td></td>
- </tr>
- <tr>
- <td>Cookie name:</td>
- <td><input type="text" name="cookie_name" value="<?php echo $cookie_name; ?>"></td>
- <td></td>
- </tr>
- <tr>
- <td>Cookie domain:</td>
- <td><input type="text" name="cookie_domain" value="<?php echo $cookie_domain; ?>"></td>
- <td></td>
- </tr>
- <tr>
- <td>Cookie path:</td>
- <td><input type="text" name="cookie_path" value="<?php echo $cookie_path; ?>"></td>
- <td></td>
- </tr>
- <tr>
- <td>Cookie seed:</td>
- <td><input type="text" name="cookie_seed" value="<?php echo $cookie_seed; ?>"></td>
- <td>Just some random junk.</td>
- </tr>
- <tr>
- <td>Cookie expire:</td>
- <td><input type="text" name="cookie_expire" value="<?php echo $cookie_expire; ?>"></td>
- <td>Set an amount of seconds when the cookie will expire.</td>
- </tr>
- <tr>
- <td></td>
- <td><input type="submit" name="submit"></td>
- <td></td>
- </tr>
- </table>
- </form>
-
- <?php
- }
- if ($submit) {
- if ($mysql_db_create) {
- $link = mysqli_connect($mysql_hostname, $mysql_db_su_username, $mysql_db_su_password) or die("cannot connect to db");
-
- if (mysqli_query($link, "CREATE DATABASE IF NOT EXISTS $mysql_db_name")) {
- print_msg ("Database $mysql_db_name created", "success");
- }
- else {
- html_db ();
- print_msg (mysqli_error ($link), "error");
- require_once (ABSOLUTE_PATH . "footer.php");
- }
- if (mysqli_query($link, "GRANT ALL PRIVILEGES ON $mysql_db_name.* TO '$mysql_db_username'@'$mysql_hostname' IDENTIFIED BY '$mysql_db_password'")) {
- print_msg ("User $mysql_db_username created", "success");
- }
- else {
- html_db ();
- print_msg (mysqli_error ($link), "error");
- require_once (ABSOLUTE_PATH . "footer.php");
- }
-
- }
- mysqli_close($link);
- $dsn = array(
- 'db_username' => $mysql_db_username,
- 'db_password' => $mysql_db_password,
- 'db_hostname' => $mysql_hostname,
- 'db_name' => $mysql_db_name,
- );
- $link = mysqli_connect ($dsn['db_hostname'], $dsn['db_username'], $dsn['db_password']) or die("cannot connect to db");
-
- {
- {
- mysqli_select_db($link, $dsn['db_name']) or die("cannot select db");
-
- ############## DB support ##############
- print_msg ("DB connection succeeded", "success");
- $query = "SHOW TABLES";
- $tables = array ();
- $result = mysqli_query($link, $query);
- while ($row = mysqli_fetch_row($result)) {
- array_push ($tables, $row[0]);
- }
- # the bookmark table
- if (!in_array ("bookmark", $tables)) {
- if (create_table_bookmark ($link)) {
- print_msg ("Table bookmark created", "success");
- }
- else {
- print_msg (mysqli_error ($link), "error");
- }
- }
- else {
- print_msg ("Table bookmark exists, checking for version:", "notice");
-
- # check for favicon support
- upgrade_table ($link, "bookmark", "favicon", "ALTER TABLE bookmark ADD COLUMN favicon varchar(200)");
- # check for public field in table
- upgrade_table ($link, "bookmark", "public", "ALTER TABLE bookmark ADD COLUMN public ENUM('0','1') DEFAULT 0 NOT NULL");
- }
- # the folder table
- if (!in_array ("folder", $tables)) {
- if (create_table_folder ($link)) {
- print_msg ("Table folder created", "success");
- }
- else {
- print_msg (mysqli_error ($link), "error");
- }
- }
- else {
- print_msg ("Table folder exists, checking for version:", "notice");
- # check for public field in table
- upgrade_table ($link, "folder", "public", "ALTER TABLE folder ADD COLUMN public ENUM('0','1') DEFAULT 0 NOT NULL");
- }
- # the user table
- if (!in_array ("user", $tables)) {
- if (create_table_user ($link)) {
- print_msg ("Table user created", "success");
- if (create_admin_user ($link)) {
- print_msg ("Admin user created (see below)", "success");
- $admin_message = 'Initial user created. Login with username "admin" and password "admin"';
- }
- }
- else {
- print_msg (mysqli_error ($link), "error");
- }
- }
- else {
- print_msg ("Table user exists, checking for version:", "notice");
- # check for date_format field in table
- upgrade_table ($link, "user", "date_format", "ALTER TABLE user ADD COLUMN date_format SMALLINT(6) NOT NULL DEFAULT '0' AFTER show_column_date");
- # check for show_public field in table
- upgrade_table ($link, "user", "show_public", "ALTER TABLE user ADD COLUMN show_public ENUM('0','1') DEFAULT 1 NOT NULL");
- # check for admin field in table
- upgrade_table ($link, "user", "admin", "ALTER TABLE user ADD COLUMN admin ENUM('0','1') DEFAULT 0 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 '<p>Paste the configuration shown below in the configuration file <span style="font-family:courier">./config/config.php</span></p>' . "\n";
- if ($admin_message != '') {
- echo $admin_message;
- }
- print_msg ("<p>IMPORTANT! Do not forget to remove this install.php script.</p>");
- echo '<pre style="background-color: #E0E0E0; border: 1px black solid; padding: 20px">';
- echo $config;
- echo "</pre>\n";
- echo '<a href="./index.php">Now go Bookmark...</a>';
- }
- }
- }
- else {
- html_db ();
- }
- require_once (ABSOLUTE_PATH . "footer.php");
- ?>
|