Archives for category: Uncategorized

Was getting an error when trying to connect to my samba share:

 

Resolved it with this blog post: https://www.techcrumble.net/2018/03/you-cant-access-this-shared-folder-because-your-organizations-security-policies-block-unauthenticated-guest-access/

 

So I found that this access is blocking from the local group policy and I opened the Run window (Win + R) and typed gpedit.msc to open the Local Group Policy Editor.

Navigated to Computer Configuration -> Administrative Templates -> Network -> Lanman Workstation and selected the Enable insecure guest logons as shown in the below screenshot

By default it was disabled and I have enabled the policy

OpenVPN was crashing (connection time-outs around 8pm) a couple times.  Can’t risk it.

 

Followed these instructions to disable connectivity if openVPN drops:

https://www.raspberrypi.org/forums/viewtopic.php?t=223589

Final IPTables rules:

Chain INPUT (policy DROP)
target prot opt source destination
ACCEPT all -- anywhere anywhere
ACCEPT all -- 192.168.1.0/24 anywhere
ACCEPT udp -- anywhere anywhere udp spt:domain
ACCEPT udp -- anywhere anywhere udp spt:1198
ACCEPT all -- anywhere anywhere

Chain FORWARD (policy DROP)
target prot opt source destination

Chain OUTPUT (policy DROP)
target prot opt source destination
ACCEPT all -- anywhere anywhere
ACCEPT all -- anywhere 192.168.1.0/24
ACCEPT udp -- anywhere anywhere udp dpt:domain
ACCEPT udp -- anywhere anywhere udp dpt:1198
ACCEPT all -- anywhere anywhere

 

 

Built a script to restart openvpn if not running -run it hourly

https://www.raspberrypi.org/forums/viewtopic.php?t=33890

#!/bin/bash
for i in openvpn ; do
if [[ $( pidof "$i" | wc -l ) -eq 0 ]] ; then
        echo $( date +%Y-%m-%d\ %H:%M:%S ) "$i has crashed! Process Restarted" >> /var/log/crashlog
        logger "$i" has crashed! Process Restarted.
        /etc/init.d/"$i" start
fi
done

#if [[ $( pidof smbd | wc -l ) -eq 0 || $( pidof nmbd | wc -l ) -eq 0 ]]; then
        #/etc/init.d/samba restart
        #echo $( date +%Y-%m-%d\ %H:%M:%S ) "Samba has crashed! Process Restarted"
        #logger Samba has crashed! Process Restarted.
#fi
exit

 

Followed directions here:

https://www.sbprojects.net/projects/raspberrypi/exim4.php

 

Getting A Message Transfer Agent

Before your Pi can send emails it needs a message transfer agent (MTA). I have two flavours for you. The first one is exim4, the other one is SSMTP. The choice is yours. Needless to say, you will only need one of the two MTAs.
Thanks to the Debian packaging system this is easily done by typing one of the following commands.

Exim4

sudo apt-get install exim4

After installing exim4 we need to configure it. This is done by the following command:

sudo dpkg-reconfigure exim4-config

Now you need to answer some questions. Don’t worry I’ll give you the answers to those questions.

  • The first screen asks you what type of mail server you need. Select the second option: “mail sent by smarthost; received via SMTP or fetchmail”
  • The next question asks for the system mail name: Set to same as hostname (raspberrypi)
  • Now it asks you what IP addresses should be allowed to use the server. Leave as is (127.0.0.1 ; ::1)
  • Other destinations for which mail is accepted: raspberrypi
  • Machines to relay mail for: Leave blank.
  • IP address or host name of outgoing smarthost: Replace by: smtp.gmail.com::587
  • Hide local mail name in outgoing mail: Select: No
  • Keep number of DNS-queries minimal: Select: No
  • Delivery method for local mail: Select: “Maildir format in home directory”
  • Split configuration into small files: Select: No
  • Root and postmaster mail recipient: Enter: pi

After answering all these questions exim4 will restart and we’re halfway home.

