Implement login requirement for adding/changing entries.
This commit is contained in:
		
							parent
							
								
									2dc4dd923d
								
							
						
					
					
						commit
						a27446465a
					
				
							
								
								
									
										4
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										4
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| 
						 | 
					@ -1,3 +1,7 @@
 | 
				
			||||||
 | 
					# Installation specific .htaccess and auth passwd file in ajax/
 | 
				
			||||||
 | 
					ajax/.htaccess
 | 
				
			||||||
 | 
					ajax/links.auth
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# OS generated files
 | 
					# OS generated files
 | 
				
			||||||
.DS_Store
 | 
					.DS_Store
 | 
				
			||||||
.DS_Store?
 | 
					.DS_Store?
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										10
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								README.md
									
									
									
									
									
								
							| 
						 | 
					@ -1,3 +1,11 @@
 | 
				
			||||||
# LinkProvider
 | 
					# LinkProvider
 | 
				
			||||||
 | 
					
 | 
				
			||||||
A basic website/service to keep a list of URLs/Links and provide a URL for retrieving the list as a JSON object.
 | 
					A basic website/service to keep a list of URLs/Links and provide a URL for retrieving the list as a JSON object.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## After Installation
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					- Create a database and maybe user for use by the Link Manager then import the db.sql file.
 | 
				
			||||||
 | 
					- Copy the config-dist.php file to config.php and edit the settings as appropriate.
 | 
				
			||||||
 | 
					- Go into the ajax/ folder.
 | 
				
			||||||
 | 
					  - Add a user with: htpasswd -c links.auth username.
 | 
				
			||||||
 | 
					  - Copy the .htaccess-dist file to .htaccess, then edit the full path to this links.auth file.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										6
									
								
								ajax/.htaccess-dist
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								ajax/.htaccess-dist
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,6 @@
 | 
				
			||||||
 | 
					AuthType Basic
 | 
				
			||||||
 | 
					AuthName "Links"
 | 
				
			||||||
 | 
					AuthUserFile /full/path/to/this/links.auth
 | 
				
			||||||
 | 
					Require valid-user
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					RedirectMatch 404 links.auth
 | 
				
			||||||
							
								
								
									
										9
									
								
								ajax/index.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								ajax/index.php
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,9 @@
 | 
				
			||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					require '../header.php';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$parent = dirname($_SERVER['SCRIPT_URL'], 1);
 | 
				
			||||||
 | 
					if ( isset($_SERVER['REMOTE_USER']) ) $_SESSION['validated'] = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					header("Location: {$parent}");
 | 
				
			||||||
 | 
					exit();
 | 
				
			||||||
| 
						 | 
					@ -19,7 +19,7 @@ $description = $_REQUEST['description'];
 | 
				
			||||||
$link = new WebLink($id);
 | 
					$link = new WebLink($id);
 | 
				
			||||||
