Tuesday, March 09, 2021

sending emails as a particular Google Workspace user from Moodle

My reply to a query about a Moodle instance sending emails with a professor's email id instead of a generic address, and how to change it - 

1. Please try logging on to the-desired-email@ourdomain.tld on your browser, see if there is some issue with the username and password.

2. As you know, on moodle, you have to set up the outgoing email configuration with that username and pw at
Site administration > Server > Email > Outgoing mail configuration.

3. The sending of emails has to be authenticated and set up

4. Why the professor's account works and not the-desired-email account - probably because the professor's account has SMTP enabled from earlier. 

You could please do the setup for (3.) using the recommended option, using smtp-relay.gmail.com 

Monday, March 08, 2021

ssh keep alive

ssh kept timing out on one of our servers - when the terminal window inactive for 10 minutes or something like that. Came across this article to fix it - did it using the client side, adding the line: ServerAliveInterval 60
to the file /etc/ssh/ssh_config


Sunday, March 07, 2021

failed attempts to build the moodle app apk

 Documenting my failed attempts to build the Moodle Android app.

Edit: The successful attempt is documented in this post.

For customizing
We may need to follow
http://blog.vinodsingh.com/2020/05/how-to-customize-moodle-mobile-app.html

But even the basic moodleapp fails to build - as below.
Android Studio version etc as of March 4th to 7th 2021.


Steps for build
---------------

Following https://docs.moodle.org/dev/Setting_up_your_development_environment_for_Moodle_Mobile_2
except for some exceptions, and ignoring errors.

wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash




nvm install node
# don't do nvm use 11 - current version is 15, that works. 11 has bugs.

sudo apt-get install libsecret-1-dev

git clone https://github.com/moodlehq/moodleapp.git moodleapp
cd moodleapp
git checkout integration

# dont't run npm run setup - run each individually, since errors can be ignored.
npm install 
#(
#npm ERR! npm ERR! network aborted
#npm ERR! npm ERR! network This is a problem related to network connectivity.
#Re-ran ...
#)
#Took ~ 10 minutes on lenovoPC, 2 minutes on GCP.

npx cordova prepare 
# ignore the errors.
#Failed to restore plugin "phonegap-plugin-push". You might need to try adding it again. 
# Error: CordovaError: Failed #to fetch plugin 
# git+https://github.com/moodlemobile/phonegap-plugin-push.git#moodle-v3 via registry.
#Probably this is either a connection problem, or plugin spec is incorrect.
#Check your connection and plugin name/version/URL.
# (Ran again, due to internet breakage)


npx gulp

npm start
# Did not show any errors, showed waiting for connection

npx ionic cordova platform remove android
npx ionic cordova platform remove ios
npx ionic cordova platform add android
# did not do npx ionic cordova platform add ios
# ignored the error, 
# Failed to fetch platform cordova-android@^9.0.0
#Probably this is either a connection problem, or platform spec is incorrect.
# in verbose mode, 
#npm ERR! errno ENOTFOUND
#npm ERR! network request to https://registry.npmjs.org/coffeescript failed, 
#reason: getaddrinfo ENOTFOUND #registry.npmjs.org
#npm ERR! network This is a problem related to network connectivity.
# Ran again, 
# npx ionic cordova platform add android --verbose
# Platform android already exists.
# did remove and add again, then looks like it is not a connection problem, but platform spec is incorrect

# https://stackoverflow.com/questions/55965450/failed-to-fetch-platform-cordova-android8-0-0
# ignoring,

npm run dev:android
# gave error, but wrote
#cordova-android-support-gradle-release: Android platform: V7+
#cordova-android-support-gradle-release: Wrote custom version '27.1.0' to 
#/home/user/moodleapp/platforms/android/app/#build.gradle
#cordova-android-support-gradle-release: Wrote custom version '27.1.0' to 
#/home/user/moodleapp/platforms/android/
#cordova-android-support-gradle-release/moodlemobile-cordova-android-support-gradle-release.gradle
#[ERROR] An error occurred while running subprocess cordova.

# on GCP, error was No valid Android SDK root found.
# did again on a fresh terminal so that .bashrc is processed again,
# then it worked.

sudo apt-get install gradle
sudo apt-get install libgradle-android-plugin-java

