Page MenuHomePhabricator

WindowsZeroConf.php

Authored By
hach-que
Aug 11 2014, 1:09 PM
Size
2 KB
Referenced Files
None
Subscribers
None

WindowsZeroConf.php

<?php
final class WindowsZeroConf extends Phobject {
public function getEncodedUserData(PassphraseCredential $credential) {
return base64_encode($this->getUserData($credential));
}
private function getUserData(PassphraseCredential $credential) {
$type = PassphraseCredentialType::getTypeByConstant(
$credential->getCredentialType());
if (!$type) {
throw new Exception(pht('Credential has invalid type "%s"!', $type));
}
if (!$type->hasPublicKey()) {
throw new Exception(pht('Credential has no public key!'));
}
$username = $credential->getUsername();
$publickey = $type->getPublicKey(
PhabricatorUser::getOmnipotentUser(),
$credential);
$publickey = trim($publickey);
$username = str_replace('"', '`"', $username);
$publickey = str_replace('"', '`"', $publickey);
$start = '<powershell>';
$data = <<<EOF
\$username = "$username";
\$publickey = "$publickey";
EOF;
$script = <<<'EOF'
# Create Cygwin64 directory
mkdir C:\cygwin64
# Download Cygwin64
wget https://s3-us-west-2.amazonaws.com/windows-build-agent/CygwinPack.zip `
-OutFile C:\CygwinPack.zip
# Extract Cygwin64
$shell = new-object -com shell.application
$zip = $shell.NameSpace("C:\CygwinPack.zip")
foreach($item in $zip.items())
{
$shell.Namespace("C:\cygwin64").copyhere($item)
}
# Setup SSHD
$env:PATH = $env:PATH + ";c:\cygwin64\bin"
C:\cygwin64\bin\chmod.exe +r /etc/passwd
C:\cygwin64\bin\chmod.exe +r /etc/group
C:\cygwin64\bin\chmod.exe a+x /var
C:\cygwin64\bin\bash.exe C:\cygwin64\bin\ssh-host-config -y -w SSHPRIV1@
$objOu = [ADSI]"WinNT://localhost"
$objUser = $objOU.Create("User", $username)
$objUser.setpassword("SSHPRIV1@")
$objUser.SetInfo()
C:\cygwin64\bin\mkpasswd.exe > C:\cygwin64\etc\passwd
mkdir C:\cygwin64\home\$username\.ssh
$keyline = "$publickey Automatically Defined Key"
Set-Content `
-Path C:\cygwin64\home\$username\.ssh\authorized_keys `
-Value $keyline
Set-Service sshd -StartupType Automatic
Start-Service sshd
</powershell>
EOF;
echo $start . $data . $script;
return $start . $data . $script;
}
}

File Metadata

Mime Type
text/plain; charset=utf-8
Storage Engine
amazon-s3
Storage Format
Raw Data
Storage Handle
phabricator/tl/tn/j6lo2wrv3pad5p25
Default Alt Text
WindowsZeroConf.php (2 KB)

Event Timeline