Set mitmdump proving multi domain - proxy

You need to set up map-remote on multiple phone URLs in autotest, but how do you do it via the command line?
launch example:
case ANDROID -> {
String[] command = {"mitmdump",
"--listen-port", String.valueOf(port),
"--set", "confdir=" + Objects.requireNonNull(Proxy.class.getClassLoader().getResource("mitmproxy")).toURI().getPath() + "/mitmproxy-certs",
"--map-remote", "|" + mapRemotePattern + "|http://localhost:" + String.valueOf(mockPort),
"--modify-headers", "/~hq localhost/Host/" + hostHeader,
"--save-stream-file", fileNameNetworkLog};
startMitmdump(command);
}
I can't find the answer in the documentation
when trying to add 1 more map-remote field with different url, then it doesn't work
If you try to write mapRemote by regular expression OR, to 2 url , then it doesn't work either.

Related

Set proxy with PAC script in node webkit

I am attempting to configure proxy settings that include custom rules depending on the host - i.e. use HTTP proxy if the host contains the string "example", otherwise use DIRECT, i.e:
Host
Rule
example.com
HTTP: 127.0.0.1:8888
example2.com
HTTP: 127.0.0.1:8888
exampl3.com
DIRECT
In chrome, I can easily achieve this using a PAC script such as:
chrome.proxy.settings.set({
value: {
mode: "pac_script",
pacScript: {
data: "function FindProxyForURL (url, host) {\n" +
" if (host.indexOf('example') > -1)\n" +
" return 'PROXY 127.0.0.1:8888';\n" +
" return 'DIRECT';\n" +
"}"
}
},
scope: 'regular'
}, callback);
I would like to achieve the same result for node webkit (chromium). Looking at the docs, I can't see a way to implement the same PAC script - there is a section for App.setProxyConfig(config, pac_url) at:
https://docs.nwjs.io/en/latest/References/App/#appsetproxyconfigconfig-pac_url
But it seems you can only set proxy rules that vary by request protocol, rather than by the host/domain.
Is what I'm trying to achieve possible?
Update 1
I can get the PAC url to work using syntax as follows:
var ngui = require('nw.gui');
ngui.App.setProxyConfig('','http://myhost.com/pacProxy');
and then hosting a pac file with the following contents:
function FindProxyForURL(url, host) {
if (host.indexOf('example') > -1)
return 'PROXY 127.0.0.1:8888';
return 'DIRECT';
}
but this is requiring me to host the PAC file on a webserver - using "file:///path/to/pacfile" as the URL will only returned an empty string.
This won't work for me, as I need to dynamically set the proxy scheme/host/port contained within the file as well. I've tried to implement a hacky workaround which involves writing a new PAC configuration to a file when there is a need to change the proxy settings, e.g.:
var path = require('path');
var fs = require('fs');
var pacFile = path.join(path.resolve(),'/proxy.pac');
function createPacProxy(host,portNum){
return "function FindProxyForURL(url, host) {\n" +
" if (host.indexOf('example') > -1)\n" +
" return 'PROXY " + host + ":" + parseInt(portNum, 10) + "';\n" +
" return 'DIRECT';\n" +
"}";
}
fs.writeFileSync(pacFile,createPacProxy(host,portNum));
And then starting a local express server to host it as required. However:
(a) this seems like a ridiculous approach for something theoretically straightforward
(b) when running the express server in the same node-webit node context, there seems to be a delay in synchronous callback from ngui.App.setProxyConfig which is causing UI functions to hang. (Doesn't seem to occur if a separate node process runs the server however)
(c) Updating the PAC script and rerunning ngui.App.setProxyConfig fails unless ngui.App.setProxyConfig is executed without a PAC url in between. (Not a particularly big issue as I can run "ngui.App.setProxyConfig("direct://");" in between the updates

Customized help display in PicoCli?

I have a use case where I need to post the entire help for a CLI in a specified format. I have found a way to do that using the following:
#CommandLine.Command(name="myAp",
synopsisSubcommandLabel = "", usageHelpWidth = 120,
commandListHeading = "",
customSynopsis = "\n\nArguments for MyApp operation.\n"
+ "\n"
+ "Operations:\n"
+ " create Create the stuff\n"
+ " list List the stuff\n"
+ " add Add things\n"
+ " -r --type One or both of [Type1, Typ2]\n"
+ " -a --annualCost AnnualCost\n"
+ " -n --number Number of each type thing\n"
+ " subtract Subtract things\n"
+ " -r --reasons Combination of\n"
+ " fiscal (fiscal reason)\n"
+ " operational (operational reason\n"
+ " other (other reason)\n"
+ " -h Display this help message and exit\n"
)
class PicoCliParser {
// All of my other Parameters and options here
#Option(names = { "-h", "--help" }, usageHelp = true, hidden = true)
boolean helpRequested = false;
public static void main(String[] args) throws Exception {
PicoCliParser parser = new PicoCliParser();
CommandLine cmd = new CommandLine(parser);
try {
CommandLine.ParseResult parseResult = cmd.parseArgs(args);
System.err.println("parseResults: " + parseResult.matchedArgs().toString());
if (cmd.isUsageHelpRequested()) {
cmd.usage(System.out);
}
} catch (CommandLine.ParameterException e) {
}
}
}
If the user enters -h or --help, the help prints out in the format that I want, If they do not enter -h or -H it doesn't.
Is there a better way to do this?
If we add additional commands in the future, then whoever adds them has to remember to update the help string.
Your solution works, but has the drawback (like you mentioned) that the usage help message is static and won't reflect future updates like new subcommands or options being added.
Picocli does provide a way to customize the usage help message dynamically via its Help API. This allows you to reorder or replace sections in the usage help message. I believe the section you want to replace is the command list section.
This will require a bit of a deep dive into the picocli usage help model. To help you get started, the picocli-examples module has some custom help examples. This example shows how to modify the usage help message to show the full command hierarchy (without options though), which is fairly close to what you want to do. You could take it as a starting point. If you have more questions feel free to raise tickets on the picocli github issue tracker (or here).

How to get installed VisualStudio extensions programmatically?

How can I get a list of installed VisualStudio extensions? Somehow through DTE? Just the names would be fair enough.
Does this help:
System.IServiceProvider serviceProvider = package as System.IServiceProvider;
Microsoft.VisualStudio.ExtensionManager.IVsExtensionManager em =
(Microsoft.VisualStudio.ExtensionManager.IVsExtensionManager)serviceProvider.GetService(
typeof(Microsoft.VisualStudio.ExtensionManager.SVsExtensionManager));
string result = "";
foreach(Microsoft.VisualStudio.ExtensionManager.IInstalledExtension i in em.GetInstalledExtensions())
{
Microsoft.VisualStudio.ExtensionManager.IExtensionHeader h = i.Header;
if (!h.SystemComponent)
result += h.Name + " (by " + h.Author + ") v" + h.Version + " " + h.MoreInfoUrl + System.Environment.NewLine;
}
Copied from https://vlasovstudio.com/visual-commander/commands.html #20.
Another possibility, if you don't want DTE, because you are not running from within Visual Studio or are concerned about performance you can query the extensions from the file system / registry:
For User Extensions
%LocalAppData%\Microsoft\VisualStudio*.vsix
For General Extensions
\Common7\IDE\Extensions*.vsix
IF you want to be 100% correct you can look up the paths in
\Common7\IDE\devenv.pkgdef
NOTE: There can be additional paths in the PkgDefSearchPath.
To check wether a User Extensions is enabled or not you have to query the registry:
HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\10.0\ExtensionManager\EnabledExtensions
There are some other rules that apply, which you can find in this blog from Microsoft:
http://blogs.msdn.com/b/visualstudio/archive/2010/02/19/how-vsix-extensions-are-discovered-and-loaded-in-vs-2010.aspx

Spring Cloud Config Server in 'native' mode doesn't quite work in Windows environment

Got what I needed to work on OSX. On Windows, things went a little south.
I am using 'native' mode to share a local properties file across multiple services (spring cloud client). I have:
-Dspring.cloud.config.server.native.searchLocations=C:/Development/SVN/WSR_20150711/wsr-config/config/
And C:\Development\SVN\WSR_20150711\wsr-config\config\wsr\wsr-dev.properties exists. But looks like spring cloud config server is not picking up this file when I specify the resource via URI /wsr/dev/wsr -- which works in OSX and Linux.
I did a little digging around and found that there might be some issue with the code at NativeEnvironmentRepository, line 135 - 158:
if (normal.startsWith("file:")) {
normal = new File(normal.substring("file:".length()))
.getAbsolutePath();
}
for (String pattern : StringUtils
.commaDelimitedListToStringArray(getLocations(searchLocations,
result.getLabel()))) {
if (!pattern.contains(":")) {
pattern = "file:" + pattern;
}
if (pattern.startsWith("file:")) {
pattern = StringUtils.cleanPath(new File(pattern
.substring("file:".length())).getAbsolutePath()) + "/";
}
if (logger.isTraceEnabled()) {
logger.trace("Testing pattern: " + pattern
+ " with property source: " + name);
}
if (normal.startsWith(pattern)
&& !normal.substring(pattern.length()).contains("/")) {
matches = true;
break;
}
}
Looks like by forcing 'normal' through the new File(..).getAbsolutePath() bit forces the slash to change from / to \ (or \\ some times), and thus is not matching against the patten variable (create at the next for loop).
In debug mode, I can see that pattern is set to C: /Development/SVN/WSR_20150711/wsr-config/config/ while normal is set to C:\\Development\\SVN\\WSR_20150711\\wsr-config\\config\\wsr\\wsr-dev.properties.
Thoughts? Any chance we can fix this soon?
This is a known issue that has been fixed. See https://github.com/spring-cloud/spring-cloud-config/issues/150

Texture Packer Command line multiple images

I’m using TexturePacker from the command line and am unable to get it to pack multiple sprites into 1 sheet. It allows me to do 1 sprite so the command is fine.
This is the command I am using.
"TexturePacker --format sparrow --texture-format atf --opt DXT5
--max-width 2048 --max-height 2048 --size-constraints POT --pack-mode Best --enable-rotation --trim-mode Trim --algorithm MaxRects
--multipack --border-padding 5 --shape-padding 5 --reduce-border-artifacts --scale " + sheetInfo.scale + " --data " + imageOutputDirectory + "\" + lanfPrefix + "\" + sheetInfo.name +
".xml " + "--sheet " + imageOutputDirectory + "\" + lanfPrefix + "\"
+ sheetInfo.name + ".atf image1.png image2.png";
Any ideas why this isn't working? According to the documentation, it should work.
I was unable to find any real way to fix this even contacted the developer of texture packer but got no response. Instead I was able to accomplish the desired outcome by copying all needed files to a temp directory and then add the directory to the end of the texturepacker call instead of individual images.
Due to the poor TexturePacker documentation, it took me much trial and error to figure this out!
To add multiple images to a single sprite sheet, here is a sample command that will create an atlas called out.png (the default) containing images img_1 to img_4...
TexturePacker --format unity-texture2d img_1.png img_2.png img_3.png img_4.png
The key is the list of image filenames separated only by spaces. I am working from Python, so here is the script I use to create the same atlas that the sample line above will give you. Using glob with wildcards allows me to select images from a folder containing many images and eliminates the need to isolate the files I want into a folder just for TexturePacker's sake.
import subprocess, glob
TP = r"C:\Program Files\CodeAndWeb\TexturePacker\bin\TexturePacker.exe"
baseFrame = "img"
def FillAtlas(baseFrame):
globString = baseFrame + "_*.png"
frameList = glob.glob(globString)
imgList = []
for frame in frameList:
imgList.append(frame)
TPargs = [TP, "--format", "unity-texture2d"] + imgList
subprocess.call(TPargs)
FillAtlas(baseFrame)

Resources