if ( $link->setURL($url) === false ) {
 | 
					if ( $link->setURL($url) === false ) {
 | 
				
			||||||
   $data['success'] = false;
 | 
					   $data['success'] = false;
 | 
				
			||||||
   $data['message'] = "Invalid URL! URL cannot be left blank.";
 | 
					   $data['message'] = "Invalid URL! URL cannot be left blank and must be well formed.";
 | 
				
			||||||
   pushData();
 | 
					   pushData();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
if ( $link->setTitle($title) === false ) {
 | 
					if ( $link->setTitle($title) === false ) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -56,6 +56,7 @@ class WebLink {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   public function setURL($value) {
 | 
					   public function setURL($value) {
 | 
				
			||||||
      if ( is_null($value) || ($value == "") ) return false;
 | 
					      if ( is_null($value) || ($value == "") ) return false;
 | 
				
			||||||
 | 
					      if ( !filter_var($value, FILTER_VALIDATE_URL) ) return false;
 | 
				
			||||||
      $this->url = $value;
 | 
					      $this->url = $value;
 | 
				
			||||||
      return true;
 | 
					      return true;
 | 
				
			||||||
   }
 | 
					   }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -16,6 +16,7 @@ foreach ( $links as $link ) {
 | 
				
			||||||
   $row['description_safe'] = $link->getDescription(HTMLSAFE);
 | 
					   $row['description_safe'] = $link->getDescription(HTMLSAFE);
 | 
				
			||||||
   $data['links'][] = $row;
 | 
					   $data['links'][] = $row;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					$data['canedit'] = $_SESSION['validated'];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pushData($data);
 | 
					pushData($data);
 | 
				
			||||||
exit();
 | 
					exit();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -35,7 +35,7 @@ echo $extrasheets;
 | 
				
			||||||
    <img class='navbar-logo' src='images/logo.png' onerror="this.style.display='none'" /><a href='#!' class='brand-logo'><?php echo PAGETITLE; ?></a>
 | 
					    <img class='navbar-logo' src='images/logo.png' onerror="this.style.display='none'" /><a href='#!' class='brand-logo'><?php echo PAGETITLE; ?></a>
 | 
				
			||||||
    <a href='#' data-target='mobile-menu' class='sidenav-trigger'><i class='material-icons'>menu</i></a>
 | 
					    <a href='#' data-target='mobile-menu' class='sidenav-trigger'><i class='material-icons'>menu</i></a>
 | 
				
			||||||
    <ul class='right hide-on-med-and-down'>
 | 
					    <ul class='right hide-on-med-and-down'>
 | 
				
			||||||
      <li><a href='#!' onClick='openNewLinkModal()'>Add A Link</a></li>
 | 
					      <?php if ( !$_SESSION['validated'] ) { ?><li><a href='ajax/index.php'>Log In</a></li><?php } ?>
 | 
				
			||||||
    </ul>
 | 
					    </ul>
 | 
				
			||||||
  </div>
 | 
					  </div>
 | 
				
			||||||
</nav>
 | 
					</nav>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -6,7 +6,9 @@ includeHTMLHeader("Link Manager");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
?>
 | 
					?>
 | 
				
			||||||
<h3 class='center-align'>Links</h3>
 | 
					<h3 class='center-align'>Links</h3>
 | 
				
			||||||
 | 
					<?php if ( $_SESSION['validated'] ) { ?>
 | 
				
			||||||
<div class='row center-align'><a href='#!' class='tooltipped' data-position='bottom' data-tooltip='Register a new link' onClick='openEditLinkModal()'>Add A New Link</a></div>
 | 
					<div class='row center-align'><a href='#!' class='tooltipped' data-position='bottom' data-tooltip='Register a new link' onClick='openEditLinkModal()'>Add A New Link</a></div>
 | 
				
			||||||
 | 
					<?php } ?>
 | 
				
			||||||
<table class='bordered striped highlight'>
 | 
					<table class='bordered striped highlight'>
 | 
				
			||||||
  <thead>
 | 
					  <thead>
 | 
				
			||||||
    <tr>
 | 
					    <tr>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -49,7 +49,7 @@ function toast(message, delay, classname) {
 | 
				
			||||||
function openEditLinkModal(id = 0) {
 | 
					function openEditLinkModal(id = 0) {
 | 
				
			||||||
    var instance = M.Modal.getInstance($('#editlink_modal'));
 | 
					    var instance = M.Modal.getInstance($('#editlink_modal'));
 | 
				
			||||||
    $.ajax({
 | 
					    $.ajax({
 | 
				
			||||||
        url: 'getlinks/getlinkdata.php',
 | 
					        url: 'ajax/getlinkdata.php',
 | 
				
			||||||
        dataType: 'json',
 | 
					        dataType: 'json',
 | 
				
			||||||
        data: {id: id},
 | 
					        data: {id: id},
 | 
				
			||||||
        success: function(data, stat, jqo) {
 | 
					        success: function(data, stat, jqo) {
 | 
				
			||||||
| 
						 | 
					@ -75,13 +75,15 @@ function openEditLinkModal(id = 0) {
 | 
				
			||||||
function updateLinkList() {
 | 
					function updateLinkList() {
 | 
				
			||||||
    $.ajax({
 | 
					    $.ajax({
 | 
				
			||||||
        type: 'GET',
 | 
					        type: 'GET',
 | 
				
			||||||
        url: 'ajax/getlinks.php',
 | 
					        url: 'getlinks/index.php',
 | 
				
			||||||
        dateType: 'json',
 | 
					        dateType: 'json',
 | 
				
			||||||
        success: function(data, stat, jqo) {
 | 
					        success: function(data, stat, jqo) {
 | 
				
			||||||
            var tabledata = "";
 | 
					            var tabledata = "";
 | 
				
			||||||
            for (var i=0; i<data.links.length; i++) {
 | 
					            for (var i=0; i<data.links.length; i++) {
 | 
				
			||||||
                var link = data.links[i];
 | 
					                var link = data.links[i];
 | 
				
			||||||
                tabledata += "<tr class='clickable' onClick='openEditLinkModal(" + link.id + ")'>";
 | 
					                tabledata += "<tr";
 | 
				
			||||||
 | 
					                if ( data.canedit ) tabledata += " class='clickable' onClick='openEditLinkModal(" + link.id + ")'";
 | 
				
			||||||
 | 
					                tabledata += ">";
 | 
				
			||||||
                tabledata += "<td>" + link.url_safe + "</td>";
 | 
					                tabledata += "<td>" + link.url_safe + "</td>";
 | 
				
			||||||
                tabledata += "<td>" + link.title_safe + "</td>";
 | 
					                tabledata += "<td>" + link.title_safe + "</td>";
 | 
				
			||||||
                tabledata += "<td>" + link.description_safe + "</td>";
 | 
					                tabledata += "<td>" + link.description_safe + "</td>";
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -6,3 +6,4 @@ if ( php_sapi_name() == "cli" ) exit();
 | 
				
			||||||
session_name(SESSNAME);
 | 
					session_name(SESSNAME);
 | 
				
			||||||
session_start();
 | 
					session_start();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if ( !isset($_SESSION['validated']) ) $_SESSION['validated'] = false;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user