Skip to content
Permalink
Browse files

auto-generate the lists

for every not automated task, there is a manager. make it automatic so they can
escape.
  • Loading branch information...
fzerorubigd committed Apr 11, 2018
1 parent 1cf8240 commit 5048cac6232d2e97c7f7d5a7c3ee7684d80e9a9d
Showing with 273 additions and 5 deletions.
  1. +3 −0 .gitattributes
  2. +1 −0 .gitignore
  3. +2 −3 FOD.ppx
  4. +19 −0 Makefile
  5. +19 −1 OmegaProfile.pac
  6. +45 −0 fodcmd/foxyproxy.go
  7. +83 −0 fodcmd/main.go
  8. +41 −0 fodcmd/pac.go
  9. +59 −0 fodcmd/proxifier.go
  10. +1 −1 foxyproxy-patterns.json
@@ -0,0 +1,3 @@
POD.ppx linguist-generated=true
foxyproxy-patterns.json linguist-generated=true
OmegaProfile.pac linguist-generated=true
@@ -0,0 +1 @@
fodcmd/fodcmd
@@ -26,8 +26,7 @@
<RuleList>
<Rule enabled="true">
<Name>FOD</Name>
<Targets>*.developer.android.com
.atlassian.com;*.bintray.com;*.bitbucket.org;*.developers.google.com;*.domains.google.com;*.dl.google.com;*.appengine.google.com;*.google.ai;*.unity3d.com;*.cloud.google.com;*.analytics.google.com;*.fiber.google.com;*.dl-ssl.google.com;*.dns.google.com;*.firebase.google.com;*.firebase.com;*.googleapis.com;*.java.com;*.khanacademy.org;*.oracle.com;*.storage.googleapis.com;*.themeforest.net;*.flurry.com;*.softlayer.com;*.download.virtualbox.org;*.sun.com;*.dev.mysql.com;*.mongodb.org;*.mongodb.com;*.envato.com;*.adobe.com;*.apps.admob.com;*.cp.maxcdn.com;*.codecanyon.net;*.amd.com;*.idaas.iam.ibm.com;*.mbed.com;*.netbeans.org;*.vmware.com;*.toggl.com;*.docker.com;*.googlesource.com;*.polymer-project.org;*.udemy.com;*.material.io;*.teamviewer.com;*.intel.com;*.developer.chrome.com;*.backtory.com;*.github.com;*.maven.org;*.jitpack.io;*.maven.google.com;*.nvidia.com;*.kaggle.com;*.tensorflow.org</Targets>
<Targets>*.android.com;*.teamtreehouse.com;*.upwork.com;*.arcgis.com;*.php.net;*.githubusercontent.com;*.slack.com;*.photodune.net;*.videohive.net;*.audiojungle.net;*.3docean.net;*.sparkjava.com;*.graphicriver.net;*.goanimate.com;*.atlassian.com;*.clients6.google.com;*.incredibuild.com;*.epicgames.com;*.packagist.org;*.jenkov.com;*.bintray.com;*.withgoogle.com;*.coinbase.com;*.schema.org;*.invisionapp.com;*.bitbucket.org;*.developers.google.com;*.nativescript.org;*.domains.google.com;*.tensorflow.org;*.apple.com;*.aws.amazon.com;*.dl.google.com;*.rapid7.com;*.appengine.google.com;*.envato-static.com;*.newrelic.com;*.google.ai;*.telerik.com;*.ai.google;*.doubleclickbygoogle.com;*.doubleclick.net;*.gstatic.com;*.googleadservices.com;*.googletagmanager.com;*.google-analytics.com;*.googleusercontent.com;*.en25.com;*.tinypng.com;*.demandbase.com;*.appspot.com;*.unity3d.com;*.sourceforge.net;*.unity.com;*.expo.io;*.myfonts.net;*.design.google.com;*.stripe.com;*.gravatar.com;*.cloud.google.com;*.analytics.google.com;*.fiber.google.com;*.dl-ssl.google.com;*.dns.google.com;*.firebase.google.com;*.firebase.com;*.googleapis.com;*.jetbrains.com;*.seleniumhq.org;*.invis.io;*.java.com;*.vuforia.com;*.gradle.org;*.fabric.io;*.godoc.org;*.khanacademy.org;*.oracle.com;*.crashlytics.com;*.golang.org;*.storage.googleapis.com;*.spring.io;*.themeforest.net;*.flurry.com;*.softlayer.com;*.mailgun.com;*.bootstrapcdn.com;*.download.virtualbox.org;*.sun.com;*.books.google.com;*.dev.mysql.com;*.mongodb.org;*.mongodb.com;*.envato.com;*.adobe.com;*.apps.admob.com;*.cp.maxcdn.com;*.codecanyon.net;*.amd.com;*.payments.google.com;*.idaas.iam.ibm.com;*.mbed.com;*.netbeans.org;*.vmware.com;*.toggl.com;*.docker.com;*.docker.io;*.gcr.io;*.bugsnag.com;*.googlesource.com;*.polymer-project.org;*.udemy.com;*.material.io;*.teamviewer.com;*.intel.com;*.developer.chrome.com;*.backtory.com;*.github.com;*.jfrog.org;*.sonatype.org;*.maven.org;*.jitpack.io;*.maven.google.com;*.cloudfront.net;*.nvidia.com;*.rstudio.com;*.sendgrid.com;*.tensorflow.org;*.kaggle.com;*.issuetracker.google.com;*.archive.ubuntu.com;*.elastic.co;*.launchpad.net;*.medium.com;*.code.google.com;*.realm.io;*.maas.io;*.docs.datastax.com;*.releases.hashicorp.com;*.tinyjpg.com;*.livefyre.com;*.slack-edge.com;*.cloudera.com;*.pegahtech.ir;*.apache.org;*.vagrantup.com;*.metasploit.com;*.rapid7.com;*.coursera.org;*.npmjs.org</Targets>
<Action type="Proxy">100</Action>
</Rule>
<Rule enabled="true">
@@ -40,4 +39,4 @@
<Action type="Direct" />
</Rule>
</RuleList>
</ProxifierProfile>
</ProxifierProfile>
@@ -0,0 +1,19 @@
ROOT=$(realpath $(dir $(firstword $(MAKEFILE_LIST))))
GO=$(shell which go)


