Compare commits
	
		
			7 Commits
		
	
	
		
			0d74e59634
			...
			e4bbfd5f60
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| e4bbfd5f60 | |||
| 9f2977d2c0 | |||
| 3f461ae142 | |||
| bb979200cd | |||
| 88231a9583 | |||
| 320d1fccc9 | |||
| 8b7ccda1b1 | 
| 
						 | 
					@ -8,4 +8,4 @@ A quick and dirty web interface to provide access for downloading e-books and se
 | 
				
			||||||
* Execute: `composer install`
 | 
					* Execute: `composer install`
 | 
				
			||||||
* Copy `variables-dist.php` to `variables.php` and edit appropriately
 | 
					* Copy `variables-dist.php` to `variables.php` and edit appropriately
 | 
				
			||||||
* Create database on SQL server, create a DB user for this application, and import the `books_initial.sql`
 | 
					* Create database on SQL server, create a DB user for this application, and import the `books_initial.sql`
 | 
				
			||||||
* Create a cron job that runs `install/parsebooks.php` daily
 | 
					* Create a cron job that runs `scripts/parsebooks.php` daily
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -14,6 +14,7 @@ function sendResponse($data) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$data = array();
 | 
					$data = array();
 | 
				
			||||||
$data['validated'] = $validated;
 | 
					$data['validated'] = $validated;
 | 
				
			||||||
 | 
					$data['admin'] = $_SESSION['admin'];
 | 
				
			||||||
$data['bookdir'] = $_SESSION['bookdir'];
 | 
					$data['bookdir'] = $_SESSION['bookdir'];
 | 
				
			||||||
$data['bookdirname'] = basename($_SESSION['bookdir']);
 | 
					$data['bookdirname'] = basename($_SESSION['bookdir']);
 | 
				
			||||||