Edits as per
https://docs.moodle.org/dev/Setting_up_your_development_environment_for_Moodle_Mobile_2#Compiling_using_AOT

npm run ionic:build -- --prod
# LenovoPC bogged down since it uses too much memory and goes into swap, trying on cloud dev machine.
# GCP finished in 6 minutes - used nearly all of 16 GB RAM. 200% cpu of 4 core machine.
npx cordova run android

# on GCP, gave response as below
# npx cordova run android
Conflict found, edit-config changes from config.xml will overwrite plugin.xml changes
9.0.0
cordova-android-support-gradle-release: Android platform: V7+
cordova-android-support-gradle-release: Wrote custom version '27.1.0' to 
/home/user/moodleapp/platforms/android/app/build.gradle
#cordova-android-support-gradle-release: 
#Wrote custom version '27.1.0' to 
#/home/user/moodleapp/platforms/android/cordova-android-support-gradle-release/moodlemobile-cordova-android-support-gradle-release.gradle
Cannot find module 'xcode'
Require stack:
- /home/user/moodleapp/plugins/cordova-plugin-add-swift-support/src/add-swift-support.js
- /home/user/moodleapp/node_modules/cordova-lib/src/hooks/HooksRunner.js
- /home/user/moodleapp/node_modules/cordova-lib/src/plugman/install.js
- /home/user/moodleapp/node_modules/cordova-lib/src/plugman/plugman.js
- /home/user/moodleapp/node_modules/cordova-lib/cordova-lib.js
- /home/user/moodleapp/node_modules/cordova/src/help.js
- /home/user/moodleapp/node_modules/cordova/src/cli.js
- /home/user/moodleapp/node_modules/cordova/bin/cordova

###########

# so tried importing into android studio
# https://cordova.apache.org/docs/en/10.x/guide/platforms/android/index.html#debugging
# 

#android studio gave error as follows:
# ~/androidstudioerr.txt
#Manifest merger failed : uses-sdk:minSdkVersion 19 cannot be smaller than version 22 declared in library [:CordovaLib] 
#/home/user/moodleapp/platforms/android/CordovaLib/build/intermediates/library_manifest/debug/AndroidManifest.xml 
#as the library might be using APIs not available in 19
#	Suggestion: use a compatible library with a minSdk of at most 19,
#		or increase this project's minSdk version to at least 22,
#		or use tools:overrideLibrary="org.apache.cordova" to force usage (may lead to runtime failures
#
# https://github.com/apache/cordova-android/issues/1070
# so edited config.xml with the info as given in the above, but that gave unbound prefix error.
# 
# Then, tried changing minSdkVersion=22 (from 19) on line 212 of config.xml
# still
# so, https://www.learningsomethingnew.com/how-and-why-to-change-your-android-cordova-apps-min-sdk-version
# but cordova platform rm android
# cordova: command not found.
# so tried
npx ionic cordova platform remove android
npx ionic cordova platform add android
# but the same error inside android studio.

Edit: The successful attempt is documented in this post.

Thursday, March 04, 2021

German letters without diacritics

Sometimes we have to post descriptions on our schedule page of German programs, which may contain diacritics. But our schedule software currently doesn't support unicode, so I've to convert those to characters without diacritics. This page has a handy conversion guide - mostly adding e for umlauts.



Tuesday, March 02, 2021

REISUB - for restarting linux machines which are unresponsive

From http://blog.kember.net/articles/reisub-the-gentle-linux-restart/

https://en.wikipedia.org/wiki/Magic_SysRq_key
says that on linux mint, it is Ctrl Alt PrtScr, and then - slowly - 

Alt + REISUO to shut down, REISUB to reboot.

  • Switch from RAW to XLATE
  • Send Sigterm
  • Send Sigkill
  • Sync all mounted filesystems
  • remount in read-only
  • Shutdown.

Running Linux Mint 20 on a Lenovo B460 laptop, on hitting Ctrl Alt F2 and seeing the 2nd terminal, 
R
E
I
show "This SysReq is disabled."

has details on the bitmask etc. 

cat /proc/sys/kernel/sysrq

