Knowledge Base

Integration with Silktide

Last Modified:
11 Nov 2024
User Level:
Administrator +

Silktide, a platform for website auditing, offers the ability to provide detailed reports for each web page that was found during its scan of the website. The tool is set up to periodically re-scan pages and provide updated information. Rather than wait for the automated scan, updated pages can be sent directly to the Silktide API endpoint, allowing Sliktide to re-scan them immediately. The following article explains how to configure that integration between a Terminalfour site and the SilkTide API.

How it works

A PHP script placed on the Terminalfour server, is triggered periodically using a cron job. It identifies the list of published files that were updated in the last publish and sends them to the Silktide API. The configuration of this script is done via Terminalfour where the web developer can decide to turn on and off the functionality or determine the defer time for the re-scan.

Features

  • The script will send the information in batches of 1000 URLs by default
  • The script will run once per publish time; a check is in place to ensure that it does not run twice
  • The script can configure the following information:
    • the number of seconds to wait before asking Silktide to rescan the page (allowing a transfer of the files to run to the webserver, if required)
    • the number of files to send in each batch
    • the delay in seconds between batches
  • If the script fails, it will pick up all the missing URLs and send them to Silktide the next time it runs successfully
  • If the local report does not save for any reason, and the script could not get the latest time when it was run, it will check all URLs within the last 2 hours
  • The script has the ability to be disabled at any time by the web developer

Requirements

SilkTide API

Terminalfour

  • Version: 8.3+

Server

  • PHP 7.2+
  • PHP extension: cURL
  • Requires time-based job scheduler (Cron for Unix) - it can be set up on one of the web servers but it may be preferable on the Terminalfour server.

Installation Guide

The following installation guide will explain how to set up the Integration. It is divided into steps to step through the process.

Before you start

Before we can start on the installation please ensure that:

Installing the required files

Firstly, the required files will be added:

  1. Unzip the installation files downloaded. The zip contains 2 folders, content-types and media-library. We are going to focus on the media-library one for now.
  2. The media-library files contains 4 files. If you do not already have a Media Type that handles PHP, JSON and PHAR, it will need to be created, or modify an existing one to include those extentions.
  3. The Media Type will require a specific Media Layout that will only output the path to the file (e.g. path/*). If this does not exist, create it as follows:
    1. Go to Assets > Content Types and select Media Content Type
    2. Go to the Content Layouts tab and ensure that path/* exists or otherwise create it as follow:
      1. Name: path/*
      2. File Extensions: Default
      3. Syntax type: HTML/XML
      4. Content layout processor: T4 Standard Content
      5. Content Layout Code:
        <t4 type="content" name="Media" output="file" modifiers="" />
        
      6. Save it
  4. Next, we will add the files to the Media Library.
  5. Add a new media category or select a pre-existing one as you wish
  6. Add the 4 files as media files:
    1. utils.js: We will see this later on it will be used as part of the programmable layout that publish out the correct config information
    2. silktide-integration.phar: is PHP Archive that contains all the logic of the code
    3. run.php the script responsible for sending the information.
    4. config.json the file that helps to configure the information
  7. Once the files are in the Media Library, make a note of the Media ID of each file as they are used later, when configuring the code
  8. After that we need to ensure that they get published otherwise the script will not work.  Create a Code content item in a hidden page of the site that contains the Media T4 Tag for each file.
  9. Publish the channel.

Once this has been completed, the files should all be published within the Channel's Output Directory.

To ensure that everything so far is working as intended, manually run a publish. If all steps are working correctly you should be able to navigate to the hidden page you created, that will contain the links/paths to the required files. They will be something similar to:

/media-library/categorised/[your-folder-path]/

Please ensure to note done the exact folder (where in the code block above is specified as [your-folder-path].

  • You should see the above path
  • You should have noted down the 4 Media IDs of the 4 files uploaded
  • You should have noted down the Channel Output Directory
  • You should have noted down the [your-folder-path] that appeared during the publish report

After publishing out and everything works as expected we can continue to set up the rest of the website. Please proceed as follow:

  1. The first thing we are going to set up the config.json properly, to do so Go to Section Metadata Content to create a new element called "Disable Silktide Integration". 
  2. First we need to run a SQL query to make sure the Section Metadata Content type is not a system content type. Please see Edit a Section Meta Data Content type.
  3. Once the Section Meta Data is a normal content type, you need to ensure you have a list called Yes or if you don't have it create a new one by going to Assets > Lists
    1. Name: Yes
    2. List Items: Yes
      1. Name: Yes
      2. Value: yes
      3. Selected: unchecked
      4. Sublist: None
  4. Once you have the list we can used in the new element we need to add inside the Section Metadata Content Type, Go to Assets > Content Types and select the Section Metadata Content type (usually called Section Meta Description):
    1. Name: "Disable Silktide Integration" 
    2. Description: "Check if you want to disable the Silktide Integration (the check should be valid only on the Home)"
    3. Type: Checkbox, List: Yes
    4. Use as filename: false
    5. Required: false
  5. Once saved the element you can reset it back as System Content Type following the same documentation above
  6. After create a new element we need to add the 2 new content layouts to it, Go back to Assets > Content Types and select again the Section Metadata Content type, this time going to Content layouts
  7. Add the following content layout that is responsible to provide the value of the element just added
    1. Name: text/silktide-flag
    2. File Extensions: Default
    3. Syntax type: HTML/XML
    4. Content layout processor: T4 Standard Content
    5. Content Layout Code: 

      <t4 type="content" name="Disable Silktide Integration" output="normal" display_field="value" />
    6. Save it. 
  8. Add another content layout, that will be used to set up the config.json information:
    1. Name: text/silktide-config-json
    2. File Extensions: Default
    3. Syntax type: Javascript
    4. Content layout processor: Javascript Content
    5. Content Layout Code: Please copy the content of the file placed inside the installation file zip under /content-types/section-meta-description/text-silktode-config-json.js

    6. Before saving in the code just copied replace at line 19 
      <!-- INSERT SILKTIDE TOKEN -->
       with the SilkTide API Token (see Before you start paragraph) and 
      <!-- INSERT ID-->
        with the utils.js Media ID just created at point 12.a in the previous paragraph.
    7. Save it.
  9. Once we have the content layout for the config.js we need a navigation object that retrieve its content and we can place it in the config.json media file added previously. Therefore go to Assets > Navigation.
  10. And create 2 new navigation objects, for both content layouts just created.
    1. Navigation Type: Related Content
    2. Name: Silktide Integration: get SilkTide Config JSON for Current Channel
    3. Description: Returns text/silktide-config-json from Section Meta Description
    4. Primary Group: Global
    5. Options: [x] Show pending content in preview and [x] Cache output
    6. Output title: leave blank
    7. Fetch Method: Use Section
    8. Section: Please select the Home section of your channel
    9. Content layout: Use alternate content layout
    10. Alternate content layout: text/silktide-config-json
    11. Before HTML: leave blank
    12. After HTML: leave blank
    13. Save changes
    14. Build the t4 tag for this navigation object and save it in a notepad file for later
  11. Now we need the second navigation object for the Disable Silktide Integration with the following attributes:
    1. Navigation Type: Related Content
    2. Name: Silktide Integration: get Flag
    3. Description: Returns text/silktide-flag from Section Meta Description
    4. Primary Group: Global
    5. Options: [x] Show pending content in preview and [x] Cache output
    6. Output title: leave blank
    7. Fetch Method: Use Section
    8. Section: Please select the Home section of your channel
    9. Content layout: Use alternate content layout
    10. Alternate content layout: text/silktide-flag 
    11. Before HTML: leave blank
    12. After HTML: leave blank
    13. Save changes
    14. Build the t4 tag for this navigation object and save it in a notepad file for later
  12. Once we have the 2 navigation object we can finish up to set up the Media Files with all references
  13. Go to Content > Media Library and select config.json
  14. Edit config.json, editor tab replace all content with the new t4 tag created at point 10, and save it
  15. Edit run.php, go to the editor tab and for $config['config'] replace 
    <!-- INSERT ID -->
    with the config.json Media ID and $config['library'] replace 
    <!-- INSERT ID -->
    with silktide-integration.phar Media ID, and $config['disable'] with the navigation t4 tag created at point 11
  16. Save it all
  17. Publish out the results

If everything works as expected you should see a functional PHP script that returns a JSON format and display the Report of the transaction made at a URL like https://www.[yourdomain]/media/[your-folder-path]/run.php.

After this the only outstanding issue is to ensure to add a schedule task on the Terminalfour Application server or one of the web servers that points to server location of the above script [Channel Output Directory]/media/[your-folder-path]/run.php 

After that is done the Integration should be in place and working correctly.

Read the report

The script added can be triggered manually by going directly to the URL and it will run the script and publish the report that will look like something similar to

{
    message: "WARNING: No new URL found",
    report: {
        time: 1606836659,
        successfulTime: 1606842343,
        error: false,
        requests: [ ]
    }
}

The message visible can be different depending on the work done by the script here to summarise all different status.

The format is in JSON

  • message: will show the result action done for the manual run just reported
  • report: contains the latest report that runs
  • report.time: Timestamp when the latest report performed.
  • report.successfulTime: The timestamp of last time where the report was successful 
  • error: if there script run in any error
  • requests: the requested information performed to the SikTide API

How to read the message

Message Description
WARNING: No new URL found

The script run correctly but did not find any new URL to publish.
The report shows the current empty report with no request in it

WARNING: Script already executed for the last publish, please publish again to process a new request. The script was already run for the latest publish, therefore the script does not run it twice and a message its shown.
The report shown is the previous successful report.
SUCCESS: Sent request to SilkTide

The script run correctly and did found the URLs to send.
The report will contains the URLs sent to SilkTide.

ERROR: Issue during HTTP Request to SilkTide

Shown when an error occurred. It is possible that that for example SilkTide API Token is incorrect or the script was not able to send to SilkTide the requests.
The report will show the report the current report with the error found.

Temporarily Disable the Script

It is possible to temporarily disable the script, if needed. In this case both a manual trigger or the scheduled one will not perform any action and no request will be sent to SilkTide.

  1. Go to Site Structure and edit Home section
  2. In the Advanced Section Information, check "Disable Silktide Integration"
  3. Publish Section

This will disable the script and not allows it run until the flag is unchecked again and its change is not published out.

Change the config file

Another thing that maybe it is needed is to change the setting of the config.json file. To change this:

  1. Go to Assets > Content Type
  2. Edit the Section Metadata content type
  3. Go to Content Layouts tab
  4. Select text/silktide-config-json
  5. In Content Layout Code it is possible to change the following variables
    1. silkTideApiURL = 'https://api.silktide.com/cms/update' (the SilkTide API Endpoint)
    2. silkTideApiKey = '<!-- INSERT SILKTIDE TOKEN →' (the SilkTide API Token) 
    3. silkTideDeferSec = 1800 (the number of seconds to wait before SilkTide will retest the URLs sent)
    4. bulkLimit = 1000 (the number of URLs sent in batches)
    5. delayInSeconds = 0 (the number of seconds to wait before each HTTP Request batches)
    6. basePage = 'index.php' (the basename to remove used as channel default)
  6. Once the variables are changed Save the content layout.
  7. And perform a Publish section of the Home to ensure that the new settings are applied
  8. Please ensure to manually trigger the script to ensure that the change took place
Back to top