Changeset 533

Show
Ignore:
Timestamp:
04/24/08 16:31:41 (7 months ago)
Author:
sidtheduck
Message:

+ Fix for ticket #147 - escaping characters for password storage in plog-config.php

+ Fix for ticket #145 - UPDATE instead of INSERT INTO SQL plog-config table if already installed to prohibit duplicate row entries

+ Type editing for install sequence of events - still needs more work for displaying errors during final install of tables and creation of initial collection / album

+ Hopefully the last of apostrophe (') edits and possibly a fix for ticket #111 - need to take another in-depth look at the add, edit, move, delete functions in plog-admin-functions.php and possibly re-write / re-edit them to be more consistent with each other.

Location:
trunk
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • trunk/_install.php

    r494 r533  
    1313}; 
    1414 
    15 // try to proceed to the admin interface. Only succeeds if the configuration is set 
     15// Create the SQL tables and try to proceed to the admin interface. 
     16// Only proceeds if the configuration is set. 
    1617if (!empty($_POST['proceed']) && defined('PLOGGER_DB_HOST')) { 
    1718        $mysql = check_mysql(PLOGGER_DB_HOST,PLOGGER_DB_USER,PLOGGER_DB_PW,PLOGGER_DB_NAME); 
     
    2223                connect_db(); 
    2324                $col = add_collection(plog_tr("Plogger test collection"),plog_tr("Feel free to delete it")); 
    24                 $alb = add_album(plog_tr("Plogger test album"),plog_tr("feel free to delete it"),$col["id"]);   // undefined index id 
     25                // only attempt to create an album if the collection was created - sloppy fix for multiple installs 
     26                if (!empty($col['id'])) { 
     27                        $alb = add_album(plog_tr("Plogger test album"),plog_tr("feel free to delete it"),$col['id']); 
     28                } 
    2529                unset($_SESSION["plogger_config"]); 
    2630                unset($_SESSION["install_values"]); 
  • trunk/lib/plogger/form_setup.php

    r527 r533  
    44}; 
    55?> 
    6 <h1>Plogger Installation</h1> 
    7 <p>To install, simply fill out the following form.  If there are any problems, you will be notified and asked to fix them before the installation will continue.  After the installation has finished, you will be redirected to your Plogger home page.</p> 
     6<h1>Plogger Configuration Setup</h1> 
     7<p>To install, simply fill out the following form.  If there are any problems, you will be notified and asked to fix them before the installation will continue.  After the installation has finished, you will be redirected to the Plogger admin page.</p> 
    88<form action="_install.php" method="post"> 
    99<input type="hidden" name="action" value="install" /> 
     
    7373        </tr> 
    7474        <tr> 
    75                 <td class="form_label"><label for="ftp_path">FTP Path to Plogger Folder (from FTP login):</label></td> 
     75                <td class="form_label"><label for="ftp_path">FTP Path to Plogger Base Folder (from FTP login):</label></td> 
    7676                <td class="form_input"><input type="text" name="ftp_path" id="ftp_path" value="<?=$form['ftp_path']?>" /></td> 
    7777        </tr> 
     
    7979   <tr> 
    8080                <td class="submitButtonRow" colspan="2"> 
    81                         <input type="submit" name="submit" id="submit" value="Install" /> 
     81                        <input type="submit" name="submit" id="submit" value="Proceed" /> 
    8282                </td> 
    8383        </tr> 
  • trunk/lib/plogger/form_setup_complete.php

    r422 r533  
    44}; 
    55?> 
     6<h1>Plogger Install</h1> 
    67<form method="POST"> 
    7 <p>Setup is now complete</p> 
     8<p>Configuration setup is now complete.<br/>Click 'Install' to finish installation.</p> 
    89<p>Your username is <?=$_SESSION['install_values']['admin_username']?> and your password is `<?=$_SESSION['install_values']['admin_password']?>`</p> 
    910<?php if (!empty($_SESSION["plogger_config"])) { ?> 
     
    1112<?php } ?> 
    1213<p> 
    13 <input type="submit" name="proceed" value="Proceed"/> 
     14<input type="submit" name="proceed" value="Install"/> 
    1415</p> 
    1516</form> 
  • trunk/lib/plogger/install_functions.php

    r530 r533  
    1313                foreach($errors as $error) { 
    1414                        print '<li>' . $error . '</li>'; 
    15                 }; 
     15                } 
    1616                print '</ul>'; 
    1717                print '<form method="GET" action="_install.php"><input type="submit" value="Try again"/></form>'; 
    1818                return false; 
    19         }; 
     19        } 
    2020 
    2121        if (defined('PLOGGER_DB_HOST')) { 
     
    2525                        print '<p>Plogger is already installed!</p>'; 
    2626                        return false; 
    27                 }; 
    28         }; 
     27                } 
     28        } 
    2929 
    3030        $ok = false; 
     
    3434                if (empty($form['db_host'])) { 
    3535                        $errors[] = 'Please enter the name of your MySQL host.'; 
    36                 }; 
     36                } 
    3737 
    3838                if (empty($form['db_user'])) { 
    3939                        $errors[] = 'Please enter the MySQL username.'; 
    40                 }; 
     40                } 
    4141 
    4242                if (empty($form['db_pass'])) { 
    43                         $errors[] = 'Please enter the MySQL password.'; 
    44                 } 
     43                        $errors[] = 'Please enter the MySQL password.'; 
     44                } 
    4545                 
    4646                if (empty($form['db_name'])) { 
    4747                        $errors[] = 'Please enter the MySQL database name.'; 
    48                 }; 
     48                } 
    4949                 
    5050                if (empty($form['gallery_name'])) { 
    5151                        $errors[] = 'Please enter the name for your gallery.'; 
    52                 }; 
     52                } 
    5353                 
    5454                if (empty($form['admin_email'])) { 
    5555                        $errors[] = 'Please enter your e-mail address.'; 
    56                 }; 
     56                } 
    5757       
    58       if (ini_get('safe_mode')==1) { 
    59       //if safe_mode enabled, check the FTP information form inputs 
     58                if (ini_get('safe_mode')==1) { 
     59                        //if safe_mode enabled, check the FTP information form inputs 
    6060                        if (empty($form['ftp_host'])) { 
    61                            $errors[] = 'Please enter the name of your FTP host.'; 
    62                    }; 
    63  
    64                    if (empty($form['ftp_user'])) { 
    65                            $errors[] = 'Please enter the FTP username.'; 
    66                    }; 
    67  
    68                    if (empty($form['ftp_pass'])) { 
    69             $errors[] = 'Please enter the FTP password.'; 
    70          } 
     61                                $errors[] = 'Please enter the name of your FTP host.'; 
     62                        } 
     63 
     64                        if (empty($form['ftp_user'])) { 
     65                                $errors[] = 'Please enter the FTP username.'; 
     66                        } 
     67 
     68                        if (empty($form['ftp_pass'])) { 
     69                                $errors[] = 'Please enter the FTP password.'; 
     70                        } 
    7171          
    72          if (!empty($form['ftp_path'])) { 
    73             if (substr($form['ftp_path'],0,1)!="/"){ 
    74                $form['ftp_path']="/".$form['ftp_path']; 
    75             }; 
    76             if (substr($form['ftp_path'],-1)!="/"){ 
    77                $form['ftp_path']=$form['ftp_path']."/"; 
    78             }; 
    79          } 
    80                 }; 
     72                        if (!empty($form['ftp_path'])) { 
     73                                if (substr($form['ftp_path'],0,1)!="/"){ 
     74                                        $form['ftp_path'] = "/".$form['ftp_path']; 
     75                                } 
     76                                if (substr($form['ftp_path'],-1)!="/"){ 
     77                                        $form['ftp_path'] = $form['ftp_path']."/"; 
     78                                } 
     79                        } 
     80                } 
    8181 
    8282                if (empty($errors)) { 
    83                         $errors = check_mysql($form['db_host'],$form['db_user'],$form['db_pass'],$form['db_name']); 
     83                        $mysql_errors = check_mysql($form['db_host'],$form['db_user'],$form['db_pass'],$form['db_name']); 
     84                        if (ini_get('safe_mode')==1) { 
     85                                $ftp_errors = check_FTP($form['ftp_host'], $form['ftp_user'], $form['ftp_pass'], $form['ftp_path']); 
     86                        }else{ 
     87                                $ftp_errors = array(); 
     88                        } 
     89                        $errors = array_merge($mysql_errors, $ftp_errors); 
    8490                        $ok = empty($errors); 
    85                 }; 
     91                } 
    8692 
    8793                if (!$ok) { 
     
    106112                        } else { 
    107113                                $_SESSION["plogger_config"] = $conf; 
    108                         }; 
     114                        } 
    109115                        require(PLOGGER_DIR . 'lib/plogger/form_setup_complete.php'); 
    110116                        return true; 
    111                 }; 
    112         }; 
     117                } 
     118        } 
    113119 
    114120        // most of the time it's probably running on localhost 
    115121        if (empty($form['db_host'])) { 
    116122                $form['db_host'] = 'localhost'; 
    117         }; 
     123        } 
    118124   if (empty($form['ftp_host'])) { 
    119125                $form['ftp_host'] = 'localhost'; 
    120         }; 
     126        } 
    121127 
    122128        $init_vars = array('db_user','db_pass','db_name','gallery_name','admin_email','ftp_user','ftp_pass','ftp_path'); 
     
    124130                if (empty($form[$var])) { 
    125131                        $form[$var] = ""; 
    126                 }; 
    127         }; 
     132                } 
     133        } 
    128134        require(PLOGGER_DIR . 'lib/plogger/form_setup.php'); 
    129135} 
     
    139145        if (1 == version_compare($mysql_version,$mysql_charset_support)) { 
    140146                $default_charset = "DEFAULT CHARACTER SET UTF8"; 
    141         }; 
     147        } 
    142148 
    143149        maybe_add_table( 
     
    283289                        VALUES('$key','$long_ago','$size')"; 
    284290                mysql_query($sql); 
    285         }; 
     291        } 
    286292 
    287293        $config['default_theme_dir'] = PLOGGER_DIR . 'themes/default/'; 
     
    293299         
    294300        $config = array_map('mysql_real_escape_string',$config); 
    295  
    296         $query = "INSERT INTO `".TABLE_PREFIX."config` 
    297                 (`theme_dir`, 
    298                 `compression`, 
    299                 `max_thumbnail_size`, 
    300                 `max_display_size`, 
    301                 `thumb_num`, 
    302                 `admin_username`, 
    303                 `admin_email`, 
    304                 `admin_password`, 
    305                 `date_format`, 
    306                 `feed_title`, 
    307                 `gallery_name`, 
    308                 `gallery_url`) 
    309         VALUES 
    310                 ('${config['default_theme_dir']}', 
    311                 75, 
    312                 100, 
    313                 500, 
    314                 20, 
    315                 '${config['admin_username']}', 
    316                 '${config['admin_email']}', 
    317                 MD5('${config['admin_password']}'), 
    318                 'n.j.Y', 
    319                 'Plogger Photo Feed', 
    320                 '${config['gallery_name']}', 
    321                 '${config['baseurl']}')"; 
     301         
     302        $row_exist = mysql_query("SELECT * FROM `".TABLE_PREFIX."config`"); 
     303        $row_exist_num = mysql_num_rows($row_exist); 
     304 
     305        if ($row_exist_num == 0) { 
     306                $query = "INSERT INTO `".TABLE_PREFIX."config` 
     307                        (`theme_dir`, 
     308                        `compression`, 
     309                        `max_thumbnail_size`, 
     310                        `max_display_size`, 
     311                        `thumb_num`, 
     312                        `admin_username`, 
     313                        `admin_email`, 
     314                        `admin_password`, 
     315                        `date_format`, 
     316                        `feed_title`, 
     317                        `gallery_name`, 
     318                        `gallery_url`) 
     319                VALUES 
     320                        ('${config['default_theme_dir']}', 
     321                        75, 
     322                        100, 
     323                        500, 
     324                        20, 
     325                        '${config['admin_username']}', 
     326                        '${config['admin_email']}', 
     327                        MD5('${config['admin_password']}'), 
     328                        'n.j.Y', 
     329                        'Plogger Photo Feed', 
     330                        '${config['gallery_name']}', 
     331                        '${config['baseurl']}')"; 
     332        } else { 
     333                $query = "UPDATE `".TABLE_PREFIX."config` SET 
     334                        `theme_dir` = '${config['default_theme_dir']}', 
     335                        `compression` = 75, 
     336                        `max_thumbnail_size` = 100, 
     337                        `max_display_size` = 500, 
     338                        `thumb_num` = 20, 
     339                        `admin_username` = '${config['admin_username']}', 
     340                        `admin_email` = '${config['admin_email']}', 
     341                        `admin_password` = MD5('${config['admin_password']}'), 
     342                        `date_format` = 'n.j.Y', 
     343                        `feed_title` = 'Plogger Photo Feed', 
     344                        `gallery_name` = '${config['gallery_name']}', 
     345                        `gallery_url` = '${config['baseurl']}'"; 
     346        } 
    322347 
    323348        mysql_query($query) or die(mysql_error().'<br /><br />'. $query); 
    324349 
    325         mail($config['admin_email'],"Your new gallery","You have successfully installed your new Plogger gallery. You can manage it at ${config['baseurl']}/admin Username is ${config['admin_username']} and password ${config['admin_password']}."); 
     350        mail($config['admin_email'],"Your new gallery","You have successfully installed your new Plogger gallery. You can manage it at ${config['baseurl']}admin Username is ${config['admin_username']} and password ${config['admin_password']}."); 
    326351} 
    327352 
     
    332357        $cfg_file .= 'define("PLOGGER_DB_HOST","'.$db_host.'");'."\n"; 
    333358        $cfg_file .= 'define("PLOGGER_DB_USER","'.$db_user.'");'."\n"; 
    334         $cfg_file .= 'define("PLOGGER_DB_PW","'.$db_pass.'");'."\n"; 
     359        $cfg_file .= 'define("PLOGGER_DB_PW","'.addcslashes($db_pass, '\\$"').'");'."\n";  // escape certain password characters stored in double quotes (\) ($) (") 
    335360        $cfg_file .= 'define("PLOGGER_DB_NAME","'.$db_name.'");'."\n"; 
    336361        $cfg_file .= ''."\n"; 
    337362        $cfg_file .= '// define("PLOGGER_EMBEDDED","");        // 1/0 (True/False) if set will overrule automatic check'."\n"; 
    338363        $cfg_file .= '// define("PLOGGER_LOCALE","");         // da_DK de et fr pl ro_RO tr ...etc.'."\n"; 
    339     if (ini_get('safe_mode')==1) { 
    340     //if safe_mode enabled, write the FTP workaround information to plog-config.php with db information 
    341        $cfg_file .= "\n"; 
    342        $cfg_file .= '// these values are used to connect via FTP.'."\n"; 
    343        $cfg_file .= 'define("PLOGGER_FTP_HOST","'.$ftp_host.'");'."\n"; 
    344            $cfg_file .= 'define("PLOGGER_FTP_USER","'.$ftp_user.'");'."\n"; 
    345            $cfg_file .= 'define("PLOGGER_FTP_PW","'.$ftp_pass.'");'."\n"; 
    346            $cfg_file .= 'define("PLOGGER_FTP_PATH","'.$ftp_path.'");'."\n"; 
    347    }; 
     364        if (ini_get('safe_mode')==1) { 
     365        //if safe_mode enabled, write the FTP workaround information to plog-config.php with db information 
     366                $cfg_file .= "\n"; 
     367                $cfg_file .= '// these values are used to connect via FTP.'."\n"; 
     368                $cfg_file .= 'define("PLOGGER_FTP_HOST","'.$ftp_host.'");'."\n"; 
     369                $cfg_file .= 'define("PLOGGER_FTP_USER","'.$ftp_user.'");'."\n"; 
     370                $cfg_file .= 'define("PLOGGER_FTP_PW","'.addcslashes($ftp_pass, '\\$"').'");'."\n";  // escape certain password characters stored in double quotes (\) ($) (") 
     371                $cfg_file .= 'define("PLOGGER_FTP_PATH","'.$ftp_path.'");'."\n"; 
     372        } 
    348373 
    349374        $cfg_file .= "?>\n"; 
     
    358383        while($row = mysql_fetch_array($res,MYSQL_NUM)) { 
    359384                if ($row[0] == $column) $found = true; 
    360         }; 
     385        } 
    361386        if (!$found) { 
    362387                mysql_query("ALTER TABLE $table ADD `$column` ". $add_sql); 
     
    364389        } else { 
    365390                return "<li>$column already present in database."; 
    366         }; 
     391        } 
    367392} 
    368393 
     
    373398        while($row = mysql_fetch_array($res,MYSQL_NUM)) { 
    374399                if ($row[0] == $column) $found = true; 
    375         }; 
     400        } 
    376401        if ($found) { 
    377402                $sql = "ALTER TABLE $table DROP `$column`"; 
     
    380405        } else { 
    381406                //print "$column does not exist<br/>"; 
    382         }; 
     407        } 
    383408} 
    384409 
     
    391416                if (mysql_error()) { 
    392417                        var_dump(mysql_error()); 
    393                 }; 
     418                } 
    394419        } else { 
    395420                return "<li>Table `$table` already exists, ignoring."; 
    396         }; 
     421        } 
    397422} 
    398423 
     
    407432        if (gd_missing()) { 
    408433                $errors[] = "PHP GD module was not detected."; 
    409         }; 
     434        } 
    410435 
    411436        if (!function_exists('mysql_connect')) { 
    412437                $errors[] = "PHP MySQL module was not detected."; 
    413         }; 
     438        } 
    414439 
    415440        $files_to_read = array("./","./admin","./css","./images","./lib","./thumbs","./uploads"); 
     
    437462                        $errors[] = "Cannot connect to MySQL with the information provided. MySQL error: "  
    438463                                        . mysql_error(); 
    439                 }; 
    440         }; 
     464                } 
     465        } 
    441466        $select = @mysql_select_db($database); 
    442467        if (!$select) { 
    443468                $errors[] = "Couldn't find the database $database. MySQL error: " . mysql_error(); 
    444469 
    445         }; 
     470        } 
     471        return $errors; 
     472} 
     473 
     474function check_FTP($host, $user, $pass, $path) { 
     475        $errors = array(); 
     476 
     477        $connection = @ftp_connect($host); 
     478        if (!$connection) { 
     479                $errors[] = "Couldn't connect to FTP host \"$host\".  Please check your FTP Host:"; 
     480        } else { 
     481                $login = @ftp_login($connection, $user, $pass); 
     482                if (!$login) { 
     483                        $errors[] = "Couldn't login to FTP host \"$host\" with username \"$user\" and password \"$pass\".  Please check your FTP Username: and FTP Password:"; 
     484                } else { 
     485                        $checkdir = @ftp_chdir($connection, $path."images/"); // check to see if the images/ folder is accessible 
     486                        if (!$checkdir) { 
     487                                $errors[] = "Couldn't find the Plogger images\ folder along the path \"$path\".  Please check your FTP Path to Plogger Base Folder (from FTP login):"; 
     488                        } 
     489                } 
     490        } 
     491        @ftp_close($connection); 
    446492        return $errors; 
    447493} 
     
    457503        if (file_exists($cf)) { 
    458504                return is_writable($cf); 
    459         }; 
     505        } 
    460506        return is_writable(PLOGGER_DIR); 
    461507}        
  • trunk/plog-functions.php

    r531 r533  
    10931093                        $pic = get_picture_by_id($id); 
    10941094                        $album = $pic["parent_album"]; 
    1095                         $rv = $config["baseurl"].substr(SmartStripSlashes($pic['path']), 0, -4); 
     1095                        $rv = $config["baseurl"].str_replace("%2F", "/", rawurlencode(substr(SmartStripSlashes($pic['path']), 0, -4))); 
    10961096                } 
    10971097        } else {