"0 - disable every SysRq function.
1 - enable every SysRq function.
2 - enable control of console logging level
4 - enable control of keyboard (SAK, unraw)
8 - enable debugging dumps of processes etc.
16 - enable sync command
32 - enable remount read-only
64 - enable signalling of processes (term, kill, oom-kill)
128 - allow reboot/poweroff
256 - allow nicing of all RT tasks
438 = 2 + 4 + 16 + 32 + 128 + 256, so only the functions associated with those numbers are allowed. Read all about it in the documentation."

deploy from github to server with php

https://docs.github.com/en/github/authenticating-to-github/adding-a-new-ssh-key-to-your-github-account

https://medium.com/riow/deploy-to-production-server-with-git-using-php-ab69b13f78ad

But then didn't use because of this,

https://medium.com/@skoskie/oh-no-c1068ed30c6b

Friday, February 26, 2021

server admin activities for an Asst. Admin

Excerpts from my reply to a colleague in a sister institution who had joined recently and wanted to get up to speed with his duties - 

These are the activities I have done to help the LMS team - 


1. Setting DNS records in Cloudflare - 

https://ns1.com/resources/dns-types-records-servers-and-queries

https://en.wikipedia.org/wiki/Cloudflare

https://support.cloudflare.com/hc/en-us/articles/360019093151-Managing-DNS-records-in-Cloudflare

The DNS records are currently handled by V----, I help him when needed.


2. Helping with load testing for servername.our.domain - R--- did most of the work - 

https://hnsws.blogspot.com/2020/12/load-testing-moodle-server-log-in-with.html

https://docs.moodle.org/310/en/Performance_recommendations#Hardware_configuration

Please see the test reports made by Prof. S----- and R-----.


3. Setting up SSL (https) using bitnami's tool - bncert-tool

https://hnsws.blogspot.com/2020/12/location-of-apache-configuration-files.html

In case the machine in question is not a bitnami VM,

https://hnsws.blogspot.com/2020/11/setting-up-letsencrypt-certificates-for.html

https://certbot.eff.org/


4. For doing the above (point 3.), you will need to know how to use the command-line, and how to use ssh - 

https://www.ucl.ac.uk/isd/what-ssh-and-how-do-i-use-it

https://en.wikipedia.org/wiki/PuTTY

https://www.chiark.greenend.org.uk/~sgtatham/putty/faq.html

https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AccessingInstancesLinux.html

https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/putty.html


5. If you are not familiar with the Linux terminal (command-line), 

https://www.google.com/search?q=getting+started+with+the+linux+command+line


Thursday, February 25, 2021

creating a backup of a web server

Process followed for creating a copy of one of our web servers on a backup server - 
  • Copied the conf files using sftp.
  • Created the user using adduser 
  • mkdir downloads as the new user,
  • added to www-data group and changed permissions as on our server,
    # chown nameofuser:www-data downloads
    # chmod 755 downloads

  • Check if server2 has enough disk space before running rsync.
    Currently seems to have ~600 GB available.

  • Ran a2ensite for all the missing sites, and 
  • service apache2 reload
Edit: Now that the servers run https sites, must remember to set up suitable ACME clients as available for the respective OS, for managing LetsEncrypt certificates. 

For up-to-date Ubuntu-based Linux distros, 
sudo apt install certbot python3-certbot-apache

For older distros without support, acme.sh is what I have used in the past.

For Windows, win-acme is a good option.

Monday, February 22, 2021

certbot missing apache plugin

I too faced the same issue described in the post below, with the same solution - 
apt install python3-certbot-apache

https://community.letsencrypt.org/t/certbot-missing-apache-plugin/58579

Moodle directory permissions

"Invalid permissions detected when trying to create a directory. Turn debugging on for further details." 

Simple fix would be:

sudo chown -R  www-data:www-data /var/www/our_moodle_dir
sudo chown -R  www-data:www-data /var/www/our_moodle_files_dir

mount a new data disk on an Azure Linux VM

https://blog.e-zest.com/how-to-create-attach-and-mount-a-disk-to-linux-vm-microsoft-azure

Basically create the disk from the Azure portal, then

  • find the name of the device using dmesg - for eg. /dev/sdc
  • sudo fdisk /dev/sdc
  • sudo mkfs -t ext4 /dev/sdc1
  • sudo mkdir DriveFolder; sudo mount /dev/sdc1 DriveFolder
  • append to /etc/fstab using sudo blkid to find the UUID of the disk. Eg. 
    UUID=33333333-3b3b-3c3c-3d3d-3e3e3e3e3e3e   /datadrive   ext4   defaults,nofail   1   2

