Booker

Tuesday, October 3, 2017

How to configure mail forwarder, using Mandrill as a gateway

Mandrill API activation

After creating a new mandrill free account.
Validate DKIM and SPF in mailchimp's Mandrill account.

Then send validation domain mail, and steal the content in the API log, from the failed section.
The mail will contain a body having the full url to validate the domain, open that in any browser, where you are logged using Mandrill, then it will light up green.

Mail gateway

sudo apt-get install ssmtp

sudo vim /etc/ssmtp/ssmtp.conf
# The person who gets all mail for userids < 1000
# Make this empty to disable rewriting.
root=support

# The place where the mail goes. The actual machine name is required no
# MX records are consulted. Commonly mailhosts are named mail.domain.com
mailhub=smtp.mandrillapp.com:587
# Where will the mail seem to come from?
#rewriteDomain=
#Auth info found at: SMTP & API Info, Mandrill's Settings dashboard
AuthUser={My Mandrill USER}
AuthPass={MY Mandrill API KEY}

# The full hostname
hostname=freedom.local

# Are users allowed to set their own From: address?
# YES - Allow the user to specify their own From: address
# NO - Use the system generated From: address
FromLineOverride=YES
sudo vim /etc/ssmtp/revaliases
# Replace root@ with whatever name
support:support@freedom.local:smtp.mandrillapp.com:587

The resulting mail will be like this:
support <support@freedom.local>

Testing 

echo "My mail content" | sudo ssmtp -vvv damjandimitrioski@gmail.com

PHP setup

 sudo vim /etc/php5/fpm/php.ini
locate the [mail function] section and uncomment it
sendmail_path = /usr/sbin/ssmtp -t 
After change, restart php service.
sudo service php5-fpm restart

Testing

$ php -a
php >  mail("petko@gmail.com", "My subject", "My ugly short content");


Saturday, January 28, 2017

Filter for retrieving select field items

The following code needs to be put inside your theme functions.php

/**
 * @param $group_NAME
 * @return array
 */
function fetchACFFields($group_NAME)
{
 // Fetch fields for a given ACF fields group (PRO only)
 $groups = acf_get_field_groups();
 $fields_group = [];
 foreach ($groups as $group) {
  $title = $group['title'];
  if ($title == $group_NAME) {
   $f = acf_get_fields($group['ID']);
   foreach ($f as $i) {
    $fields_group[$group['title']]['fields'][$i['name']] = $i;
    $fields_group[$group['title']]['fields'][$i['name']]['value'] = get_field($i['key']);
   }
   break;
  }
 }
 return $fields_group;
}
add_filter( 'fetch_acf_fields', 'fetchACFFields', 10, 2 );

/**
 * @param $fields_group
 * @param $mysubfield
 * @return array
 */
function fetchSubfieldChoices($group_NAME, $mysubfield)
{
 $fields_group = apply_filters('fetch_acf_fields', $group_NAME);
 // Find choices from subfield
 $first_key = array_keys($fields_group)[0];
 $root = $fields_group[$first_key];

 $choices = [];
 foreach ($root['fields'] as $subfield) {
  foreach ($subfield['sub_fields'] as $sub_field) {
   $sub_field_name = $sub_field['name'];

   if ($sub_field_name == $mysubfield) {
    $choices = $sub_field['choices'];
   }
  }
 }
 return $choices;
}

