Library written on PHP7 for generating XML files with configuration for WPKG installer.
composer require drteam/wpkg-php
Check links for more info about WPKG.
If you need Active Directory support for generation hosts.xml from domain PCs you can
look at WPKG-AD project, which based on this library.
Some examples with descriptions you can find here.
Configuration settings for runtime behavior of wpkg.js
Using the Config class, you can override the settings, if you specified a value different from the default value, your parameter will be added to the XML file.
If you do not specify anything, a configuration with default parameters will be generated.
$_config = new \WPKG\Config();
// Overwrite some attributes$_config
->with('wpkg_base', 'http://example.com')
->with('quitonerror', true)
->with('debug', true);
// Now we can set the variables$_config
->withVariable('PROG_FILES32', "%ProgramFiles%", null, "x86")
->withVariable('PROG_FILES32', "%ProgramFiles(x86)%", null, "x64")
->withVariable('DESKTOP', "%ALLUSERSPROFILE%\Desktop", "Windows xp")
->withVariable('DESKTOP', "%PUBLIC%\Desktop", "Windows 7");
// Show current variant of generated XMLecho$_config->show();Result of execution:
<?xml version="1.0" encoding="UTF-8"?>
<configxmlns:profiles="http://www.wpkg.org/config"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.wpkg.org/config xsd/config.xsd">
<languages>
... a lot of lines with translations ...
</languages>
<paramname="wpkg_base"value="http://example.com"/>
<paramname="quitonerror"value="true"/>
<paramname="debug"value="true"/>
<variables>
<variablename="PROG_FILES32"value="%ProgramFiles%"architecture="x86"/>
<variablename="PROG_FILES32"value="%ProgramFiles(x86)%"architecture="x64"/>
<variablename="DESKTOP"value="%ALLUSERSPROFILE%\Desktop"os="Windows xp"/>
<variablename="DESKTOP"value="%PUBLIC%\Desktop"os="Windows 7"/>
</variables>
</config>At the moment, translations (creators of the WPKG project call them languages) are available for the following languages:
- English
- French
- German
- Italian
- Russian (added by me)
- Spanish
Translations was taken from the config.xml file that was in the wpkg-1.3.1-bin.zip archive from the official website of the WPKG project.
All available translations of wpkg-php you can find here.
If you do not see your language on the list and want to help the project, then you can suggest your translation variant via issues or PR. Pay attention to LCID, these are unique language identifiers, a complete list of them you can find here.
Mappings between machine names and profile names.
If you want generate few hosts in separated files:
// Root container$_host = new \WPKG\Host();
// Need to add some parameters$_host
->with('name', 'host1')
->with('profile-id', 'profile1');
echo$_host->show();Result is:
<?xml version="1.0" encoding="UTF-8"?>
<hosts:wpkgxmlns:hosts="http://www.wpkg.org/hosts"xmlns:wpkg="http://www.wpkg.org/wpkg"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.wpkg.org/hosts xsd/hosts.xsd">
<hostname="host1"profile-id="profile1"/>
</hosts:wpkg>You also can set array of profiles:
// Root container$_host = new \WPKG\Host();
// Need to add some parameters$_host
->with('name', 'host1')
->with('profile-id', ['profile1', 'profile2', 'profile3']);
echo$_host->show();And in result must be:
<hosts:wpkgxmlns:hosts="http://www.wpkg.org/hosts"xmlns:wpkg="http://www.wpkg.org/wpkg"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.wpkg.org/hosts xsd/hosts.xsd">
<hostname="host1"profile-id="profile1">
<profileprofile-id="profile2"/>
<profileprofile-id="profile3"/>
</host>
</hosts:wpkg>If you need one large file with all your hosts:
// Root container$_hosts = newHosts();
/** * Test host #1 */$host1 = newHost();
$host1
->with('name', 'host1')
->with('profile-id', 'profile1');
$_hosts->setHost($host1);
/** * Test host #2 */$host2 = newHost();
$host2
->with('name', 'host2')
->with('profile-id', ['profile1', 'profile2', 'profile3']);
$_hosts->setHost($host2);
/** * Test host #3 */$host3 = newHost();
$host3
->with('name', 'host3')
->with('profile-id', 'profile3');
$_hosts->setHost($host3);
echo$_hosts->show();Result file hosts.xml into the wpkg_path folder
<?xml version="1.0" encoding="UTF-8"?>
<hosts:wpkgxmlns:hosts="http://www.wpkg.org/hosts"xmlns:wpkg="http://www.wpkg.org/wpkg"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.wpkg.org/hosts xsd/hosts.xsd">
<hostname="host1"profile-id="profile1"/>
<hostname="host2"profile-id="profile1">
<profileprofile-id="profile2"/>
<profileprofile-id="profile3"/>
</host>
<hostname="host3"profile-id="profile3"/>
</hosts:wpkg>This class based on adLdap library, so you can use any configuration parameters from this library.
Basic usage:
use \WPKG\Drivers\ADImport;
// Read AD configuration$_config = include__DIR__ . '/adldap.php';
// Set Import object for work and put configuration inside$_import = newADImport($_config);
// You also can set config via specific method//$_import->setConfig($_config);// Choose work mode (only hosts available) and output the XML$_hosts = $_import->import('hosts');
$out = $_hosts->show();
print_r($out);You should saw something like this:
<?xml version="1.0" encoding="UTF-8"?>
<hosts:wpkgxmlns:hosts="http://www.wpkg.org/hosts"xmlns:wpkg="http://www.wpkg.org/wpkg"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.wpkg.org/hosts xsd/hosts.xsd">
<hostname="user1.example.com"profile-id="default"/>
<hostname="user2.example.com"profile-id="default"/>
<hostname="user3.example.com"profile-id="default"/>
</hosts:wpkg>Specifies which packages will be installed/executed for each WPKG profile.
If you want generate few profiles in separated files:
useWPKG\Profile;
$_profile = new \WPKG\Profile();
$_profile
->with('id', 'profile1')
->with('packages', 'DotNet')
->with('depends', 'profile2');
// Show current variant of generated configecho$_profile->show();Result file (with name like .xml, eg profile1.xml like in current example) you can find into the wpkg_path/profiles/ subfolder:
<?xml version="1.0" encoding="UTF-8"?>
<profiles:profilesxmlns:profiles="http://www.wpkg.org/profiles"xmlns:wpkg="http://www.wpkg.org/wpkg"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.wpkg.org/profiles xsd/profiles.xsd">
<profileid="profile1">
<dependsprofile-id="profile2"/>
<packagepackage-id="DotNet"/>
</profile>
</profiles:profiles>You as in hosts also can set array of packages or depends.
If you need one large file with all your profiles:
$_profiles = new \WPKG\Profiles();
/** * Test profile #1 */$pr1 = newProfile();
$pr1->with('id', 'profile1');
$_profiles->setProfile($pr1);
/** * Test profile #2 */$pr2 = newProfile();
$pr2->with('id', 'profile2')
->with('packages', 'DotNet');
$_profiles->setProfile($pr2);
/** * Test profile #3 */$pr3 = newProfile();
$pr3->with('id', 'profile3')
->with('packages', ['Firefox', 'Chromium', 'Opera'])
->with('depends', 'profile1');
$_profiles->setProfile($pr3);
/** * Test profile #4 */$pr4 = newProfile();
$pr4->with('id', 'profile4')
->with('packages', ['SuperBank', 'AnotherBank'])
->with('depends', ['profile1', 'profile2']);
$_profiles->setProfile($pr4);
/** * Test profile #5 */$pr5 = newProfile();
$pr5->with('id', 'profile5')
->with('depends', 'profile3');
$_profiles->setProfile($pr5);
// Show current variant of generated configecho$_profiles->show();Result:
<?xml version="1.0" encoding="UTF-8"?>
<profiles:profilesxmlns:profiles="http://www.wpkg.org/profiles"xmlns:wpkg="http://www.wpkg.org/wpkg"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.wpkg.org/profiles xsd/profiles.xsd">
<profileid="profile1"/>
<profileid="profile2">
<packagepackage-id="DotNet"/>
</profile>
<profileid="profile3">
<dependsprofile-id="profile1"/>
<packagepackage-id="Firefox"/>
<packagepackage-id="Chromium"/>
<packagepackage-id="Opera"/>
</profile>
<profileid="profile4">
<dependsprofile-id="profile1"/>
<dependsprofile-id="profile2"/>
<packagepackage-id="SuperBank"/>
<packagepackage-id="AnotherBank"/>
</profile>
<profileid="profile5">
<dependsprofile-id="profile3"/>
</profile>
</profiles:profiles>Defines software packages (commands for WPKG to install/uninstall programs, etc.)
If you want generate few packages in separated files:
use \WPKG\Package;
use \WPKG\PackageCheckExits;
$_package = newPackage();
$_exits = newPackageCheckExits();
// Overwrite the attributes of tha class$_package
->with('id', 'wpkg1')
->with('name', 'Windows Packager sample 1')
->with('revision', 1)
->with('priority', 0)
->with('reboot', 'false');
// Small check for Windows 7$_package
->withCheck('registry', 'exists', 'HKLM\Software\wpkg\full\key\not\part\of\it')
->withCheck('file', 'exists', 'C:\wpkg\wpkg.bat')
->withCheck('uninstall', 'exists', 'WPKG 0.6-test1');
// Add few variables to package config$_package
->withVariable('PROG_FILES32', "%ProgramFiles(x86)%", null, "x64")
->withVariable('DESKTOP', "%ALLUSERSPROFILE%\Desktop", "Windows xp");
// We need set exit codes for some installation stages$_exits
->add(0)
->add(3010, true)
->add('any')
->add(2);
// Run command$_package
->withCommand('install', 'msiexec /i /qn "%SOFTWARE%\path\to\msi"', 'test', $_exits)
->withCommand('remove', 'msiexec /x /qn "%SOFTWARE%\path\to\msi"')
->withCommand('upgrade', 'msiexec /i /qn "%SOFTWARE%\path\to\msi"')
->withCommand('downgrade', null, 'remove')
->withCommand('downgrade', null, 'install');
echo$_package->show();Result:
<?xml version="1.0" encoding="UTF-8"?>
<packages:packagesxmlns:packages="http://www.wpkg.org/packages"xmlns:wpkg="http://www.wpkg.org/wpkg"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.wpkg.org/packages xsd/packages.xsd">
<packageid="wpkg1"name="Windows Packager sample 1"revision="1"priority="0"reboot="false">
<checktype="registry"condition="exists"path="HKLM\Software\wpkg\full\key\not\part\of\it"/>
<checktype="file"condition="exists"path="C:\wpkg\wpkg.bat"/>
<checktype="uninstall"condition="exists"path="WPKG 0.6-test1"/>
<variablename="PROG_FILES32"value="%ProgramFiles(x86)%"architecture="x64"/>
<variablename="DESKTOP"value="%ALLUSERSPROFILE%\Desktop"os="Windows xp"/>
<commands>
<commandtype="install"cmd='msiexec /i /qn "%SOFTWARE%\path\to\msi"'include="test">
<exitcode="0"/>
<exitcode="3010"reboot="true"/>
<exitcode="any"/>
<exitcode="2"/>
</command>
<commandtype="remove"cmd='msiexec /x /qn "%SOFTWARE%\path\to\msi"'/>
<commandtype="upgrade"cmd='msiexec /i /qn "%SOFTWARE%\path\to\msi"'/>
<commandtype="downgrade"include="remove"/>
<commandtype="downgrade"include="install"/>
</commands>
</package>
</packages:packages>If you need one large file with all your packages:
use \WPKG\Package;
use \WPKG\PackageCheckExits;
use \WPKG\Packages;
// Root container$_packages = newPackages();
/** * Test package #1 */$pk1 = newPackage();
$pk1->with('id', 'time')
->with('name', 'Time Synchronization')
->with('priority', 100)
->with('execute', 'always')
->withCheck('host', 'os', 'windows 7')
->withCommand('install', 'net time \\timeserver /set /yes');
$_packages->setPackage($pk1);
/** * Test package #2 */$pk2 = newPackage();
$pk2_exits = newPackageCheckExits();
// We need set exit codes for some installation stages$pk2_exits
->add(0)
->add(3010, true)
->add('any')
->add(2);
$pk2->with('id', 'wpkg')
->with('name', 'Windows Packager sample 1')
->with('revision', 1)
->with('priority', 0)
->with('reboot', 'false')
->withCheck('registry', 'exists', 'HKLM\Software\wpkg\full\key\not\part\of\it')
->withCheck('file', 'exists', 'C:\wpkg\wpkg.bat')
->withCheck('uninstall', 'exists', 'WPKG 0.6-test1')
->withCommand('install', 'msiexec /i /qn "%SOFTWARE%\path\to\msi"', 'test', $pk2_exits)
->withCommand('remove', 'msiexec /x /qn "%SOFTWARE%\path\to\msi"')
->withCommand('upgrade', 'msiexec /i /qn "%SOFTWARE%\path\to\msi"')
->withCommand('downgrade', null, 'remove')
->withCommand('downgrade', null, 'install');
$_packages->setPackage($pk2);
/** * Test package #3 */$pk3 = newPackage();
$pk3->with('id', 'time3')
->with('name', 'Time Synchronization')
->with('priority', 100)
->with('execute', 'always')
->withCheck('host', 'os', 'windows 7')
->withCommand('install', 'net time \\timeserver /set /yes');
$_packages->setPackage($pk3);
echo$_packages->show();Result:
<?xml version="1.0" encoding="UTF-8"?>
<packages:packagesxmlns:packages="http://www.wpkg.org/packages"xmlns:wpkg="http://www.wpkg.org/wpkg"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.wpkg.org/packages xsd/packages.xsd">
<packageid="time"name="Time Synchronization"priority="100"execute="always">
<checktype="host"condition="os"path="windows 7"/>
<commands>
<commandtype="install"cmd="net time \timeserver /set /yes"/>
</commands>
</package>
<packageid="wpkg"name="Windows Packager sample 1"revision="1"priority="0"reboot="false">
<checktype="registry"condition="exists"path="HKLM\Software\wpkg\full\key\not\part\of\it"/>
<checktype="file"condition="exists"path="C:\wpkg\wpkg.bat"/>
<checktype="uninstall"condition="exists"path="WPKG 0.6-test1"/>
<commands>
<commandtype="install"cmd="msiexec /i /qn "%SOFTWARE%\path\to\msi""include="test">
<exitcode="0"/>
<exitcode="3010"reboot="true"/>
<exitcode="any"/>
<exitcode="2"/>
</command>
<commandtype="remove"cmd="msiexec /x /qn "%SOFTWARE%\path\to\msi""/>
<commandtype="upgrade"cmd="msiexec /i /qn "%SOFTWARE%\path\to\msi""/>
<commandtype="downgrade"include="remove"/>
<commandtype="downgrade"include="install"/>
</commands>
</package>
<packageid="time3"name="Time Synchronization"priority="100"execute="always">
<checktype="host"condition="os"path="windows 7"/>
<commands>
<commandtype="install"cmd="net time \timeserver /set /yes"/>
</commands>
</package>
</packages:packages>First you need enable the importer class
use \WPKG\Drivers\XMLImport;
// Create new object$_import = newXMLImport();
// Content of hosts file$_hosts_file = file_get_contents('config.xml');
// Read and parse file to normal format$_hosts = $_import->import($_hosts_file);
// Print array to stdOutprint_r($_hosts);Now inside $_hosts variable you can find the \WPKG\Hosts object with all hosts which was imported.
Same operation for all other configurations, library can check which config you are loaded.
- Discord - Join us on Discord.
- GitHub Issues - Got issues? Please tell us!
- Roadmap - Want to contribute? Get involved!
- Main the WPKG website - https://wpkg.org/
- WPKG documentation page - https://wpkg.org/Documentation
- Article on Wikipedia - https://en.wikipedia.org/wiki/WPKG_(software)
