0

その場でCRXファイルを作成する必要があります。これは私のCMSバックエンド用なので、CMSバックエンドをWebアプリとしてインストールし、Webアプリにさらにいくつかの特権を提供できる認証済みユーザー専用になります。問題は、バックエンドが多くのドメインで使用されているため、各ドメインのCRXファイルを作成するのはかなりの作業であるということです。そのため、PHPが独自のドメインとおそらくカスタムアイコンを使用して生成するCRXファイルをオンデマンドで作成する方が簡単だと思いました。

4

4 に答える 4

1

ドキュメントページでは、CRXパッケージのフォーマットについて説明しています。そのフォーマットを実装したサードパーティのライブラリはたくさんあります。次のページでは、形式を学習し、Ruby / Bashスクリプトをダウンロードすることができます(他のスクリプトもオンラインで見つけることができます)。独自のパッケージャーを実装する場合は、そこに記載されている形式に従うことができます。

https://developer.chrome.com/extensions/crx

この形式に本当に従いたくない場合は、PHPスクリプトに次のいずれかを実行させることができます。

  1. Chromeバイナリを使用するchrome.exe --pack-extension=c:\myext --pack-extension-key=c:\myext.pem
  2. PHPのRubyまたはBashスクリプトを使用します(システムコマンドを呼び出すことができます)

お役に立てば幸いです。

于 2011-01-30T20:00:49.507 に答える
0

また、PHPでCTXを作成する方法をまだ探している人は、次の質問を参照してください:PHPでGoogleChromeCrxファイルを作成する

于 2011-11-28T16:33:16.407 に答える
0

これは私にとってはうまくいきます:DIは実際のパスからnullに変更するだけで、その変更は新しいchromeでは機能しません:D

/***クラスCrxGenerator**フォルダとpem秘密鍵からChrome拡張機能CRXパッケージを作成します**CRX形式のドキュメントに基づく:http ://developer.chrome.com/extensions/crx.html * * @author:Tomasz Banasiak * @license:MIT * @date:2013-11-03 * /

クラスCrxGenerator{constTEMP_ARCHIVE_EXT ='.zip';

private $sourceDir = null;
private $cacheDir = '';

private $privateKeyContents = null;
private $publicKeyContents = null;

private $privateKey = null;
private $publicKey = null;

/**
 * @param $file Path to PEM key
 * @throws Exception
 */
public function setPrivateKey($file) {
    if (!file_exists($file)) {
        throw new Exception('Private key file does not exist');
    }

    $this->privateKeyContents = file_get_contents($file);
    $this->privateKey = $file;
}

/**
 * @param $file Path to PUB key
 * @throws Exception
 */
public function setPublicKey($file) {
    if (!file_exists($file)) {
        throw new Exception('Private key file does not exist');
    }

    $this->publicKeyContents = file_get_contents($file);
    $this->publicKey = $file;
}

/**
 * @param $cacheDir dir specified for caching temporary archives
 * @throws Exception
 */
public function setCacheDir($cacheDir) {
    if (!is_dir($cacheDir)) {
        throw new Exception('Cache dir does not exist!');
    }

    $this->cacheDir = $cacheDir;
}

/**
 * @param $sourceDir Extension source directory
 */
public function setSourceDir($sourceDir) {
    $this->sourceDir = $sourceDir;
}

/**
 * @param $outputFile path to output file
 * @throws Exception
 */
public function generateCrx($outputFile) {
    $basename = basename($outputFile);
    // First step - create ZIP archive
    $zipArchive = $this->cacheDir . DIRECTORY_SEPARATOR . $basename . self::TEMP_ARCHIVE_EXT;

    $result = $this->createZipArchive(
        $this->sourceDir,
        $zipArchive
    );

    if (!$result) {
        throw new Exception('ZIP creation failed');
    }

    $zipContents = file_get_contents($zipArchive);

    // Second step - create file signature
    $privateKey = openssl_pkey_get_private($this->privateKeyContents);
    openssl_sign($zipContents, $signature, $privateKey, 'sha1');
    openssl_free_key($privateKey);

    // Create output file

    $crx = fopen($outputFile, 'wb');
    fwrite($crx, 'Cr24');
    fwrite($crx, pack('V', 2));
    fwrite($crx, pack('V', strlen($this->publicKeyContents)));
    fwrite($crx, pack('V', strlen($signature)));
    fwrite($crx, $this->publicKeyContents);
    fwrite($crx, $signature);
    fwrite($crx, $zipContents);
    fclose($crx);

    // Clear cache
    unset($zipArchive);
}

/**
 * @param $source - source dir
 * @param $outputFile - output file
 * @return bool - success?
 */
private function createZipArchive($source, $outputFile) {
    if (!extension_loaded('zip') || !file_exists($source)) {
        return false;
    }

    $zip = new ZipArchive();
    if (!$zip->open($outputFile, ZIPARCHIVE::CREATE)) {
        return false;
    }

     $source = str_replace('\\', '/', realpath($source));

    if (is_dir($source) === true) {
        $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST);
        foreach ($files as $file) {
            $file = str_replace('\\', '/', $file);

            // Exclude "." and ".." folders
            if( in_array(substr($file, strrpos($file, '/') + 1), array('.', '..')) ) {
                continue;
            }

            $file = $file;

            if (is_dir($file) === true) {
                $zip->addEmptyDir(str_replace($source . '/', '', $file . '/'));
            }
            else if (is_file($file) === true) {
                $zip->addFromString(str_replace($source . '/', '', $file), file_get_contents($file));
            }
        }
    }
    else if (is_file($source) === true) {
        $zip->file_get_contents($source);
    echo  $source;
    }

    return $zip->close();
}

}

于 2013-12-19T03:26:12.443 に答える
-1

探していたものを正確に見つけたようです。Chromeチームは、単純なマニフェストファイルを使用するだけで、CRXのないWebアプリを作成するためにこのオプションを作成しました。

独自のWebアプリを作成し、インストールのためにWebサイトに公開する方がはるかに簡単です。また、多くのドメインを持つWebサイトが多数あり、ドメインごとにカスタムCRXファイルを作成する必要がない場合の問題も解決します。ドメインごとにマニフェストファイルをその場で作成する小さなPHPスクリプトを作成するだけです。

于 2011-02-04T11:13:50.267 に答える