Thursday, 18 January 2018

How To Secure Your Redis Installation on CentOS 6.x with Password Authentication | Configuring a Redis Password for CentOS




Using CentOS 6.x, for applying Password Authentication in Redis through requirepass Configuration, we need to edit the redis.conf file.

Open the configuration file(name of the file may vary in your machine):

/etc/redis/6379.conf

Find # requirepass foobared and change it in following way:
1
requirepass yourpassword
Save your changes and restart redis-server
1
service redis_6379 restart
1
redis-cli
1
127.0.0.1:6379>set test "TestEntry"
Since we have applied password in Redis Configurtion file "/etc/redis/6379.conf" , we will get NOAUTH error as follows:
1
(error) NOAUTH Authentication required.
while being in redis-cli, write following command with your password for authentication:
1
2
127.0.0.1:6379> auth yourpassword
OK
And then when you will set any value, it will return OK
1
2
127.0.0.1:6379> set test "TestEntry"
OK
We can also run redis-cli directly with password authentication by using following command:
1
redis-cli -a "yourpassword"
We get OK when we run redis-cli in this way and set any value:
1
2
127.0.0.1:6379> set test2 "TestEntry2"
OK

Tuesday, 16 January 2018

Python - HTML to Text for sending SMS - SMS Safe characters - remove \xa0


Following code are some of the alternatives for removing special characters from string:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
from bs4 import BeautifulSoup
 
raw_html = 'Dear Parent,
 
<span style="font-size: 1rem;">This is a test message, </span><span style="font-size: 1rem;">kindly ignore it. </span>
 
<span style="font-size: 1rem;">Thanks</span>
 
'
 
clean_text = BeautifulSoup(raw_html, "lxml").text
 
print clean_text
 
#u'Dear Parent,\xa0This is a test message,\xa0kindly ignore it.\xa0Thanks'
The above code produces these characters \xa0 in the string. To remove them properly, we can use two ways. The first one is BeautifulSoup's get_text method with strip argument as True
1
2
3
4
clean_text = BeautifulSoup(raw_html, "lxml").get_text(strip=True)
 
print clean_text
# Dear Parent,This is a test message,kindly ignore it.Thanks
The other option is to use python's library unicodedata
1
2
3
4
5
6
7
8
9
import unicodedata
 
clean_text = BeautifulSoup(raw_html, "lxml").text
print clean_text
#u'Dear Parent,\xa0This is a test message,\xa0kindly ignore it.\xa0Thanks'
 
new_str = unicodedata.normalize("NFKD",clean_text)
print new_str
# u'Dear Parent,This is a test message,kindly ignore it.Thanks'