all: build
$(ROOT)/fodcmd/fodcmd -domains=$(ROOT)/domains -foxyproxy=$(ROOT)/foxyproxy-patterns.json -pac=$(ROOT)/OmegaProfile.pac -proxifier=$(ROOT)/FOD.ppx

build:
cd $(ROOT)/fodcmd && $(GO) build .

foxyproxy: build
$(ROOT)/fodcmd/fodcmd -domains=$(ROOT)/domains -foxyproxy=$(ROOT)/foxyproxy-patterns.json

pac: build
$(ROOT)/fodcmd/fodcmd -domains=$(ROOT)/domains -pac=$(ROOT)/OmegaProfile.pac

proxifier: build
$(ROOT)/fodcmd/fodcmd -domains=$(ROOT)/domains -proxifier=$(ROOT)/FOD.ppx

Some generated files are not rendered by default. Learn more.

@@ -0,0 +1,45 @@
package main

import (
"encoding/json"
"io"
"strings"
)

type foxyPattern struct {
Enabled bool `json:"enabled"`
Name string `json:"name"`
Pattern string `json:"pattern"`
IsRegEx bool `json:"isRegEx"`
CaseSensitive bool `json:"caseSensitive"`
BlackList bool `json:"blackList"`
MultiLine bool `json:"multiLine"`
}

type foxyStruct struct {
Patterns []foxyPattern `json:"patterns"`
}

func nameToFoxyPattern(in string) string {
return strings.Replace(in, ".", "*", 1) + "/*"
}

func foxyProxy(target io.Writer, domains ...string) error {
all := foxyStruct{
Patterns: make([]foxyPattern, len(domains)),
}

for i := range domains {
all.Patterns[i] = foxyPattern{
true,
domains[i],
nameToFoxyPattern(domains[i]),
false,
false,
false,
false,
}
}
enc := json.NewEncoder(target)
return enc.Encode(all)
}
@@ -0,0 +1,83 @@
package main

// there is a lot of better library out there. specially I hate the standard flag library.
// but I want this one, clean and tidy. so hell with it :)
import (
"bufio"
"flag"
"io"
"log"
"os"
"path/filepath"
)

var (
listFile *string
foxy *string
pac *string
ppx *string
)

func check(err error) {
if err != nil {
log.Fatal(err)
}
}

func openFile(f string) (io.WriteCloser, error) {
fl, err := os.Create(f)
if err != nil {
return nil, err
}
return fl, nil
}

