Merging API clean up from develop

This commit is contained in:
Ro 2021-06-14 12:29:52 -07:00
commit 3d8c421f76
18 changed files with 221 additions and 17 deletions

10
.gitignore vendored
View file

@ -69,3 +69,13 @@ config.codekit3
/src/styles/main/_posts.sass
/src/styles/main/_settings.sass
/src/styles/main/_structure.sass
/src/com/Base.js
/src/com/actions/Mailer.js
/src/com/actions/NavActions.js
/src/com/actions/SettingsActions.js
/src/com/controllers/NavIndex.js
/src/com/controllers/PageEditor.js
/src/com/controllers/SettingsIndex.js
/src/com/ui/TextEditor.js
/src/libraries/FipamoAPI.js
/src/styles/main/_settings.sass

View file

@ -19,17 +19,20 @@ include "../brain/utility/Sorting.inc.php";
include "../brain/utility/Setup.inc.php";
include "../brain/utility/Maintenance.inc.php";
include "../brain/utility/Mailer.inc.php";
include "../brain/utility/HandleCors.inc.php";
class App
{
public function __construct()
{
// set up cors
new HandleCors();
$app = AppFactory::create();
$twig = Twig::create("../brain/views/");
$app->add(TwigMiddleware::create($app, $twig));
//set up routing
$app->get(
"/[{first}[/{second}[/{third}[/{fourth}]]]]",
"/[{first}[/{second}[/{third}[/{fourth}[/{fifth}]]]]]",
"\RouteControl:get"
);
$app->post(

View file

@ -1,4 +1,5 @@
<?php
use function _\filter;
class PagesAPI
{
@ -6,6 +7,37 @@ class PagesAPI
{
}
public static function getPageContent($request, $args)
{
$task = $args["fourth"];
$content = (new Book("../content/pages"))->getContents();
switch ($task) {
case "published":
//$pageNum = $args["fifth"]; not not needed but gonna keep remnant in case it becomes useful/needed
$published = filter($content, function ($item) {
return $item["published"] == true && $item["deleted"] == false;
});
$result = ["pages" => $published, "totalPages" => count($published)];
//$result = (new Book("../content/pages"))->getPages($pageNum, 4, $task);
break;
case "single":
$uuid = $args["fifth"];
$result = (new Book("../content/pages"))->findPageById($uuid);
break;
case "tags":
$result = Settings::getTags();
break;
default:
$result = [
"message" => "Hm, no task. That's unfortunate",
"type" => "TASK_NONE",
];
break;
}
return $result;
}
public static function handlePageTask($request, $args)
{
$task = $args["fourth"];

View file

@ -17,9 +17,22 @@ class APIControl
array $args
): ResponseInterface {
$filename = "";
switch (isset($args["third"]) ? $args["third"] : "none") {
case "status":
$result = AuthAPI::status();
break;
case "page":
//echo
if (Member::verifyKey($_GET["key"])) {
$result = PagesAPI::getPageContent($request, $args);
} else {
$result = [
"message" => "API access denied, homie",
"type" => "API_ERROR",
];
}
break;
case "files":
if (Session::active()) {

View file

@ -37,6 +37,9 @@ class DashControl
"lastBackup" => $updated->format("Y M D d"),
"currentTheme" => $settings["global"]["theme"],
"themes" => $themes,
"apiStatus" => isset($settings["global"]["externalAPI"])
? $settings["global"]["externalAPI"]
: "false",
"mailOption" => $settings["email"]["active"],
"mailConfig" => $settings["email"],
"status" => Session::active(),

View file

@ -44,6 +44,7 @@ class Auth
"email" => $found["email"],
"role" => $found["role"],
"avatar" => $found["avi"],
"key" => $found["key"],
];
$token = Token::create(

View file

@ -7,6 +7,21 @@ class Member
{
}
public static function verifyKey(string $key)
{
if (isset($key)) {
$folks = (new Settings())->getFolks();
$found = find($folks, ["key" => $key]);
if ($found) {
return true;
} else {
return false;
}
} else {
return false;
}
}
public static function updateData(string $key, string $data, $secret = null)
{
$folks = (new Settings())->getFolks();

View file

@ -5,7 +5,7 @@ use function _\remove;
class Settings
{
private $folks;
private $tags;
private static $tags;
private $themes = [];
private static $settings;
@ -13,7 +13,7 @@ class Settings
{
//gets all settings files and converts to php objects
$this->folks = json_decode(file_get_contents("../config/folks.json"), true);
$this->tags = json_decode(file_get_contents("../config/tags.json"), true);
self::$tags = json_decode(file_get_contents("../config/tags.json"), true);
self::$settings = json_decode(
file_get_contents("../config/settings.json"),
true
@ -38,6 +38,7 @@ class Settings
$settings["global"]["private"] = $data["global"]["private"];
$settings["global"]["renderOnSave"] = $data["global"]["renderOnSave"];
$settings["global"]["theme"] = $data["global"]["theme"];
$settings["global"]["externalAPI"] = $data["global"]["externalAPI"];
Member::updateData("handle", $data["member"]["handle"]);
Member::updateData("email", $data["member"]["email"]);
@ -122,6 +123,11 @@ class Settings
return self::$settings;
}
public static function getTags()
{
return self::$tags;
}
public static function updateGlobalData($key, $data)
{
$settings = self::$settings;

View file

@ -0,0 +1,51 @@
<?php
class handleCors
{
public function __construct()
{
//check settings to see if external api access is allowed
$config = new Settings();
$settings = $config->getSettings();
if ($settings["global"]["externalAPI"]) {
//echo "API STATUS: " . $settings["global"]["externalAPI"];
if ($settings["global"]["externalAPI"] == "true") {
//echo "API ACCESS ACTIVE";
// checks to see if origin is set
if (isset($_SERVER["HTTP_ORIGIN"])) {
// You can decide if the origin in $_SERVER['HTTP_ORIGIN'] is something you want to allow, or as we do here, just allow all
header("Access-Control-Allow-Origin: {$_SERVER["HTTP_ORIGIN"]}");
} else {
//No HTTP_ORIGIN set, so we allow any. You can disallow if needed here
//never allow just any domain, so turn CORS off if no No HTTP_ORIGIN is set
//header("Access-Control-Allow-Origin: *");
}
header("Access-Control-Allow-Credentials: true");
header("Access-Control-Max-Age: 600"); // cache for 10 minutes
if ($_SERVER["REQUEST_METHOD"] == "OPTIONS") {
if (isset($_SERVER["HTTP_ACCESS_CONTROL_REQUEST_METHOD"])) {
header(
"Access-Control-Allow-Methods: POST, GET, OPTIONS, DELETE, PUT"
);
} //Make sure you remove those you do not want to support
if (isset($_SERVER["HTTP_ACCESS_CONTROL_REQUEST_HEADERS"])) {
header(
"Access-Control-Allow-Headers: {$_SERVER["HTTP_ACCESS_CONTROL_REQUEST_HEADERS"]}"
);
}
//Just exit with 200 OK with the above headers for OPTIONS method
exit(0);
}
} else {
//echo "API ACCESS ACTIVE";
}
} else {
//value doesn't exist, so whatevs
//echo "API ACCESS VALUE NOT PRESENT";
}
}
}

View file

@ -31,7 +31,7 @@
<div id="wrapper">
{% apply spaceless %}
<div id="left">
<a href="/dashboard"><img id="the-logo" src="/assets/images/global/the-logo.svg"/></a>
<a href="/dashboard"><img id="the-logo" src="/assets/images/global/fipamo-logo.svg"/></a>
</div>
<div id="right">
{% if status %}

View file

@ -1,6 +1,6 @@
<div id="dash-login">
<div id="dash-form" class="dash-form">
<img id="the-logo" src="/assets/images/global/the-logo.svg"/>
<img id="the-logo" src="/assets/images/global/fipamo-logo.svg"/>
<form id="login" class='login' name="login" action="/@/dashboard/login" method="POST">
<input type="text" name="handle" class="form-control" placeholder="Handle" required ">
<input type="password" name="password" class="form-control" placeholder="Password" required">

View file

@ -13,7 +13,7 @@
<div id="dash-index-wrapper">
<div id="dash-init" class="dash-init">
<form id="init-form">
<img id="the-logo" src="/assets/images/global/the-logo.svg"/>
<img id="the-logo" src="/assets/images/global/fipamo-logo.svg"/>
<input type="text" name="new_member_handle" id="new_member_handle" placeholder="handle"/>
<input type="text" name="new_member_email" id="new_member_email" placeholder="email"/>
<input type="text" name="new_member_pass" id="new_member_pass" placeholder="password"/>
@ -27,7 +27,7 @@
</div>
<div id="dash-restore" class="dash-restore">
<form id="init-restore">
<img id="the-logo" src="/assets/images/global/the-logo.svg"/>
<img id="the-logo" src="/assets/images/global/fipamo-logo.svg"/>
<input type="text" name="restore_member_handle" id="restore_member_handle" placeholder="handle"/><input type="text" name="restore_member_pass" id="restore_member_pass" placeholder="password"/>
<div>
<label>Grab your backup zip</label>

View file

@ -13,7 +13,7 @@
<div id="dash-index-wrapper">
<div id="dash-login">
<div id="dash-reset" class="dash-reset">
<img id="the-logo" src="/assets/images/global/the-logo.svg"/>
<img id="the-logo" src="/assets/images/global/fipamo-logo.svg"/>
<form id="reset" class='login' name="reset" action="/@/dashboard/login" method="POST">
<input type="password" id="new_password"name="new_password" class="form-control" placeholder="New Password" required">

View file

@ -11,7 +11,7 @@
{% endblock %}
{% block stylesheets %}
<link rel="stylesheet" type="text/css" href="/assets/css/dash.css?=dfdvcvb">
<link rel="stylesheet" type="text/css" href="/assets/css/dash.css?=asdfdf">
{% endblock %}
{% block mainContent %}
@ -58,9 +58,10 @@
</div>
<div class="columns">
<div class="column is-full">
<textarea id="settings-desc" type='text' name='settings_desc' class='settings-dec' placeholder='description stuff', autofocus>{{desc}}</textarea>
<textarea id="settings-desc" type='text' name='settings_desc' class='settings-dec' placeholder='description stuff', autofocus>{{desc}}</textarea><br />
<label>YOUR API KEY</label><br />
<span id="key">{{member['key']}}</span>
</div>
</div>
@ -115,6 +116,27 @@
{{ include("dash/partials/mailforms.twig") }}
{% endapply %}
<button id="send-mail">TEST MAIL</button>
<br /><br />
<label>API SETTINGS</label><br />
<div id="settings-api">
{% if apiStatus is defined and apiStatus == "true" %}
<button id="api-access-toggle" title="allow external api" data-enabled="true">
<svg id="api-access-toggle" class="icons">
<use id="api-access-toggle" xlink:href="/assets/images/global/sprite.svg#entypo-landline"/>
</svg>
</button>
<span id="api-status">EXTERNAL API ACCESS ENABLED</span>
{% else %}
<button id="api-access-toggle" title="allow external api" data-enabled="false">
<svg id="api-access-toggle" class="icons">
<use id="api-access-toggle" xlink:href="/assets/images/global/sprite.svg#entypo-landline"/>
</svg>
</button>
<span id="api-status">EXTERNAL API ACCESS NOT ENABLED</span>
{% endif %}
</div>
</div>
</div>

View file

@ -2527,10 +2527,21 @@ svg.icons {
#settings-index #settings-index-wrapper textarea {
background: #1D3040;
width: 93%;
height: 128px;
height: 80px;
color: #f5ab35;
padding: 10px;
display: inline-block;
margin-bottom: 10px;
}
#settings-index #settings-index-wrapper span#key {
color: #EFEBE3;
background: #1D3040;
font-size: 0.9em;
border-radius: 3px;
padding: 5px;
display: block;
width: 95%;
overflow: hidden;
}
#settings-index #settings-index-wrapper #option-settings #theme-settings a {
width: 95%;
@ -2585,6 +2596,42 @@ svg.icons {
display: none;
visibility: hidden;
}
#settings-index #settings-index-wrapper #option-settings #mail-settings #settings-api {
background: #1D3040;
border-radius: 3px;
padding: 10px;
}
#settings-index #settings-index-wrapper #option-settings #mail-settings #settings-api span {
color: #EFEBE3 !important;
margin: -13px 0 0 5px;
position: relative;
vertical-align: middle;
display: inline-block;
font-weight: bold;
}
#settings-index #settings-index-wrapper #option-settings #mail-settings #settings-api button {
color: #EFEBE3;
border-radius: 3px;
width: 40px;
margin: 0;
}
#settings-index #settings-index-wrapper #option-settings #mail-settings #settings-api button svg {
width: 25px;
height: 20px;
fill: #EFEBE3;
}
#settings-index #settings-index-wrapper #option-settings #mail-settings #settings-api button[data-enabled=false] {
background: #b2cce5;
}
#settings-index #settings-index-wrapper #option-settings #mail-settings #settings-api button[data-enabled=false] svg {
fill: #1D3040;
}
#settings-index #settings-index-wrapper #option-settings #mail-settings #settings-api button[data-enabled=true] {
background: #fc6399;
}
#settings-index #settings-index-wrapper #option-settings #mail-settings #settings-api button[data-enabled=true] svg {
fill: #EFEBE3;
}
@media only screen and (max-width: 480px) {
#settings-actions {

View file

Before

Width:  |  Height:  |  Size: 4.6 KiB

After

Width:  |  Height:  |  Size: 4.6 KiB

File diff suppressed because one or more lines are too long

View file

@ -1,4 +1,5 @@
<?php
require "../vendor/autoload.php";
include "../brain/App.inc.php";
new App();