jpgpi250 / piholemanual

files referred to in my pihole installation manual
115 stars 14 forks source link

Regex.sh doesnt't nog work correctly if a \ is used #2

Closed eejeel closed 4 years ago

eejeel commented 4 years ago

Hi

in your script a \ in a regex file is not stored in the database.

For example (from https://github.com/mmotti/pihole-regex/blob/master/miscellaneous/amp.list) ^(.+[.-])?amp(project)?. It becomes ^(.+[.-])?amp(project)?.

or from https://github.com/mmotti/pihole-regex/blob/master/social/facebook.list ^(.+[_.-])?(facebook|fb(cdn|sbx)?|tfbnw).[^.]+$

I discover this because I also use your script for storing a local regex file with f.i. (^|.) (cdn.dns[0-6].).*

I investigate some time but at the moment cannot find the reason. Cause is the do loop. A manual update works correct sudo sqlite3 /etc/pihole/gravity.db "insert or ignore into domainlist (domain, type, enabled, comment) values ('.in-addr.arpa$', 3, 1, 'test1');"

With this script you can see the output in a file that ^mads. becomes ^mads. No database access

=== script ====

!/usr/bin

rm /home/pi/regex-processed.txt sudo curl https://raw.githubusercontent.com/mmotti/pihole-regex/master/regex.list -o /home/pi/regex.list while read regex do echo "$regex" >> /home/pi/regex-processed.txt

done < /home/pi/regex.list

======= Also echo \"$regex\" >> /home/pi/regex-processed.txt or echo $regex >> /home/pi/regex-processed.txt doesn't work. Do you have an idea?

Another point: I also have expand you script with a backup and delete before updating the database table. In this case removed regex lines are also removed in teh databease

sudo sqlite3 /etc/pihole/gravity.db "SELECT domain FROM domainlist WHERE type="3";" >> /home/pi/regex.list.backup sudo sqlite3 /etc/pihole/gravity.db "DELETE FROM domainlist WHERE type="3";"

jpgpi250 commented 4 years ago

thank you for reporting this. there was indeed a problem with backslashes, the problem is solved by replacing 'while read regex' by 'while read -r regex'

if you want to import entries, using special characters, you need to identify these characters, by preceding them with a backslash. Example: sudo sqlite3 /etc/pihole/gravity.db "insert or ignore into domainlist (domain, type, enabled, comment) values (\"^mads\\.\", 3, 1, \"mmotti regex\");"

The script is only intended to import the mmotti regular expressions once, backup, delete and restore is not part of the goal the script wants to achieve (ref. the manual)

I've updated the script in the repository.

jpgpi250 commented 4 years ago

closed after 21 days