Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Mac OS X proxies #16

Open
thekid opened this issue Jun 9, 2016 · 2 comments
Open

Support Mac OS X proxies #16

thekid opened this issue Jun 9, 2016 · 2 comments

Comments

@thekid
Copy link
Member

thekid commented Jun 9, 2016

From /Library/Preferences/SystemConfiguration/preferences.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>CurrentSet</key>
    <string>/Sets/8DD211B4-4284-455D-8F0F-209916D5A782</string>
    <key>Model</key>
    <string>MacBookPro10,1</string>
    <key>NetworkServices</key>
    <dict>
        <key>73B15BE1-D77D-4336-82E6-376B27803928</key>
        <dict>
            <key>DNS</key>
            <dict/>
            <key>IPv4</key>
            <dict>
                <key>ConfigMethod</key>
                <string>DHCP</string>
            </dict>
            <key>IPv6</key>
            <dict>
                <key>ConfigMethod</key>
                <string>Automatic</string>
            </dict>
            <key>Interface</key>
            <dict>
                <key>DeviceName</key>
                <string>en0</string>
                <key>Hardware</key>
                <string>Ethernet</string>
                <key>Type</key>
                <string>Ethernet</string>
                <key>UserDefinedName</key>
                <string>Ethernet</string>
            </dict>
            <key>Proxies</key>
            <dict>
                <key>ExceptionsList</key>
                <array>
                    <string>*.local</string>
                    <string>169.254/16</string>
                </array>
                <key>FTPPassive</key>
                <integer>1</integer>
                <key>HTTPEnable</key>
                <integer>1</integer>
                <key>HTTPPort</key>
                <integer>3128</integer>
                <key>HTTPProxy</key>
                <string>proxy.example.com</string>
            </dict>
            <key>SMB</key>
            <dict/>
            <key>UserDefinedName</key>
            <string>Ethernet</string>
        </dict>
    </dict>
    <key>Sets</key>
    <dict>
        <key>8DD211B4-4284-455D-8F0F-209916D5A782</key>
        <dict>
            <key>Network</key>
            <dict>
                <key>Global</key>
                <dict>
                    <key>IPv4</key>
                    <dict>
                        <key>ServiceOrder</key>
                        <array>
                            <string>73B15BE1-D77D-4336-82E6-376B27803928</string>
                        </array>
                    </dict>
                </dict>
                <key>Service</key>
                <dict>
                    <key>73B15BE1-D77D-4336-82E6-376B27803928</key>
                    <dict>
                        <key>__LINK__</key>
                        <string>/NetworkServices/73B15BE1-D77D-4336-82E6-376B27803928</string>
                    </dict>
                </dict>
            </dict>
            <key>UserDefinedName</key>
            <string>Automatic</string>
        </dict>
    </dict>
    <key>System</key>
    <dict>
        <key>Network</key>
        <dict>
            <key>HostNames</key>
            <dict>
                <key>LocalHostName</key>
                <string>Timms-Mac</string>
            </dict>
        </dict>
        <key>System</key>
        <dict>
            <key>ComputerName</key>
            <string>Timm’s Mac</string>
            <key>ComputerNameEncoding</key>
            <integer>0</integer>
        </dict>
    </dict>
</dict>
</plist>
@thekid
Copy link
Member Author

thekid commented Jun 9, 2016

PList parser:

<?php namespace parse;

use util\cmd\Console;
use util\profiling\Timer;

$timer= Timer::measure(function() use($argv) {
  $parser= xml_parser_create();
  xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
  xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
  xml_parse_into_struct($parser, file_get_contents($argv[1]), $elements);
  xml_parser_free($parser);

  $result= [];
  $key= null;
  foreach ($elements as $tag) {
    if ('open' === $tag['type'] && 'dict' === $tag['tag']) {
      $key ? $path.= '/'.$key : $path= '';
    } else if ('complete' === $tag['type']) {
      if ('key' === $tag['tag']) {
        $key= $tag['value'];
      } else if (!isset($tag['value'])) {
        $result[$path.'/'.$key]= null;  // Empty values
      } else if ('string' === $tag['tag']) {
        $result[$path.'/'.$key][]= $tag['value'];
      } else if ('integer' === $tag['tag']) {
        $result[$path.'/'.$key][]= (int)$tag['value'];
      } else if ('true' === $tag['tag']) {
        $result[$path.'/'.$key][]= true;
      } else if ('false' === $tag['tag']) {
        $result[$path.'/'.$key][]= false;
      }
    } else if ('close' === $tag['type'] && 'dict' === $tag['tag']) {
      $path= substr($path, 0, strrpos($path, '/'));
    }
  }

  Console::writeLine($result);
});
Console::writeLinef('Took %.3f seconds', $timer->elapsedTime());