Sunday, February 21, 2021

mounting Azure blob storage

We looked at the different ways in which Azure storage could be mounted on a Linux Moodle instance, using blobfuse

but did not find any mentions using
mount
or
crontab -l (for various users)

Edit: It turned out it was using Moodle's Object storage file system plugin, which manages all the storage from within Moodle. But see this caveat.

Fresh install of Moodle on Ubuntu 20.04 with apt

Using the command at https://www.tecmint.com/install-moodle-in-ubuntu/

sudo apt update
sudo apt install php-common php-iconv php-curl php-mbstring php-xmlrpc php-soap php-zip php-gd php-xml php-intl php-json libpcre3 libpcre3-dev graphviz aspell ghostscript clamav

Then git-based install after

sudo apt install git

Edit: For the error "PHP has not been properly configured with the MySQLi extension for it to communicate with MySQL. Please check your php.ini file or recompile PHP."
we can follow the installation instructions at
https://docs.moodle.org/310/en/Step-by-step_Installation_Guide_for_Ubuntu

Installing the lapp stack on Ubuntu 20

https://kb.amijani.net/web-server/how-to-install-lapp-apache-php-postgresql-on-ubuntu-20-04/

Basically, 
sudo apt install apache2
sudo apt install php7.4 libapache2-mod-php7.4 openssl php-imagick php7.4-common php7.4-curl php7.4-gd php7.4-imap php7.4-intl php7.4-json php7.4-ldap php7.4-mbstring php7.4-pgsql php-ssh2 php7.4-xml php7.4-zip unzip

Then install PostgreSQL with
https://www.digitalocean.com/community/tutorials/how-to-install-postgresql-on-ubuntu-20-04-quickstart


Thursday, February 18, 2021

connecting to a pptp VPN

A VPN to some servers was configured on Windows 10 clients as 
Type of sign-in info: User name and password
and under "Advanced", 
VPN type: Automatic.

Other windows clients were able to log on to the VPN with no problems, but when I tried with Linux Mint and the default pptp VPN settings, the connection was failing. My first thought was that some setting was missing, but it turned out that the reason for the VPN to fail was that my internet connection was via a mobile hotspot - just connecting via a broadband connection did the trick, I did not have to do any port-forwarding or any settings on the router. And then I found that some mobile hotspots work too - 
LG Q6 with Airtel 4G on primary SIM slot - no
LG Q6 with Airtel 3G on primary SIM slot - sometimes works. 
Redmi 4 with Jio SIM - works
Realme U1 with Jio SIM in secondary SIM slot - no
JioFi router (2018 model) - works
BSNL ADSL broadband with wifi router - works

With the default routing, all connections are routed through the VPN, and normal internet browsing doesn't work. With the help of this post, changed the routing so that only connections to those machines which are on the VPN are routed through the VPN.

Screenshot of VPN settings

/var/log/syslog gave the internal gateway info, which is on the private subnet, different from the external gateway which is on a public subnet.

 


making a rectangle in Gimp

  1. Select using Rectangle Select Tool
  2. Edit - Stroke Selection

Wednesday, February 17, 2021

rsync, screen and ssh-agent

On some of our other Ubuntu servers, rsync in a cron job as root works fine with ssh and key-based authentication. But not on a CentOS server I recently logged on to, because ssh-agent was not automatically started on login.

So, I have to run the following - 

eval `ssh-agent -s` 
ssh-add /path/to/keyfile.pem

and then do the ssh -i keyfile user@remoteserver

If I want to run a long rsync job from within screen, I need to run the above commands again from within screen, or else the ssh-agent is not accessible from within screen.

The next issue was the use of rsync with directories which had spaces in them. Instead of laboriously escaping each space with a backslash, I used the --protect-args method.

rsync -azvhrt --protect-args -e ssh  "/local path/with spaces/directory to copy" "user@remotemachine.tld:/remote/path/with spaces/"

Monday, February 15, 2021

Friday, February 12, 2021

forcing chrome to reconnect to a website

For purposes like profiling site load speeds etc, making Chrome close connection to a web server and start over - 

Go to
chrome://net-internals#sockets
and close idle sockets.

Also works for sessions opened with SSH tunnels, when we want to close the connection immediately.