Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ public/*
!public/index.php
!public/console.php
!public/assets
!public/console2.php
public/assets/env/config.json
Binary file added equal.dev
Binary file not shown.
10 changes: 10 additions & 0 deletions packages/core/actions/config/create-package.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@
throw new Exception("directory_creation_failed", QN_ERROR_UNKNOWN);
}

if(!mkdir(QN_BASEDIR.'/packages/'.$params['package']."/init/data", 0775)) {
throw new Exception("directory_creation_failed", QN_ERROR_UNKNOWN);
}

if(!mkdir(QN_BASEDIR.'/packages/'.$params['package']."/init/demo", 0775)) {
throw new Exception("directory_creation_failed", QN_ERROR_UNKNOWN);
}

if(!mkdir(QN_BASEDIR.'/packages/'.$params['package']."/i18n", 0775)) {
throw new Exception("directory_creation_failed", QN_ERROR_UNKNOWN);
}
Expand All @@ -71,6 +79,8 @@
throw new Exception("directory_creation_failed", QN_ERROR_UNKNOWN);
}



// create empty manifest (from template)
$template = <<<EOT
{
Expand Down
4 changes: 0 additions & 4 deletions packages/core/actions/config/create-view.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@
throw new Exception("view_id_invalid",QN_ERROR_INVALID_PARAM);
}

if(strcmp($type, "form")!==0 && strcmp($type, "list")!==0 && strcmp($type, "search")!==0 && strcmp($type, "app")!==0 && strcmp($type, $package)!==0 ) {
$test = strcmp($type, "list");
throw new Exception("view_type_invalid",QN_ERROR_INVALID_PARAM);
}

$file = QN_BASEDIR."/packages/{$package}/views/{$entity}.{$type}.{$name}.json";

Expand Down
117 changes: 117 additions & 0 deletions packages/core/actions/config/update-init-data.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<?php
/*
This file is part of the eQual framework <http://www.github.com/cedricfrancoys/equal>
Some Rights Reserved, Cedric Francoys, 2010-2021
Licensed under GNU LGPL 3 license <http://www.gnu.org/licenses/>
*/

use function PHPUnit\Framework\stringStartsWith;

list($params, $providers) = eQual::announce([
'description' => "save a representation of a view to a json file",
'response' => [
'content-type' => 'text/plain',
'charset' => 'UTF-8',
'accept-origin' => '*'
],
'params' => [
'package' => [
'description' => 'Name of the entity.',
'type' => 'string',
'required' => true
],
'type' => [
'description' => 'type of init-data you want to gather',
'help' => '',
'type' => 'string',
'default' => 'init',
'selection' => [
'init','demo'
]
],
'payload' => [
'description' => 'View definition (JSON).',
'type' => 'text',
'required' => true
]
],
'providers' => ['context']
]);

/** @var \equal\php\context Context */
list($context) = [$providers['context']];

if( ($decoded = json_decode($params['payload'],true)) === null) {
throw new Error("payload not valid",QN_ERROR_INVALID_PARAM);
}

$package = equal::run("do","sanitize_path",["path" => $params['package'], "name_only"=>true]);


$trad = [
"init" => "data",
"demo" => "demo"
];

$path = QN_BASEDIR."/packages/$package/init/{$trad[$params['type']]}";

if(!is_dir($path)) {
throw new Exception("malformed package",QN_ERROR_INVALID_CONFIG);
}

$files = flattenFolder($path);

$backups = [];

foreach($files as $file) {
unlink($path.'/'.$file.'.bak');
$res = rename($path.'/'.$file,$path.'/'.$file.'.bak');
if(!$res) {
throw new Exception("io error",QN_ERROR_INVALID_CONFIG);
}
$backups[] = $path.'/'.$file.'.bak';
}


foreach($decoded as $file => $content) {

$sanitized_filename = equal::run("do","sanitize_path",["path" => $file, "name_only"=>false]);
$f = fopen($path.'/'.$sanitized_filename,"w");
if(!$f) {
throw new Exception("io error",QN_ERROR_INVALID_CONFIG);
}
$json = json_encode($content,JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT);
if(!$json) {
throw new Exception("encoding error",QN_ERROR_INVALID_CONFIG);
}
fputs($f,$json);
fclose($f);
}

foreach($backups as $file) {
unlink($file);
}


$context->httpResponse()
->status(201)
->send();


function flattenFolder(string $path,string $suffix = ""):array {
$res = [];
$scan = scandir($path);
foreach($scan as $item) {
if(str_starts_with($item,".")) {
continue;
}
if(str_ends_with($item,".json")) {
$res[] = "$suffix$item";
continue;
}
if(is_dir("$path/$item")) {
$res = array_merge($res,flattenFolder("$path/$item","$suffix$item/"));
}
}
return $res;
}
80 changes: 80 additions & 0 deletions packages/core/actions/sanitize/path.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php