Result for above:

$ xp parse.script.php preferences.plist
[
  /CurrentSet => ["/Sets/8DD211B4-4284-455D-8F0F-209916D5A782"]
  /Model => ["MacBookPro10,1"]
  /NetworkServices/73B15BE1-D77D-4336-82E6-376B27803928/DNS => null
  /NetworkServices/73B15BE1-D77D-4336-82E6-376B27803928/IPv4/ConfigMethod => ["DHCP"]
  /NetworkServices/73B15BE1-D77D-4336-82E6-376B27803928/IPv6/ConfigMethod => ["Automatic"]
  /NetworkServices/73B15BE1-D77D-4336-82E6-376B27803928/Interface/DeviceName => ["en0"]
  /NetworkServices/73B15BE1-D77D-4336-82E6-376B27803928/Interface/Hardware => ["Ethernet"]
  /NetworkServices/73B15BE1-D77D-4336-82E6-376B27803928/Interface/Type => ["Ethernet"]
  /NetworkServices/73B15BE1-D77D-4336-82E6-376B27803928/Interface/UserDefinedName => ["Ethernet"]
  /NetworkServices/73B15BE1-D77D-4336-82E6-376B27803928/Proxies/ExceptionsList => ["*.local", "169.254/16"]
  /NetworkServices/73B15BE1-D77D-4336-82E6-376B27803928/Proxies/FTPPassive => [1]
  /NetworkServices/73B15BE1-D77D-4336-82E6-376B27803928/Proxies/HTTPEnable => [1]
  /NetworkServices/73B15BE1-D77D-4336-82E6-376B27803928/Proxies/HTTPPort => [3128]
  /NetworkServices/73B15BE1-D77D-4336-82E6-376B27803928/Proxies/HTTPProxy => ["proxy.example.com"]
  /NetworkServices/73B15BE1-D77D-4336-82E6-376B27803928/SMB => null
  /NetworkServices/73B15BE1-D77D-4336-82E6-376B27803928/UserDefinedName => ["Ethernet"]
  /Sets/8DD211B4-4284-455D-8F0F-209916D5A782/Network/Global/IPv4/ServiceOrder => ["73B15BE1-D77D-4336-82E6-376B27803928"]
  /Sets/8DD211B4-4284-455D-8F0F-209916D5A782/Network/Service/73B15BE1-D77D-4336-82E6-376B27803928/__LINK__ => ["/NetworkServices/73B15BE1-D77D-4336-82E6-376B27803928"]
  /Sets/8DD211B4-4284-455D-8F0F-209916D5A782/UserDefinedName => ["Automatic"]
  /System/Network/HostNames/LocalHostName => ["Timms-Mac"]
  /System/System/ComputerName => ["Timm’s Mac"]
  /System/System/ComputerNameEncoding => [0]
]
Took 0.003 seconds

@thekid
Copy link
Member Author

thekid commented Jun 9, 2016

Theory:

// I'm uncertain about this, how do we now which one is active?
$service= $plist[$plist['/CurrentSet'].'/Network/Global/IPv4/ServiceOder'][0];

// Probable
$network= $plist[$plist['/CurrentSet'].'/Network/Service/'.$service.'/__LINK__'][0];
if ($plist[$network.'/Proxies/HTTPEnable'][0]) {
  return new HttpProxy(
    $plist[$network.'/Proxies/HTTPProxy'][0],
    $plist[$network.'/Proxies/HTTPPort'][0],
    $plist[$network.'/Proxies/ExceptionsList']
  );
} else {
  return HttpProxy::NONE;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant