-
Notifications
You must be signed in to change notification settings - Fork 24
MODS Package Capture
This Package contains one 'WebApp' which can Capture a Package and download it after its installation on your Synology. This can be useful if you want to study how an SPK is done, or modify it, but can't download it from its SPK server.
Use this package at your own risk !
Find the source code here
This Package is based on findings published here and updated here.
Before its installation, a SPK is downloaded into /volume[i]/@tmp/@synopkg/@download/ and named @SYNOPKG_DOWNLOAD_[PackageName]. [i] is probably always 1 but, just in case the @tmp folder is on another volume, 'MODS Package Capture' will search for all @tmp existing on a volume between 1 and 12. Notice that @SYNOPKG_DOWNLOAD_[PackageName] has not extension ".spk".
Once downloaded, the DSM expands @SYNOPKG_DOWNLOAD_[PackageName] into /volume[i]/@tmp/pkginstall/. This version of 'MODS Capture Package' does not capture that.
As soon as expanded, @SYNOPKG_DOWNLOAD_[PackageName] is deleted (and as soon as installed, the expanded files are also deleted). For that reason, 'MODS Capture Package' loops until it find the file @SYNOPKG_DOWNLOAD_* and copy it (hard link) into a new folder "/volume[i]/@tmp/SynoCapture/". An hard link is created so it's immediate and the file is not removed when the DSM deletes it.
Finally 'MODS Capture Package' download locally the file @SYNOPKG_DOWNLOAD_[PackageName] renamed into [PackageName].spk
'MODS Capture Package' is a 'WebApp' running in a DSM iframe (I.e.: a set of html and/or php pages). It uses the 'router.cgi' trick described here to not depend on the 'Init_3rdparty' Package usually required to run a 'WebApp' from the DSM.
'MODS Capture Package' has only two php pages:
- services.php: it is the back end part, running shell scripts to do the actual capture.
- index.php: it is the front end, based on Jquery and doing ajax calls to the back end.
The front end displays:
- a listbox with the various volumes where a @tmp folder exists and
- a link to trigger the capture.
- a link to recover (=download) the package that was possibly captured but couldn't be deleted for any reason.
Once you click on the link to trigger the capture, the front end calls a back end service to do the capture and display a modal popup message, waiting for the spk to be downloaded. If you close that popup, the front end will call again the back to cancel the capture.
As soon as you have clicked on the link, you must go to the DSM Package Center and install the package that you want to capture.
Once the capture is completed server side, the download starts and the modal popup is closed.
The download is based on the jquery plugin of John Culviner.
The back end offers three services: one to start the capture, one to cancel it and one to (re)download the last captured spk.
Cancel
When the service is called to cancel the capture, it simply creates two files named 'stop' and 'cancel' into the folder folder/volume[i]/@tmp/SynoCapture/
Capture
When the service is called to capture a package during its installation, it runs in the background a shell script which loops until file named 'stop' is found in the folder/volume[i]/@tmp/SynoCapture/
During that loop, the shell script creates a hard copy of any file found in /volume[i]/@tmp/@synopkg/@download/ I know this is a bit brute force but, sometimes, the SPK is deleted so quickly that I had to implement something very study simple and fast. That's why I kept a shell script to do it instead of a php procedure.
During the loop of the shell script, run in the background, the service also loops, during maximum 2 minutes, and monitor the folder /volume[i]/@tmp/SynoCapture/.
- If it finds a file named like @SYNOPKG_DOWNLOAD_* it creates two files: one named 'stop' and one named 'found' in /volume[i]/@tmp/SynoCapture/
- If it does not find such a file within the given timeframe, it creates two files: one named 'stop' and one named 'cancelled' in /volume[i]/@tmp/SynoCapture/
As soon as a file 'stop' is found by the shell script (possibly created by a 'Cancel'), this one ends its own loop and rename the file @SYNOPKG_DOWNLOAD_[PackageName] into @SYNOPKG_DOWNLOAD_[PackageName].spk
As soon as a file 'stop' is found by the the service, it also ends its monitoring loop and checks if the is also a file 'found' (or 'cancel').
- If a file 'found' exists, the service will rename @SYNOPKG_DOWNLOAD_[PackageName].spk into [PackageName].spk, read it and return it with a 'File Transfer' HTTP Header.
- Otherwise, the service will return an "error".
This Package has been generated with 'Mods Packager'. It illustrates how an application based on php and shell scripts can be run on Synology, in a DSM iframe.
When used within a DSM access via https, the download of the captured package can failed with an error ERR_HTTP2_PROTOCOL_ERROR. In such a case, you can use the link to recover the package. The problem is usually due to the option "enable HTTP/2" in the Control Panel > Network > DSM Settings.