Old CrossFamily Front Page

Posted on by admin | Leave a comment

Security Websites

Some useful links to security related online checking tools:

Trackback an IP address – https://ipinfo.io
Run an application through a sandbox check – https://www.joesandbox.com
Online check a file/url/IP – https://www.virustotal.com/gui/home/search

Posted in Security | Tagged , , | Leave a comment

Telegram Bot API

The Telegram Bot API can be found here!

The web hooks look interesting for two way communication between bot and user(s), and looks simple enough to implement so possibly a future activity.

 

Posted in Code | Tagged | Leave a comment

Bot Notifications using Telegram

This PHP setup is based off of the excellent Python article provided by Man Hay Hong.

To get started you need to download/install Telegram and set yourself up as a user.

Once it is installed you need to setup a new bot by interacting with @BotFather and sending the following:

  • /start {this will provide some help info}
  • /newbot {@botfather will walk you through creating your new bot}

You now have your bot token – keep this safe as it enables anyone to control your bot and for you to interact through it.

Now you need your chatID so using the following URL in your browser you will see the additional info you need:

  • https://api.telegram.org/botput_your_token_here/getUpdates

Look for the following and record the digits as that is your chatID:

{"id":xxxxxxxxxxxxx <<<<<< chatID

Again, keep this information secure.

I used the following PHP code to then send messages from my internal web server. The code does also check that any messages sent originate internally otherwise it throws an error.

<?php
$bot_token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$bot_chatid = 'xxxxxxxxxxxx';

/* telegram_getUpdates() - get telepgram update info */
function telegram_getUpdates() {
global $bot_token;

$send_mesg = 'https://api.telegram.org/bot' . $bot_token . '/getUpdates';
$retval = file_get_contents($send_mesg);

return $retval;
}

/* telegram_notify() - send message to telegram user from bot */
function telegram_notify($mesg) {
global $bot_token, $bot_chatid;

$url = 'https://api.telegram.org/bot' . $bot_token . '/sendMessage';
$data = array('chat_id' => $bot_chatid , 'parse_mode' => 'Markdown', 'text' => $mesg);

// use key 'http' even if you send the request to https://...
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);

$retval = json_decode( $result);

return $retval;
}

if (preg_match('/192\.168\.1\./', $_SERVER['HTTP_X_REAL_IP'])) {
// Local network access via WEB
$mesg = '';

if (isset($_GET['mesg'])) {
/* We have a message to send so send it! */
$mesg = htmlspecialchars($_GET["mesg"]);

$result =  telegram_notify($mesg);
if ( $result->ok == true) 
echo "Sent";
else 
echo "Failed - " . $result->description;
} else {
/* No message so get the status instead */
$result = telegram_getUpdates();
echo $result;
}
} else {
// If we see a remote connection then send a 404
http_response_code(404);
}

?>

 

Posted in Code, Uncategorized | Tagged , , | Leave a comment

Powering ESP8266 & other devices

While I get this sorted out this page will be a holding page for parts located:

  • MT3608 DC to DC Boost converter (3.7v to 5v)
  • TP4056 Lithium Battery Charging board
  • 18650 Lithium battery
Posted in Electronics, Uncategorized | Tagged | Leave a comment

ESP8266 – Getting Started with MicroPython

For a couple of pounds I purchased a couple of ESP8266 NodeMCU WEMOS development boards to play with. Decided to go with the NodeMCU versions so that they come with a micro USB and 3.3 regulator onboard.

As I’ve been playing with Python for a while I decided to download MicroPython on to the ESP to provide control of real-world devices. Instructions on downloading, formatting and getting started with MicroPython can be found here.

I’ve included my notes here as things were not as plain-sailing as I would have liked.

Connecting the ESP8266 to my Mac – sounds easy but the hardest part is finding a USB cable that has data connections instead of just being wired for 5v-GND. Most charging cables come with only power wired so after trying about 6 cables I found one that worked.

So how did I know I had a good cables as all powered up the ESP? You need to see if your Mac shows the USB device turning up. Before connecting type “ls /dev | grep -I usb” and then connect the device. You should see the device show up if the cable has the right connections.

Now download the esptool for programming the ESP and transmits the firmware to the ESP.

https://github.com/espressif/esptool

And down a copy of the Micropython Firmware from the above MicroPython site.

To program the ESP I used the following command:

esptool.py --port /dev/ttyUSB_DEVICE --baud 460800 write_flash --flash_size=detect 0 FIRMWARE>BIN

      ttyUSB_DEVICE is your device found from the ls /dev command above
      FIRMWARE.BIN is the file you downloaded from the MicroPython site

With luck the firmware would have downloaded and successfully been verified – woohoo!

Now you can connect to the device and get a REPL prompt.

REPL prompt – that sounds easy but it took a few goes to find the right command on the Mac to create a serial connection to the ESP on the USB port and then get it working. The “screen” command is available on the Mac and the speed to connect with is 115200.

