Installing xrdp on Ubuntu

xrdp – RDP server for Linux

It is installed in Ubuntu with the following command:

sudo apt-get install xrdp

To connect to an xrdp server from Windows, you can use the standard Remote Desktop client by typing mstsc.exe at the command prompt.
The configuration is located here /etc/xrdp/, logs are written here – /var/log/xrdp-sesman.log

You can restart xrdp like this:

sudo /etc/init.d/xrdp restart

You can also install the Xfce graphical shell:

sudo apt-get -y install xfce4

And specify it by default.

echo xfce4-session >~/.xsession

I recommend not using root user to work in a graphical environment, but create an individual user.
See my article – Administering Ubuntu Users

The solution to the warning “mismatch_cnt is not 0 on /dev/md*”

Replaced once the junk drive in the software RAID1, added it to the raid, it successfully synchronized, installed GRUB.
After a while I received an email message:

Subject: Cron <root@server> /usr/sbin/raid-check
WARNING: mismatch_cnt is not 0 on /dev/md2

In my case, raid-check found that the mismatch_cnt counter is not equal to 0 for /dev/md2, which means that there may be broken sectors on the disk, or it simply needs to be resynchronized. Since I installed GRUB after adding the disk to the raid, this is probably the cause.

Example of viewing the counters of all arrays:

cat /sys/block/md*/md/mismatch_cnt

Or each in turn:

cat /sys/block/md0/md/mismatch_cnt
cat /sys/block/md1/md/mismatch_cnt
cat /sys/block/md2/md/mismatch_cnt

View the status of raids:

cat /sys/block/md*/md/sync_action

If mismatch_cnt is not 0 for any array, then you can try to resynchronize it:

echo 'repair' >/sys/block/md2/md/sync_action

And check:

echo 'check' >/sys/block/md2/md/sync_action

If you want to cancel the action:

echo 'idle' >/sys/block/md2/md/sync_action

Let’s see the synchronization status and other data of the array:

cat /proc/mdstat

If errors appear due to a bad disk, I recommend that you look at SMART and check it as I wrote in these articles:
Diagnostics HDD using smartmontools
Linux disk test for errors and broken sectors

See also:
How to fix the problem with mdadm disks

Troubleshooting PHP Warning “Permission denied /var/cpanel/php/sessions/ea-php56/”

Once I updated EasyApache 3 to EasyApache 4 in cPanel and noticed in the PHP logs the following:

[29-Mar-2018 15:54:45 UTC] PHP Warning:  Unknown: open(/var/cpanel/php/sessions/ea-php56/sess_3d96o7nnlnnr473p8619vqkdm1, O_RDWR) failed: Permission denied (13) in Unknown on line 0
[29-Mar-2018 15:54:45 UTC] PHP Warning:  Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/var/cpanel/php/sessions/ea-php56) in Unknown on line 0

The warning occurs because PHP can not write session files to a directory to which it does not have access rights.
I looked at the rights of this directory, the group and owner was root, and it was also allowed to write and execute for everyone, except reading.

To resolve this warning, you can open full access for everyone:

chmod 777 /var/cpanel/php/sessions/ea-php56

Or open a PHP configuration, for example in the nano editor:

nano /opt/cpanel/ea-php56/root/etc/php.ini

To find:

session.save_path = "/var/cpanel/php/sessions/ea-php56"

And change to:

session.save_path = "/tmp"

That used to be on the old EasyApache3 in the PHP configuration /usr/local/lib/php.ini.

After that, the warning did not appear.

See also:
Migration from EasyApache 3 to EasyApache 4

The warning solution “The MaxMind Geolite databases will soon be deprecated” in Cpanel

Once launched a server security check by clicking “Check Server Security” in “Main” – “Plugins” – “ConfigServer Security & Firewall” and saw a warning:

Firewall Check
CC_OLDGEOLITE option check
The MaxMind Geolite databases will soon be deprecated, disable CC_OLDGEOLITE to start using the new Geolite2 databases

