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`
 | 
			
		||||
* 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 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['validated'] = $validated;
 | 
			
		||||
$data['admin'] = $_SESSION['admin'];
 | 
			
		||||
$data['bookdir'] = $_SESSION['bookdir'];
 | 
			
		||||
$data['bookdirname'] = basename($_SESSION['bookdir']);
 | 
			
		||||
$data['kindlemail'] = "";
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -88,3 +88,17 @@ a {
 | 
			
		|||
.hide {
 | 
			
		||||
   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;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										38
									
								
								header.php
									
									
									
									
									
								
							
							
						
						
									
										38
									
								
								header.php
									
									
									
									
									
								
							| 
						 | 
				
			
			@ -1,27 +1,25 @@
 | 
			
		|||
<?php
 | 
			
		||||
 | 
			
		||||
session_name('JackpotGeneric');
 | 
			
		||||
session_start();
 | 
			
		||||
 | 
			
		||||
require 'authfunctions.php';
 | 
			
		||||
 | 
			
		||||
if ( !isset($_SESSION['validated']) ) {
 | 
			
		||||
   $_SESSION['validated'] = false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
if ( !isset($_SESSION['sentfile']) ) {
 | 
			
		||||
   $_SESSION['sentfile'] = "";
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
if ( !isset($_SESSION['hash']) ) {
 | 
			
		||||
   $_SESSION['hash'] = "";
 | 
			
		||||
}
 | 
			
		||||
if ( isset($_REQUEST['hash']) ) {
 | 
			
		||||
   $_SESSION['hash'] = $_REQUEST['hash'];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
if ( !isset($_SESSION['bookdir']) ) {
 | 
			
		||||
   $_SESSION['bookdir'] = "/";
 | 
			
		||||
if ( php_sapi_name() != "cli" ) {
 | 
			
		||||
   session_name('JackpotGeneric');
 | 
			
		||||
   session_start();
 | 
			
		||||
   if ( !isset($_SESSION['validated']) ) {
 | 
			
		||||
      $_SESSION['validated'] = false;
 | 
			
		||||
   }
 | 
			
		||||
   if ( !isset($_SESSION['sentfile']) ) {
 | 
			
		||||
      $_SESSION['sentfile'] = "";
 | 
			
		||||
   }
 | 
			
		||||
   if ( !isset($_SESSION['hash']) ) {
 | 
			
		||||
      $_SESSION['hash'] = "";
 | 
			
		||||
   }
 | 
			
		||||
   if ( isset($_REQUEST['hash']) ) {
 | 
			
		||||
      $_SESSION['hash'] = $_REQUEST['hash'];
 | 
			
		||||
   }
 | 
			
		||||
   if ( !isset($_SESSION['bookdir']) ) {
 | 
			
		||||
      $_SESSION['bookdir'] = "/";
 | 
			
		||||
   }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 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>
 | 
			
		||||
  </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-ui-1.14.1/jquery-ui.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 searchTimeout = null;
 | 
			
		||||
var lastSearch = "";
 | 
			
		||||
var admin = false;
 | 
			
		||||
 | 
			
		||||
$(document).ready(function() {
 | 
			
		||||
   getContents();
 | 
			
		||||
| 
						 | 
				
			
			@ -41,6 +42,7 @@ $(document).ready(function() {
 | 
			
		|||
         getContents();
 | 
			
		||||
      }
 | 
			
		||||
   });
 | 
			
		||||
   $("#parsebooks").on("click", parseBooks);
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
function showKindleMail() {
 | 
			
		||||
| 
						 | 
				
			
			@ -65,6 +67,8 @@ function getContents() {
 | 
			
		|||
      dataType : 'json',
 | 
			
		||||
      success  : function(data, stat, jqo) {
 | 
			
		||||
                    if ( data.validated == false ) redirectToLogin();
 | 
			
		||||
                    admin = data.admin;
 | 
			
		||||
                    if ( admin ) $("#parsebooks").removeClass("hide");
 | 
			
		||||
                    if ( data.kindlemail != kindlemail ) {
 | 
			
		||||
                       kindlemail = data.kindlemail;
 | 
			
		||||
                       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) {
 | 
			
		||||
   var myToast = $.toast({
 | 
			
		||||
      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
 | 
			
		||||
 | 
			
		||||
require dirname(__FILE__) . "/../variables.php";
 | 
			
		||||
require dirname(__FILE__) . "/../header.php";
 | 
			
		||||
 | 
			
		||||
$dbbooks = 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) {
 | 
			
		||||
   global $globaldbh, $parsedbooks;
 | 
			
		||||
   global $globaldbh, $parsedbooks, $count_new, $count_total;
 | 
			
		||||
   $contents = glob($path . "/*");
 | 
			
		||||
   foreach ( $contents as $item ) {
 | 
			
		||||
      if ( is_dir($item) ) {
 | 
			
		||||
| 
						 | 
				
			
			@ -16,12 +28,17 @@ function walkBooks($path = BOOKDIR) {
 | 
			
		|||
         $dbfile = basename($item);
 | 
			
		||||
         $dbmtime = date("Y-m-d H:i:s", filemtime($item));
 | 
			
		||||
         $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->bindValue(":path", $dbpath, PDO::PARAM_STR);
 | 
			
		||||
         $sth->bindValue(":filename", $dbfile, PDO::PARAM_STR);
 | 
			
		||||
         $sth->bindValue(":mtime", $dbmtime, PDO::PARAM_STR);
 | 
			
		||||
         $sth->execute();
 | 
			
		||||
         try {
 | 
			
		||||
            $sth->execute();
 | 
			
		||||
            $count_new++;
 | 
			
		||||
         } catch (PDOException $e) {
 | 
			
		||||
         }
 | 
			
		||||
         $count_total++;
 | 
			
		||||
      }
 | 
			
		||||
   }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -40,7 +57,22 @@ foreach ( $dbbooks as $dbbook ) {
 | 
			
		|||
   if ( !is_file(BOOKDIR . $dbbook) ) {
 | 
			
		||||
      $sth->bindValue(":target", $dbbook, PDO::PARAM_STR);
 | 
			
		||||
      $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:
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user