list($params, $providers) = eQual::announce([
'description' => 'This is the core_config_init-data controller created with core_config_create-controller.',
'response' => [
'accept-origin' => [
0 => '*',
],
'charset' => 'utf-8',
'schema' => [
'type' => 'string',
'qty' => 'one',
'usage' => '',
],
],
'params' => [
'path' => [
'description' => 'path you want to sanitize',
'help' => '',
'type' => 'string',
'required' => true,
],
'name_only' => [
'description' => 'delete all slashes',
'help' => '',
'type' => 'boolean',
'default' => 'false',
],
],
'access' => [
'visibility' => 'protected',
'groups' => [
0 => 'users',
],
],
'providers' => [
0 => 'context',
],
]);
/** @var \equal\php\context Context */
$context = $providers['context'];
$banned = [
"%2e%2e%2f ",
"../",
"%2e%2e/ ",
"../",
"..%2f ",
"../",
"%2e%2e%5c ",
"..\\",
"%2e%2e\\",
"..\\",
"..%5c ",
"..\\",
"%252e%252e%255c",
"..\\",
"..%255c",
"..\\",
"\0"
];

$path = $params['path'];
$sanitized = $params['path'];


foreach ($banned as $banned_item) {
$sanitized = str_replace($banned_item,"",$sanitized);
}

if($params['name_only']) {
$sanitized = str_replace("/","",$sanitized);
$sanitized = str_replace("\\","",$sanitized);
}


// controller logic goes here
$context->httpResponse()
->body($sanitized)
->status(200)
->send();
2 changes: 1 addition & 1 deletion packages/core/apps/workbench/sources
Submodule sources updated 70 files
+1 −1 angular.json
+2 −0 compile.sh
+1 −1 serve.sh
+48 −8 src/app/_services/embbedapi.service.ts
+2 −2 src/app/in/autocomplete/autocomplete.component.ts
+1 −1 src/app/in/controllers/_components/return-type-editor/_objects/ReturnValue.ts
+1 −1 src/app/in/controllers/_components/return-type-editor/return-type-editor.component.html
+2 −3 src/app/in/controllers/_components/return-type-editor/return-type-editor.component.ts
+14 −0 src/app/in/init-data/_component/entity-dialog/entity-dialog.component.html
+0 −0 src/app/in/init-data/_component/entity-dialog/entity-dialog.component.scss
+25 −0 src/app/in/init-data/_component/entity-dialog/entity-dialog.component.spec.ts
+30 −0 src/app/in/init-data/_component/entity-dialog/entity-dialog.component.ts
+66 −0 src/app/in/init-data/_component/init-popup-editor/init-popup-editor.component.html
+20 −0 src/app/in/init-data/_component/init-popup-editor/init-popup-editor.component.scss
+25 −0 src/app/in/init-data/_component/init-popup-editor/init-popup-editor.component.spec.ts
+26 −0 src/app/in/init-data/_component/init-popup-editor/init-popup-editor.component.ts
+60 −0 src/app/in/init-data/_component/init-sidepane/init-sidepane.component.html
+66 −0 src/app/in/init-data/_component/init-sidepane/init-sidepane.component.scss
+25 −0 src/app/in/init-data/_component/init-sidepane/init-sidepane.component.spec.ts
+185 −0 src/app/in/init-data/_component/init-sidepane/init-sidepane.component.ts
+25 −0 src/app/in/init-data/_component/lang-popup/lang-popup.component.html
+22 −0 src/app/in/init-data/_component/lang-popup/lang-popup.component.scss
+25 −0 src/app/in/init-data/_component/lang-popup/lang-popup.component.spec.ts
+47 −0 src/app/in/init-data/_component/lang-popup/lang-popup.component.ts
+23 −0 src/app/in/init-data/_component/param-list/param-list.component.html
+67 −0 src/app/in/init-data/_component/param-list/param-list.component.scss
+25 −0 src/app/in/init-data/_component/param-list/param-list.component.spec.ts
+83 −0 src/app/in/init-data/_component/param-list/param-list.component.ts
+232 −0 src/app/in/init-data/_objects/init-data.ts
+37 −0 src/app/in/init-data/init-data.component.html
+8 −0 src/app/in/init-data/init-data.component.scss
+25 −0 src/app/in/init-data/init-data.component.spec.ts
+98 −0 src/app/in/init-data/init-data.component.ts
+67 −0 src/app/in/init-data/init-data.module.ts
+187 −0 src/app/in/menu/_object/Menu.ts
+35 −0 src/app/in/menu/menu-editor/_components/item-editor/item-editor.component.html
+76 −0 src/app/in/menu/menu-editor/_components/item-editor/item-editor.component.scss
+25 −0 src/app/in/menu/menu-editor/_components/item-editor/item-editor.component.spec.ts
+41 −0 src/app/in/menu/menu-editor/_components/item-editor/item-editor.component.ts
+161 −0 src/app/in/menu/menu-editor/menu-editor.component.html
+98 −0 src/app/in/menu/menu-editor/menu-editor.component.scss
+25 −0 src/app/in/menu/menu-editor/menu-editor.component.spec.ts
+138 −0 src/app/in/menu/menu-editor/menu-editor.component.ts
+15 −4 src/app/in/menu/menu-info/menu-info.component.html
+43 −0 src/app/in/menu/menu-info/menu-info.component.scss
+3 −1 src/app/in/menu/menu-info/menu-info.component.ts
+18 −0 src/app/in/menu/menu-routing.module.ts
+42 −2 src/app/in/menu/menu.module.ts
+6 −0 src/app/in/models/field-editor/_components/field-editor-sp/field-editor-sp.component.html
+7 −0 src/app/in/models/field-editor/_components/field-editor-sp/field-editor-sp.component.ts
+1 −0 src/app/in/models/field-editor/_object/Field.ts
+11 −0 src/app/in/multi-autocomplete/multi-autocomplete.component.html
+0 −0 src/app/in/multi-autocomplete/multi-autocomplete.component.scss
+25 −0 src/app/in/multi-autocomplete/multi-autocomplete.component.spec.ts
+80 −0 src/app/in/multi-autocomplete/multi-autocomplete.component.ts
+28 −0 src/app/in/multi-autocomplete/multi-autocomplete.module.ts
+2 −6 src/app/in/package/_components/package-info/package-info.component.html
+4 −0 src/app/in/package/_components/package-info/package-info.component.ts
+9 −0 src/app/in/package/package-routing.module.ts
+2 −0 src/app/in/package/package.component.html
+12 −15 src/app/in/package/package.component.ts
+3 −1 src/app/in/package/package.module.ts
+7 −7 src/app/in/type-input/type-input.component.html
+4 −0 src/app/in/type-input/type-input.component.scss
+10 −1 src/app/in/type-input/type-input.component.ts
+1 −8 src/app/in/views/_services/view.service.ts
+5 −5 src/app/in/views/vieweditor/vieweditor.module.ts
+1 −2 src/app/in/views/views.module.ts
+2 −0 test.sh
+ web.app
Binary file modified packages/core/apps/workbench/web.app
100755 → 100644
Binary file not shown.
97 changes: 97 additions & 0 deletions packages/core/data/config/init-data.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php

