This tar file contains a version of the Smap server.  You can run upgrade an existing installation or install 
a fresh installation.  The latter will delete your existing data. Hence if you have already installed Smap Server
only do an upgrade.

Upgrading
----------
Deploy a new version of Smap.  If you have already installed smap you can update it with the new
version.  Your existing data will not be affected.

It would be a good idea to 

  1. Backup your database before upgrading
  2. Stop Apache so that there are no uploads happening during the upgrade
  
cd ~/smap/deploy
sudo ./patchdb.sh
sudo ./deploy.sh

Only version 2.4 of Apache web server is supported in version 15.09.

From version 15.09 onwards the location of file storage is assumed to be "/smap".  The install scripts no longer
allow you to set a different location.  If you store your files in a different location on disk and you don't
want to use a symbolic link from /smap then you will need to update this location in the following files:
   *  smap-volatile.conf  (In the apache sites-available directory)
   *  subscribers.conf (In the /etc/init directory)
   *  subscribers_fwd.conf (In the /etc/init directory)
   *  bu.sh (in postgres home directory)
   *  re.sh (in postgres home directory)

Version 15.09 is also moving away from supporting http.  https will be required from most access.  However because android phones 
cannot use https if the certificate has not been signed by a certificate authority, the services used by android are still 
available from http.  You should enable the redirects to https in /etc/apache2/sites-available/smap.conf.  This will then allow 
connection without initially specifying https. 

Version 15.03
-------------
If you are using email you will need to add your email domain to the organisation setings or the server table if you
are using the same email server for all organisations. For example if you want your emails to come from
joe@organisation.net then your email domain will be organisation.net

The following needs to be added to the apache configuration files. This is for the new webforms
interface that uses a java web service rather than PHP.
    ProxyPass         /webForm ajp://localhost:8009/surveyMobileAPI/webForm
    ProxyPassReverse  /webForm ajp://localhost:8009/surveyMobileAPI/webForm
    
    <Location /webForm>
        AuthType Digest
        AuthName "smap"
        AuthDigestDomain /
        AuthDigestProvider dbd
        AuthDBDUserRealmQuery "select password from users where ident = %s and realm = %s"
        Require valid-user
    </Location>
    

Version 15.02
-------------
The following chages are applied by the patchdb.sh script.  You may need to apply them manually of you have customised your
installation.

   - Changes the name of the fieldManager war file to fieldManagerServer.war.  The reverse proxy settings in the 
     apache configuration filese will need to be changed. For example to:
     
    ProxyPass         /fieldManagerServer   ajp://localhost:8009/fieldManagerServer timeout=600
    ProxyPassReverse  /fieldManagerServer   ajp://localhost:8009/fieldManagerServer

	- You can remove the old fieldManager.war file
	  sudo rm /var/lib/tomcat7/webapps/fieldManager.war
	  
	- Add a folder called "organisation" under the media folder.  The default would be /smap/media/orgnisation
	  however you may have specified a different base directory {your location/media/organisation
	  Set the owner of this folder to "tomcat7"    
	  
	  You may need to reinstall pyxform.  If you get an error when uploading a template that states that pyxform module
	  is missing then reinstall pyxform using the commands in section 16 of the install.sh script.
	  
Version 14.10.02 needs the following added to /etc/apache2/sites-available/default-ssl.conf (Assuming version 2.4 of Apache)
Add after the <location /surveyKPI> entry

	<Location /surveyKPI/onetimelogon>
		Require all granted
	</Location>

Also update 000-default.conf to 
	redirect /resetPassword.html to https
	redirect /forgottenPassword.html to https
Use the existing redirect statements as a template

If you are going to allow the server to send emails in order to reset passwords then you will need to
set up an email server, or gain access to one, and then update the smtp_host parameter for the organisation. The
organisaiton values are set on the Admin | users page.

You should also add the following to the submission directive in the apache configuration files in /etc/apache2/sites-available
	AuthDigestNonceLifetime -1
This will prevent timeouts when uploading large attachments

Version 14.10 needs the following added to Apache configuration files (Assuming version 2.4 of Apache)

    ProxyPass         /formXMLLocal ajp://localhost:8009/surveyMobileAPI/formXML
    ProxyPassReverse  /formXMLLocal ajp://localhost:8009/surveyMobileAPI/formXML
    ProxyPass         /instanceXMLLocal ajp://localhost:8009/surveyMobileAPI/instanceXML
    ProxyPassReverse  /instanceXMLLocal ajp://localhost:8009/surveyMobileAPI/instanceXML

# Local access points for webforms
    <Location /formXMLLocal>
       	Require ip  127.0.0.1
	</Location>

	<Location /instanceXMLLocal>
    	Require ip  127.0.0.1
	</Location>


Installation
------------

WARNING.  This will do a clean install and will delete all your existing data!  The install will also modify configuration 
files for apache, tomcat and postgres.  The assumption is that you are installing on a new Ubuntu version possibly
running as a virtual machine.  If you want to install on an existing server that already has Apache, Tomcat or Postgres 
then you may want to do a manual installation following the steps in the install.sh file as a guide.  You can also
do this if you are running a different flavour of linux.  If you want to update the install script to support your
linux version then I can add those updates to the source code.

If you want to install on Windows then you will have to proceed with a manual installation. Smap Server hasn't been
tested on Windows in several years so there are likely to be some issues. 

Smap installation is performed by running the install.sh script.  
After running the script the steps described in Post Install Configuration will need to be performed
	

Pre-requisites / assumptions:
	1. Ubuntu server. Testing has been done with Versions 14.04 and 16.04
	2. Hardware (minimum)
		2 GB of memory
		1 CPU
		20 GB of disk
	3. Apache 2.2 / 2.4, Tomcat 7, Postgres 9.3 and Postgis 2.1, openjdk 7 will be installed from Ubuntu sources or updated if they are already installed

##### Installing
	1. Logon as a user other than root 
	2. Run the install script
		./install.sh
		
To logon to smap:
	user: admin
	password: admin
	
You should change the above password as soon as possible.

##### Set up Backups
	1. Create a file called "passwordfile" in the postgres home directory owned by postgres
	2. The file should contain the password used to encrypt backups.  A copy of this password needs to be kept
	   in a safe place.
	3. As postgres type "crontab -e" and add the following line to the end of the file:
			44 19 * * * /var/lib/postgresql/bu.sh >> /var/lib/postgresql/cron.log 2 >&1
	4. You will need to organsise for the backup *.gpg file to be copied to an offsite location each time it is created