func load(path string) ([]string, error) {
f, err := os.Open(path)
if err != nil {
return nil, err
}
defer f.Close()

var domains []string
sc := bufio.NewScanner(f)
for sc.Scan() {
domains = append(domains, sc.Text())
}
return domains, sc.Err()
}

func execute(p string, fn func(io.Writer, ...string) error, domains ...string) error {
if p != "" {
fl, err := openFile(p)
check(err)
defer fl.Close()

return fn(fl, domains...)
}

return nil
}

func main() {
flag.Parse()
domains, err := load(*listFile)
check(err)

check(execute(*foxy, foxyProxy, domains...))
check(execute(*ppx, proxifier, domains...))
check(execute(*pac, pacFile, domains...))
}

func init() {
p, err := os.Getwd()
if err != nil {
log.Fatal(err)
}

p = filepath.Join(p, "domains")
listFile = flag.String("domains", p, "domains file list")
foxy = flag.String("foxyproxy", "", "path to build foxyproxy pattern, empty means ignore")
pac = flag.String("pac", "", "path to build pac file, empty means ignore")
ppx = flag.String("proxifier", "", "path to build proxifier config, empty means ignore")
}
@@ -0,0 +1,41 @@
package main

import (
"io"
"strings"
"text/template"
)

var pacTmpl = template.Must(template.New("pac").Funcs(template.FuncMap{
"escape": jsEscape,
}).Parse(`var FindProxyForURL = function(init, profiles) {
return function(url, host) {
"use strict";
var result = init, scheme = url.substr(0, url.indexOf(":"));
do {
result = profiles[result];
if (typeof result === "function") result = result(url, host, scheme);
} while (typeof result !== "string" || result.charCodeAt(0) === 43);
return result;
};
}("+auto switch", {
"+auto switch": function(url, host, scheme) {
"use strict";{{ range $d := . }}
if (/(?:^|\.){{$d|escape}}$/.test(host)) return "+fod";{{end}}
return "DIRECT";
},
"+fod": function(url, host, scheme) {
"use strict";
if (/^127\.0\.0\.1$/.test(host) || /^::1$/.test(host) || /^localhost$/.test(host)) return "DIRECT";
return "PROXY fod.backtory.com:8118";
}
});
`))

func jsEscape(in string) string {
return strings.Replace(in[1:], ".", "\\.", -1)
}

func pacFile(target io.Writer, domains ...string) error {
return pacTmpl.Execute(target, domains)
}
@@ -0,0 +1,59 @@
package main

import (
"io"
"strings"
"text/template"
)

var xmlTmpl = template.Must(template.New("xml").Parse(`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ProxifierProfile version="101" platform="Windows" product_id="0" product_minver="310">
<Options>
<Resolve>
<AutoModeDetection enabled="false" />
<ViaProxy enabled="true">
<TryLocalDnsFirst enabled="false" />
</ViaProxy>
<ExclusionList>%ComputerName%; localhost; *.local</ExclusionList>
</Resolve>
<Encryption mode="basic" />
<HttpProxiesSupport enabled="true" />
<HandleDirectConnections enabled="false" />
<ConnectionLoopDetection enabled="true" />
<ProcessServices enabled="false" />
<ProcessOtherUsers enabled="false" />
</Options>
<ProxyList>
<Proxy id="100" type="HTTPS">
<Address>fod.backtory.com</Address>
<Port>8118</Port>
<Options>48</Options>
</Proxy>
</ProxyList>
<ChainList />
<RuleList>
<Rule enabled="true">
<Name>FOD</Name>
<Targets>{{.}}</Targets>
<Action type="Proxy">100</Action>
</Rule>
<Rule enabled="true">
<Name>Localhost</Name>
<Targets>localhost; 127.0.0.1; %ComputerName%</Targets>
<Action type="Direct" />
</Rule>
<Rule enabled="true">
<Name>Default</Name>
<Action type="Direct" />
</Rule>
</RuleList>
</ProxifierProfile>`))

func proxifier(target io.Writer, domains ...string) error {
d := make([]string, len(domains))
for i := range domains {
d[i] = "*" + domains[i]
}

return xmlTmpl.Execute(target, strings.Join(d, ";"))
}

Large diffs are not rendered by default.

0 comments on commit 5048cac

Please sign in to comment.
You can’t perform that action at this time.