### Example CSP Header Configuration for Mosparo Source: https://documentation.mosparo.io/docs/integration/csp This example shows how to configure the Content-Security-Policy header to include directives for Mosparo. Ensure 'mosparo.example.com' is replaced with your actual Mosparo installation URL. ```http Content-Security-Policy: default-src 'self'; img-src 'self' https://mosparo.example.com; script-src 'self' https://mosparo.example.com; style-src 'self' https://mosparo.example.com; connect-src 'self' https://mosparo.example.com ``` -------------------------------- ### Install Frontend Dependencies Source: https://documentation.mosparo.io/docs/installation/install/source Install the Node.js dependencies required for the frontend using npm. ```bash npm install ``` -------------------------------- ### Example Authorization Header Value Source: https://documentation.mosparo.io/docs/api/rule_package This is an example of the complete Authorization header value after constructing it. ```text Authorization: WFN0UU5ha0VpSmsxb01JWEo2X1J4bWQzajVnTmNRYWUzNG4xRzNhUjZGVTphYmNlYjNjMzgxNmU3NGNhYzdhZDFlYTIwZmE3ODU3ZDBlMjk1YmQzODU2ZTcwZjE2NTMxNDU3YTU0ZDRiMmZj ``` -------------------------------- ### Example Authorization Header Value Source: https://documentation.mosparo.io/docs/api/rule_package This is an example of the complete Authorization header value after base64 encoding. ```text Authorization: WFN0UU5ha0VpSmsxb01JWEo2X1J4bWQzajVnTmNRYWUzNG4xRzNhUjZGVTo5MWNhODkxZWM5ZGJlNDEyMmQ5YTJmYmM3NDMxMjJhOWJlYWRmMTdmYWRlNzYzN2IxNGNlMjljYmYwNjY5YzNk ``` -------------------------------- ### Install Composer Dependencies Source: https://documentation.mosparo.io/docs/installation/install/source Execute Composer to install the necessary PHP dependencies for Mosparo. The `--no-dev` flag ensures only production dependencies are installed. ```bash composer install --no-dev ``` -------------------------------- ### Example Authorization Header Source: https://documentation.mosparo.io/docs/api/rule_package An example of the Authorization header format after being generated using the public key and HMAC-SHA256 hash. ```text Authorization: WFN0UU5ha0VpSmsxb01JWEo2X1J4bWQzajVnTmNRYWUzNG4xRzNhUjZGVTpkZjA0MTc2NTZmOWUwNWY1ODcyMzhlMzdkNmJkMDUyYTRmZDUwNmUwY2QxMDhjYmU1MDFhZGE2OTg3NjM0MjA5 ``` -------------------------------- ### Start Mosparo Containers with Docker Compose Source: https://documentation.mosparo.io/docs/installation/install/docker This command starts all services defined in your `docker-compose.yaml` file in detached mode. Ensure you are in the directory containing the `docker-compose.yaml` file before running. ```bash docker-compose up -d ``` -------------------------------- ### Request Submit Token Response Example Source: https://documentation.mosparo.io/docs/api/frontend This is an example of the JSON response received when requesting a submit token. It includes the submit token and various messages for different scenarios. ```json { "submitToken":"_wc0MPl5EQuwuJeTMq8uoF7WFpFdoZZf35ctawmasmc", "messages":{ "label":"Ich akzeptiere, dass die Formulareingaben auf Spam \u00fcberpr\u00fcft und f\u00fcr 14 Tage verschl\u00fcsselt gespeichert werden.", "accessibilityCheckingData":"Wir \u00fcberpr\u00fcfen Ihre Daten. Bitte warten Sie.", "accessibilityDataValid":"Ihre Daten enthalten kein Spam. Sie k\u00f6nnen das Formular absenden.", "errorGotNoToken":"mosparo hat keinen Absende-Token ausgestellt.", "errorInternalError":"Es trat ein Fehler auf. Bitte wiederholen Sie den Vorgang.", "errorNoSubmitTokenAvailable":"Kein Absende-Token verf\u00fcgbar. Die Validierung Ihrer Daten ist nicht m\u00f6glich.", "errorSpamDetected":"In Ihren Daten ist Spam enthalten.", "errorLockedOut":"Sie wurden tempor\u00e4r gesperrt. Bitte versuchen Sie es nach %datetime% erneut.", "errorDelay":"Ihre Anfrage wurde verz\u00f6gert. Bitte warten Sie %seconds% Sekunden.", "hpLeaveEmpty":"Dieses Feld leer lassen" } } ``` -------------------------------- ### Hash Index Response Example Source: https://documentation.mosparo.io/docs/api/rule_package This is an example of the hash index returned by the API. Each line represents a rule or rule item, formatted as UUID::type/hash/id. ```text cf164449-ea85-4312-bec0-ae551de90891::r/3fed3c117b45765b8d3e57744d18d266/115 2f51af01-eea7-4fe4-b7bb-5b41790b3a44::i/569bbb49eea5ca57dc109b5223fc210c/1552 9cecd7ca-bc68-4c48-8a82-fa3af5778be7::i/e73b0046cc24782de57f953c6bc3801a/1553 2f737ffe-ff20-4bcb-a3de-0a039b710b62::i/3fbf46288fd00219fb12b77ef39e46f8/1554 cc7e2cf4-6574-45fb-a9de-6beefd0d8180::i/846ee5b4b570c98b0da9d751cd14dba6/1555 752b0bff-8cb9-42eb-87bd-c5529a709107::i/3b97a60179e9bdb4b86f4508f983e92f/1556 ``` -------------------------------- ### Example Authorization Header Value Source: https://documentation.mosparo.io/docs/api/verification This is an example of the formatted Authorization header value after generating the HMAC hash and base64 encoding it. This value should be sent with your API request. ```text Authorization: WFN0UU5ha0VpSmsxb01JWEo2X1J4bWQzajVnTmNRYWUzNG4xRzNhUjZGVTpRcWZCeHNtT2ZJTXcwLXVWTm5SVmREbE1VWmRMcFRHMXhvMHl5aWZ5THJJOjNiZGQzODVjYWE1M2UzZGE3NmE4ZGNiZmNhYTBkOWY0ZTA0ZDhjMTg5ZmFiMDNiYTQxMzgzZGVlYTIzNmIyZDM= ``` -------------------------------- ### Example formData Structure Source: https://documentation.mosparo.io/docs/api/frontend This example shows the required structure for the formData argument when calling the check-form-data endpoint. Ensure empty arrays are represented as JSON objects. ```json { "fields": [ { "name": "username", "value": "example", "fieldPath": "input[text].username" } ], "ignoredFields": [ "password" ] } ``` -------------------------------- ### Embed Simple CSS Resources Source: https://documentation.mosparo.io/docs/integration/custom Include mosparo's CSS in your website's header by linking to the provided URL. Replace `` with your mosparo installation address and `` with your project's unique ID. ```html ``` -------------------------------- ### Example HTML Form with mosparo Integration Source: https://documentation.mosparo.io/docs/integration/custom This HTML form includes fields for name, email, and message, along with a mosparo integration script. It requires the mosparo-frontend.js script and initialization with your mosparo host, UUID, and public key. ```html
``` -------------------------------- ### Update mosparo via Command Line Source: https://documentation.mosparo.io/docs/installation/update Use this command to initiate the self-update process for mosparo from the command line. Ensure you are in your mosparo installation directory. ```bash php bin/console mosparo:self-update ``` -------------------------------- ### Original Form Field Source: https://documentation.mosparo.io/docs/integration/bypass_protection This is an example of a standard text input field before any potential manipulation. ```html ``` -------------------------------- ### Docker Run Environment Variables Source: https://documentation.mosparo.io/docs/installation/configure/environment_variables Specify environment variables when starting a Docker container directly from the command line. ```bash docker run -d -e MOSPARO_CACHE_ADAPTER='memcached' -p 8080:80 --name mosparo_container mosparo/mosparo:latest ``` -------------------------------- ### Generate HMAC Hash and Authorization Header Source: https://documentation.mosparo.io/docs/api/rule_package This example demonstrates how to generate the HMAC-SHA256 hash and format the Authorization header using PHP. Ensure you have your public and private keys. ```php $publicKey = 'XStQNakEiJk1oMIXJ6_Rxmd3j5gNcQae34n1G3aR6FU'; $privateKey = 'stH6Ugo4FcbQLp6_KPlOYltFMHfY59rxCUQRk3_AxYQ'; $apiEndpoint = '/api/v1/rule-package/1/batch'; $requestData = ['tasks' => [ ['type' => 'update_rule_package', 'data' => ['lastUpdatedAt' => '2026-05-01T12:00:00+00:00', 'refreshInterval' => 60]], ]]; $hmacHash = hash_hmac('sha256', $apiEndpoint . json_encode($requestData), $privateKey); $authHeader = base64_encode($publicKey . ':' . $hmacHash); ``` -------------------------------- ### Link Mosparo Container to a Dockerized Database Source: https://documentation.mosparo.io/docs/installation/install/docker This command runs the Mosparo container and links it to an existing MySQL server container named 'mysql-server'. Adjust the container name to match your database setup. Ensure the database is accessible via the specified link. ```bash docker run –link mysql-server -p 127.0.0.1:8080:80 -d mosparo/mosparo ``` -------------------------------- ### Initialize mosparo for Multi-step Forms (Automatic Mode) Source: https://documentation.mosparo.io/docs/integration/multi_step_forms This script initializes mosparo for a multi-step form in automatic mode. Ensure the mosparo-frontend.js script is loaded and replace placeholders with your actual project details. This setup is crucial for request-based multi-step forms. ```html ``` -------------------------------- ### Run Mosparo Docker Image Directly Source: https://documentation.mosparo.io/docs/installation/install/docker This command starts a single Mosparo container, mapping host port 8080 to the container's port 80 and running it in detached mode. Use this for simpler deployments where Docker Compose is not preferred. ```bash docker run -p 127.0.0.1:8080:80 -d mosparo/mosparo ``` -------------------------------- ### Nginx Reverse Proxy Configuration Source: https://documentation.mosparo.io/docs/installation/configure/reverse_proxy Configure Nginx to forward essential headers to Mosparo when it's not directly accessible. This setup is for a standard installation at the root of a domain. ```nginx server { listen 443 ssl http2; server_name [domain]; index index.html index.htm index.php; # Reverse proxy configuration - Start location / { proxy_set_header Host $http_host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto https; proxy_pass http://127.0.0.1:8080; } # Reverse proxy configuration - End [sslConfiguration] # Configure according to your needs } ``` -------------------------------- ### Build Frontend Resources Source: https://documentation.mosparo.io/docs/installation/install/source Build the frontend resources for production. Use `npm run dev` for development builds. ```bash npm run build ``` -------------------------------- ### Import Project via CLI Source: https://documentation.mosparo.io/docs/usage/tools Use the CLI command to import project settings. Specify the project ID and the file path. You must also determine which parts to import using the available arguments. ```bash php bin/console mosparo:import ``` -------------------------------- ### Health Check Response Example Source: https://documentation.mosparo.io/docs/api/health This is an example of a successful response from the `/api/v1/health/check` endpoint. It indicates the service is healthy and the database is connected. ```json { "service": "mosparo", "healthy": true, "databaseStatus": "connected", "error": null } ``` -------------------------------- ### Import Project Settings using CLI Source: https://documentation.mosparo.io/docs/cli Use this command to import project settings, rules, and rule packages from a file into a specific project. You can selectively import different types of settings. The `--force` option bypasses interactive prompts for applying changes. ```bash ./bin/console mosparo:import [--generalSettings|--no-generalSettings] [--designSettings|--no-designSettings] [--securitySettings|--no-securitySettings] [--rules|--no-rules] [--handlingExistingRules HANDLINGEXISTINGRULES] [--rulePackages|--no-rulePackages] [-f|--force] [--] ``` -------------------------------- ### Embed and Initialize mosparo JavaScript Widget Source: https://documentation.mosparo.io/docs/integration/custom Include the mosparo-frontend.js script and initialize the mosparo widget after the window has loaded. Replace placeholders like '', '', '', and '' with your actual project values. ```html ``` -------------------------------- ### Example check-form-data Response Source: https://documentation.mosparo.io/docs/api/frontend This is an example of a successful response from the check-form-data endpoint. The 'valid' property indicates if the data is considered spam, and 'validationToken' is used for further verification. ```json { "valid":true, "validationToken":"VXihNRK84O55IzHQD_G7aumyzDHOIiEZGnh1v2XyZJw" } ``` -------------------------------- ### Configure Production Environment Source: https://documentation.mosparo.io/docs/installation/install/source Create a `.env.local` file and set `APP_ENV` to `prod` to configure Mosparo for production use. ```dotenv APP_ENV=prod ``` -------------------------------- ### Initialize mosparo JavaScript Source: https://documentation.mosparo.io/docs/integration/custom Embed the mosparo script and initialize the mosparo class with your project details. ```APIDOC ## Embedding JavaScript Embed the mosparo script on your website. Then initialize mosparo with the code below. ```html ``` ### Parameters of the mosparo class Parameter| Type| Required| Description ---|---|---|--- ``| String| Required| HTML ID of the div container you inserted into your form. ``| String| Required| Host of your mosparo installation ``| String| Required| Unique identification number of the project in mosparo ``| String| Required| Public key of the project in mosparo ``| Object| Optional| Additional options ``` -------------------------------- ### Nginx Reverse Proxy Configuration for Subpath Installation Source: https://documentation.mosparo.io/docs/installation/configure/reverse_proxy Set up Nginx to proxy Mosparo when installed under a subpath. This configuration ensures correct header forwarding, including `X-Forwarded-Host` and `X-Forwarded-Prefix`. ```nginx server { listen 443 ssl http2; server_name [domain]; root /var/www/; index index.html index.htm index.php; # Reverse proxy configuration - Start location /app/ { rewrite /app/(.*) /$1 break; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto https; proxy_set_header X-Forwarded-Host $http_host; proxy_set_header X-Forwarded-Prefix /app; proxy_pass http://127.0.0.1:8080; } # Reverse proxy configuration - End [sslConfiguration] # Configure according to your needs } ``` -------------------------------- ### Checkout Latest Stable Version Source: https://documentation.mosparo.io/docs/installation/install/source Optional: Check out the tag of the latest stable version if you prefer not to use the development branch. Replace `[lastVersionTag]` with the actual tag name. ```bash git checkout tags/[lastVersionTag] ``` -------------------------------- ### API Response Example Source: https://documentation.mosparo.io/docs/api/rule_package This is a standard successful response from an API endpoint. It indicates that the operation was processed correctly. ```json { "result": true, "errors": [] } ``` -------------------------------- ### Initializing mosparo with Submit Token Source: https://documentation.mosparo.io/docs/integration/multi_step_forms Initialize mosparo in subsequent form steps using the submit token obtained from the first step. This ensures mosparo correctly validates the complete form data. ```javascript var m; var step = 1; var maxSteps = 3; window.onload = function(){ m = new mosparo('', '', '', '', { submitToken: '', }); }; ``` -------------------------------- ### Get Rule Items Source: https://documentation.mosparo.io/docs/api/rule_package Retrieve a list of rule items for a given rule within a rule package. Supports pagination. ```APIDOC ## GET /api/v1/rule-package/{id}/rules/{ruleId}/rule-items ### Description If you want to get the list of rule items in a rule, you can use this API endpoint. ### Authentication To secure the API endpoint, authentication is required. The `Authorization` header must be sent with the request. You must set the project's public key as the username in the header. An HMAC-SHA256 hash of the API endpoint URL, combined with the request data serialized as JSON, must be set as the password. The private key will be used as the HMAC-SHA256 key. ``` Authorization: [base64 of :] ``` ### Parameters #### Query Parameters - **page** (Integer) - Optional - Sets the page that you want to receive from this list. - **perPage** (Integer) - Optional - Tells the endpoint how many rule items you want to receive in one response. ### Response #### Success Response (200) - **result** (Boolean) - Returns `true` if the request is successful, or `false` if something went wrong. - **ruleItems** (Array) - The array contains all the rule items for this page (see Properties of `ruleItems`). - **page** (Integer) - Tells you which page you requested. - **totalPages** (Integer) - Tells you how many pages you can request. ##### Properties of `ruleItems` - **id** (Integer) - The ID of the rule item cache in mosparo. - **uuid** (Integer) - The UUID of this rule item, which was specified in the rule package. - **type** (String) - The type of the rule item, for example `word`. - **value** (String) - Contains the value of the rule item. - **rating** (Float) - Defines the rating of the rule item. #### Response Example ```json { "result": true, "ruleItems": [ { "id": 1552, "uuid": "2f51af01-eea7-4fe4-b7bb-5b41790b3a44", "type": "word", "value": "pills", "rating": 3.0 } ], "page": 1, "totalPages": 5 } ``` #### Error Response (205) If the rule package does not have a cache (the rule package was never loaded into mosparo), the response is a simple JSON object that looks as follows: ```json { "result": false, "noCache": true } ``` ``` -------------------------------- ### Update Mosparo Source: https://documentation.mosparo.io/docs/cli Initiates an interactive process to update Mosparo to its latest version. Use this command to keep your Mosparo installation up-to-date. ```bash ./bin/console mosparo:self-update ``` -------------------------------- ### Initialize mosparo with Callbacks and Listen to Events Source: https://documentation.mosparo.io/docs/integration/custom Initialize mosparo with various callback functions for different events and attach event listeners to specific DOM elements for custom event handling. This allows for fine-grained control over the validation process. ```javascript var m = mosparo('', '', '', '', { onBeforeGetFormData: function (formElement) { console.log('onBeforeGetFormData', formElement); }, onGetFieldValue: function (fieldElement, value) { console.log('onGetFieldValue', fieldElement, value); return value; }, onCheckForm: function (valid) { console.log('onCheckForm', valid); }, onResetState: function () { console.log('onResetState'); }, onAbortSubmit: function () { console.log('onAbortSubmit'); }, onSwitchToInvisible: function () { console.log('onSwitchToInvisible'); }, onValidateFormInvisible: function () { console.log('onValidateFormInvisible'); }, onSubmitFormInvisible: function () { console.log('onSubmitFormInvisible'); } }); document.getElementById('contact-form').addEventListener('before-get-form-data', function (ev) { console.log(ev); }); document.getElementById('name-field').addEventListener('before-get-field-value', function (ev) { console.log(ev); }); document.getElementById('contact-form').addEventListener('collect-request-data', function (ev) { m.metadata.randomNumber = Math.random(); }); document.getElementById('contact-form').addEventListener('form-checked', function (ev) { console.log(ev, ev.detail.valid); }); document.getElementById('contact-form').addEventListener('submit-aborted', function (ev) { console.log(ev); }); document.getElementById('contact-form').addEventListener('state-reseted', function (ev) { console.log(ev); }); document.getElementById('contact-form').addEventListener('switch-to-invisible', function (ev) { console.log(ev); }); document.getElementById('contact-form').addEventListener('validate-form-invisible', function (ev) { console.log(ev); }); document.getElementById('contact-form').addEventListener('submit-form-invisible', function (ev) { console.log(ev); }); ``` -------------------------------- ### IIS web.config for mosparo URL Rewriting Source: https://documentation.mosparo.io/docs/installation/configure/microsoft_iis Add this web.config file to the public directory of your mosparo installation to enable URL rewriting for IIS. ```xml ``` -------------------------------- ### Get Rules in Rule Package Source: https://documentation.mosparo.io/docs/api/rule_package Retrieves a list of all rules within a specified rule package. Supports pagination for large rule sets. ```APIDOC ## GET /api/v1/rule-package/{id}/rules ### Description Retrieves a list of all rules in the specified rule package. This endpoint supports pagination to manage large rule sets efficiently. ### Method GET ### Endpoint /api/v1/rule-package/{id}/rules ### Parameters #### Path Parameters - **id** (integer) - Required - The ID of the rule package. #### Query Parameters - **page** (integer) - Optional - Sets the page number for the list of rules. - **perPage** (integer) - Optional - Specifies the number of rules to return per page. ### Authentication Authentication is required using an `Authorization` header. The header value should be a base64 encoding of the project's public key and an HMAC-SHA256 hash of the API endpoint URL and request data, signed with the private key. ``` Authorization: [base64 of :] ``` ### Request Example ```json { "page": 1, "perPage": 1000 } ``` ### Response #### Success Response (200) - **result** (boolean) - Returns `true` if the request is successful, or `false` if an error occurred. - **rules** (array) - An array containing the rules for the requested page. Each rule object has the following properties: - **id** (integer) - The ID of the rule cache in mosparo. - **uuid** (integer) - The UUID of this rule, as specified in the rule package. - **type** (string) - The type of the rule (e.g., `word`). - **name** (string) - The name of the rule. - **description** (string) - The description of the rule. - **numberOfItems** (integer) - The number of items this rule contains. - **spamRatingFactor** (float) - The factor by which each rule item is multiplied if it matches. - **updatedAt** (string) - The timestamp when the rule cache was last updated (Format: `Y-m-d\TH:i:sP`). - **listRoute** (string) - The URL to fetch the rule items for this rule. - **page** (integer) - The requested page number. - **totalPages** (integer) - The total number of available pages. #### Response Example ```json { "result": true, "rules": [ { "id": 115, "uuid": "cf164449-ea85-4312-bec0-ae551de90891", "type": "word", "name": "Blocked words", "description": "", "numberOfItems": 143, "spamRatingFactor": 3.0, "updatedAt": "2026-05-01T12:00:00+00:00", "listRoute": "/api/v1/rule-package/1/rules/115/rule-items" } ], "page": 1, "totalPages": 5 } ``` #### Error Response (205) If the rule package does not have a cache (i.e., it was never loaded into mosparo): ```json { "result": false, "noCache": true } ``` ``` -------------------------------- ### Initialize mosparo with onGetFormData Callback Source: https://documentation.mosparo.io/docs/integration/multi_step_forms Initialize mosparo with the `onGetFormData` callback to handle data collection from multi-step forms. This callback allows you to merge data from different form steps before submission. ```javascript var m; window.onload = function(){ m = new mosparo('', '', '', '', { forceInvisible: true, // For all steps except the last one (if you want to use the visible mode) onGetFormData: function (form, formData) { // Now, depending on how your form works, you can replace or add your data to the form data from the last step: // IF you collect the data from all steps: formData.fields = yourFormData; formData.ignoredFields = yourIgnoredFields; // IF you let mosparo collect the form data from the last step, combine it with your data: //formData.fields = yourFormData.concat(formData.fields); //formData.ignoredFields = yourIgnoredFields.concat(formData.ignoredFields); return formData; }, }); }; ``` -------------------------------- ### Export Project Settings via CLI Source: https://documentation.mosparo.io/docs/usage/tools Use the CLI command to export project settings. Specify the project ID and optionally a file path to save the export. All settings are exported by default if not specified. ```bash php bin/console mosparo:export [] ``` -------------------------------- ### No Cache Response Example Source: https://documentation.mosparo.io/docs/api/rule_package This JSON object is returned when the rule package has not been loaded into mosparo and therefore has no cache. The HTTP status code for this response is 205. ```json { "result": false, "noCache": true } ```