@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
use App\Services\RequisitionExpiry;
|
||||
use App\Services\StandaloneRuntime;
|
||||
use Illuminate\Contracts\Console\Kernel;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
require dirname(__DIR__).'/vendor/autoload.php';
|
||||
$root = dirname(__DIR__);
|
||||
$check = in_array('--check', $argv, true);
|
||||
$once = in_array('--once', $argv, true);
|
||||
if ($check === $once) {
|
||||
throw new LogicException('Choose read-only check or explicitly authorised single passage.');
|
||||
}
|
||||
$planPath = $root.'/docs/proofs/approval-deadlines-task-proposal.json';
|
||||
$plan = json_decode(file_get_contents($planPath), true, 32, JSON_THROW_ON_ERROR);
|
||||
$source = json_decode(file_get_contents('C:/laragon/data/sgf-tempo/secrets/payables-demo-compras.json'), true, 32, JSON_THROW_ON_ERROR);
|
||||
if ($source['APP_ENV'] !== 'payable-testing' || $source['DB_HOST'] !== '127.0.0.1'
|
||||
|| realpath($source['HOST_ROOT']) !== realpath($root)
|
||||
|| ! preg_match('/^compras_receipts_test_([a-f0-9]{12})$/D', $source['DB_DATABASE'], $match)
|
||||
|| $source['DB_USERNAME'] !== 'payable_qa_'.$match[1]
|
||||
|| ($source['COMPRAS_RUNTIME_ENABLED'] ?? null) !== 'true'
|
||||
|| $source['COMPRAS_RUNTIME_INSTALLATION_ID'] !== $plan['installation_id']) {
|
||||
throw new LogicException('Approval deadline evaluation target mismatch.');
|
||||
}
|
||||
if ($once) {
|
||||
$approvalPath = $root.'/docs/proofs/approval-deadlines-task-authorization.json';
|
||||
$approval = is_file($approvalPath) ? json_decode(file_get_contents($approvalPath), true, 32, JSON_THROW_ON_ERROR) : [];
|
||||
if (($approval['state'] ?? null) !== 'approved' || ($approval['scope'] ?? null) !== 'existing_pilot_approval_deadline_task'
|
||||
|| ! hash_equals($approval['proposal_sha256'], hash_file('sha256', $planPath))) {
|
||||
throw new LogicException('APPROVAL_DEADLINE_TASK_NOT_AUTHORIZED');
|
||||
}
|
||||
}
|
||||
foreach ([...$source, 'CACHE_STORE' => $check ? 'array' : ($source['CACHE_STORE'] ?? 'file'),
|
||||
'PGOPTIONS' => $check ? '-c default_transaction_read_only=on' : '', 'DB_CONNECTION' => 'pgsql', 'DB_URL' => '',
|
||||
'LOG_CHANNEL' => 'stderr'] as $key => $value) {
|
||||
putenv($key.'='.$value);
|
||||
$_ENV[$key] = $_SERVER[$key] = $value;
|
||||
}
|
||||
$app = require $root.'/bootstrap/app.php';
|
||||
$app->make(Kernel::class)->bootstrap();
|
||||
app(StandaloneRuntime::class)->assertLoadedPackages();
|
||||
if (! app(RequisitionExpiry::class)->ready()) {
|
||||
throw new LogicException('Approval deadline capability unavailable.');
|
||||
}
|
||||
if ($check) {
|
||||
if (DB::selectOne('SHOW default_transaction_read_only')->default_transaction_read_only !== 'on') {
|
||||
throw new LogicException('Deadline task preflight must be read-only.');
|
||||
}
|
||||
echo json_encode(['state' => 'ready', 'database_enforced_read_only' => true, 'installation_verified' => true,
|
||||
'pending_requests_with_configured_cycle_policy' => DB::table('requisitions')->where('status', 'pending')->whereNotNull('approval_snapshot->approval_expiry')->count(),
|
||||
'business_commands' => false, 'task_installed_or_started' => false], JSON_THROW_ON_ERROR).PHP_EOL;
|
||||
exit;
|
||||
}
|
||||
$lock = fopen($root.'/storage/framework/approval-deadlines-evaluation.lock', 'c');
|
||||
if ($lock === false) {
|
||||
throw new RuntimeException('Deadline task lock unavailable.');
|
||||
}
|
||||
if (! flock($lock, LOCK_EX | LOCK_NB)) {
|
||||
fclose($lock);
|
||||
exit(0);
|
||||
}
|
||||
$status = ['started_at' => gmdate('c'), 'result' => 'running', 'scope' => 'Compras pilot 8005 approval deadlines'];
|
||||
$statusPath = $root.'/storage/framework/approval-deadlines-status.json';
|
||||
$save = static function (array $state) use ($statusPath): void {
|
||||
$temporary = $statusPath.'.'.bin2hex(random_bytes(4)).'.tmp';
|
||||
file_put_contents($temporary, json_encode($state, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR));
|
||||
if (! rename($temporary, $statusPath)) {
|
||||
throw new RuntimeException('Deadline task status unavailable.');
|
||||
}
|
||||
};
|
||||
try {
|
||||
$save($status);
|
||||
$exitCode = Artisan::call('sgc:approval-deadlines-tick');
|
||||
$status += ['finished_at' => gmdate('c'), 'exit_code' => $exitCode];
|
||||
$status['result'] = $exitCode === 0 ? 'passed' : 'retry_pending';
|
||||
$save($status);
|
||||
} finally {
|
||||
flock($lock, LOCK_UN);
|
||||
fclose($lock);
|
||||
}
|
||||
echo json_encode($status, JSON_THROW_ON_ERROR).PHP_EOL;
|
||||
exit($exitCode);
|
||||
@@ -5,14 +5,26 @@ use Illuminate\Contracts\Console\Kernel;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
require dirname(__DIR__).'/vendor/autoload.php';
|
||||
if (! in_array('--read-only', $argv, true)) {
|
||||
$installed = in_array('--installed-read-only', $argv, true);
|
||||
if (! in_array('--read-only', $argv, true) && ! $installed) {
|
||||
throw new LogicException('READ_ONLY_ACTIVATION_PREFLIGHT_REQUIRED');
|
||||
}
|
||||
$root = dirname(__DIR__);
|
||||
$plan = json_decode(file_get_contents($root.'/docs/proofs/compras-standalone-pilot-activation-proposal.json'), true, 512, JSON_THROW_ON_ERROR);
|
||||
$sourcePath = 'C:/laragon/data/sgf-tempo/secrets/payables-demo-compras.json';
|
||||
$source = json_decode(file_get_contents($sourcePath), true, 32, JSON_THROW_ON_ERROR);
|
||||
if (! hash_equals($plan['active_settings_sha256'], hash_file('sha256', $sourcePath))
|
||||
$expectedSettings = $plan['active_settings_sha256'];
|
||||
$expectedManifest = $plan['frontend']['previous_manifest_sha256'];
|
||||
if ($installed) {
|
||||
$activation = json_decode(file_get_contents($root.'/docs/proofs/compras-standalone-pilot-activation.json'), true, 32, JSON_THROW_ON_ERROR);
|
||||
$previous = json_decode(file_get_contents($activation['backup_directory'].'/settings.before.private.json'), true, 32, JSON_THROW_ON_ERROR);
|
||||
if ($activation['state'] !== 'passed' || $source !== [...$previous, ...$plan['proposed_runtime_settings']]) {
|
||||
throw new LogicException('ACTIVATION_POSTCHECK_SETTINGS_DIFFER');
|
||||
}
|
||||
$expectedSettings = hash_file('sha256', $sourcePath);
|
||||
$expectedManifest = $plan['frontend']['manifest_sha256'];
|
||||
}
|
||||
if (! hash_equals($expectedSettings, hash_file('sha256', $sourcePath))
|
||||
|| $source['APP_ENV'] !== 'payable-testing' || $source['DB_HOST'] !== '127.0.0.1'
|
||||
|| realpath($source['HOST_ROOT']) !== realpath($root)
|
||||
|| ! preg_match('/^compras_receipts_test_([a-f0-9]{12})$/D', $source['DB_DATABASE'], $match)
|
||||
@@ -22,7 +34,7 @@ if (! hash_equals($plan['active_settings_sha256'], hash_file('sha256', $sourcePa
|
||||
}
|
||||
$assets = $root.'/'.$plan['frontend']['candidate_root'];
|
||||
if (! hash_equals($plan['frontend']['manifest_sha256'], hash_file('sha256', $assets.'/manifest.json'))
|
||||
|| ! hash_equals($plan['frontend']['previous_manifest_sha256'], hash_file('sha256', $root.'/public/build/manifest.json'))) {
|
||||
|| ! hash_equals($expectedManifest, hash_file('sha256', $root.'/public/build/manifest.json'))) {
|
||||
throw new LogicException('ACTIVATION_PREFLIGHT_MANIFEST_CHANGED');
|
||||
}
|
||||
foreach ($plan['frontend']['files'] as $file => $hash) {
|
||||
@@ -51,12 +63,13 @@ $runtime->assertLoadedPackages();
|
||||
if (! $runtime->enabled() || count(array_filter(StandaloneRuntime::FEATURES, fn ($name) => $runtime->requested($name))) !== 24) {
|
||||
throw new LogicException('ACTIVATION_PREFLIGHT_CAPABILITIES_INCOMPLETE');
|
||||
}
|
||||
if (! hash_equals($plan['active_settings_sha256'], hash_file('sha256', $sourcePath))) {
|
||||
if (! hash_equals($expectedSettings, hash_file('sha256', $sourcePath))) {
|
||||
throw new LogicException('ACTIVATION_PREFLIGHT_SETTINGS_CHANGED');
|
||||
}
|
||||
$result = ['date' => gmdate('c'), 'state' => 'passed', 'database_enforced_read_only' => true,
|
||||
'all_24_capabilities_start_with_pinned_installed_packages' => true, 'source_instance_preserved' => true,
|
||||
'frontend_assets_verified' => count($plan['frontend']['files']), 'active_settings_changed' => false,
|
||||
'assets_published' => false, 'new_grants_or_business_commands' => false];
|
||||
file_put_contents($root.'/docs/proofs/compras-standalone-pilot-activation-preflight.json', json_encode($result, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR).PHP_EOL);
|
||||
'mode' => $installed ? 'installed_configuration_read_only_postcheck' : 'prospective_read_only_preflight',
|
||||
'assets_published' => $installed, 'new_grants_or_business_commands' => false];
|
||||
file_put_contents($root.'/docs/proofs/'.($installed ? 'compras-standalone-pilot-activation-check.json' : 'compras-standalone-pilot-activation-preflight.json'), json_encode($result, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR).PHP_EOL);
|
||||
echo json_encode($result, JSON_THROW_ON_ERROR).PHP_EOL;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
// In-process GET validation only: existing actors, array sessions, pre-execution SQL write refusal.
|
||||
// No routes, login shortcuts, users, grants or changes are installed by this checker.
|
||||
use App\Http\Middleware\HandleInertiaRequests;
|
||||
use App\Models\User;
|
||||
use App\Services\StandaloneRuntime;
|
||||
use Illuminate\Contracts\Http\Kernel;
|
||||
@@ -35,7 +36,8 @@ $app = require $root.'/bootstrap/app.php';
|
||||
$kernel = $app->make(Kernel::class);
|
||||
$kernel->bootstrap();
|
||||
$onlyReads = static function (string $sql): void {
|
||||
if (! preg_match('/^\s*(SELECT\b|SHOW\b|SET\s+LOCAL\b|SET\s+CONSTRAINTS\b)/i', $sql)) {
|
||||
if (! preg_match('/^\s*(SELECT\b|SHOW\b|SET\s+LOCAL\b|SET\s+CONSTRAINTS\b)/i', $sql)
|
||||
&& strcasecmp(trim($sql), 'SET TRANSACTION ISOLATION LEVEL REPEATABLE READ READ ONLY') !== 0) {
|
||||
throw new LogicException('PROFILE_CHECK_SQL_WRITE_REFUSED');
|
||||
}
|
||||
};
|
||||
@@ -72,7 +74,7 @@ foreach (['admin', 'procurement', 'finance', 'warehouse'] as $role) {
|
||||
$request = Request::create('http://127.0.0.1:8005'.$path, 'GET', server: ['REMOTE_ADDR' => '127.0.0.1',
|
||||
'HTTP_ACCEPT' => 'application/json', 'HTTP_X_INERTIA' => 'true']);
|
||||
$app->instance('request', $request);
|
||||
$request->headers->set('X-Inertia-Version', app(\App\Http\Middleware\HandleInertiaRequests::class)->version($request));
|
||||
$request->headers->set('X-Inertia-Version', app(HandleInertiaRequests::class)->version($request));
|
||||
Auth::guard('web')->setUser($actor);
|
||||
$session = app('session')->driver();
|
||||
$session->start();
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
import fs from 'node:fs/promises';
|
||||
import crypto from 'node:crypto';
|
||||
import assert from 'node:assert/strict';
|
||||
|
||||
const plan = JSON.parse(await fs.readFile('docs/proofs/compras-standalone-pilot-activation-proposal.json', 'utf8'));
|
||||
const activation = JSON.parse(await fs.readFile('docs/proofs/compras-standalone-pilot-activation.json', 'utf8'));
|
||||
assert.equal(activation.state, 'passed');
|
||||
assert.equal(plan.target, 'http://127.0.0.1:8005');
|
||||
let verified = 0;
|
||||
const queue = Object.entries(plan.frontend.files);
|
||||
await Promise.all(Array.from({ length: 3 }, async () => {
|
||||
for (;;) {
|
||||
const entry = queue.shift();
|
||||
if (!entry) return;
|
||||
const [file, hash] = entry;
|
||||
assert.ok(file.startsWith('assets/') && !file.includes('..'));
|
||||
const response = await fetch(`${plan.target}/build/${file}`, { signal: AbortSignal.timeout(10000) });
|
||||
assert.equal(response.status, 200, file);
|
||||
assert.equal(crypto.createHash('sha256').update(new Uint8Array(await response.arrayBuffer())).digest('hex'), hash, file);
|
||||
verified++;
|
||||
}
|
||||
}));
|
||||
const response = await fetch('https://compras.tempo.co.mz/dashboard', { signal: AbortSignal.timeout(15000) });
|
||||
assert.equal(response.status, 200);
|
||||
const html = await response.text();
|
||||
const bootstrap = html.match(/<script data-page="app" type="application\/json">([\s\S]*?)<\/script>/);
|
||||
assert.ok(bootstrap, 'Expected public Inertia bootstrap');
|
||||
const page = JSON.parse(bootstrap[1]);
|
||||
assert.equal(page.props.auth.user, null);
|
||||
assert.deepEqual(page.props.commonFinanceNavigation, { payments: false, ledger: false, configuration: false });
|
||||
const manifest = JSON.parse(await fs.readFile('public/build/manifest.json', 'utf8'));
|
||||
assert.ok(html.includes(manifest['resources/js/app.tsx'].file));
|
||||
const proof = { date: new Date().toISOString(), state: 'passed', pilot_asset_responses_and_hashes: verified,
|
||||
public_domain_html_delivers_new_entry: true, public_anonymous_identity_preserved: true,
|
||||
private_finance_navigation_not_exposed_publicly: true, new_grants_or_business_operations: false };
|
||||
await fs.writeFile('docs/proofs/compras-standalone-published-assets.json', JSON.stringify(proof, null, 2) + '\n');
|
||||
console.log(JSON.stringify(proof));
|
||||
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
use App\Services\WindowsTaskXml;
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
require dirname(__DIR__).'/vendor/autoload.php';
|
||||
$root = dirname(__DIR__);
|
||||
$planPath = $root.'/docs/proofs/approval-deadlines-task-proposal.json';
|
||||
$plan = json_decode(file_get_contents($planPath), true, 32, JSON_THROW_ON_ERROR);
|
||||
$apply = in_array('--apply-authorized', $argv, true);
|
||||
if (realpath($root) !== realpath('C:/laragon/www/compras') || $plan['task_name'] !== 'Compras-Pilot-Approval-Deadlines'
|
||||
|| str_replace('\\', '/', PHP_BINARY) !== $plan['php_executable']) {
|
||||
throw new LogicException('DEADLINE_TASK_INSTALLATION_TARGET');
|
||||
}
|
||||
foreach ($plan['file_sha256'] as $file => $hash) {
|
||||
if (! hash_equals($hash, hash_file('sha256', $root.'/'.$file))) {
|
||||
$correctionPath = $root.'/docs/proofs/approval-deadlines-task-encoding-fix.json';
|
||||
$correction = is_file($correctionPath) ? json_decode(file_get_contents($correctionPath), true, 32, JSON_THROW_ON_ERROR) : [];
|
||||
if ($file !== 'scripts/install-approval-deadlines-task.php' || ($correction['scope_unchanged'] ?? false) !== true
|
||||
|| ($correction['original_installer_sha256'] ?? null) !== $hash
|
||||
|| ($correction['original_proposal_sha256'] ?? null) !== hash_file('sha256', $planPath)
|
||||
|| ! hash_equals($correction['corrected_installer_sha256'] ?? '', hash_file('sha256', $root.'/'.$file))
|
||||
|| ! hash_equals($correction['xml_transport_sha256'] ?? '', hash_file('sha256', $root.'/app/Services/WindowsTaskXml.php'))) {
|
||||
throw new LogicException('DEADLINE_TASK_SOURCE_CHANGED');
|
||||
}
|
||||
}
|
||||
}
|
||||
$run = static function (array $command, int $timeout = 15) use ($root): string {
|
||||
$process = new Process($command, $root, timeout: $timeout);
|
||||
$process->run();
|
||||
if (! $process->isSuccessful()) {
|
||||
throw new RuntimeException('DEADLINE_TASK_NATIVE_COMMAND_FAILED');
|
||||
}
|
||||
|
||||
return $process->getOutput();
|
||||
};
|
||||
$scheduler = getenv('SystemRoot').'/System32/schtasks.exe';
|
||||
$tasks = $run([$scheduler, '/Query', '/FO', 'CSV', '/NH']);
|
||||
foreach (preg_split('/\r?\n/', trim($tasks)) as $row) {
|
||||
$name = str_getcsv($row, escape: '')[0] ?? '';
|
||||
if ($name === '\\'.$plan['task_name']) {
|
||||
throw new LogicException('DEADLINE_TASK_ALREADY_EXISTS_NEVER_OVERWRITE');
|
||||
}
|
||||
}
|
||||
$health = json_decode(trim($run([PHP_BINARY, 'scripts/approval-deadlines-evaluation.php', '--check'])), true, 32, JSON_THROW_ON_ERROR);
|
||||
if ($health['state'] !== 'ready' || $health['database_enforced_read_only'] !== true) {
|
||||
throw new LogicException('DEADLINE_TASK_PILOT_NOT_READY');
|
||||
}
|
||||
$identity = str_getcsv(trim($run([getenv('SystemRoot').'/System32/whoami.exe', '/user', '/fo', 'csv', '/nh'])), escape: '');
|
||||
$sid = $identity[1] ?? '';
|
||||
if (! preg_match('/^S-1-\d+(?:-\d+)+$/D', $sid)) {
|
||||
throw new LogicException('DEADLINE_TASK_CURRENT_USER_UNAVAILABLE');
|
||||
}
|
||||
$escape = static fn (string $value) => htmlspecialchars($value, ENT_XML1 | ENT_QUOTES, 'UTF-8');
|
||||
$start = (new DateTimeImmutable('now', new DateTimeZone('Africa/Johannesburg')))->modify('+1 minute')->format('c');
|
||||
$php = $escape($plan['php_executable']);
|
||||
$arguments = $escape('"'.$root.'/scripts/approval-deadlines-evaluation.php" --once');
|
||||
$directory = 'C:/laragon/data/compras/tasks/approval-deadlines-'.gmdate('Ymd-His').'-'.bin2hex(random_bytes(6));
|
||||
if (! mkdir($directory, 0700, true)) {
|
||||
throw new LogicException('DEADLINE_TASK_PRIVATE_STORAGE');
|
||||
}
|
||||
$working = $escape($root);
|
||||
$xml = '<?xml version="1.0" encoding="UTF-8"?>'.
|
||||
'<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">'.
|
||||
'<RegistrationInfo><Description>Compras pilot: existing configured approval deadlines only.</Description></RegistrationInfo>'.
|
||||
'<Triggers><TimeTrigger><StartBoundary>'.$start.'</StartBoundary><Enabled>true</Enabled><Repetition><Interval>PT1M</Interval><StopAtDurationEnd>false</StopAtDurationEnd></Repetition></TimeTrigger>'.
|
||||
'<LogonTrigger><Enabled>true</Enabled><UserId>'.$sid.'</UserId></LogonTrigger></Triggers>'.
|
||||
'<Principals><Principal id="CurrentUser"><UserId>'.$sid.'</UserId><LogonType>InteractiveToken</LogonType><RunLevel>LeastPrivilege</RunLevel></Principal></Principals>'.
|
||||
'<Settings><MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy><DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries><StopIfGoingOnBatteries>false</StopIfGoingOnBatteries><AllowHardTerminate>true</AllowHardTerminate><StartWhenAvailable>true</StartWhenAvailable><Enabled>true</Enabled><Hidden>true</Hidden><ExecutionTimeLimit>PT1M</ExecutionTimeLimit></Settings>'.
|
||||
'<Actions Context="CurrentUser"><Exec><Command>'.$php.'</Command><Arguments>'.$arguments.'</Arguments><WorkingDirectory>'.$working.'</WorkingDirectory></Exec></Actions></Task>';
|
||||
$document = WindowsTaskXml::parse($xml);
|
||||
$xpath = new DOMXPath($document);
|
||||
$xpath->registerNamespace('t', 'http://schemas.microsoft.com/windows/2004/02/mit/task');
|
||||
if ($xpath->query('//t:Exec')->length !== 1 || $xpath->evaluate('string(//t:LogonType)') !== 'InteractiveToken'
|
||||
|| $xpath->evaluate('string(//t:RunLevel)') !== 'LeastPrivilege' || $xpath->query('//t:Triggers/*')->length !== 2) {
|
||||
throw new LogicException('DEADLINE_TASK_XML_SCOPE');
|
||||
}
|
||||
$xmlPath = $directory.'/task.private.xml';
|
||||
$fileBytes = WindowsTaskXml::encode($xml);
|
||||
file_put_contents($xmlPath, $fileBytes);
|
||||
$record = ['date' => gmdate('c'), 'state' => 'preview', 'task_name' => $plan['task_name'], 'current_user_only' => true,
|
||||
'credentials_stored' => false, 'run_level' => 'Limited', 'poll_interval' => 'PT1M', 'overlap' => 'IgnoreNew', 'time_limit' => 'PT1M',
|
||||
'private_definition' => $xmlPath, 'xml_sha256' => hash('sha256', $fileBytes), 'pilot_ready' => true,
|
||||
'eligible_requests' => $health['pending_requests_with_configured_cycle_policy'], 'native_command' => $plan['business_command'],
|
||||
'task_installed_or_started' => false, 'powershell_execution_policy_changed' => false];
|
||||
if (! $apply) {
|
||||
file_put_contents($root.'/docs/proofs/approval-deadlines-task-preflight.json', json_encode($record, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR).PHP_EOL);
|
||||
echo json_encode($record, JSON_THROW_ON_ERROR).PHP_EOL;
|
||||
exit;
|
||||
}
|
||||
$approvalPath = $root.'/docs/proofs/approval-deadlines-task-authorization.json';
|
||||
$approval = is_file($approvalPath) ? json_decode(file_get_contents($approvalPath), true, 32, JSON_THROW_ON_ERROR) : [];
|
||||
if (($approval['state'] ?? null) !== 'approved' || ($approval['scope'] ?? null) !== $plan['scope']
|
||||
|| ! hash_equals($approval['proposal_sha256'], hash_file('sha256', $planPath))) {
|
||||
throw new LogicException('DEADLINE_TASK_NOT_AUTHORIZED');
|
||||
}
|
||||
$resultPath = $root.'/docs/proofs/approval-deadlines-task-installation.json';
|
||||
if (is_file($resultPath)) {
|
||||
throw new LogicException('DEADLINE_TASK_PREVIOUS_RESULT');
|
||||
}
|
||||
$run([$scheduler, '/Create', '/TN', $plan['task_name'], '/XML', $xmlPath]); // No /F: never replace another task.
|
||||
$installed = $run([$scheduler, '/Query', '/TN', $plan['task_name'], '/XML']);
|
||||
$installedDocument = WindowsTaskXml::parse($installed);
|
||||
$installedXpath = new DOMXPath($installedDocument);
|
||||
$installedXpath->registerNamespace('t', 'http://schemas.microsoft.com/windows/2004/02/mit/task');
|
||||
foreach (['Command', 'Arguments', 'WorkingDirectory', 'LogonType', 'RunLevel', 'MultipleInstancesPolicy', 'ExecutionTimeLimit'] as $element) {
|
||||
if ($installedXpath->evaluate('string(//t:'.$element.')') !== $xpath->evaluate('string(//t:'.$element.')')) {
|
||||
throw new LogicException('DEADLINE_TASK_INSTALLED_DEFINITION_DIFFERS');
|
||||
}
|
||||
}
|
||||
$record['state'] = 'installed';
|
||||
$record['task_installed_or_started'] = true;
|
||||
file_put_contents($resultPath, json_encode($record, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR).PHP_EOL);
|
||||
$run([$scheduler, '/Run', '/TN', $plan['task_name']]);
|
||||
$record['initial_pass_requested'] = true;
|
||||
$record['state'] = 'awaiting_passage_verification';
|
||||
file_put_contents($resultPath, json_encode($record, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR).PHP_EOL);
|
||||
echo json_encode($record, JSON_THROW_ON_ERROR).PHP_EOL;
|
||||
Reference in New Issue
Block a user