add_filter( 'fetch_subfield_choices', 'fetchSubfieldChoices', 10, 2 );
and then execute:
/**
$choices = apply_filters('fetch_subfield_choices', $group_NAME, $mysubfield); 

Saturday, December 24, 2016

Bash TCP open ports scanner

We can use the following code to scan a given target machine (or router)
echo "enter hostname or ip> ";
read myhost; for port in {7990..8003};
do
    (timeout 1 bash -c "echo >/dev/tcp/$myhost/$port" && echo "port $port is open" || echo "failed")
     2>&1 | grep -v "refused";
done

oneliners:
echo "enter hostname or ip> "; read myhost; for port in {7990..8003}; do (timeout 1 bash -c "echo >/dev/tcp/$myhost/$port" && echo "port $port is open" || echo "failed") 2>&1 | grep -v "refused"; done

without showing errors:
echo "enter hostname or ip> "; read myhost; for port in {7990..8003}; do (timeout 1 bash -c "echo >/dev/tcp/$myhost/$port" && echo "port $port is open") 2>&1 | grep -v "refused"; done

Thursday, April 7, 2016

Need mail server, tired of configuring mail servers ?

How to configure mail forwarder, using GMAIL as a gateway

Opening a security hole

visit:
https://www.google.com/settings/security/lesssecureapps
set it it to "Turn on"
A mail with notification will arrive at your mail and a spam notification on your Android device :@.


Otherwise google will send rejecting during authorization.

Mail gateway

sudo apt-get install ssmtp

sudo vim /etc/ssmtp/ssmtp.conf
root=damjandimitrioski@gmail.com
mailhub=smtp.gmail.com:587
hostname=freedom
FromLineOverride=YES
AuthUser=damjandimitrioski # not sure if username or it doesn't care for the domain
AuthPass={PUT YOUR PASSWORD}
FromLineOverride=yes
UseSTARTTLS=YES # Otherwise Google will complains about SSL stuff
sudo vim /etc/ssmtp/revaliases
# Replace root@ with whatever name
root:root@freedom:smtp.gmail.com:25

The resulting mail will be like this:
root <damjandimitrioski.gmail.com>

Testing 

echo "My mail content" | sudo ssmtp -vvv damjandimitrioski@gmail.com

PHP setup

 sudo vim /etc/php5/fpm/php.ini
locate the [mail function] section and uncomment it
sendmail_path = /usr/sbin/ssmtp -t 
After change, restart php service.
sudo service php5-fpm restart

Testing

$ php -a
php >  mail("petko@gmail.com", "My subject", "My ugly short content");


Friday, March 11, 2016

GNU/Linux Groups reloading without reboot/logout

  • Too lazy to reboot.
  • Having too much running important things.
  • Must do it now !

No more reboot !

 the newgrp command is used to start a new session having the group or all new group reread from the groups configuration.

What it does, it starts a new bash session and newly invoked commands use the new groups.

How to do it ?


In your favourite DE press ALT + F2, then type:
bash -c 'newgrp <<< dolphin' (or use nautilus, rox, etc)

Explanation

  • bash will open a new shell session and invoke a command
  • newgrp will reload that session
  • and STDIN redirection will inject commands e.g dolphin into the new session

 Caveats

  • We cannot create new directories/files
  • Renaming files raises error, the renamed file visually looks changed, but refreshing the directory will revert the name.
  • Creating new file does the same thing.
  • Creating new directory does the same thing.

What's possible

Only edit existing files - Useful for Sublime and such to quickly edit something.

For using an IDE

  1. it's useful that we first chown the directory to our username
  2. create the project with the IDE
  3. play around, until everything is written
  4. chown back to the intended group
  5. run the ide either with:
    bash -c 'newgrp <<< ~/.local/bin/idea-IU/bin/idea.sh'
  6. alternatively run it in dolphin's terminal, but that's silly

Troubleshoot and tricks

If you need to pass arguments to the command:
bash -c 'newgrp <<< "dolphin ~/bin"'
Notice the double quotes surround the command,  well, without them nothing will happen :D.

Alternative

sg couchbase -c dolphin
much like the newgrp command, however sg accepts a command

Caveats

you must know the group, alas only one group.
Which means this command sucks!

Monday, January 25, 2016

Working with several computers via LAN - part 1

When it comes to multiple computers, in order to share data, and to save time finding ip's, waiting for ssh to establish a connection.

You'll need a tool for a data sharing.
Luckily, I found some software, it's called Dukto.

It can be download from here, it supports RPM and DEB packages.

Also it can installed on mac. The window$ version I bet it's crashing due to windows is unstable for network operations, but it can be installed there as well.



What the program does, it listens on the installed computer and looks for other users across the LAN.

Each user is called a buddy, and you're able to perform the following operations to a given buddy:
  • Send a message
  • Send the current copied text (from the clipboard)
  • Send a file (support drag & drop)
  • Send a whole directory (supports drag & drop)
When you're a recipient, you can click on the received message to be copied to the your clipboard.

You don't confirm to receive a file/directory, the file/directory is automatically stored in the directory set in the settings (be sure before use to set the received files directories to a more suitable location).
Each file/directory is listed in the Recent tab.  

Thursday, November 12, 2015

WebStorm slow debugger start







Do you've a slow nodejs startup time during debugging in WebStorm ?
- Well, don't worry.

With this solution, probably will start in under 1s :).
Open WebStorm, go to the Help Menu, click on the Find Action menu item.














then type Registry.





















In the dialog type this key: "js.debugger.v8.use.any.break", after you find the
key, uncheck the Enabled state.
Click close, and that's it.





















You can run the debug run configuration now, as usual.


Hopefully this solution will help someone :).