$data['kindlemail'] = "";
 | 
					$data['kindlemail'] = "";
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -88,3 +88,17 @@ a {
 | 
				
			||||||
.hide {
 | 
					.hide {
 | 
				
			||||||
   display: none;
 | 
					   display: none;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					#parsebooks {
 | 
				
			||||||
 | 
					   right: 0;
 | 
				
			||||||
 | 
					   bottom: 0;
 | 
				
			||||||
 | 
					   position: fixed;
 | 
				
			||||||
 | 
					   z-index: 100;
 | 
				
			||||||
 | 
					   color: var(--primary-color);
 | 
				
			||||||
 | 
					   font-weight: bold;
 | 
				
			||||||
 | 
					   font-size: 16pt;
 | 
				
			||||||
 | 
					   cursor: pointer;
 | 
				
			||||||
 | 
					   padding: 0.5em;
 | 
				
			||||||
 | 
					   margin: 0.25em;
 | 
				
			||||||
 | 
					   border: 2px solid var(--box-border);
 | 
				
			||||||
 | 
					   border-radius: 10px;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										10
									
								
								header.php
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								header.php
									
									
									
									
									
								
							| 
						 | 
					@ -1,27 +1,25 @@
 | 
				
			||||||
<?php
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
session_name('JackpotGeneric');
 | 
					 | 
				
			||||||
session_start();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
require 'authfunctions.php';
 | 
					require 'authfunctions.php';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if ( php_sapi_name() != "cli" ) {
 | 
				
			||||||
 | 
					   session_name('JackpotGeneric');
 | 
				
			||||||
 | 
					   session_start();
 | 
				
			||||||
   if ( !isset($_SESSION['validated']) ) {
 | 
					   if ( !isset($_SESSION['validated']) ) {
 | 
				
			||||||
      $_SESSION['validated'] = false;
 | 
					      $_SESSION['validated'] = false;
 | 
				
			||||||
   }
 | 
					   }
 | 
				
			||||||
 | 
					 | 
				
			||||||
   if ( !isset($_SESSION['sentfile']) ) {
 | 
					   if ( !isset($_SESSION['sentfile']) ) {
 | 
				
			||||||
      $_SESSION['sentfile'] = "";
 | 
					      $_SESSION['sentfile'] = "";
 | 
				
			||||||
   }
 | 
					   }
 | 
				
			||||||
 | 
					 | 
				
			||||||
   if ( !isset($_SESSION['hash']) ) {
 | 
					   if ( !isset($_SESSION['hash']) ) {
 | 
				
			||||||
      $_SESSION['hash'] = "";
 | 
					      $_SESSION['hash'] = "";
 | 
				
			||||||
   }
 | 
					   }
 | 
				
			||||||
   if ( isset($_REQUEST['hash']) ) {
 | 
					   if ( isset($_REQUEST['hash']) ) {
 | 
				
			||||||
      $_SESSION['hash'] = $_REQUEST['hash'];
 | 
					      $_SESSION['hash'] = $_REQUEST['hash'];
 | 
				
			||||||
   }
 | 
					   }
 | 
				
			||||||
 | 
					 | 
				
			||||||
   if ( !isset($_SESSION['bookdir']) ) {
 | 
					   if ( !isset($_SESSION['bookdir']) ) {
 | 
				
			||||||
      $_SESSION['bookdir'] = "/";
 | 
					      $_SESSION['bookdir'] = "/";
 | 
				
			||||||
   }
 | 
					   }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// vim: sw=3 ts=3 et mouse-=a:
 | 
					// vim: sw=3 ts=3 et mouse-=a:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -37,6 +37,9 @@ $curpath = $_SESSION['bookdir'];
 | 
				
			||||||
    <input placeholder="Enter Address" name="edit_kindle" id="edit_kindle" size="40" required>
 | 
					    <input placeholder="Enter Address" name="edit_kindle" id="edit_kindle" size="40" required>
 | 
				
			||||||
  </div>
 | 
					  </div>
 | 
				
			||||||
</div>
 | 
					</div>
 | 
				
			||||||
 | 
					<div id='parsebooks' class='hide'>
 | 
				
			||||||
 | 
					  Parse
 | 
				
			||||||
 | 
					</div>
 | 
				
			||||||
<script type='text/javascript' src='core/jquery-3.6.3.min.js'></script>
 | 
					<script type='text/javascript' src='core/jquery-3.6.3.min.js'></script>
 | 
				
			||||||
<script type='text/javascript' src='core/jquery-ui-1.14.1/jquery-ui.min.js'></script>
 | 
					<script type='text/javascript' src='core/jquery-ui-1.14.1/jquery-ui.min.js'></script>
 | 
				
			||||||
<script type='text/javascript' src='core/jquery.toast.min.js'></script>
 | 
					<script type='text/javascript' src='core/jquery.toast.min.js'></script>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										41
									
								
								js/books.js
									
									
									
									
									
								
							
							
						
						
									
										41
									
								
								js/books.js
									
									
									
									
									
								
							| 
						 | 
					@ -3,6 +3,7 @@ var kindlemail = "";
 | 
				
			||||||
var currentpath = "";
 | 
					var currentpath = "";
 | 
				
			||||||
var searchTimeout = null;
 | 
					var searchTimeout = null;
 | 
				
			||||||
var lastSearch = "";
 | 
					var lastSearch = "";
 | 
				
			||||||
 | 
					var admin = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$(document).ready(function() {
 | 
					$(document).ready(function() {
 | 
				
			||||||
   getContents();
 | 
					   getContents();
 | 
				
			||||||
| 
						 | 
					@ -41,6 +42,7 @@ $(document).ready(function() {
 | 
				
			||||||
         getContents();
 | 
					         getContents();
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
   });
 | 
					   });
 | 
				
			||||||
 | 
					   $("#parsebooks").on("click", parseBooks);
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function showKindleMail() {
 | 
					function showKindleMail() {
 | 
				
			||||||
| 
						 | 
					@ -65,6 +67,8 @@ function getContents() {
 | 
				
			||||||
      dataType : 'json',
 | 
					      dataType : 'json',
 | 
				
			||||||
      success  : function(data, stat, jqo) {
 | 
					      success  : function(data, stat, jqo) {
 | 
				
			||||||
                    if ( data.validated == false ) redirectToLogin();
 | 
					                    if ( data.validated == false ) redirectToLogin();
 | 
				
			||||||
 | 
					                    admin = data.admin;
 | 
				
			||||||
 | 
					                    if ( admin ) $("#parsebooks").removeClass("hide");
 | 
				
			||||||
                    if ( data.kindlemail != kindlemail ) {
 | 
					                    if ( data.kindlemail != kindlemail ) {
 | 
				
			||||||
                       kindlemail = data.kindlemail;
 | 
					                       kindlemail = data.kindlemail;
 | 
				
			||||||
                       showKindleMail();
 | 
					                       showKindleMail();
 | 
				
			||||||
| 
						 | 
					@ -157,6 +161,41 @@ function setKindleMail(email) {
 | 
				
			||||||
   });
 | 
					   });
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function parseBooks() {
 | 
				
			||||||
 | 
					   if ( !admin ) return;
 | 
				
			||||||
 | 
					   var myToast = $.toast({
 | 
				
			||||||
 | 
					      text : "<h2><strong>Parsing Books</strong></h2>",
 | 
				
			||||||
 | 
					      showHideTransition : 'slide',
 | 
				
			||||||
 | 
					      bgColor : '#033e9e',
 | 
				
			||||||
 | 
					      textColor : '#eee',
 | 
				
			||||||
 | 
					      hideAfter : false,
 | 
				
			||||||
 | 
					      textAlign : 'left',
 | 
				
			||||||
 | 
					      position : 'top-right'
 | 
				
			||||||
 | 
					   });
 | 
				
			||||||
 | 
					   $.ajax({
 | 
				
			||||||
 | 
					      url      : 'scripts/parsebooks.php',
 | 
				
			||||||
 | 
					      dataType : 'json',
 | 
				
			||||||
 | 
					      success  : function(data, stat, jqo) {
 | 
				
			||||||
 | 
					                    myToast.reset();
 | 
				
			||||||
 | 
					                    var message = "";
 | 
				
			||||||
 | 
					                    message += "<h2><strong>Books Parsed:</strong></h2>";
 | 
				
			||||||
 | 
					                    message += "<hr>";
 | 
				
			||||||
 | 
					                    message += "<h3><strong>New:</strong> " + data.new + "</h3><br />";
 | 
				
			||||||
 | 
					                    message += "<h3><strong>Purged:</strong> " + data.purged + "</h3><br />";
 | 
				
			||||||
 | 
					                    message += "<h3><strong>Total:</strong> " + data.total + "</h3><br />";
 | 
				
			||||||
 | 
					                    $.toast({
 | 
				
			||||||
 | 
					                       text : message,
 | 
				
			||||||
 | 
					                       showHideTransition : 'slide',
 | 
				
			||||||
 | 
					                       bgColor : '#137c1e',
 | 
				
			||||||
 | 
					                       textColor : '#eee',
 | 
				
			||||||
 | 
					                       hideAfter : 10000,
 | 
				
			||||||
 | 
					                       textAlign : 'left',
 | 
				
			||||||
 | 
					                       position : 'top-right'
 | 
				
			||||||
 | 
					                    });
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					   });
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function sendToKindle(fileid, filename) {
 | 
					function sendToKindle(fileid, filename) {
 | 
				
			||||||
   var myToast = $.toast({
 | 
					   var myToast = $.toast({
 | 
				
			||||||
      text : "<h3><strong>Sending: " + filename + "</strong></h3>",
 | 
					      text : "<h3><strong>Sending: " + filename + "</strong></h3>",
 | 
				
			||||||
| 
						 | 
					@ -191,3 +230,5 @@ function sendToKindle(fileid, filename) {
 | 
				
			||||||
                 }
 | 
					                 }
 | 
				
			||||||
   });
 | 
					   });
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// vim: ts=3 sw=3 ai:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,12 +1,24 @@
 | 
				
			||||||
<?php
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
require dirname(__FILE__) . "/../variables.php";
 | 
					require dirname(__FILE__) . "/../variables.php";
 | 
				
			||||||
 | 
					require dirname(__FILE__) . "/../header.php";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$dbbooks = array();
 | 
					$dbbooks = array();
 | 
				
			||||||
$parsedbooks = array();
 | 
					$parsedbooks = array();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$cli = ( php_sapi_name() != "cli" ) ? false : true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if ( !$cli ) {
 | 
				
			||||||
 | 
					   $validated = require_login(NOREDIRECT);
 | 
				
			||||||
 | 
					   if ( !$validated || !$_SESSION['admin'] ) exit();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$count_total = 0;
 | 
				
			||||||
 | 
					$count_new = 0;
 | 
				
			||||||
 | 
					$count_purged = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function walkBooks($path = BOOKDIR) {
 | 
					function walkBooks($path = BOOKDIR) {
 | 
				
			||||||
   global $globaldbh, $parsedbooks;
 | 
					   global $globaldbh, $parsedbooks, $count_new, $count_total;
 | 
				
			||||||
   $contents = glob($path . "/*");
 | 
					   $contents = glob($path . "/*");
 | 
				
			||||||
   foreach ( $contents as $item ) {
 | 
					   foreach ( $contents as $item ) {
 | 
				
			||||||
      if ( is_dir($item) ) {
 | 
					      if ( is_dir($item) ) {
 | 
				
			||||||
| 
						 | 
					@ -16,12 +28,17 @@ function walkBooks($path = BOOKDIR) {
 | 
				
			||||||
         $dbfile = basename($item);
 | 
					         $dbfile = basename($item);
 | 
				
			||||||
         $dbmtime = date("Y-m-d H:i:s", filemtime($item));
 | 
					         $dbmtime = date("Y-m-d H:i:s", filemtime($item));
 | 
				
			||||||
         $parsedbooks[] = $dbpath . (($path == BOOKDIR) ? "" : "/") . $dbfile;
 | 
					         $parsedbooks[] = $dbpath . (($path == BOOKDIR) ? "" : "/") . $dbfile;
 | 
				
			||||||
         $query = "INSERT INTO books (path, filename, mtime) VALUES(:path, :filename, :mtime) ON DUPLICATE KEY UPDATE id=id";
 | 
					         $query = "INSERT INTO books (path, filename, mtime) VALUES(:path, :filename, :mtime)";
 | 
				
			||||||
         $sth = $globaldbh->prepare($query);
 | 
					         $sth = $globaldbh->prepare($query);
 | 
				
			||||||
         $sth->bindValue(":path", $dbpath, PDO::PARAM_STR);
 | 
					         $sth->bindValue(":path", $dbpath, PDO::PARAM_STR);
 | 
				
			||||||
         $sth->bindValue(":filename", $dbfile, PDO::PARAM_STR);
 | 
					         $sth->bindValue(":filename", $dbfile, PDO::PARAM_STR);
 | 
				
			||||||
         $sth->bindValue(":mtime", $dbmtime, PDO::PARAM_STR);
 | 
					         $sth->bindValue(":mtime", $dbmtime, PDO::PARAM_STR);
 | 
				
			||||||
 | 
					         try {
 | 
				
			||||||
            $sth->execute();
 | 
					            $sth->execute();
 | 
				
			||||||
 | 
					            $count_new++;
 | 
				
			||||||
 | 
					         } catch (PDOException $e) {
 | 
				
			||||||
 | 
					         }
 | 
				
			||||||
 | 
					         $count_total++;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
   }
 | 
					   }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -40,7 +57,22 @@ foreach ( $dbbooks as $dbbook ) {
 | 
				
			||||||
   if ( !is_file(BOOKDIR . $dbbook) ) {
 | 
					   if ( !is_file(BOOKDIR . $dbbook) ) {
 | 
				
			||||||
      $sth->bindValue(":target", $dbbook, PDO::PARAM_STR);
 | 
					      $sth->bindValue(":target", $dbbook, PDO::PARAM_STR);
 | 
				
			||||||
      $sth->execute();
 | 
					      $sth->execute();
 | 
				
			||||||
 | 
					      $count_purged++;
 | 
				
			||||||
   }
 | 
					   }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if ( $cli ) {
 | 
				
			||||||
 | 
					   echo "New Books: {$count_new}\n";
 | 
				
			||||||
 | 
					   echo "Purged Books: {$count_purged}\n";
 | 
				
			||||||
 | 
					   echo "Total Books: {$count_total}\n";
 | 
				
			||||||
 | 
					} else {
 | 
				
			||||||
 | 
					   $data = array();
 | 
				
			||||||
 | 
					   $data["new"] = $count_new;
 | 
				
			||||||
 | 
					   $data["purged"] = $count_purged;
 | 
				
			||||||
 | 
					   $data["total"] = $count_total;
 | 
				
			||||||
 | 
					   header('Content-Type: application/json');
 | 
				
			||||||
 | 
					   echo json_encode($data);
 | 
				
			||||||
 | 
					   exit();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// vim: set sw=3 ts=3:
 | 
					// vim: set sw=3 ts=3:
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user