dbxapp 4.1.3
CMS, Shop, Workflows und modulare Geschäftsanwendungen
Loading...
Searching...
No Matches
dbxForm_structure_test.php
Go to the documentation of this file.
1<?php
2
11
12$root = dirname(__DIR__, 2);
13$moduleRoot = $root . DIRECTORY_SEPARATOR . 'modules';
14$errors = array();
16
17$iterator = new RecursiveIteratorIterator(
18 new RecursiveDirectoryIterator($moduleRoot, FilesystemIterator::SKIP_DOTS)
19);
20
21foreach ($iterator as $file) {
22 if (!$file->isFile() || strtolower($file->getExtension()) !== 'htm') {
23 continue;
24 }
25
26 $path = str_replace('\\', '/', $file->getPathname());
27 $relativePath = '/' . ltrim(str_replace(
28 '\\',
29 '/',
30 substr($file->getPathname(), strlen($moduleRoot))
31 ), '/');
32 if (strpos($relativePath, '/vendor/') !== false
33 || strpos($relativePath, '/add_ons/') !== false
34 || strpos($relativePath, '/work/') !== false) {
35 continue;
36 }
37 if (strpos($path, '/modules/dbx/tpl/htm/frame-report-head.htm') !== false
38 || strpos($path, '/modules/dbx/tpl/htm/frame-report-foot.htm') !== false) {
39 // dbxReport setzt diese beiden Rahmenfragmente gemeinsam zusammen.
40 continue;
41 }
42
43 $html = (string)file_get_contents($file->getPathname());
44 $html = (string)preg_replace('/<!--.*?-->/s', '', $html);
45 if (!preg_match('/<\/?form\b/i', $html)) {
46 continue;
47 }
48
49 $checked++;
50 preg_match_all('/<\/?form\b[^>]*>/i', $html, $matches);
51 $depth = 0;
52 foreach ($matches[0] as $tag) {
53 if (preg_match('/^<\s*\/form\b/i', $tag)) {
54 $depth--;
55 if ($depth < 0) {
56 $errors[] = $path . ': schließendes </form> ohne Öffnung';
57 $depth = 0;
58 }
59 continue;
60 }
61
62 $depth++;
63 if ($depth > 1) {
64 $errors[] = $path . ': verschachteltes <form>';
65 }
66 }
67 if ($depth !== 0) {
68 $errors[] = $path . ': Form-Tags sind nicht ausgeglichen';
69 }
70}
71
73 'dbxAdmin/tpl/htm/fdedit-create-from-dd.htm',
74 'dbxContent_admin/tpl/htm/cms-media-upload-form.htm',
75 'dbxContent_admin/tpl/htm/cms-external-video-form.htm',
76 'dbxKi/tpl/htm/ki-briefing-page-create.htm',
77 'dbxKi/tpl/htm/ki-briefing-page-update.htm',
78 'dbxKi/tpl/htm/ki-briefing-page-translation.htm',
79 'dbxKi/tpl/htm/ki-bundle-start.htm',
80 'dbxKi/tpl/htm/ki-module-briefing.htm',
81 'dbxKi/tpl/htm/ki-module-bundle-import.htm',
82 'dbxKi/tpl/htm/ki-translation-sync-all.htm',
83 'dbxShop_admin/tpl/htm/shop-product-channel-mapping.htm',
84 'dbxShop/tpl/htm/shop-cart-report.htm',
85 'dbxShop/tpl/htm/shop-checkout-form.htm',
86 'dbxShop/tpl/htm/shop-withdrawal-form.htm',
87 'dbxWorkflow/tpl/htm/workflow-review.htm',
88 'dbxWorkflow/tpl/htm/workflow-step-choice.htm',
89 'dbxWorkflow_admin/tpl/htm/workflow-bind-generator.htm',
90);
91
92foreach ($requiredTemplates as $relative) {
93 $path = $moduleRoot . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $relative);
94 $html = is_file($path) ? (string)file_get_contents($path) : '';
95 if ($html === '') {
96 $errors[] = $relative . ': Template fehlt';
97 continue;
98 }
99 if (strpos($html, '[dbx:form]') === false) {
100 $errors[] = $relative . ': [dbx:form] für Security-/Restfelder fehlt';
101 }
102}
103
104foreach (array(
105 'dbxAdmin/tpl/htm/fdedit-create-from-dd.htm',
106 'dbxShop_admin/tpl/htm/shop-product-channel-mapping.htm',
107 'dbxShop/tpl/htm/shop-checkout-form.htm',
108 'dbxShop/tpl/htm/shop-withdrawal-form.htm',
109) as $relative) {
110 $path = $moduleRoot . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $relative);
111 $html = is_file($path) ? (string)file_get_contents($path) : '';
112 if (strpos($html, '{obj:form_msg}') === false) {
113 $errors[] = $relative . ': zentraler dbxForm-Meldungsplatz fehlt';
114 }
115}
116
117$shopServicePath = $moduleRoot . DIRECTORY_SEPARATOR . 'dbxShop' . DIRECTORY_SEPARATOR . 'include'
118 . DIRECTORY_SEPARATOR . 'dbxShopService.class.php';
119$shopService = (string)file_get_contents($shopServicePath);
120foreach (array(
121 '$cartReport->submit()' => 'Warenkorb-Report',
122 '$buyForm->submit()' => 'Add-to-cart-Formular',
123 '$row = $this->repo()->saveWithdrawal($values)' => 'Widerrufsformular',
124 'if ($form->submit())' => 'dbxForm-Submit',
125) as $needle => $label) {
126 if (strpos($shopService, $needle) === false) {
127 $errors[] = 'dbxShopService: Token-Guard fehlt für ' . $label;
128 }
129}
130
131$shopAdminPath = $moduleRoot . DIRECTORY_SEPARATOR . 'dbxShop_admin' . DIRECTORY_SEPARATOR . 'include'
132 . DIRECTORY_SEPARATOR . 'dbxShopAdmin.class.php';
133$shopAdmin = (string)file_get_contents($shopAdminPath);
134foreach (array(
135 '$form->submit()' => 'zentraler Karten-Token-Guard',
136 '$this->postedFormError' => 'sichtbare Karten-Fehlermeldung',
137 '$content .= $this->shopMediaFormTemplates($this->shopMediaConfig())' => 'Medienformulare außerhalb der Kartenform',
138) as $needle => $label) {
139 if (strpos($shopAdmin, $needle) === false) {
140 $errors[] = 'dbxShopAdmin: ' . $label . ' fehlt';
141 }
142}
143foreach (array('productImagesPanel', 'productGroupImagePanel') as $method) {
144 if (preg_match(
145 '/private function ' . preg_quote($method, '/') . '\b.*?(?=\n\s*private function )/s',
147 $methodMatch
148 ) && strpos($methodMatch[0], 'shopMediaFormTemplates(') !== false) {
149 $errors[] = 'dbxShopAdmin: Medienformular ist noch in ' . $method . ' verschachtelt';
150 }
151}
152
153$cmsJs = (string)file_get_contents($root . DIRECTORY_SEPARATOR . 'js' . DIRECTORY_SEPARATOR . 'lib'
154 . DIRECTORY_SEPARATOR . 'cms.js');
155$cmsJsWithoutComments = (string)preg_replace('~/\*.*?\*/|//[^\r\n]*~s', '', $cmsJs);
156if (preg_match('/[\'"`][^\'"`]*<form\b/i', $cmsJsWithoutComments)) {
157 $errors[] = 'cms.js: Formular-Markup wird wieder in JavaScript erzeugt';
158}
159
160$editorClass = (string)file_get_contents(
161 $moduleRoot . DIRECTORY_SEPARATOR . 'dbxEditor' . DIRECTORY_SEPARATOR . 'dbxEditor.class.php'
162);
163$editorTemplate = (string)file_get_contents(
164 $moduleRoot . DIRECTORY_SEPARATOR . 'dbxEditor' . DIRECTORY_SEPARATOR . 'tpl'
165 . DIRECTORY_SEPARATOR . 'htm' . DIRECTORY_SEPARATOR . 'editor.htm'
166);
167$aceJs = (string)file_get_contents(
168 $root . DIRECTORY_SEPARATOR . 'js' . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'ace.js'
169);
170foreach (array(
171 array($editorClass, "array('save', 'delete', 'rename', 'copy')", 'dbxEditor: gemeinsamer Mutations-Guard fehlt'),
172 array($editorClass, '$form->submit()', 'dbxEditor: dbxForm-Submit-Prüfung fehlt'),
173 array($editorTemplate, 'dbx-editor-security', 'dbxEditor: Sicherheitstoken fehlt im Editor-Template'),
174 array($aceJs, 'function requestMutation(data)', 'ace.js: zentrale Mutationsfunktion fehlt'),
175 array($aceJs, "method: 'POST'", 'ace.js: Mutationen werden nicht per POST gesendet'),
176) as $check) {
177 if (strpos($check[0], $check[1]) === false) {
178 $errors[] = $check[2];
179 }
180}
181if (strpos($aceJs, 'dbx_run1=delete&file=') !== false
182 || strpos($aceJs, "requestJson('?dbx_modul=dbxEditor&dbx_run1=rename") !== false
183 || strpos($aceJs, "requestJson('?dbx_modul=dbxEditor&dbx_run1=copy") !== false) {
184 $errors[] = 'ace.js: schreibende Editor-Aktion verwendet wieder einen GET-Aufruf';
185}
186
187$formClass = (string)file_get_contents($root . DIRECTORY_SEPARATOR . 'include' . DIRECTORY_SEPARATOR . 'dbxForm.class.php');
188if (!preg_match('/function get_security_data\‍(\‍).*?\$this->store_sysdata\‍(\‍)/s', $formClass)) {
189 $errors[] = 'dbxForm: AJAX-Folgetoken wird nicht unmittelbar in der Session gespeichert';
190}
191
192if ($checked === 0) {
193 $errors[] = 'Keine aktiven Formular-Templates gefunden';
194}
195
197 fwrite(STDERR, "Formular-Strukturprüfung fehlgeschlagen:\n - " . implode("\n - ", array_unique($errors)) . "\n");
198 exit(1);
199}
200
201echo "OK: {$checked} Formular-Templates sind ausgeglichen, nicht verschachtelt und die migrierten Formulare sind abgesichert.\n";
foreach( $it as $file) if($checked===0) $formClass
foreach($iterator as $file) $requiredTemplates
if(preg_match('/ $editorClass[\'"`][^\'"`] *< form\b/i', $cmsJsWithoutComments))
foreach(array(' $cartReport->submit()'=> 'Warenkorb-Report', ' $buyForm->submit()'=> 'Add-to-cart-Formular', ' $row=$this->repo() ->saveWithdrawal($values)'=> 'Widerrufsformular', 'if($form->submit())'=> 'dbxForm-Submit',) as $needle=> $label) $shopAdminPath
foreach( $requiredTemplates as $relative) foreach(array('dbxAdmin/tpl/htm/fdedit-create-from-dd.htm', 'dbxShop_admin/tpl/htm/shop-product-channel-mapping.htm', 'dbxShop/tpl/htm/shop-checkout-form.htm', 'dbxShop/tpl/htm/shop-withdrawal-form.htm',) as $relative) $shopServicePath
exit
Definition index.php:146