2022-10-11 17:52:48 +08:00
|
|
|
<?php
|
|
|
|
echo "\x1b[33;1m === Nextcloud === \x1b[0m\n";
|
|
|
|
|
2022-12-23 20:50:31 +08:00
|
|
|
$cert_dir = $_SERVER['HOME'].'/.nextcloud/certificates';
|
|
|
|
|
2022-10-11 17:52:48 +08:00
|
|
|
$nc_destination = "{$destPath}snappymail-{$package->version}-nextcloud.tar";
|
|
|
|
|
|
|
|
@unlink($nc_destination);
|
|
|
|
@unlink("{$nc_destination}.gz");
|
|
|
|
|
|
|
|
$nc_tar = new PharData($nc_destination);
|
2022-12-23 20:50:31 +08:00
|
|
|
$hashes = [];
|
2022-10-11 17:52:48 +08:00
|
|
|
|
2023-01-03 19:58:38 +08:00
|
|
|
file_put_contents(ROOT_DIR . '/integrations/nextcloud/snappymail/VERSION', $package->version);
|
|
|
|
$file = ROOT_DIR . '/integrations/nextcloud/snappymail/appinfo/info.xml';
|
|
|
|
file_put_contents($file, preg_replace('/<version>[^<]*</', "<version>{$package->version}<", file_get_contents($file)));
|
|
|
|
|
2022-10-11 17:52:48 +08:00
|
|
|
$nc_tar->buildFromDirectory('./integrations/nextcloud', "@integrations/nextcloud/snappymail/@");
|
2022-12-23 20:50:31 +08:00
|
|
|
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator('integrations/nextcloud/snappymail'));
|
|
|
|
foreach ($files as $file) {
|
|
|
|
if (is_file($file)) {
|
|
|
|
$name = str_replace('\\', '/', $file);
|
|
|
|
$name = str_replace('integrations/nextcloud/snappymail/', '', $name);
|
2022-12-29 17:59:07 +08:00
|
|
|
$name = str_replace('.htaccess', '_htaccess', $name);
|
2022-12-23 20:50:31 +08:00
|
|
|
$hashes[$name] = hash_file('sha512', $file);
|
|
|
|
}
|
|
|
|
}
|
2022-10-11 17:52:48 +08:00
|
|
|
|
|
|
|
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator('snappymail/v'), RecursiveIteratorIterator::SELF_FIRST);
|
|
|
|
foreach ($files as $file) {
|
|
|
|
if (is_file($file)) {
|
2022-11-04 23:56:43 +08:00
|
|
|
$newFile = str_replace('\\', '/', $file);
|
2022-11-05 19:07:26 +08:00
|
|
|
// $newFile = str_replace("'snappymail/v/'.", '', $newFile);
|
2022-11-04 23:56:43 +08:00
|
|
|
$nc_tar->addFile($file, "snappymail/app/{$newFile}");
|
2022-12-23 20:50:31 +08:00
|
|
|
$hashes["app/{$newFile}"] = hash_file('sha512', $file);
|
2022-10-11 17:52:48 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
$nc_tar->addFile('data/.htaccess');
|
|
|
|
$nc_tar->addFromString('data/VERSION', $package->version);
|
|
|
|
$nc_tar->addFile('data/README.md');
|
|
|
|
$nc_tar->addFile('_include.php', 'snappymail/app/_include.php');
|
2022-10-13 16:24:35 +08:00
|
|
|
*/
|
2022-12-29 17:59:07 +08:00
|
|
|
$nc_tar->addFile('.htaccess', 'snappymail/app/_htaccess');
|
2022-12-25 02:03:41 +08:00
|
|
|
$hashes['app/.htaccess'] = hash_file('sha512', '.htaccess');
|
2022-10-11 17:52:48 +08:00
|
|
|
|
|
|
|
$index = file_get_contents('index.php');
|
|
|
|
$index = str_replace('0.0.0', $package->version, $index);
|
2022-11-05 19:07:26 +08:00
|
|
|
//$index = str_replace('snappymail/v/', '', $index);
|
2022-10-11 17:52:48 +08:00
|
|
|
$nc_tar->addFromString('snappymail/app/index.php', $index);
|
2022-12-25 02:03:41 +08:00
|
|
|
$hashes['app/index.php'] = hash('sha512', $index);
|
2022-12-23 20:50:31 +08:00
|
|
|
|
2022-10-11 17:52:48 +08:00
|
|
|
$nc_tar->addFile('README.md', 'snappymail/app/README.md');
|
2022-12-25 02:03:41 +08:00
|
|
|
$hashes['app/README.md'] = hash_file('sha512', 'README.md');
|
2022-12-23 20:50:31 +08:00
|
|
|
|
2022-11-02 18:33:25 +08:00
|
|
|
$nc_tar->addFile('CHANGELOG.md', 'snappymail/CHANGELOG.md');
|
2022-12-23 20:50:31 +08:00
|
|
|
$hashes['CHANGELOG.md'] = hash_file('sha512', 'CHANGELOG.md');
|
2022-10-11 17:52:48 +08:00
|
|
|
|
|
|
|
$data = file_get_contents('dev/serviceworker.js');
|
|
|
|
$nc_tar->addFromString('snappymail/app/serviceworker.js', $data);
|
2022-12-25 02:03:41 +08:00
|
|
|
$hashes['app/serviceworker.js'] = hash('sha512', $data);
|
2022-12-23 20:50:31 +08:00
|
|
|
|
2022-12-25 02:03:41 +08:00
|
|
|
spl_autoload_register(function($name){
|
|
|
|
$file = __DIR__ . '/' . str_replace('\\', '/', $name) . '.php';
|
|
|
|
echo "{$file}\n";
|
|
|
|
require $file;
|
|
|
|
});
|
|
|
|
|
|
|
|
ksort($hashes);
|
|
|
|
$cert = file_get_contents($cert_dir.'/snappymail.crt');
|
|
|
|
$rsa = new \phpseclib\Crypt\RSA();
|
|
|
|
$rsa->loadKey(file_get_contents($cert_dir.'/snappymail.key'));
|
|
|
|
$x509 = new \phpseclib\File\X509();
|
|
|
|
$x509->loadX509($cert);
|
|
|
|
$x509->setPrivateKey($rsa);
|
|
|
|
$rsa->setSignatureMode(\phpseclib\Crypt\RSA::SIGNATURE_PSS);
|
|
|
|
$rsa->setMGFHash('sha512');
|
|
|
|
$rsa->setSaltLength(0);
|
|
|
|
$signature = $rsa->sign(json_encode($hashes));
|
2022-12-23 20:50:31 +08:00
|
|
|
$nc_tar->addFromString('snappymail/appinfo/signature.json', json_encode([
|
|
|
|
'hashes' => $hashes,
|
|
|
|
'signature' => base64_encode($signature),
|
2022-12-25 02:03:41 +08:00
|
|
|
'certificate' => $cert
|
2022-12-23 20:50:31 +08:00
|
|
|
], JSON_PRETTY_PRINT));
|
2022-10-11 17:52:48 +08:00
|
|
|
|
|
|
|
$nc_tar->compress(Phar::GZ);
|
|
|
|
unlink($nc_destination);
|
|
|
|
$nc_destination .= '.gz';
|
|
|
|
|
2022-12-23 20:50:31 +08:00
|
|
|
$signature = shell_exec("openssl dgst -sha512 -sign {$cert_dir}/snappymail.key {$nc_destination} | openssl base64");
|
2022-10-21 18:48:33 +08:00
|
|
|
file_put_contents($nc_destination.'.sig', $signature);
|
|
|
|
|
2022-10-11 17:52:48 +08:00
|
|
|
echo "{$nc_destination} created\n";
|