Now you’ll have to enter your account details. As root, edit the file /etc/exim4/passwd.client and add the next three lines at the end of the file.

gmail-smtp.l.google.com:YOU@gmail.com:PASSWORD
*.google.com:YOU@gmail.com:PASSWORD
smtp.gmail.com:YOU@gmail.com:PASSWORD

Needless to say that you’ll have to change YOU to your Gmail login name, and PASSWORD to your password on all three lines. After that you only have to update and restart exim4 and you’re done! The next two lines will do that for you:

sudo update-exim4.conf
sudo service exim4 restart

SSMTP

sudo apt-get install ssmtp mailutils mpack

Now edit the file /etc/ssmtp/ssmtp.conf as root and add the next lines. Please note that some of the lines already exist and may need to be changed. Others don’t exist yet and need to be added to the end of the file.

mailhub=smtp.gmail.com:587
hostname=ENTER YOUR RPI'S HOST NAME HERE
AuthUser=YOU@gmail.com
AuthPass=PASSWORD
useSTARTTLS=YES

Again you’ll have to replace YOU with your gmail login name and PASSWORDwith your (application specific) gmail password.
After this you’re done. You don’t even have to restart the SSMTP server (in fact, there is none).

The Final Touches

Some processes, for instance crontabs, can send mails to root or other system users. If you don’t want to miss any of them you can setup some aliases. You can do that by editing the file /etc/aliases. Here’s what mine looks like:

# /etc/aliases
mailer-daemon: postmaster
postmaster: root
nobody: root
hostmaster: root
usenet: root
news: root
webmaster: root
www: root
ftp: root
abuse: root
noc: root
security: root
root: pi
pi: youremail@example.com

It may be necessary to run the next command to make the changes in aliases active:

sudo newaliases

This tells the system to redirect all mail to root, while mail to root is redirected to the user pi, while mail to user pi is finally redirected to my own mail account. This way all system mail will eventually be sent to my own mail account, no matter to what local user the mail was originally sent.

If you are like me, you will probably have more than one Raspberry Pi mailing you some status information. And unless you use different mail accounts for all your RPis it becomes harder and harder to find out which one is mailing you. The next command will setup a new full name (pi @ domotics) for the user name pi, with which you can idintify the source of the e-mail.

sudo chfn -f "pi @ domotics" pi

PS: The aliases don’t appear to work with the SSMTP setup. Nothing I tried seemed to work. Although SSMTP is easier to setup, I recommend you to use the Exim4 approach to get a more complete mail experience.
But if it is simplicity you’re after, feel free to use SSMTP.

A Better Mail User Agent

By default the program bsd-mailx is installed on the Raspberry Pi as the mail user agent. Every time you invoke the mail command, bsd-mailx is executed. There’s one thing that I don’t like about this program and that it won’t allow you to send attachments with your mails.
So let’s remove that program and install a better alternative:

sudo apt-get install heirloom-mailx
sudo rm /etc/alternatives/mail
sudo ln -s /usr/bin/heirloom-mailx /etc/alternatives/mail

After that you can simply do something like mail -a attachment.file -s “Subject line” to@example.com to send an email with a file attached to it.

Testing

To test your outgoing mail simply execute the next command:

mail -s "This is the subject line" root@localhost

Then type the body of the message, this is only a test so anything will do. When you’re done typing the body type a dot (.) at the beginning of a new line and hit Enter. The mail should now be sent to root, which is redirected to pi, which is redirected to your normal email address.
You can also send a mail directly to your own email address if you want to, however that would be skipping testing the redirections.

Below you see two other ways of sending mail from your RPi. Both methods will send the file body.txt as message body.

mail -s "This is the subject line" someone@example.com < body.txt
cat body.txt | mail -s "This is the subject line" someone@example.com

I’ve been messing with this for a while and finally got it working – thanks recent Python class!

Here’s the code

 

import json
import urllib2
import time
from datetime import datetime, timedelta, date

