mirror of
https://github.com/edoardottt/cariddi.git
synced 2026-09-22 17:44:58 +02:00
73 lines
1.9 KiB
Go
73 lines
1.9 KiB
Go
/*
|
|
==========
|
|
Cariddi
|
|
==========
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see http://www.gnu.org/licenses/.
|
|
|
|
@Repository: https://github.com/edoardottt/cariddi
|
|
|
|
@Author: edoardottt, https://www.edoardoottavianelli.it
|
|
|
|
@License: https://github.com/edoardottt/cariddi/blob/main/LICENSE
|
|
|
|
*/
|
|
|
|
package scanner
|
|
|
|
//Info struct
|
|
// Name = the name that identifies the information
|
|
// Regex = The regular expression to be matched
|
|
type Info struct {
|
|
Name string
|
|
Regex []string
|
|
}
|
|
|
|
//InfoMatched struct
|
|
// Info = Info struct
|
|
// Url = url in which the information is found
|
|
// Match = the string matching the regex
|
|
type InfoMatched struct {
|
|
Info Info
|
|
Url string
|
|
Match string
|
|
}
|
|
|
|
//GetInfoRegexes returns all the info structs
|
|
func GetInfoRegexes() []Info {
|
|
var regexes = []Info{
|
|
{
|
|
"Email address",
|
|
[]string{
|
|
`(?i)([a-zA-Z0-9_.+-]+@[a-zA-Z0-9]+[a-zA-Z0-9-]*\.[a-zA-Z0-9-.]*[a-zA-Z0-9]{2,})`},
|
|
},
|
|
{
|
|
"HTML comment",
|
|
[]string{
|
|
`(?i)(\<![\s]*--[\-!@#$%^&*:;ºª.,"'(){}\w\s\/\\[\]]*--[\s]*\>)`},
|
|
},
|
|
}
|
|
return regexes
|
|
}
|
|
|
|
//RemoveDuplicateInfos removes duplicates from Infos found
|
|
func RemoveDuplicateInfos(input []InfoMatched) []InfoMatched {
|
|
keys := make(map[string]bool)
|
|
list := []InfoMatched{}
|
|
for _, entry := range input {
|
|
if _, value := keys[entry.Match+entry.Url]; !value {
|
|
keys[entry.Url] = true
|
|
list = append(list, entry)
|
|
}
|
|
}
|
|
return list
|
|
}
|