screen /dev/cuUSB_DEVICE 115200

I found that I sometimes got an error about no Pty device. This turned out to be zombie screen processes locking out the device port. Perform a “ps -ef | grep -i usb” to find the zombie processes and kill them (show no mercy).

 You can not follow the instructions on the MicroPython site to interact with the REPL prompt. If you want to upload/download files then you will need “WebREPL“.

http://micropython.org/webrepl

Notes on uploading files to Execute

  • Use the web version of WebREPL or WebREPL.py to send or get files from the ESP
  • I found that once a file is uploaded you need to reset before attempting to run the file. A soft reset can be performed by pressing Ctrl-D in the browser or at the REPL command prompt in screen
  • To run the file import it!

Controlling a 5050 WS2812B RGB LED Ring

This was a few pounds on Ebay so tried to connect it to the ESP8266 WEMOS which was pretty simple after I soldered some wires on. I connected the 5v and GND straight to the ESP pins, and the Din (DI) wire to D2 on the WEMOS. This is GPIO04 (pin out found here). 

Power consumption = each led is around 18mA on.

If you want to create an online wiring diagram with drag-n-drop components then use https://www.circuito.io/app which is pretty cool.

To control the leds you need to run some MicroPython code on the ESP but you can use the example below:

import machine, neopixel
np = neopixel.NeoPixel(machine.Pin(4), 12) #we have 12 leds on GPIO4

np[0] = (128, 0, 0) # Led 0 half bright single color - red I think
np[2] = (0, 128, 0) # Led 2 another colour
np[4] = (0, 0, 128)

np.write()

You should have some (3) leds now light up, if it all works!

 

Posted in Electronics | Tagged , , , | Leave a comment

git Quick Reference

Pull Code from a Repository
    git clone http://{server/repository.git

Add Files to Local Repository
    git add *

Status of Local Files
    git status

Commit Changes Locally
    git commit -m "Adding new files"

Commit Change to Remote Main Branch
    git push origin master

Refresh Local Files in Case Other Updates Took Place
    git pull origin master

Creating a development branch
    git checkout -b develop origin

Push new branch back to the server
    git push -u origin develop

 

An excellent and more detailed quick reference guide is located here and cheatsheets here.

A great article on managing versions and releases is here

Posted in Uncategorized | Leave a comment

Installing Gitea (my own GitHub)

To install Gitea on a Synology under Docker you can pretty much follow the instructions found here

I used the custome setup with some minor changes to the USER-UID & USER-GID for the account I want to run under on the Synology. 

docker-compose.yml:

version: "2"
networks:
  gitea:
    external: false
services:
  server:
    image: gitea/gitea:latest
    environment:
      - USER_UID={enter User ID here}
      - USER_GID={enter Group ID here}
    restart: always
    networks:
      - gitea
    volumes:
      - ./gitea:/data
    ports:
      - "3000:3000"
      - "222:22"

The above will use a SQLite database which should be fine. 

When running “sudo docker-compose up -d” an error was generated for failing to mount “gitea” due to permissions. Manually creating the folder and re-running the command fixed the issue.

Checking Docker on the Synology finds that the container is running and connecting with a browser to http://{server}:3000 with bring up the Gitea page – woohoo!

 

Posted in Code, Docker | Tagged , , , | Leave a comment

SVN Quick Reference

View Repository
    svn ls svn://{server}/projects

Import New Folders in to Repository
   svn import {folder} svn://{server}/projects/{folder} -m "{comment}"

Checkout Folder/Files from Repository
  svn co svn://{server}/projects/{folder}

View Status of Files in Folder
  svn status

Checkin Changed Files to Repository
  svn commit -m "{comment}"

Pull Latest Files from Repository
  svn update

Posted in Code | Tagged , | Leave a comment

Docker Quick Reference

View/Change Container Status
    docker ps                 {list running containers}
    docker ps -a              {list all containers even exited ones}
    docker container pause ID {pause running container}
    docker container stop ID  {stop running container}
    docker container kill ID  {Kill a running container}
    docker logs -f ID         {continually follow output of container}
 
Access Running Container
   docker ps                               {find ID of running container}
   docker commit ID mysnapshot             {create a snapshot}
   docker run -t -i mysnapshot /bin/bash   {run a bash shell}
                                           {-i interactive, -t terminal}
 
Building/Running a Container {containing python code}
   docker build -t {name} .
   docker  run -i -t {name} python run.py
 
Deleting Images
   docker image list      {list images}
   docker rmi image_ID.   {remove image}
 
   If you are unable to delete due to container in use
      docker ps                   {get container name}
      docker rm container_name    {remove exited container}
      docker rmi image_id         {remove image}
 
Mounting Local File Systems
This will mount the current directory as /mnt/app for the container to access:
    docker run -it -v ${PWD}:/mnt/app instabot /bin/bash
 
Docker Documentation
 
 
Posted in Code, Docker | Leave a comment