start adding web ui functions

This commit is contained in:
CodePoet80 committed 2021-05-05 21:18:55 -04:00
1 parent a7fc9d908d
commit e95266b21d
13 files changed
+232 -317

No files matched your search

-157
View File
@@ -1,157 +0,0 @@
<?php
setcookie("grandmaster", "", time() - 3600);
include("common.php");
include("web-functions.php");
?>
<html>
<head>
<title>Check Mate - Your To Do List Anywhere</title>
<link rel="shortcut icon" href="favicon.ico">
<link rel="stylesheet" href="style.css">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=1" />
<link rel="icon" href="icon.png" type="image/png">
<style>
small { font-size: 13px; }
</style>
<script>
function swapTech() {
document.getElementById("imgIcon").src = "images/icon.png";
if (document.getElementById("divDisagree")) {
document.getElementById("divDisagree").innerHTML = "<input class=\"button\" type=\"button\" id=\"btnDisagree\" value=\"Disagree\" onclick=\"document.location='index.php'\"/>"
}
if (document.getElementById("divLogin")) {
document.getElementById("divLogin").innerHTML = "<input class=\"button\" type=\"button\" id=\"btnLogin\" value=\"Log-in\" onclick=\"document.location='index.php'\"/>"
}
}
</script>
<?php
function getUserIP()
{
// Get real visitor IP behind CloudFlare network
if (isset($_SERVER["HTTP_CF_CONNECTING_IP"])) {
$_SERVER['REMOTE_ADDR'] = $_SERVER["HTTP_CF_CONNECTING_IP"];
$_SERVER['HTTP_CLIENT_IP'] = $_SERVER["HTTP_CF_CONNECTING_IP"];
}
$client = @$_SERVER['HTTP_CLIENT_IP'];
$forward = @$_SERVER['HTTP_X_FORWARDED_FOR'];
$remote = $_SERVER['REMOTE_ADDR'];
if(filter_var($client, FILTER_VALIDATE_IP))
{
$ip = $client;
}
elseif(filter_var($forward, FILTER_VALIDATE_IP))
{
$ip = $forward;
}
else
{
$ip = $remote;
}
return $ip;
}
if (isset($_POST["agreedBy"]))
{
$readURL = get_function_endpoint("new-user");
$json = file_get_contents($readURL);
if (strpos(strtolower($json), "{\"error\":\"failed to write to file\"}")) {
$debugMsg .= "The notation file could not be written.<br>";
$debugMsg .= "Administrator: ensure your notations folder and all contents are writeable by the web server user.";
echo $debugMsg;
} else {
$data = json_decode($json);
}
}
?>
</head>
<body background='images/chessboard.jpg' 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">
<form method="POST">
<table width="600" height="300" border="1" class="tableBorder">
<tr>
<td>
<table width="100%" height="100%" bgcolor="lightgray" border="0" class="tableLogin" cellpadding="5">
<tr>
<td colspan="4" align="center">
<img src="images/icon.gif" style="margin-top:8px;" id="imgIcon"/><br/>
<b>Check Mate - User Agreement</b><br/>
&nbsp;
</td>
</tr>
<tr>
<td width="20">&nbsp;</td>
<td colspan="2">
Checkmate is free to use, and free to host. If you want to host it yourself, visit the <a href="https://github.com/codepoet80/checkmate-service">GitHub repo</a> for more information.<br>
If you want to use this version, there are a few things you need to agree to...
<small>
<?php
echo file_get_contents("tandc.html");
?>
</small>
</td>
<td width="20">&nbsp;</td>
</tr>
<?php
if (isset($debugMsg)) {
echo "<tr><td colspan='4' align='center' bgcolor='pink' border='1'><b>Error: " . $debugMsg . "</b></td></tr>";
}
if (isset($_POST["agreedBy"]) && isset($data) && isset($data->move) && isset($data->grandmaster)) {
//Never do PHP + HTML like this. Very spaghetti.
?>
<tr>
<td width="20">&nbsp;</td>
<td colspan="2">
Record this information; you will use it to log-in to your To Do list. It is not case sensitive. It cannot be changed, and you should not share it publicly.
</td>
<td width="20">&nbsp;</td>
</tr>
<tr>
<td width="20">&nbsp;<input type="hidden" name="agreedBy" value="<?php echo getUserIP() ?>"/></td>
<td align="left" valign="bottom"><b>Your Chess Move:</b><br> <?php echo $data->move ?></td>
<td align="left" valign="bottom"><b>Your Grand Master:</b><br> <?php echo $data->grandmaster ?></td>
<td width="20">&nbsp;</td>
</tr>
<tr>
<td width="20">&nbsp;</td>
<td colspan="2" align="center">
<div id="divLogin"><a href="index.php">Log-In</a></div>
</td>
<td width="20">&nbsp;</td>
</tr>
<?php
}
else {
?>
<tr>
<td colspan="4" align="center">
Click the appropriate button below to indicate your response to these terms.
</td>
</tr>
<tr>
<td width="20">&nbsp;<input type="hidden" name="agreedBy" value="<?php echo getUserIP() ?>"/></td>
<td align="left" valign="bottom"><div id="divDisagree"><a href="index.php">Disagree</a></div></td>
<td align="right" valign="bottom"><input class="button" type="submit" id="btnSubmit" value="Agree"/><img src="images/spacer.gif" width="20"></td>
<td width="20">&nbsp;</td>
</tr>
<?php
}
?>
<tr>
<td colspan="4"></td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</body>
</html>
-15
View File
@@ -1,15 +0,0 @@
var checkmate = {
//globals
}
checkmate.detectXHR = function() {
if (typeof new XMLHttpRequest().responseType === 'string') {
try {
var xhr = new XMLHttpRequest();
return true;
} catch (ex) {
return false;
}
}
return false;
}
-38
View File
@@ -1,38 +0,0 @@
<?php
include("common.php");
$auth = get_authorization();
//Make sure the file exists and can be loaded
$file = get_filename_from_move($auth['move']);
$jsondata = get_notation_data($file, $auth['grandmaster']);
//Write changes to file
$updatedtaskdata = remove_completed_tasks($jsondata);
$written = file_put_contents($file, json_encode($updatedtaskdata, JSON_PRETTY_PRINT));
//Output the results
header('Content-Type: application/json');
if (!$written) {
echo "{\"error\":\"failed to write to file\"}";
} else {
$movedata = convert_move_to_public_schema($updatedtaskdata);
print_r (json_encode($movedata));
}
exit();
//Update an existing task with new data
function remove_completed_tasks($oldtaskdata){
$updatedtasks = array();
$existingtasks = $oldtaskdata['moves'];
foreach ($existingtasks as $existingtask)
{
if ($existingtask['completed'] != true)
{
array_push($updatedtasks, $existingtask);
}
}
$oldtaskdata['moves'] = $updatedtasks;
return $oldtaskdata;
}
?>
+16
View File
@@ -230,6 +230,22 @@
"publishTime": "2021-05-03T03:11:19Z"
}
}
},
{
"guid": "6093430b98a3a",
"contenttype": "application\/json",
"content": {
"youtubeId": "XegHMc35Bo8",
"videoName": "Gera MX, Christian Nodal - Botella Tras Botella (Video Oficial)",
"videoDetails": "2021-04-23 - 3:27 (HD)",
"selectedState": true,
"detailClass": "touchpad",
"imageWidth": "178px",
"imgPos": "8px 2px !important",
"titleMargin": "182px",
"topMargin": "4px",
"thumbnail": "https:\/\/i.ytimg.com\/vi\/XegHMc35Bo8\/mqdefault.jpg"
}
}
]
}
+111
View File
@@ -0,0 +1,111 @@
<?php
function create_new_user($username, $sharephrase, $password, $errorhandler = default_error_handler) {
if (isset($username) && $username != "" && isset($sharephrase) && $sharephrase != "" && isset($password) && $password != "") {
//check for valid username
$disallowed = array("con", "prn", "aux", "nul", "com", "do", "done", "elif", "else", "esac", "fi", "for", "function", "if", "in", "select", "then", "until", "while", "time");
$username = strtolower($username);
if (preg_match('/[^a-z]/', $username))
{
$errorhandler("username not valid: must be one word, alphabetic characters only");
return null;
}
if (in_array($username, $disallowed)) {
$errorhandler("username not valid: must not be OS reserved word");
return null;
}
//check for valid sharephrase
$sharephrase = strtolower($sharephrase);
if (preg_match('/[^a-z ]/', $sharephrase))
{
$errorhandler("sharephrase not valid: use combinations provided by service");
return null;
}
//check for valid password
$password = strtolower($password);
if (preg_match('/[^A-Za-z0-9 ]/', $password))
{
$errorhandler("password not valid: use only letters, numbers and spaces");
return null;
} else {
$password = base64_encode($password);
}
//re-run the username uniqueness check
if (file_exists("data/" . $username)) {
$errorhandler("user or service name already in use");
return null;
}
//try create the folder
if (!is_dir("data")){
$errorhandler("data folder could not be found on server");
return null;
} else {
try {
mkdir("data/" . $username);
}
catch (exception $e)
{
$errorhandler("could not create user storage: check permissions on server.");
return null;
}
}
//try create the data file
try {
//Load the template, populate this user's values, and save as a new file
$newfile = "data/" . $username . "/sharelog.json";
$templatefile = file_get_contents("sharelog-template.json");
$templatedata = json_decode($templatefile);
$templatedata->sharephrase = $sharephrase;
$templatedata->password = $password;
if (isset($sharetype)) {
$req_sharetype = strtolower($sharetype);
if (in_array($req_sharetype, $supported_content_types))
$templatedata->sharetype = $sharetype;
}
$written = file_put_contents($newfile, json_encode($templatedata, JSON_PRETTY_PRINT));
}
catch (exception $e)
{
$errorhandler("could not create sharelog in user storage: check for valid template and permissions on server");
return null;
}
return "{\"success\":\"new user created!\"}";
} else {
$errorhandler("post data payload incomplete, missing username, sharephrase or password");
return null;
}
return null;
}
function add_share_data($newsharedata, $oldsharedata, $sharephrase, $contenttype, $newid, $errorhandler = default_error_handler){
global $config;
if (!isset($newsharedata) || !isset($oldsharedata) || !isset($sharephrase) || !isset($contenttype) || !isset($newid)) {
$errorhandler("functional call missing required parameters!");
return null;
}
if ($oldsharedata['sharephrase'] != $sharephrase || $sharephrase == $config['readonlykey']) {
$errorhandler("not authorized: sharephrase not valid or read-only");
return null;
}
$updatedsharedata = $oldsharedata;
$newshareentry = new stdClass();
$newshareentry->guid = $newid;
$newshareentry->contenttype = $contenttype;
$newshareentry->content = $newsharedata;
array_push($updatedsharedata['shares'], $newshareentry);
return $updatedsharedata;
}
function default_error_handler($error) {
die ($error);
}
?>
+1 -1
View File
@@ -33,7 +33,7 @@
<table width="400" height="100%" bgcolor="white" border="0" class="tableOption">
<tr>
<td colspan="3" align="center">
<a href="web-new-user.php">
<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/>
</a>
+2 -69
View File
@@ -1,6 +1,6 @@
<?php
include("common.php");
include("functions.php");
header('Content-Type: application/json');
//Make sure they sent a client id
@@ -21,74 +21,7 @@ catch (Exception $e) {
}
if (isset($postdata->username) && $postdata->username != "" && isset($postdata->sharephrase) && $postdata->sharephrase != "" && isset($postdata->password) && $postdata->password != "") {
//check for valid username
$disallowed = array("con", "prn", "aux", "nul", "com", "do", "done", "elif", "else", "esac", "fi", "for", "function", "if", "in", "select", "then", "until", "while", "time");
$username = strtolower($postdata->username);
if (preg_match('/[^a-z]/', $username))
{
gracefuldeath_json("username not valid: must be one word, alphabetic characters only");
}
if (in_array($username, $disallowed)) {
gracefuldeath_json("username not valid: must not be OS reserved word");
}
//check for valid sharephrase
$sharephrase = strtolower($postdata->sharephrase);
if (preg_match('/[^a-z ]/', $sharephrase))
{
gracefuldeath_json("sharephrase not valid: use combinations provided by service");
}
//check for valid password
$password = strtolower($postdata->password);
if (preg_match('/[^A-Za-z0-9 ]/', $password))
{
gracefuldeath_json("password not valid: use only letters, numbers and spaces");
} else {
$password = base64_encode($password);
}
//re-run the username uniqueness check
if (file_exists("data/" . $username)) {
gracefuldeath_json("user or service name already in use");
}
//try create the folder
if (!is_dir("data")){
gracefuldeath_json("data folder could not be found on server");
} else {
try {
mkdir("data/" . $username);
}
catch (exception $e)
{
gracefuldeath_json("could not create user storage: check permissions on server.");
}
}
//try create the data file
try {
//Load the template, populate this user's values, and save as a new file
$newfile = "data/" . $username . "/sharelog.json";
$templatefile = file_get_contents("sharelog-template.json");
$templatedata = json_decode($templatefile);
$templatedata->sharephrase = $sharephrase;
$templatedata->password = $password;
if (isset($postdata->sharetype)) {
$req_sharetype = strtolower($postdata->sharetype);
if (in_array($req_sharetype, $supported_content_types))
$templatedata->sharetype = $postdata->sharetype;
}
$written = file_put_contents($newfile, json_encode($templatedata, JSON_PRETTY_PRINT));
}
catch (exception $e)
{
gracefuldeath_json("could not create sharelog in user storage: check for valid template and permissions on server");
}
echo "{\"success\":\"new user created!\"}";
echo(create_new_user($postdata->username, $postdata->sharephrase, $postdata->password, gracefuldeath_json));
} else {
gracefuldeath_json("post data payload incomplete, missing username, sharephrase or password");
}
+1
View File
@@ -1,4 +1,5 @@
<?php
$rand_text = trim(get_random_word("adjectives"));
$rand_text = $rand_text . " " . trim(get_random_word("nouns"));
+2 -17
View File
@@ -1,5 +1,6 @@
<?php
include("common.php");
include("functions.php");
header('Content-Type: application/json');
@@ -52,7 +53,7 @@ $file = "data/" . ($auth['username'] . "/sharelog.json");
$newid = uniqid();
$sharedata = get_share_data($file, $auth['sharephrase'], gracefuldeath_json);
$updatedsharedata = add_share_data($postdata, $sharedata, $auth['sharephrase'], $reqtype, $newid);
$updatedsharedata = add_share_data($postdata, $sharedata, $auth['sharephrase'], $reqtype, $newid, gracefuldeath_json);
$written = file_put_contents($file, json_encode($updatedsharedata, JSON_PRETTY_PRINT));
//Output the results
@@ -63,20 +64,4 @@ if (!$written) {
}
exit();
function add_share_data($newsharedata, $oldsharedata, $sharephrase, $contenttype, $newid){
global $config;
if ($oldsharedata['sharephrase'] != $sharephrase || $sharephrase == $config['readonlykey'])
gracefuldeath_json("not authorized: sharephrase not valid or read-only");
$updatedsharedata = $oldsharedata;
$newshareentry = new stdClass();
$newshareentry->guid = $newid;
$newshareentry->contenttype = $contenttype;
$newshareentry->content = $newsharedata;
array_push($updatedsharedata['shares'], $newshareentry);
return $updatedsharedata;
}
?>
+1 -1
View File
@@ -27,7 +27,7 @@ h2 div span {
}
small {
font-size: x-small;
font-size: smaller;
}
input[type="checkbox"] {
+51
View File
@@ -0,0 +1,51 @@
<?php
//setcookie("grandmaster", "", time() - 3600);
include("common.php");
?>
<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>
</script>
</head>
<body class="login">
<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>Create your own Share Space</b></p>
This Sharing Service is free to use, and free to host. If you want to host it yourself, visit the <a href="https://github.com/codepoet80/sharing-service">GitHub repo</a> for more information. If you want to use this hosted version, there are a few things you need to agree to...
<div style="width: 80%; margin: 20px; text-align:left">
<small >
<?php
echo file_get_contents("tandc.html");
?>
</small>
</div>
<a href="web-new-user.php?agreed">I Agree</a> &nbsp;&nbsp; <a href="index.php">Disagree</a>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
+7
View File
@@ -0,0 +1,7 @@
<?php
echo "Welcome to your share space!<br>";
echo $_GET["username"] . "<br>";
echo $_COOKIE["sharephrase"] . "<br>";
echo $_COOKIE["password"] . "<br>";
?>
+40 -19
View File
@@ -1,7 +1,24 @@
<?php
//setcookie("grandmaster", "", 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["txtSharephrase"]) && isset($_POST["txtPassword"]))
{
$create_result = @create_new_user($_POST["txtUserName"], $_POST["txtUserName"], $_POST["txtUserName"], gracefuldeath_html);
if (isset($create_result)) {
setcookie("sharephrase", $_POST["txtSharephrase"], time() + (3600), "/");
setcookie("password", $_POST["txtPassword"], time() + (3600), "/");
header('Location: web-get-shares.php?username=' . $_POST["txtUserName"]);
}
}
function gracefuldeath_html($error) {
echo "ERROR: " . $error;
}
?>
<html>
@@ -15,23 +32,25 @@
<script>
function getNewWords() {
//var data = null;
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function () {
if (this.readyState === 4) {
document.getElementById("txtRandomWords").value = this.responseText;
}
});
xhr.open("GET", "random-words.php");
xhr.send();
if (typeof XMLHttpRequest === "function") {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (this.readyState === 4) {
document.getElementById("txtSharephrase").value = this.responseText;
}
};
xhr.open("GET", "random-words.php");
xhr.send();
} else {
document.location.reload();
}
}
</script>
</head>
<body class="login">
<table width="100%" height="100%" border="0" id="tableLayout">
<tr>
<td width="100%" height="100%" border="0" id="tdLayout" align="center">
@@ -44,12 +63,14 @@
<p><img src="images/icon-128.png" style="height: 64px; width: 64px; margin-top:8px; vertical-align:middle;" id="imgIcon"/>
&nbsp;<b>Create your own Share Space</b></p>
<p class="explainer">A Share space let's people share content with you from the web, or webOS mobile devices. Your user name is public, and will be used to make public links to content. Your Share Phrase is something you give to only those who you want to get content from -- if you only want to share with yourself, that's OK: just keep the Share Phrase private! And finally, your admin password is super private -- you can use it to change your settings, or delete content.</p>
<table style="margin: 18px;">
<tr><td>User Name: </td><td><input type="text"></td></tr>
<tr><td>Share Phrase: </td><td><input type="text" disabled="true" id="txtRandomWords" 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>Admin Password: </td><td><input type="text"></td></tr>
</table>
<input type="button" value="Let's Go!">
<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>Admin Password: </td><td><input type="text" id="txtPassword" name="txtPassword"></td></tr>
</table>
<input type="submit" value="Let's Go!">
</form>
</td>
</tr>
</table>