lots more web stuff sorta working

This commit is contained in:
CodePoet80 committed 2021-05-06 09:35:29 -04:00
1 parent e95266b21d
commit 21d589bf64
12 files changed
+179 -47

No files matched your search

+17 -5
View File
@@ -66,10 +66,14 @@ function get_authorization($errorhandler = gracefuldeath_json) {
);
}
function get_share_data($file, $sharephrase, $errorhandler = gracefuldeath_json) {
function get_share_data($username, $credential, $errorhandler = gracefuldeath_json) {
global $config;
if (!file_exists($file))
$file = "data/" . strtolower($username) . "/sharelog.json";
if (!file_exists($file)) {
$errorhandler("share service or user name not found or data file could not be opened.");
return;
}
try {
$sharedata = file_get_contents($file);
@@ -77,12 +81,16 @@ function get_share_data($file, $sharephrase, $errorhandler = gracefuldeath_json)
}
catch (exception $e) {
$errorhandler("sharedata content could not be loaded");
return;
}
//Make sure the file belongs to the requesting user
$checkphrase = strtolower($jsondata['sharephrase']);
if ($sharephrase != $checkphrase && $sharephrase != $config['readonlykey'])
$errorhandler("not authorized: sharephrase does not match");
$checkphrase = $jsondata['sharephrase'];
$adminpass = $jsondata['password'];
if ($credential != $checkphrase && base64_encode($credential) != $adminpass && $credential != $config['readonlykey']) {
$errorhandler("not authorized: credentials do not match any known key");
return;
}
return $jsondata;
}
@@ -168,4 +176,8 @@ function gracefuldeath_json($message) {
die ("{\"error\":\"". $message ."\"}");
}
function gracefuldeath_html($error) {
echo "ERROR: " . $error;
}
?>
+12 -12
View File
@@ -8,11 +8,11 @@ function create_new_user($username, $sharephrase, $password, $errorhandler = def
if (preg_match('/[^a-z]/', $username))
{
$errorhandler("username not valid: must be one word, alphabetic characters only");
return null;
return;
}
if (in_array($username, $disallowed)) {
$errorhandler("username not valid: must not be OS reserved word");
return null;
return;
}
//check for valid sharephrase
@@ -20,7 +20,7 @@ function create_new_user($username, $sharephrase, $password, $errorhandler = def
if (preg_match('/[^a-z ]/', $sharephrase))
{
$errorhandler("sharephrase not valid: use combinations provided by service");
return null;
return;
}
//check for valid password
@@ -28,7 +28,7 @@ function create_new_user($username, $sharephrase, $password, $errorhandler = def
if (preg_match('/[^A-Za-z0-9 ]/', $password))
{
$errorhandler("password not valid: use only letters, numbers and spaces");
return null;
return;
} else {
$password = base64_encode($password);
}
@@ -36,13 +36,13 @@ function create_new_user($username, $sharephrase, $password, $errorhandler = def
//re-run the username uniqueness check
if (file_exists("data/" . $username)) {
$errorhandler("user or service name already in use");
return null;
return;
}
//try create the folder
if (!is_dir("data")){
$errorhandler("data folder could not be found on server");
return null;
return;
} else {
try {
mkdir("data/" . $username);
@@ -50,7 +50,7 @@ function create_new_user($username, $sharephrase, $password, $errorhandler = def
catch (exception $e)
{
$errorhandler("could not create user storage: check permissions on server.");
return null;
return;
}
}
@@ -72,14 +72,14 @@ function create_new_user($username, $sharephrase, $password, $errorhandler = def
catch (exception $e)
{
$errorhandler("could not create sharelog in user storage: check for valid template and permissions on server");
return null;
return;
}
return "{\"success\":\"new user created!\"}";
} else {
$errorhandler("post data payload incomplete, missing username, sharephrase or password");
return null;
return;
}
return null;
return;
}
function add_share_data($newsharedata, $oldsharedata, $sharephrase, $contenttype, $newid, $errorhandler = default_error_handler){
@@ -87,11 +87,11 @@ function add_share_data($newsharedata, $oldsharedata, $sharephrase, $contenttype
if (!isset($newsharedata) || !isset($oldsharedata) || !isset($sharephrase) || !isset($contenttype) || !isset($newid)) {
$errorhandler("functional call missing required parameters!");
return null;
return;
}
if ($oldsharedata['sharephrase'] != $sharephrase || $sharephrase == $config['readonlykey']) {
$errorhandler("not authorized: sharephrase not valid or read-only");
return null;
return;
}
$updatedsharedata = $oldsharedata;
+1 -2
View File
@@ -6,8 +6,7 @@ header('Content-Type: application/json');
$auth = get_authorization();
//Make sure the file exists and can be loaded
$file = "data/" . ($auth['username'] . "/sharelog.json");
$jsondata = get_share_data($file, $auth['sharephrase'], gracefuldeath_json);
$jsondata = get_share_data($auth['username'], $auth['sharephrase'], gracefuldeath_json);
//Load and return only the task list
$sharedata = convert_shares_to_public_schema($jsondata);
Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

+6 -5
View File
@@ -1,5 +1,5 @@
<?php
//setcookie("grandmaster", "", time() - 3600);
setcookie("credential", "", time() - 3600, "/");
include("common.php");
?>
@@ -12,8 +12,9 @@
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=1" />
<meta http-equiv="pragma" content="no-cache">
</head>
<body class="login">
<table width="100%" height="100%" border="0" id="tableLayout">
<body class="login" style="margin: 0px;">
<div class="login-header"><a href="web-login.php">Login</a>&nbsp;</div>
<table width="100%" height="95%" border="0" id="tableLayout">
<tr>
<td width="100%" height="100%" border="0" id="tdLayout" align="center">
<table width="800" height="400" border="1" class="tableBorder">
@@ -23,7 +24,7 @@
<tr>
<td colspan="3" align="center">
<img src="images/icon-128.png" style="margin-top:8px;" id="imgIcon"/><br/>
<b>Share with someone else</b><br/>
<b>Share something new</b><br/>
&nbsp;
</td>
</tr>
@@ -35,7 +36,7 @@
<td colspan="3" align="center">
<a href="web-agreement.php">
<img src="images/icon-128.png" style="margin-top:8px;" id="imgIcon"/><br/>
<b>Create your own Share space</b><br/>
<b>Create a Share space</b><br/>
</a>
&nbsp;
</td>
+2 -4
View File
@@ -13,8 +13,7 @@ if (!isset($postraw) || $postraw == "")
$postdata = json_decode($postraw);
//Make sure the file exists and can be loaded
$file = "data/" . ($auth['username'] . "/sharelog.json");
$jsondata = get_share_data($file, $auth['sharephrase'], gracefuldeath_json);
$jsondata = get_share_data($auth['username'], $auth['sharephrase'], gracefuldeath_json);
//Make sure this share content is valid and allowed
$allowedtype = $jsondata['sharetype'];
@@ -49,9 +48,8 @@ if (isset($request_headers["content-type"]) && $request_headers["content-type"]
}
//Make sure the file exists and can be loaded
$file = "data/" . ($auth['username'] . "/sharelog.json");
$newid = uniqid();
$sharedata = get_share_data($file, $auth['sharephrase'], gracefuldeath_json);
$sharedata = get_share_data($auth['username'], $auth['sharephrase'], gracefuldeath_json);
$updatedsharedata = add_share_data($postdata, $sharedata, $auth['sharephrase'], $reqtype, $newid, gracefuldeath_json);
$written = file_put_contents($file, json_encode($updatedsharedata, JSON_PRETTY_PRINT));
+12
View File
@@ -50,6 +50,18 @@ input[type="checkbox"] {
background-color: white;
}
.login-header {
background-color:black; color:white; width:100%; text-align:right
}
.login-header a {
color: white;
}
.login-header a:hover {
color: white; font-style: italic;
}
a {
color: black;
text-decoration: none;
+1 -2
View File
@@ -17,8 +17,7 @@ if (count($shareparts) > 1) {
}
//Make sure the file exists and can be loaded
$file = "data/" . ($username . "/sharelog.json");
$jsondata = get_share_data($file, $config['readonlykey'], graceful_death);
$jsondata = get_share_data($username, $config['readonlykey'], graceful_death);
foreach ($jsondata['shares'] as $share => $value) {
//print_r($value);
if ($contentid == $value['guid'])
+1 -2
View File
@@ -1,7 +1,6 @@
<?php
//setcookie("grandmaster", "", time() - 3600);
setcookie("credential", "", time() - 3600, "/");
include("common.php");
?>
<html>
+43 -5
View File
@@ -1,7 +1,45 @@
<?php
if (!isset($_GET["username"]) || !isset($_COOKIE["credential"])) {
header('Location: web-login.php?username=' . $_GET["username"]);
} else {
//echo "Welcome to your share space!<br>";
//echo $_GET["username"] . "<br>";
//echo $_COOKIE["credential"] . "<br>";
}
include("common.php");
//Make sure the file exists and can be loaded
$jsondata = get_share_data($_GET["username"], $_COOKIE["credential"], gracefuldeath_html);
//Load and return only the task list
$sharedata = convert_shares_to_public_schema($jsondata);
?>
<html>
<head>
<title>webOS Share</title>
<link rel="shortcut icon" href="favicon.ico">
<link rel="stylesheet" href="style.css">
<link rel="icon" href="images/icon.png" type="image/png">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=1" />
<meta http-equiv="pragma" content="no-cache">
</head>
<body style="margin: 0px;">
<div class="login-header"><a href="index.php">Log Out</a>&nbsp;</div>
<div style="margin: 10px;">
<h1><img src="images/icon-128.png" style="height:64px;width:64px; vertical-align:middle">&nbsp; <?php echo $_GET["username"] ?> Share Space</h2>
<ul>
<?php
echo "Welcome to your share space!<br>";
echo $_GET["username"] . "<br>";
echo $_COOKIE["sharephrase"] . "<br>";
echo $_COOKIE["password"] . "<br>";
?>
foreach($sharedata->shares as $thisshare)
{
echo "<li>";
print_r(json_encode($thisshare));
echo "<br>&nbsp;<br></li>";
}
?>
</ul>
</div>
</body>
</html>
+76
View File
@@ -0,0 +1,76 @@
<?php
setcookie("credential", "", time() - 3600, "/");
include("common.php");
include("functions.php");
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
if (isset($_POST["txtUserName"]) && isset($_POST["txtCredential"]))
{
$login_result = @get_share_data($_POST["txtUserName"], $_POST["txtCredential"], gracefuldeath_html);
if (isset($login_result)) {
setcookie("credential", $_POST["txtCredential"], time() + (3600), "/");
header('Location: web-get-shares.php?username=' . $_POST["txtUserName"]);
}
}
$lastUsername = $_POST["txtUserName"];
if (isset($_GET["username"]))
$lastUsername = $_GET["username"];
?>
<html>
<head>
<title>webOS Share</title>
<link rel="shortcut icon" href="favicon.ico">
<link rel="stylesheet" href="style.css">
<link rel="icon" href="images/icon.png" type="image/png">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=1" />
<meta http-equiv="pragma" content="no-cache">
<script>
function swapTech() {
document.getElementById("imgTogglePass").style.display = "inline";
}
function togglePassword(){
var passBox = document.getElementById("txtCredential");
if(passBox.type == "text")
passBox.type = "password";
else
passBox.type = "text";
}
</script>
</head>
<body class="login" onload="swapTech()">
<table width="100%" height="100%" border="0" id="tableLayout">
<tr>
<td width="100%" height="100%" border="0" id="tdLayout" align="center">
<table width="800" height="400" border="1" class="tableBorder">
<tr>
<td>
<table width="100%" height="100%" bgcolor="white" border="0" class="tableOption">
<tr>
<td colspan="3" align="center">
<p><img src="images/icon-128.png" style="height: 64px; width: 64px; margin-top:8px; vertical-align:middle;" id="imgIcon"/>
&nbsp;<b>Log in to a Share Space</b></p>
<p class="explainer">Enter the credentials for this Share space.<br>For read-only access, use the Share phrase, to make changes, use the Admin password.</p>
<form method="POST">
<table style="margin: 18px;">
<tr><td>User Name: </td><td><input type="text" name="txtUserName" id="txtUserName" value="<?php echo $lastUsername ?>"></td></tr>
<tr><td>Password: </td><td><input type="password" id="txtCredential" name="txtCredential">&nbsp;<img src="images/eyeball.png" id="imgTogglePass" style="display:none;height:20px;width:20px; vertical-align:middle" onclick="togglePassword()"></td></tr>
</table>
<input type="submit" value="Let's Go!"><br/><br/><small><a href="index.php">Cancel</a></small>
</form>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
+8 -10
View File
@@ -1,5 +1,4 @@
<?php
//setcookie("grandmaster", "", time() - 3600);
include("common.php");
include("functions.php");
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
@@ -8,17 +7,12 @@
if (isset($_POST["txtUserName"]) && isset($_POST["txtSharephrase"]) && isset($_POST["txtPassword"]))
{
$create_result = @create_new_user($_POST["txtUserName"], $_POST["txtUserName"], $_POST["txtUserName"], gracefuldeath_html);
$create_result = @create_new_user($_POST["txtUserName"], $_POST["txtSharephrase"], $_POST["txtPassword"], gracefuldeath_html);
if (isset($create_result)) {
setcookie("sharephrase", $_POST["txtSharephrase"], time() + (3600), "/");
setcookie("password", $_POST["txtPassword"], time() + (3600), "/");
setcookie("credential", $_POST["txtPassword"], time() + (3600), "/");
header('Location: web-get-shares.php?username=' . $_POST["txtUserName"]);
}
}
function gracefuldeath_html($error) {
echo "ERROR: " . $error;
}
?>
<html>
@@ -31,6 +25,10 @@
<meta http-equiv="pragma" content="no-cache">
<script>
function swapTech() {
document.getElementById("imgNewWords").style.display = "inline";
}
function getNewWords() {
if (typeof XMLHttpRequest === "function") {
var xhr = new XMLHttpRequest();
@@ -66,10 +64,10 @@
<form method="POST">
<table style="margin: 18px;">
<tr><td>User Name: </td><td><input type="text" name="txtUserName" id="txtUserName"></td></tr>
<tr><td>Share Phrase: </td><td><input type="text" id="txtSharephrase" name="txtSharephrase" value="<?php include("random-words.php"); ?>">&nbsp;<img src="images/refresh.png" style="height:20px;width:20px; vertical-align:middle" onclick="getNewWords()"></td></tr>
<tr><td>Share Phrase: </td><td><input type="text" id="txtSharephrase" name="txtSharephrase" value="<?php include("random-words.php"); ?>">&nbsp;<img src="images/refresh.png" id="imgNewWords" style="display:none; height:20px;width:20px; vertical-align:middle" onclick="getNewWords()"></td></tr>
<tr><td>Admin Password: </td><td><input type="text" id="txtPassword" name="txtPassword"></td></tr>
</table>
<input type="submit" value="Let's Go!">
<input type="submit" value="Let's Go!"><br/><br/><small><a href="index.php">Cancel</a></small>
</form>
</td>
</tr>