diff --git a/about.php b/about.php index f15a44e..05972d0 100644 --- a/about.php +++ b/about.php @@ -1,4 +1,4 @@ - + @@ -11,10 +11,10 @@ - +
- +
@@ -99,9 +99,9 @@ stories "drabblets".
- + - + diff --git a/article.php b/article.php index f7efffe..2940567 100644 --- a/article.php +++ b/article.php @@ -1,4 +1,4 @@ - + @@ -11,7 +11,7 @@ -
- +

x·x·x

- 1)) echo sort_options("article"); echo display_stories(); @@ -36,9 +36,9 @@ echo display_stories();
- + - + diff --git a/bottombar.inc.php b/bottombar.inc.php index 8c20a1d..ab945da 100644 --- a/bottombar.inc.php +++ b/bottombar.inc.php @@ -1,5 +1,5 @@ - - + + diff --git a/display.php b/display.php index d3d6495..465b31e 100644 --- a/display.php +++ b/display.php @@ -1,4 +1,4 @@ -real_escape_string($id)." LIMIT 0, 1"; - $result = $db->query($query)or die("Query failed : ".mysql_error()); + $result = $db->query($query)or die("Query failed : ".$db->error); $row = $result->fetch_assoc(); if ($row) { diff --git a/feed.php b/feed.php index fa6d465..40697b6 100644 --- a/feed.php +++ b/feed.php @@ -1,4 +1,4 @@ -query($query) or die("Query failed : ".$db->error()); +$result = $db->query($query) or die("Query failed : ".$db->error); $most_recent = $result->fetch_row(); $now = date("D, d M Y H:i:s O"); diff --git a/get_data.lib.php b/get_data.lib.php index 1826d18..8786fe3 100644 --- a/get_data.lib.php +++ b/get_data.lib.php @@ -1,4 +1,4 @@ -real_escape_string(stripslashes($_REQUEST['id'])); + $id = $db->real_escape_string($_REQUEST['id']); return $id; } else { return NULL; @@ -252,7 +255,7 @@ function get_id() { function get_search_args() { global $db; - if (isset($_GET['search'])) { + if (isset($_GET['search']) && is_string($_GET['search'])) { $search = $db->real_escape_string($_GET['search']); return $search; } @@ -261,7 +264,7 @@ function get_search_args() { function get_order() { global $db; $order = NULL; - if (isset($_GET['order'])) { + if (isset($_GET['order']) && is_string($_GET['order'])) { $order = $db->real_escape_string($_GET['order']); } // Sort ascending by default @@ -279,7 +282,7 @@ function get_order() { function get_sort_arg() { global $db; $sort = NULL; - if (isset($_GET['sort'])) { + if (isset($_GET['sort']) && is_string($_GET['sort'])) { $sort = $db->real_escape_string($_GET['sort']); } if ($sort != "author" && @@ -292,7 +295,7 @@ function get_sort_arg() { function get_show_num() { global $db, $num_stories; $show = NULL; - if (isset($_GET['show'])) { + if (isset($_GET['show']) && is_string($_GET['show'])) { $show = $db->real_escape_string($_GET['show']); } if (is_numeric($show)) @@ -306,7 +309,7 @@ function get_show_num() { function get_start_num() { global $db; $start = NULL; - if (isset($_GET['start'])) { + if (isset($_GET['start']) && is_string($_GET['start'])) { $start = $db->real_escape_string($_GET['start']); } if (!is_numeric($start)) @@ -344,7 +347,7 @@ function which_table($move = FALSE, $action = 'read') { return 'queue'; // Viewing - } else if ($queue && ($is_admin || array_key_exists('allow_queue_image', $_SESSION))) { + } else if ($queue && ($is_admin || isset($_SESSION['allow_queue_image']))) { return 'queue'; } else { return 'xxx'; diff --git a/google.inc.php b/google.inc.php index 62af3f4..2371f4a 100644 --- a/google.inc.php +++ b/google.inc.php @@ -1,4 +1,4 @@ - - + diff --git a/index.php b/index.php index 3af5585..fbde95a 100644 --- a/index.php +++ b/index.php @@ -1,4 +1,4 @@ - + @@ -11,7 +11,7 @@ -
- +
@@ -36,7 +36,7 @@ encouraged!

You can send in an entry here; take a shufty at the guidelines.

-
- + - + diff --git a/lib/convert_entities.inc.php b/lib/convert_entities.inc.php index eba7c33..80b5974 100644 --- a/lib/convert_entities.inc.php +++ b/lib/convert_entities.inc.php @@ -1,4 +1,4 @@ -'; - $nw = new Numbers_Words(); + $nw = class_exists('Numbers_Words') ? new Numbers_Words() : NULL; // Are there later stories? Go backwards to them $string .= ''; if ($start > 0) { @@ -74,7 +75,7 @@ function get_pager() { if (isset($_GET['show'])) $string .= '&show='.$show; if (isset($_GET['sort'])) $string .= '&sort='.$sort; if (isset($_GET['order'])) $string .= '&order='.$order; - $articles = ($show == 1) ? "article" : $nw->toWords($show)." articles"; + $articles = ($show == 1) ? "article" : ($nw ? $nw->toWords($show) : $show)." articles"; $string .= '">« Next '.$articles.''; } $string .= "\n"; @@ -88,7 +89,7 @@ function get_pager() { if (isset($_GET['show'])) $string .= '&show='.$show; if (isset($_GET['sort'])) $string .= '&sort='.$sort; if (isset($_GET['order'])) $string .= '&order='.$order; - $articles = ($show == 1) ? "article" : $nw->toWords($show)." articles"; + $articles = ($show == 1) ? "article" : ($nw ? $nw->toWords($show) : $show)." articles"; $string .= '">Previous '.$articles.' »'; } $string .= "\n"; diff --git a/open_db.lib.php b/open_db.lib.php index 3c0937c..ef4641e 100644 --- a/open_db.lib.php +++ b/open_db.lib.php @@ -1,4 +1,4 @@ -connect_error) { die ("Unable to connect to database"); diff --git a/publish/addeditor.php b/publish/addeditor.php index aeb4b3a..53ab06f 100644 --- a/publish/addeditor.php +++ b/publish/addeditor.php @@ -1,4 +1,4 @@ -real_escape_string($_POST['username']); - $password = crypt($_POST['password']); - $email = $db->real_escape_string($_POST['email']); + $username = $db->real_escape_string($_POST['username'] ?? ''); + $password = $db->real_escape_string(password_hash($_POST['password'] ?? '', PASSWORD_DEFAULT)); + $email = $db->real_escape_string($_POST['email'] ?? ''); $query = "INSERT INTO $table SET". "`username` = '".$username."', ". "`password` = '".$password."', ". @@ -39,18 +39,18 @@ if (!isset($_SESSION['editor'])) { - +
- +

add editor

- +

Added editor

- +
@@ -77,12 +77,12 @@ if (!isset($_SESSION['editor'])) {
- +
- + diff --git a/publish/choose.inc.php b/publish/choose.inc.php index bb692c0..a690144 100644 --- a/publish/choose.inc.php +++ b/publish/choose.inc.php @@ -1,4 +1,4 @@ - 1)) if ($queue) { ?>

To view already-posted articles, click here.

- +

To view articles in the queue, click here.

- +
- diff --git a/publish/edit.php b/publish/edit.php index 39396a1..f3acd09 100644 --- a/publish/edit.php +++ b/publish/edit.php @@ -1,4 +1,4 @@ - - + -
- +

edit

-
- + - + diff --git a/publish/index.php b/publish/index.php index 27f0ac8..2215b0f 100644 --- a/publish/index.php +++ b/publish/index.php @@ -1,4 +1,4 @@ - + @@ -11,12 +11,12 @@ - - + + - + -
- +

submit

-
- + - + diff --git a/publish/login.php b/publish/login.php index c4704b3..e8fc8de 100644 --- a/publish/login.php +++ b/publish/login.php @@ -1,4 +1,4 @@ -real_escape_string($_POST['username']); + $username = $db->real_escape_string($_POST['username'] ?? ''); $query = "SELECT * FROM $table WHERE ". "username LIKE '".$username."' ". "LIMIT 1;"; - $getid = $db->query($query) or die("Query failed: ".$db->error()); + $getid = $db->query($query) or die("Query failed: ".$db->error); $row = $getid->fetch_assoc(); - if (isset($row)) + $stored_password = ''; + if (isset($row)) $stored_password = $row['password']; else $denied = TRUE; $getid->close(); open_db('close'); - $compare_password = $_POST['password']; - if (crypt($compare_password, $stored_password) != $stored_password) { + $compare_password = $_POST['password'] ?? ''; + // password_verify() also accepts hashes made by the old crypt() call + if (!password_verify($compare_password, $stored_password)) { $denied = TRUE; } else { $_SESSION['editor'] = $username; @@ -65,21 +67,21 @@ if (isset($_SESSION['editor'])) { - +
- +

editor login

-Access denied. Please try again.

\n"; ?> -
" method="post"> +" method="post">
@@ -108,7 +110,7 @@ if ($denied)
- + diff --git a/publish/logout.php b/publish/logout.php index 5bd3f44..9460fdf 100644 --- a/publish/logout.php +++ b/publish/logout.php @@ -1,4 +1,4 @@ -
\n"; diff --git a/publish/post.lib.php b/publish/post.lib.php index 5a2d9d9..de2335f 100644 --- a/publish/post.lib.php +++ b/publish/post.lib.php @@ -1,4 +1,4 @@ -query($query) or die("Query failed: ".$db->error()); + $getid = $db->query($query) or die("Query failed: ".$db->error); $row = $getid->fetch_row(); $id = $row[0]; } @@ -119,8 +121,9 @@ function delete_story($id, $move = FALSE) { $query = "DELETE FROM $table WHERE `id` = '".$id."' LIMIT 1;"; //echo $query; - $result = $db->query($query)or die("Query failed : ".$db->error()); + $result = $db->query($query)or die("Query failed : ".$db->error); + $message = ''; if (!$move) $message = 'Article has been deleted.'; @@ -129,13 +132,13 @@ function delete_story($id, $move = FALSE) { function get_mimetype($image_file) { $upload = getimagesize($image_file); - $mimetype = $upload['mime']; + $mimetype = $upload ? $upload['mime'] : NULL; return $mimetype; } function save_uploaded_file() { // Save uploaded file to new, temporary location - if (is_uploaded_file($_FILES['upload']['tmp_name'])) { + if (is_uploaded_file($_FILES['upload']['tmp_name'] ?? '')) { $tmp_file = $_FILES['upload']['tmp_name']; $new_file = $_SERVER['DOCUMENT_ROOT'] . "/graphics" . $tmp_file; $end_dir = dirname($new_file); @@ -164,8 +167,8 @@ function prune_images($image_file) { unlink($image_file); if ( $dir_handle = @opendir($cleanup_dir) ) { - if($dir_handle=='.' || $dir_handle=='..') continue; - while ($cleanup_file = readdir ($dir_handle)) { + while (($cleanup_file = readdir ($dir_handle)) !== FALSE) { + if ($cleanup_file == '.' || $cleanup_file == '..') continue; $cleanup_file = $cleanup_dir . "/". $cleanup_file; if (@filemtime($cleanup_file) < (time() - $age)) { @unlink($cleanup_file); @@ -184,10 +187,12 @@ function prune_images($image_file) { $validate = array(); function validate_data() { global $validate; - // extract POST variables (running through stripslashes) + // extract POST variables $result = get_post_data(TRUE); // assign their keys and values to the symbol table extract($result[0], EXTR_OVERWRITE); + $upload_error = $_FILES['upload']['error'] ?? UPLOAD_ERR_NO_FILE; + $upload_tmp = $_FILES['upload']['tmp_name'] ?? ''; if (!$author) { @@ -203,11 +208,11 @@ function validate_data() { } // 0 == no error; 4 == no file; all others are errors. - if ($_FILES['upload']['error'] > 0 && - $_FILES['upload']['error'] !== 4) { - $validate['upload'] = 'There was an error uploading the file ('.$_FILES['upload']['error'].')'; - } else if ($_FILES['upload']['tmp_name']) { - $upload = getimagesize($_FILES['upload']['tmp_name']); + if ($upload_error > 0 && + $upload_error !== 4) { + $validate['upload'] = 'There was an error uploading the file ('.$upload_error.')'; + } else if ($upload_tmp) { + $upload = getimagesize($upload_tmp); if (!$upload) $validate['upload'] = htmlspecialchars($_FILES['upload']['name']) . " wasn't an image file. Please go back."; @@ -245,7 +250,7 @@ function send_email($title, $author, $story) { $headers = 'From: x.x.x Queue '."\r\n"; $message = "Please review the queue. $author has sent the following new submission:\n\n"; if ($story) - $message .= wordwrap(preg_replace("#(|

)#", "\n", strip_tags(stripslashes(html_entity_decode_full($story))))); + $message .= wordwrap(preg_replace("#(|

)#", "\n", strip_tags(html_entity_decode_full($story)))); else $message .= ""; $message .= "\n\nhttp://xxx.org.za/publish/edit"; diff --git a/publish/preview.inc.php b/publish/preview.inc.php index 481d3d9..21b152e 100644 --- a/publish/preview.inc.php +++ b/publish/preview.inc.php @@ -1,4 +1,4 @@ -success)) { $validate['captcha'] = 'The words you typed in the captcha were not correct. Please try again.'; include('./write.inc.php'); return; @@ -21,7 +23,7 @@ if (isset($_POST['g-recaptcha-response'])) { echo '

Please review your submission. Once you\'ve finished, please click "Submit" at the bottom of the page, or click "Preview" to check it again.

'; -if (is_uploaded_file($_FILES['upload']['tmp_name']) && !isset($validate['upload'])) { +if (is_uploaded_file($_FILES['upload']['tmp_name'] ?? '') &&!isset($validate['upload'])) { $tmp_file = $_FILES['upload']['tmp_name']; $upload = getimagesize($tmp_file); $new_file = $_SERVER['DOCUMENT_ROOT'] . "/graphics" . $tmp_file; diff --git a/publish/write.inc.php b/publish/write.inc.php index 9071989..e9107c1 100644 --- a/publish/write.inc.php +++ b/publish/write.inc.php @@ -1,4 +1,4 @@ -
-
(To get line-breaks—as in poetry—instead of paragraph breaks, hit shift-enter instead of enter.)
- - for="comments">Comments: + + for="comments">Comments:
- + - +
-
'; } @@ -116,7 +116,7 @@ if (isset($file_src) || isset($img)) { ?>
-Save in queue'; } else { @@ -138,7 +138,7 @@ if (isset($file_src) || isset($img)) { -'."\n"; if (isset($file_src) || isset($img) || isset($validate['upload'])) { echo " showHide('upload')\n"; diff --git a/session.lib.php b/session.lib.php index 85fc867..a817af2 100644 --- a/session.lib.php +++ b/session.lib.php @@ -1,4 +1,4 @@ -real_escape_string($_COOKIE['PersistentAuth']); - list($username, $key) = explode("|", $cookie_data); + list($username, $key) = explode("|", $cookie_data, 2) + array('', ''); $username = $db->real_escape_string($username); $key = $db->real_escape_string($key); $query = "SELECT * FROM $table WHERE ". "username LIKE '".$username."' ". "LIMIT 1;"; - $getid = $db->query($query) or die("Query failed: ".$db->error()); + $getid = $db->query($query) or die("Query failed: ".$db->error); $row = $getid->fetch_assoc(); open_db('close'); @@ -68,11 +68,11 @@ function create_persistent_login($username) { open_db('open'); $username = $db->real_escape_string($username); - $key = substr(bin2hex(mcrypt_create_iv(100,MCRYPT_DEV_URANDOM)), 0, 200); + $key = bin2hex(random_bytes(100)); // Add session key to database $query = "INSERT INTO $table " . "(username, session) VALUES ('" . $username."', '" . $key . "');"; - $db->query($query) or die("Query failed: ".$db->error()); + $db->query($query) or die("Query failed: ".$db->error); open_db('close'); // Create cookie with key @@ -86,8 +86,8 @@ function delete_persistent_login() { $table = "persistent_sessions"; open_db('open'); - $cookie_data = $db->real_escape_string($_COOKIE['PersistentAuth']); - list($username, $key) = explode("|", $cookie_data); + $cookie_data = $db->real_escape_string($_COOKIE['PersistentAuth'] ?? ''); + list($username, $key) = explode("|", $cookie_data, 2) + array('', ''); $username = $db->real_escape_string($username); $key = $db->real_escape_string($key); @@ -95,12 +95,12 @@ function delete_persistent_login() { $query = "DELETE FROM $table " . " WHERE username LIKE '" . $username . "'" . " AND session LIKE '" . $key . "';"; - $db->query($query) or die("Query failed: ".$db->error()); + $db->query($query) or die("Query failed: ".$db->error); // Reap old sessions $query = "DELETE FROM $table " . " WHERE created < DATE_SUB(now(), INTERVAL 1 YEAR);"; - $db->query($query) or die("Query failed: ".$db->error()); + $db->query($query) or die("Query failed: ".$db->error); open_db('close'); diff --git a/sidebar.inc.php b/sidebar.inc.php index 5e71999..59d10ca 100644 --- a/sidebar.inc.php +++ b/sidebar.inc.php @@ -1,6 +1,6 @@