Hi Syscon,

>From bash/zsh:

1. install leiningen (https://leiningen.org)
2. `cd /file/location/you/store/project/sources`
3. run `lein new htaccess`
   (this will create a folder and project stub)
4. `cat /code/from/the/email > htaccess/src/htaccess/core.clj`
5. cd htaccess
6. `lein repl`

on my machine, this gives me a prompt that looks like this:
------------------------------------------------------------------------------
nREPL server started on port 63648 on host 127.0.0.1 - nrepl://127.0.0.1:63648
REPL-y 0.4.4, nREPL 0.6.0
Clojure 1.8.0
OpenJDK 64-Bit Server VM 1.8.0_265-b01
    Docs: (doc function-name-here)
          (find-doc "part-of-name-here")
  Source: (source function-name-here)
 Javadoc: (javadoc java-object-or-class-here)
    Exit: Control+D or (exit) or (quit)
 Results: Stored in vars *1, *2, *3, an exception in *e

htaccess.core=>
------------------------------------------------------------------------------

at "htaccess.core=>" you can paste in:
(return-matching-blocks "ip.of.my.interest" "/path/to/my/htaccess")

It will return a list of all the matching ip/masks from the lines that contain 
"Require not ip ".
Let me know if you would like me to clarify any of the instructions.

Alright, that's it. Good luck with managing that list.

Best Regards,
Travis


On Wed, Feb 10, 2021 at 11:09:30PM -0700, syscon edm wrote:
> Thanks Travis,  I'm surprised; there is a lot I have to learn when it
> comes to IP matching to CIDR
> I was under the impression that just looking at the beginning of CIDR
> address and I would be able to find the match.  How wrong I was :-/
> 
> Now, I can install * dev-lang/clojure  on Linux
> How do I run that code you gave me from the command line?
> I suppose I need to put it into a file, now which part?
> 
> Thanks,
> Joseph
> 
> On Wed, Feb 10, 2021 at 9:33 PM Travis Rodman <trod...@apple.com.invalid> 
> wrote:
> >
> > Hi Syscon,
> >
> > Okay, so I wrote up a little program to parse your .htaccess file, and this 
> > comes back as a match:
> > 212.129.0.0/1
> >
> > Here is the code (Clojure), so you can parse any future mystery rejections, 
> > if you like.
> > ----------------------------------------------------------------------------------------------------------------------------------------------------
> > (ns htaccess.core)
> >
> > (defn parse-ip [s]
> >   (let [v (clojure.string/split s #"/")]
> >     (flatten
> >       (if (< (count v) 2)
> >         [(clojure.string/split (get v 0) #"\.") "32"]
> >         [(clojure.string/split (get v 0) #"\.") (get v 1)]))))
> >
> > (defn convert-str-to-binary-str [s]
> >   (clojure.string/replace (format "%0$8s" (java.lang.Integer/toBinaryString 
> > (java.lang.Integer/parseUnsignedInt (clojure.string/trim s)))) " " "0"))
> >
> > (defn convert-mask-to-binary-str [s]
> >   (let [m (java.lang.Integer/parseUnsignedInt (clojure.string/trim s))
> >         m (if (< 32 m) 32 m)
> >         l0 (repeatedly m (fn [] 1))
> >         l1 (repeatedly (- 32 m) (fn [] 0))
> >         v  (apply str (flatten [l0 l1]))]
> >     v))
> >
> > (defn binary-string-to-int [s] (java.lang.Integer/parseUnsignedInt 
> > (clojure.string/trim s) 2))
> >
> > (defn masked? [p m]
> >   (let [s0  p
> >         s1  m
> >         p0  (parse-ip s0)
> >         p1  (parse-ip s1)
> >         v0  (apply str (map convert-str-to-binary-str (take 4 p0)))
> >         v1  (apply str (map convert-str-to-binary-str (take 4 p1)))
> >         m   (convert-mask-to-binary-str (last p1))
> >         im  (binary-string-to-int m)
> >         iv0 (binary-string-to-int v0)
> >         iv1 (binary-string-to-int v1)]
> >     (= (bit-and im iv0) (bit-and im iv1))))
> >
> > (defn get-mask-data [s]
> >   (map (fn [s] (clojure.string/replace s "Require not ip " ""))
> >     (filter (fn [s] (clojure.string/includes? s "Require not ip "))
> >       (with-open [rdr (clojure.java.io/reader s)]
> >         (doall (line-seq rdr))))))
> >
> > (defn return-matching-blocks [p f] (filter (fn [a] (masked? p a)) 
> > (get-mask-data f)))
> >
> > ;(return-matching-blocks "1.202.0.0" 
> > "/Users/travis/data/projects/clojure/htaccess/resources/htaccess_backup")
> > ;(return-matching-blocks "159.14.184.11" 
> > "/Users/travis/data/projects/clojure/htaccess/resources/htaccess_backup")
> > ;("212.129.0.0/1")
> > ----------------------------------------------------------------------------------------------------------------------------------------------------
> >
> > If you have other IPs that are a mystery, and don't know how to set up 
> > Clojure, you can just send them my way, I can easily re-run this. I'm not
> > going to chuck the code any time soon.
> >
> > HTH,
> > Travis
> >
> >
> > On Wed, Feb 10, 2021 at 05:25:27PM -0800, Travis Rodman wrote:
> > > Thanks, I got it... I will get back to you.
> > >
> > > Regards,
> > > Travis
> > >
> > > On Wed, Feb 10, 2021 at 06:02:45PM -0700, syscon edm wrote:
> > > > Thank you, I sent you the .htaccess file to the email address you 
> > > > provided.
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: dev-unsubscr...@community.apache.org
> > > For additional commands, e-mail: dev-h...@community.apache.org
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: dev-unsubscr...@community.apache.org
> > For additional commands, e-mail: dev-h...@community.apache.org
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscr...@community.apache.org
> For additional commands, e-mail: dev-h...@community.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@community.apache.org
For additional commands, e-mail: dev-h...@community.apache.org

Reply via email to