def sendToKodi(message):
req = urllib2.Request(‘http://TV:80/jsonrpc&#8217;)
req.add_header(‘Content-Type’, ‘application/json’)
data = {“jsonrpc”:”2.0″,”method”:”GUI.ShowNotification”,”params”:{“title”:”Caller ID”, “message”:message},”id”:1}
response = urllib2.urlopen(req, json.dumps(data))

def tail_f(file):
interval = 1.0

while True:
where = file.tell()
line = file.readline()
if not line:
time.sleep(interval)
file.seek(where)
else:
yield line

for line in tail_f(open(‘/var/log/router.log’)):
if “CID” in line:
print line
splits = line.split()
month = splits[0]
day = int(splits[1].strip())
timestamp = splits[2]
cid = line.split(“:”,3)[3]
cur_year = datetime.now().year
log_datetime = datetime.strptime(month + ” ” + str(day) + ” ” + str(cur_year) + ” ” + timestamp, “%b %d %Y %H:%M:%S”)
print “Curtime<%s> log_time<%s>”%(datetime.now(),log_datetime)
if datetime.now() < log_datetime + timedelta(seconds=10): #if within last 10 seconds
#send to kodi
print “Kodi”
sendToKodi(cid)
else:
print “old log %s %s” % (cid, log_datetime)

root@raspberrypi:/home/pi# apt-get install syslog-ng

Syslog-ng is configured via the syslog-ng.conf file found in the /etc/syslog-ng directory. You need to edit that file so that the Pi can start receiving syslog messages from the Cisco router in our test scenario. You can open syslog-ng.conf for editing using a text editor like the good oldnano. It would instantly become clear that file is well structured and has several sections. You can add the following three lines to the sections named Sources, Destinations, and Log pathsrespectively.

source s_net { udp(ip(0.0.0.0) port(514)); };
destination d_router { file("/var/log/router.log"); };
log { source(s_net); destination(d_router); };

Please keep in mind that you can also alternately the three lines together in the file and it still works. You need to restart syslog-ng to bring into effect the configuration changes you just made.

root@raspberrypi:/home/pi# service syslog-ng restart
Stopping system logging: syslog-ng.
Starting system logging: syslog-ng.

You can use the touch command to create the log file that will be used to write syslog messages from the router.

root@raspberrypi:/home/pi# touch /var/log/router.log
root@raspberrypi:/home/pi# ls /var/log/router*
/var/log/router.log

You can have a live view of the syslog messages that will be written to the router.log file using the tail command.

root@raspberrypi:/home/pi# tail -f /var/log/router.log

That’s all what we need to configure on the Pi.

http://resources.intenseschool.com/raspberry-pi-as-a-syslog-server/

http://xmodulo.com/check-internet-speed-command-line-linux.html

speedtest-cli is a simple CLI client written in Python for measuring bidirectional Internet bandwidth by using Speedtest.net infrastructure. It works with Python 2.4-3.4. Installing the latest speedtest-cli is nothing more than downloading the Python script.

http://monkeyhacks.com/raspberry-pi-as-private-git-server

 

Install Git

sudo apt-get install wget git-core

Add a “Git” User and Group

 

adduser --system --shell /bin/bash --gecos 'git version control by pi' --group --home /home/git git

passwd git
Add an Empty Git Repository

cd /home/git


mkdir test.git
cd test.git
git --bare init

Push Code to your Pi


git remote add pi git@[your IP]:/home/git/test.git


git add .
git commit -am "Initial"
git push pi master

http://blog.oliver-mueller.com/-135

 

 

http://elinux.org/RPi_Java_JDK_Installation

 

sudo apt-get update
sudo apt-get install openjdk-7-jdk

I copied the 4GB image from my first Pi to the 2nd and didn’t realize that it didn’t expand to the full SD card.  

Found a great simple instructions:

http://elinux.org/RPi_Resize_Flash_Partitions

 

Just type in raspi-config and choose the first option, ‘Expand Filesystem’.  THAT’S IT!