change names + link paths

This commit is contained in:
Dennis Eichhorn 2023-01-26 21:46:52 +01:00
parent 00ddba8bf3
commit 6a2b818dba
6 changed files with 196 additions and 5 deletions

View File

@ -18,7 +18,7 @@
* [Css Coding Standards]({%}?page=standards/css)
## Application Examples
* [Application Sample]({%}?page=example_app/app)
* [Application Sample]({%}?page=example_app/web_app)
* [Modules]({%}?page=example_module/module)
* [Packages]({%}?page=example_module/packages)
* [Language Files]({%}?page=basics/language_files)

177
example_app/c_app.md Normal file
View File

@ -0,0 +1,177 @@
/**
* Karaka
*
* @package App
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://jingga.app
*/
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include "cOMS/Utils/ApplicationUtils.h"
#include "cOMS/DataStorage/Database/Connection/ConnectionAbstract.h"
#include "cOMS/Utils/Parser/Json.h"
#include "cOMS/Utils/OSWrapper.h"
#include "cOMS/Router/Router.h"
#include "cOMS/Threads/Thread.h"
#include "cOMS/Application/ApplicationAbstract.h"
#include "Models/ResourceMapper.h"
#include "Routes.h"
#ifndef OMS_DEMO
#define OMS_DEMO false
#endif
Application::ApplicationAbstract app = {0};
int main(int argc, char **argv)
{
/* --------------- Basic setup --------------- */
const char *arg = Utils::ApplicationUtils::compile_arg_line(argc, argv);
// Set program path as cwd
char *cwd = Utils::ApplicationUtils::cwd();
if (cwd == NULL) {
printf("Couldn't get the CWD\n");
return -1;
}
char *cwdT = Utils::StringUtils::search_replace(cwd, "\\", "/");
free(cwd);
cwd = cwdT;
Utils::ApplicationUtils::chdir_application(cwd, argv[0]);
// Check config
if (!Utils::FileUtils::file_exists("config.json")) {
Controller::ApiController::notInstalled(argc, argv);
return -1;
}
/* --------------- App setup --------------- */
// Load config
FILE *in = fopen("config.json", "r");
if (in == NULL) {
printf("Couldn't open config.json\n");
return -1;
}
app.config = nlohmann::json::parse(in);
fclose(in);
// Setup db connection
DataStorage::Database::DbConnectionConfig dbdata = {
DataStorage::Database::database_type_from_str(app.config["db"]["core"]["masters"]["admin"]["db"].get_ref<const std::string&>().c_str()),
app.config["db"]["core"]["masters"]["admin"]["database"].get_ref<const std::string&>().c_str(),
app.config["db"]["core"]["masters"]["admin"]["host"].get_ref<const std::string&>().c_str(),
atoi(app.config["db"]["core"]["masters"]["admin"]["port"].get_ref<const std::string&>().c_str()),
app.config["db"]["core"]["masters"]["admin"]["login"].get_ref<const std::string&>().c_str(),
app.config["db"]["core"]["masters"]["admin"]["password"].get_ref<const std::string&>().c_str(),
};
app.pool = Threads::pool_create(app.config["app"]["threads"]["count"].get<int>());
app.db = DataStorage::Database::create_connection(dbdata);
app.db->connect();
/* --------------- Handle request --------------- */
// Handle routes
Router::Router router = generate_routes(&app);
Router::RouterFunc ptr = Router::match_route(&router, arg);
// No endpoint found
if (ptr == NULL) {
ptr = &Controller::ApiController::printHelp;
}
// Dispatch found endpoint
(*ptr)(argc, argv);
/* --------------- Cleanup --------------- */
Threads::pool_destroy(app.pool);
DataStorage::Database::free_MapperData((DataStorage::Database::MapperData *) &Models::ResourceMapper);
app.db->close();
app.db = NULL;
Router::free_router(&router);
free((char *) arg);
arg = NULL;
// Reset CWD (don't know if this is necessary)
chdir(cwd);
free(cwd);
}
/**
* Karaka
*
* @package Models
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef ROUTES_H
#define ROUTES_H
#include <stdio.h>
#include <stdlib.h>
#include "Controller/ApiController.h"
#include "Controller/InstallController.h"
#include "cOMS/Router/Router.h"
#include "cOMS/Application/ApplicationAbstract.h"
Router::Router generate_routes(Application::ApplicationAbstract *app)
{
Controller::ApiController::app = app;
Router::Router router = Router::create_router(4);
Router::set(&router, "^.*?\\-h *.*$", (void *) &Controller::ApiController::printHelp);
Router::set(&router, "^.*?\\-v *.*$", (void *) &Controller::ApiController::printVersion);
Router::set(&router, "^.*?\\-r *.*$", (void *) &Controller::ApiController::checkResources);
Router::set(&router, "^.*?\\-\\-install *.*$", (void *) &Controller::InstallController::installApplication);
return router;
}
#endif
namespace Controller {
namespace ApiController {
static Application::ApplicationAbstract *app = NULL;
void printHelp(int argc, char **argv)
{
printf(" The Online Resource Watcher app developed by jingga checks online or local resources\n");
printf(" for changes and informs the user about them.\n\n");
printf(" Run: ./App ....\n\n");
printf(" -h: Prints the help output\n");
printf(" -v: Prints the version\n");
printf("\n");
printf(" Website: https://jingga.app\n");
printf(" Copyright: jingga (c) Dennis Eichhorn\n");
}
}
}
#endif

View File

@ -4,10 +4,10 @@ After you installed the application and configured your development environment
Please note that besides the general development guide the organization also provides various other organizational documents which help to understand the processes, development status and decisions made.
* [Development process](https://github.com/Karaka-Management/Organization-Guide/blob/master/Processes/Development.md)
* [Development process](https://github.com/Karaka-Management/Organization-Guide/blob/master/Processes/01_Development.md)
* [Code inspection]({%}?page=quality/inspections)
* [Project status](https://github.com/Karaka-Management/Organization-Guide/blob/master/Project/PROJECT.md)
* [Code of conduct](https://github.com/Karaka-Management/Organization-Guide/blob/master/Policies%20%26%20Guidelines/Code%20of%20conduct.md)
* [Project status](https://github.com/orgs/Karaka-Management/projects/10)
* [Code of conduct](https://github.com/Karaka-Management/Organization-Guide/blob/master/Policies%20%26%20Guidelines/Code%20of%20Conduct.md)
* [Conflict of interest](https://github.com/Karaka-Management/Organization-Guide/blob/master/Policies%20%26%20Guidelines/Conflict%20of%20Interest%20Policy.md)
* [Activity Policy](https://github.com/Karaka-Management/Organization-Guide/blob/master/Policies%20%26%20Guidelines/Organization%20Activity%20Policy.md)
* [Organization Guidelines](https://github.com/Karaka-Management/Organization-Guide/blob/master/Policies%20%26%20Guidelines/Organization%20Guidelines.md)

View File

@ -52,7 +52,7 @@ After the installation you'll have access to the following content:
Instead of calling `php demoSetup/setup.php` which only uses a single thread you may also run `php demoSetup/setup.php -a 0` which will execute the install script in multiple threads leading to most likely 100% CPU and storage usage but therfore significantly reduce the execution time.
> You might want to call the setup script as a different user to ensure the same permissions `sudo -u wwww-data php demoSetup/setup.php`
> You may want to call the setup script as a different user to ensure the same permissions `sudo -u wwww-data php demoSetup/setup.php`
#### Annotation

View File

@ -2,6 +2,20 @@
The built in validation allows to quickly validate some basic data formats.
## Guarding
The `Guard` provides basic protection function for comman mistakes and angles of attacks:
### Path guarding
Usually no user input should be used for path construction but in some cases this might not be possible. With the path guarding you can check if the generated path would lead outside the applications root path.
```php
public static function isSafePath(string $path, string $base = '') : bool;
```
By leaving the `$base` path empty the function automatically restricts the `$path` to the parent directory of the framework.
## Validator
The `Validator` provides basic validations with: