Installing MongoDB on Oracle Enterprise Linux 7+ (tutorial)

MongoDB is a free and open-source cross-platform document-oriented database. Classified as a NoSQL database, MongoDB avoids the traditional table-based relational database structure in favor of JSON-like documents with dynamic schemas (MongoDB calls the format BSON), making the integration of data in certain types of applications easier and faster. MongoDB is developed by MongoDB Inc. and is free and open-source, published under a combination of the GNU Affero General Public License and the Apache License. As of July 2015, MongoDB is the fourth most popular type of database management system, and the most popular for document stores [wikipedia].

While it is possible to install MariaDB and MySQL in Oracle Enterprise Linux 7 during the system install, it does not include the necessary yum repository to install the MongoDB out of the box.

Well, I guess you know that already, so I’ll get straight to business. Continue reading “Installing MongoDB on Oracle Enterprise Linux 7+ (tutorial)”

WordPress plugin installation hangs and wordpress stuck in maintenance mode

Issues that can be faced after migration of a WordPress to a fresh environment with no Apache or PHP installed.

Basic installation of Apache and PHP56 proved to be insufficient, several issues were faced:

  1. 403 error while trying to access the WordPress site
  2. Update of the plugins fails with the following error:
    There is no HTTP transports available which can complete the requested request
    
  3. Update of plugins hangs for indefinite time, and WordPress stuck in Maintenance Mode

Freebsd is used as a platform for examples, so examples are applicable for FreeBSD version 9.0+, but it is irrelevant, luckily php modules name have almost the same naming convention across platforms.
Continue reading “WordPress plugin installation hangs and wordpress stuck in maintenance mode”

Setting up your own PPTP VPN server on AWS EC2 with Amazon Linux 2015.09

This quick tutor will help you set your own pptpd VPN server on AWS Amazon Linux EC2 instance, you will also configure a firewall and set up an Elastic IP, so that your VPN server will have a constant IP address.

The AMI Linux version used in this article is: 2015.09.

  1. Install the latest pptpd:
    $ sudo yum install http://poptop.sourceforge.net/yum/stable/packages/pptpd-1.4.0-1.el6.x86_64.rpm

    Check the required packages offered by dependency check and confirm your willingness to proceed.

  2. Make a backup of the config file:
    $ sudo cp /etc/pptpd.conf /etc/pptpd.conf.orig
  3. Uncomment the following two lines in /etc/pptpd.conf:
    localip 192.168.0.1
    remoteip 192.168.0.234-238,192.168.0.245
  4. Edit /etc/ppp/chap-secrets (username/password can be chosen arbitrary):
    vpnuser pptpd passw0rd *
  5. Backup the options.pptpd file:
    $ sudo cp /etc/ppp/options.pptpd /etc/ppp/options.pptpd.orig
  6. Uncomment two ms-dns lines and specify DNS servers:
    ms-dns 8.8.8.8
    ms-dns 8.8.4.4
  7. Add a rule to iptables to allow masquerading:
    sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
  8. Save iptables config (saved to /etc/sysconfig/iptables)
    sudo service iptables save
  9. Make a backup of /etc/sysctl.conf file:
    sudo cp /etc/sysctl.conf /etc/sysctl.conf.orig
  10. Edit it to allow IP forwarding:
    net.ipv4.ip_forward=1
  11. After changing the above, run the following command (otherwise the connection to VPN will be established, but no sites will be served to you):
    sudo sysctl net.ipv4.ip_forward=1
  12. Start the service and enable it startup on instance boot:
    sudo /etc/init.d/pptpd start
    sudo chkconfig pptpd on

Amazon firewall settings

Allow incoming connections to EC2 instance port 1723 in Amazon Security Groups:

  1. Login to your AWS account
  2. Proceed to EC2 Management Console
  3. Choose Security Groups from the left menu pane,
  4. Choose the security group assigned to the EC2 instance you’re setting up as the VPN server
  5. In the security group properties, choose Inbound tab
  6. Press [Edit]
  7. In the Edit inbound rules window, press [Add rule]
  8. Add the following Rule:
    • Type: Custom
    • Protocol: TCP
    • Port Range: 1723
    • Source: Anywhere
  9. Press [Save]

Assigning Elastic IP to your instance (optional)

If you haven’t assigned an elastic IP to your instance, it’s a good idea to do that now. With Elastic IP assigned, you instance will have constant IP address throughout it’s lifetime, which will not change with every reboot (as Public IP does when instance has no Elastic IP assigned).

To assign an elastic IP you need to do the following:

  1. Login to your AWS account if you haven’t done so already
  2. Go to EC2 Management Console
  3. In the Network&Security section choose Elastic IPs
  4. If there’s already IP address in the list, proceed to the next step, otherwise, press the [Allocate New Address] button
  5. Press [Yes, Allocate] if it asks you to confirm
  6. After the address is allocated, you need to associate it with the instance. Currently Amazon doesn’t charge for Elastic IPs associated with running instances.
  7. Right-click on the allocated IP address, and choose Associate address
  8. Click on the Instance field, and select your EC2 instance where you’ve set up a PPTP VPN server
  9. Press Associate

Now you can access your PPTP VPN server from anywhere even after restart.

Dynamic TaskDialog call

Below is an example of backward compatible programme on flat assembler, which shows Message Box on 2000/XP and TaskDialog on Vista/7. It utilizes the following algorithm:

  1. Determine Windows version
  2. If version < 6 then skip to 5
  3. Load COMCTL32.DLL
  4. Retrieve TaskDialog proc address and save its handle
  5. Proceed further

The algorithm of message displaying procedure:

  1. If TaskDialog handle = NULL skip to 4
  2. Display Task Dialogue
  3. Skip to 5
  4. Display Message Box
  5. Return

Note: the manifest section in resource data is mandatory, otherwise the old Common Control library will be used and no Task Dialogue address would be received

 

;Example of a dynamic task dialog by R. Gilyazov
 
format PE GUI 4.0
entry start
include 'win32w.inc'	; WideCharacter must be used for TaskDialog to work correctly
include 'encoding\win1251.inc'
 
; Task Dialog Stuff
TD_WARNING_ICON = -1
TD_ERROR_ICON = -2
TD_INFORMATION_ICON = -3
TD_SHIELD_ICON = -4
 
TDCBF_OK_BUTTON = 1
TDCBF_YES_BUTTON = 2
TDCBF_NO_BUTTON = 4
TDCBF_CANCEL_BUTTON = 8
TDCBF_RETRY_BUTTON = $10
TDCBF_CLOSE_BUTTON = $20
 
 
section '.text' code readable executable
start:
;	invoke	InitCommonControls
 
	;get windows version
	invoke	GetVersion
	cmp	al,06h				;Won't even try to load library on < Windows Vista
	jb	notvista
	;vista+
	invoke	LoadLibrary,_comctl32		;Loading COMCTL32.DLL. If already included in library section,
						;one can use GetModuleHandle instead of LoadLibrary
	cmp	eax,0
	je	notvista			;COMCTL32.DLL not in memory
 
	invoke	GetProcAddress,eax,_taskDlg	;Trying to get and address of TaskDialog API
	cmp	eax,0				;NULL - no taskdialog for today.
	je	notvista
	mov	[TaskDialog],eax		;if eax != 0, saving address of the TaskDialog API
 
 
  notvista:
	stdcall TaskBox,HWND_DESKTOP,_randomStuff,_hello,_mainInstr	 
 
	invoke	ExitProcess,0
 
 
; hWnd      - parent window handle
; lpszMsg   - message body,
; lpszTitle - title
; lpszInstr - main instruction, used only in TaskDialog.
 
; return:
; eax - ID of the button pressed
 
proc TaskBox hWnd:DWORD,lpszMsg:DWORD,lpszWndTitle:DWORD,lpszInstr:DWORD
  local dwResult:DWORD
	cmp	[TaskDialog],0	;if no TaskDialog handle
	jz	.xp		;proceed to MessageBox
 
;http://msdn.microsoft.com/en-us/library/windows/desktop/bb760540(v=vs.85).aspx
;HRESULT TaskDialog(
;  _In_   HWND hWndParent,
;  _In_   HINSTANCE hInstance,
;  _In_   PCWSTR pszWindowTitle,
;  _In_   PCWSTR pszMainInstruction,
;  _In_   PCWSTR pszContent,
;  _In_   TASKDIALOG_COMMON_BUTTON_FLAGS dwCommonButtons,
;  _In_   PCWSTR pszIcon,
;  _Out_  int *pnButton
;);
	lea	eax,[dwResult]	;button information will be stored in dwResult
	;pszIcon must contain icon id in Lo-WORD, otherwise it will be treated as a string resource identifier
	;hence "and 0FFFFh"
	invoke	TaskDialog,[hWnd],NULL,[lpszWndTitle],[lpszInstr],[lpszMsg],TDCBF_OK_BUTTON,TD_INFORMATION_ICON and 0FFFFh,eax
	mov	eax,[dwResult]
	jmp	.finish
  .xp:
	invoke	MessageBox,[hWnd],[lpszMsg],[lpszWndTitle],MB_OK+MB_ICONINFORMATION
 
  .finish:
	ret
endp
 
section '.data' data readable writeable
 
  _hello	TCHAR 'Hello World!',0
  _mainInstr	TCHAR 'Every day I''m shufflin''',0
  _randomStuff	TCHAR 'Humpty Dumpty sat on a wall, Humpty Dumpty had a great fall',13,10,\
		      'И вся королевская конница, и вся королевская рать не может Шалтая Болтая собрать',0
 
  _comctl32	TCHAR 'COMCTL32.DLL',0
  _taskDlg	db 'TaskDialog',0
 
  winver	dd ?		; windows version
  TaskDialog	dd ?		; API address will be stored here
 
section '.idata' import data readable
  library kernel,'KERNEL32.DLL',\
          user,'USER32.DLL'
 
  import kernel,\
      ExitProcess,'ExitProcess',\
      GetProcAddress,'GetProcAddress',\
      GetVersion,'GetVersion',\
      LoadLibrary,'LoadLibraryW'
 
  import user,\
      MessageBox,'MessageBoxW'            
 
 
  ;the comctl32.dll doesn't have to be included, since it would be loaded dynamically
 
section '.rsrc' resource data readable
  directory RT_MANIFEST,manifest 
  resource manifest,\ 
	 1,LANG_NEUTRAL,man 
  resdata man 
	 db '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>',13,10 
	 db '<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">',13,10 
	 db '<assemblyIdentity name="x.x.x" processorArchitecture="x86" version="5.1.0.0" type="win32"/> ',13,10 
	 db '<description>no</description>',13,10 
	 db '<dependency>',13,10 
	 db '<dependentAssembly>',13,10 
	 db '<assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="x86" publicKeyToken="6595b64144ccf1df" language="*" />',13,10 
	 db '</dependentAssembly>',13,10 
	 db '</dependency>',13,10 
	 db '</assembly>',13,10 
  endres