use function PHPUnit\Framework\stringStartsWith;

list($params, $providers) = eQual::announce([
'description' => 'This is the core_config_init-data controller created with core_config_create-controller.',
'response' => [
'charset' => 'utf-8',
'content-type' => 'application/json',
'accept-origin' => [
0 => '*',
],
],
'params' => [
'package' => [
'description' => 'Package from where you want to get the initial data files',
'help' => '',
'type' => 'string',
'usage' => 'orm/package',
'default' => 'core',
],
'type' => [
'description' => 'type of init-data you want to gather',
'help' => '',
'type' => 'string',
'default' => 'init',
'selection' => [
'init','demo'
]
],
],
'access' => [
'visibility' => 'protected',
'groups' => [
0 => 'users',
],
],
'providers' => [
0 => 'context',
],
]);
/** @var \equal\php\context Context */
$context = $providers['context'];

$package = equal::run("do","sanitize_path",["path" => $params['package'], "name_only"=>true]) ;

$trad = [
"init" => "data",
"demo" => "demo"
];

if(!is_dir(QN_BASEDIR."/packages/$package")) {
throw new Exception("package does not exists ",QN_ERROR_INVALID_PARAM);
}

$init_file_dir = QN_BASEDIR."/packages/$package/init/{$trad[$params['type']]}";

if(!is_dir($init_file_dir)) {
$context->httpResponse()
->body("{}")
->status(200)
->send();
die();
}

$filenames = flattenFolder($init_file_dir);

$res = [];

foreach($filenames as $file) {
$res[$file] = json_decode(file_get_contents("$init_file_dir/$file"),true);
}

// controller logic goes here
$context->httpResponse()
->body(json_encode($res,JSON_UNESCAPED_SLASHES))
->status(200)
->send();


function flattenFolder(string $path,string $suffix = "") {
$res = [];
$scan = scandir($path);
foreach($scan as $item) {
if(str_starts_with($item,".")) {
continue;
}
if(str_ends_with($item,".json")) {
$res[] = "$suffix$item";
continue;
}
if(is_dir("$path/$item")) {
$res = array_merge($res,flattenFolder("$path/$item","$suffix$item/"));
}
}
return $res;
}
2 changes: 1 addition & 1 deletion public/.htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ DirectoryIndex index.php index.html
RewriteEngine On
RewriteBase /

RewriteRule ^(index|console|console_json)\.php(\??.*)$ - [L]
RewriteRule ^(index|console|console_json|console2)\.php(\??.*)$ - [L]

RewriteCond %{REQUEST_FILENAME} ^(.*)\.php$ [OR]
RewriteCond %{REQUEST_FILENAME} !-f
Expand Down
Loading