This option determines which database to use, the old MaxMind Geolite or the new MaxMind Geolite2.
If the option “CC_OLDGEOLITE” is 1, which is in my case, then the old one is used, and if 0, then the new one.

To enable the use of a new one, open the CSF configuration for example in the text editor nano:

nano /etc/csf/csf.conf

Find the option CC_OLDGEOLITE and change its value from 1 to 0:

CC_OLDGEOLITE = "0"

In the nano editor, the Ctrl+X keys are used to exit, and y/n and Enter to save or discard the changes.

After the changes, restart CSF by clicking “Firewall Restart” in the menu “Main” – “Plugins” – “ConfigServer Security & Firewall”.

Sending Asterisk voicemail to multiple emails

Let’s say the voice mail is configured as I described in the article – Setting up voicemail in Asterisk.
There is the following context:

[voicemailcontext]
207 => 1111,Username,test@example.com,,attach=yes|tz=ua|delete=yes

If you want to send a voice message to several email addresses, then instead of test@example.com, for example, testmail:

[voicemailcontext]
207 => 1111,Username,testmail,,attach=yes|tz=ua|delete=yes

Then open the /etc/aliases file in a text editor:

sudo nano /etc/aliases

And let’s specify aliases for testmail:

testmail: support@example.net,user@example.net

For the changes to take effect, you need to update the alias database with the command:

cd /etc
sudo newaliases

Done, Asterisk will send a message to testmail, and it will be automatically forwarded to the specified addresses.

See also:
Redirecting mail for the root user

Setting up voicemail in Asterisk

For example, I’ll set up voice mail for SIP number 207.
Voice messages will be sent to the email using Postfix.
How to install it I described in this article – Installing and Configuring Postfix.

For starters, let’s point out the following in the context of SIP 207 (usually in /etc/asterisk/sip.conf):

mailbox=207@voicemailcontext

Next, configure the configuration of voice mail in the file /etc/asterisk/voicemail.conf:

[general]
; Format of audio files
format=wav49|gsm|wav
; From whom to send letters with notifications
serveremail=noreply@example.com
; Whether to attach to an audio file
attach=yes
; The maximum number of messages (standard 100, maximum 9999)
maxmsg=100
; Maximum message time in seconds
maxsecs=120
; Maximum greeting time in seconds
maxgreet=60
; Number of seconds of silence before recording is complete
maxsilence=10
; Threshold sensitivity to silence, the lower the sensitivity, the value from 0 to 256, standard 128
silencethreshold=128
; Maximum number of failed connection attempts
maxlogins=3
; Automatically move the listened messages to the "Old" folder. The default is on.
moveheard=yes
; The encoding of messages, the standard ISO-8859-1, with it my part of the text was displayed incorrectly, so it's better to specify UTF-8
charset=UTF-8
; Skip the line "[PBX]:" from the message header
pbxskip=yes
; The text of the line "From:"
fromstring=VoiceMail
; Letter subject
emailsubject=New voice message ${VM_MSGNUM} in the mailbox ${VM_MAILBOX}
; The contents of the letter
emailbody=Dear ${VM_NAME}:\n\n\tYou received a new voice message in length ${VM_DUR} under the number (number ${VM_MSGNUM})\nin the mailbox ${VM_MAILBOX} from ${VM_CALLERID}, at ${VM_DATE}. \n\t
; Date format
emaildateformat=%A, %d %B %Y в %H:%M:%S
pagerdateformat=%T %D
; Standard program for sending mail
mailcmd=/usr/sbin/sendmail -t

[zonemessages]
ru=Europe/Moscow|'vm-received' q 'digits/at' H 'hours' M 'minutes'
ua=Europe/Kiev|'vm-received' q 'digits/at' H 'hours' M 'minutes'

