2

RHEL/Apache/PHP のアクセス許可を変更して、シェル コマンドを使用して安全な方法で SVN への呼び出しを有効にする方法はありますか? shell_exec()、shell() または system() ?

現時点では、シェル コマンドを試行するとアクセス許可が拒否されます。

4

2 に答える 2

0

PECLにはこのための安定したPHP拡張機能(Subversionexec() )があるため、呼び出しを使用して独自のコマンドを作成する必要はありません。パッケージはこちらです。svn add ...

このようにして、コード内で必要なすべてのSVN機能に簡単にアクセスできます。

于 2012-10-12T05:25:56.170 に答える
-1

これを達成できた唯一の方法は、SSH2 ライブラリを使用し、特定のアカウントでローカルに接続することでした。そうでなければ、正しく設定できませんでした。


それは良いライブラリではありません.テストしてドキュメントを検索するのに1日かかりました.

現在使用中のライブラリ:

<?php
/**
 * 
 * Runs several SSH2 commands on the devl server as root
 * 
 */
function ssh2Run(array $commands, $catchoutput = true, $server = 'localhost', $user = 'root', $logfile = NULL){

    //Open a log file for web output
    if($logfile == NULL){ $logfile = logCreate(); }

    //Connect to ssh2
    $connection = ssh2_connect($server);
    $hostkey = ssh2_fingerprint($connection);
    logWrite($logfile, 'Connected to '.$server.', hostkey = '.$hostkey);
    ssh2_auth_pubkey_file($connection, $user, '/home/myuser/.ssh/id_rsa.pub', '/home/myuser/.ssh/id_rsa');

    //Execute the various commands and read the output to the log file
    foreach($commands as $command){

        // Run a command that will probably write to stderr (unless you have a folder named /hom)
        logWrite($logfile, 'Sending command: '.$user.'@'.$server.': '.$command);
        logWrite($logfile, '----------------------------------------------------------------------------------');
        $outputStream = ssh2_exec($connection, $command, true);
        if(is_resource($outputStream)){
            stream_set_blocking($outputStream, true);
        }

        //Catch
        if($catchoutput){

            if(is_resource($errorStream)){
                $errorStream = ssh2_fetch_stream($outputStream, SSH2_STREAM_STDERR);
            }

            // Enable blocking for both streams
            if(is_resource($errorStream)){
                stream_set_blocking($errorStream, true);
            }

            // Whichever of the two below commands is listed first will receive its appropriate output.  The second command receives nothing
            logWrite($logfile, 'Output of command:');

            //Loop the stream until it is complete
            while((is_resource($outputStream) && !feof($outputStream)) || (is_resource($errorStream) && !feof($errorStream))){

                //Content read out
                if(is_resource($outputStream) && !feof($outputStream)){
                    $outputContent = trim(fgets($outputStream));
                }else{
                    $outputContent = '';
                }
                if(is_resource($errorStream) && !feof($errorStream)){
                    $errorContent = trim(fgets($errorStream));
                }else{
                    $errorContent = '';
                }

                //Add the information to the log
                if($outputContent == '' && $errorContent == ''){ continue; }
                if($outputContent !== ''){
                    logWrite($logfile, 'OUT: '.$outputContent);
                }
                if($errorContent !== ''){
                    logWrite($logfile, 'ERROR: '.$errorContent);
                }

            }

            // Close the streams       
            if(is_resource($errorStream)){ fclose($errorStream); }
            if(is_resource($outputStream)){ fclose($outputStream); }

        }

    }

    //Return the log
    return $logfile;

}

/**
 * 
 * List files in a SFTP enabled directory
 * 
 */
function sftpList($server, $user, $path){

    //Connect to ssh2
    $connection = ssh2_connect($server);
    $hostkey = ssh2_fingerprint($connection);
    ssh2_auth_pubkey_file($connection, $user, '/home/myuser/.ssh/id_rsa.pub', '/home/myuser/.ssh/id_rsa');

    //Create our SFTP resource
    if(!$sftp = ssh2_sftp($connection)){
        throw new Exception('Unable to create SFTP connection.');
    }

    /**
      * Now that we have our SFTP resource, we can open a directory resource
      * to get us a list of files. Here we will use the $sftp resource in
      * our address string as I previously mentioned since our ssh2:// 
      * protocol allows it.
      */
    $results = array();
    $dirHandle = opendir('ssh2.sftp://'.$sftp.$path);
    while (false !== ($result = readdir($dirHandle))) {
        if ($result != '.' && $result != '..') {
            $results[] = $result;
        }
    }
    closedir($dirHandle);

    //Return the log
    return $results;

}
于 2012-10-11T18:25:09.410 に答える