; We will write the context parameters voicemailcontext, 1111 - voice mail password (you can not specify), Username - user name, test@example.com - which address to send voice messages, after the comma you can specify one more, at the end of the option
[voicemailcontext]
207 => 1111,Username,test@example.com,,attach=yes|tz=ua|delete=yes

By the way, if you do not specify “delete=yes”, when the maxmsg limit is reached, the answering machine will say a greeting, and then the text that the subscriber’s voice box is full and do not save the message, or send it to the email. In this case, you need to call the voicemail number and delete the messages. If “delete=yes” is specified, the messages are not stored on the server, they do not come to the voice mailbox, but only sent to the email, in this case the maxmsg limit does not work and the overflow is not possible.

Now, in the configuration of the dial plan /etc/asterisk/extensions.conf in the main context, add the number by calling to which you can listen to the mail:

exten => 500,1,Log(NOTICE, Dialing out from ${CALLERID(all)} to VoiceMail (500))
exten => 500,n,VoiceMailMain(0${CALLERID(num)}@voicemailcontext,s)
exten => 500,n, Hangup

And add the VoiceMail line to the dialing context of the number 207 (after which, if the number is not answered or not on the network, voice mail will work), for example:

[207]
exten => 207,1,Dial(SIP/207,30)
exten => 207,n,Answer
exten => 207,n,VoiceMail(207@voicemailcontext)

Finally we connect to the Asterisk console, reload the configuration, see the list of voice mailboxes and letters:

asterisk -rvv
sip reload
voicemail reload
dialplan reload
voicemail show users
exit

The recorded messages are stored in the directory /var/spool/asterisk/voicemail/
Sound files are stored in /usr/share/asterisk/sounds

See also:
Sending Asterisk voicemail to multiple emails
Solving the error in Asterisk “File vm-newn does not exist in any format”
How to convert audio files to ulaw, alaw, gsm, g722, etc. for Asterisk

Asterisk time based routing

Here is an example of routing calls over time in Asterisk.
Assume that the /etc/asterisk/extensions.conf file has a configured context for the trunk with the following parameters:

[Trunk_2]
exten => s,1,DIAL(SIP/6004&SIP/6003,19)
exten => s,2,Hangup()

And to resolve the time calls to different phones, we will point out for the context of this trunk only nested contexts:

[Trunk_2]
include => daytime,8:00-18:00,mon-sat,*,*
include => nighttime,18:00-8:00,mon-sun,*,*
include => sunday,8:00-22:00,sun,*,*

In fact, daytime, nighttime, sunday are only the names of contexts for which the time is written in the context of [Trunk_2], they can be called anything.

And then in these separate contexts we will already add the necessary extensions.
That is, in the afternoon:

[daytime]
exten => s,1,DIAL(SIP/6004&SIP/6003,19)
exten => s,2,Hangup()

At night:

[nighttime]
exten => s,1,DIAL(SIP/6002,19)
exten => s,2,Hangup()

And on Sunday:

[sunday]
exten => s,1,DIAL(SIP/6002,19)
exten => s,2,Hangup()

You can also, for example, create a holiday context with holidays:

include => holiday,*,*,1,jan
include => holiday,*,*,8,mar

etc.

For those who want to paint more in detail by day, I’ll give you a list of days in English:
mon – Monday
tue – Tuesday
wed – Wednesday
thu – Thursday
fri – Friday
sat – Saturday
sun – Sunday

Similarly, up to three letters and names of months are shortened.

Recovering GRUB Linux

Usually on each disk there is an MBR (master boot record) and when the computer is turned on, the BIOS accesses it for information for further download. On Linux systems, GRUB is used as the boot loader, I will write about the recovery options of which below.

You can see the version of GRUB using the command:

grub-install --version

1) First option.
We start the system with LiveCD/USB, for example in the Ubuntu Desktop image, in addition to the installation, it is possible to start the system.
Open the terminal, for this press Alt+F2 and enter the command:

gnome-terminal

Continue reading “Recovering GRUB Linux”