This guide explains how to make a developer's working copy of CSCF's Inventory application.
It does not include instructions on these related tasks, which are documented elsewhere:
AuthType basic
as detailed below.)
Inventory is a web-based application built on the LAMP stack. Server pages use the Yii
open-source web application framework.
Someone with sufficient administrative privileges, such as Daniel Allen, will need to set a few things up for you. Treat this section as informational. Someone else will probably do the setup for you.
You will need:
sudo adduser username
sudo usermod -a -G sudo,adm,sambashare,lpadmin username
Before continuing with the installation, run
sudo apt-get update
to update everything you have so far to latest version.
If you get a signature error in the end like:
Reading package lists... Done
W: GPG error: http://download.virtualbox.org/virtualbox/debian
xenial InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY A2F683C52980AECF
W: The repository 'http://download.virtualbox.org/virtualbox/debian xenial InRelease' is not signed.
N: Data from such a repository can't be authenticated and is therefore potentially dangerous to use.
N: See apt-secure(8) manpage for repository creation and user configuration details.
then for Ubuntu 16.04 try
wget -q https://www.virtualbox.org/download/oracle_vbox_2016.asc
-O- | sudo apt-key add -
or for lower Ubuntu versions try
wget -q https://www.virtualbox.org/download/oracle_vbox.asc
-O- | sudo apt-key add -
For more info on these, see new key installation.
You will create a local instance of the Git repository on the workstation and check out the files from that repository instance to an 'inv' directory directly under the web root directory. The 'inv' directory will hold both the local instance of the repository and the developer's working copy of the application.
sudo chown -R username:root /var/www/
(where username is your user name)
sudo chmod -R 755 /var/www/
cd /var/www
git clone gitlab@git.uwaterloo.ca:cscf/inv
chmod o+w inv/web/inventory/assets
so yii will be able to write to the generated assets directory.
Apache is the program that serves up the HTML documents that make up the Inventory system. It requires a bit of initial configuration. Open the /etc/apache2/apache2.conf file in a text editor and make the following changes.
sudo gedit /etc/apache2/apache2.conf
/etc/apache2/apache2.conf
file, try looking in the /etc/apache2/sites-available/default
file.
Locate the following two sections and change the AllowOverride value from None to All.
<Directory /> Options FollowSymLinks AllowOverride All Allow from All </Directory>
<Directory /var/www/> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory>
Add the following section immediately below the <Directory /var/www/> section.
<Directory /var/www/inv/> AuthType Basic AuthName "Inventory" AuthUserFile /path/to/.htpasswd </Directory>
Later, you will need to come back to this file and change the AuthUserFile value from "<path/to/.htpasswd>" to the actual path to the .htpasswd file.
Set apache to run as user:
sudo chown --recursive username
sudo service apache2 restart
ps aux|grep apache2
, to test your changes have worked. There should be one process running as root while the rest run as the newly set userid.
When starting the Apache service, you will get this unhelpful message:
Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
To suppress this message, edit the /etc/apache2/apache2.conf
file and add these lines to the bottom:
# Suppress start-up error message about server's fully qualified domain name: ServerName localhost
Add these lines to the bottom of the /etc/apache2/apache2.conf
file:
# Enable phpMyAdmin Include /etc/phpmyadmin/apache.conf
To activate the configuration changes, enter this command at the Linux command line:
sudo service apache2 restart
All you should see is:
$ sudo service apache2 restart * Restarting web server apache2 ... waiting [ OK ] $
If you get error messages, go back over the configuration changes.
If you don't get any messages, then you can confirm that the server has restarted using this command:
sudo service apache2 status
Check the last 4 lines to confirm the server has started without any errors or warnings.
Also see the Active row to check if the server was recently started.
The directive
DocumentRoot /var/www/
…tells Apache which directory is the document root. Ensure that the directive is set in
/etc/apache2/sites-enabled/000-default
(That file might be a symbolic link to /etc/apache2/sites-available/default
.)
Create a short, simple HTML document called "test.html" in the /var/www
directory and try opening it in your web browser with this URL:
http://localhost/test.html
Apache's Mod Rewrite engine catches URLs that meet specific conditions, and rewrites them as it is told to—typically making long, complex URLs in to shorter, more manageable, and more intuitive URLs. Install the engine by entering this command:
sudo a2enmod rewrite
Then restart Apache to make the change take effect.
$ sudo a2enmod rewrite Enabling module rewrite. To activate the new configuration, you need to run: service apache2 restart $ sudo service apache2 restart * Restarting web server apache2 ... waiting . [ OK ] $
When you browse to the Inventory application, you will be asked for a user name and a password. They will be validated against an entry in an encrypted .htpasswd file. It is important for security reasons that the .htpasswd file be located somewhere outside of the web-accessible part of the file system. For development purposes, we'll put it in a subdirectory of your home directory called private. To distinguish it from any other .htpasswd files you might have, we'll call the file .htpasswd-inv.
To create the .htpasswd-inv file and put your user name and password in it, enter the following commands, substituting your user name in place of jschmoe. The directory permissions allow Apache to use the directory's files, but prevent unauthorized users from listing the directory's contents. You will be asked to enter a password twice.
cd /home/jschmoe
mkdir private
chmod 711 private
htpasswd -c /home/jschmoe/private/.htpasswd-inv jschmoe
Now we need to tell Apache where to find the .htpasswd-inv file when authenticating users. Edit the /etc/apache2/apache2.conf
file and in the Directory /var/www/inv/
section, change <path/to/.htpasswd>
in the AuthUserFile directive to the location of your .htpasswd-inv file. (The directive might be in the /etc/apache2/sites-available/default
file, depending on where you put it in Allow .htaccess and .htpasswd Files to Control User Access, above.)
Example:
<Directory /var/www/inv/> AuthType Basic AuthName "Inventory" AuthUserFile /home/jschmoe/private/.htpasswd-inv </Directory>
In the Inventory application, database access is controlled by a password file called db-password.inc. We will put it in the same private directory as we did the .htpasswd-inv file, above.
define('INVENTORY_USER', '<username>'); define('INVENTORY_PASSWORD', '<password>');
define('INVENTORY_USER', 'jschmoe'); define('INVENTORY_PASSWORD', 'myRea11y$tr0ngPa$$w0rd');
In phpMyAdmin, create the user that you will use for regular database manipulation activities (that is, not root), follow these steps.
equipment
utf8_general_ci
rt-math-1
utf8_general_ci
If you're loading data NOT from CS's production database, see a sample schema with necessary data attached near the bottom of this page ("inventory.sql").
If you're loading the data from CS's production database, follow the instructions below.
cs.uwaterloo.ca/phpMyAdmin
GRANT ALL PRIVILEGES ON `equipment`.* TO 'userid'@'%.uwaterloo.ca'; GRANT ALL PRIVILEGES ON `app_opendcim`.* TO 'userid'@'%.uwaterloo.ca';
)
Each of the two *.sql files you created contains a series of SQL statements that, when executed, will create tables and insert data.
mysql -u <username> -p -h localhost equipment <equipment.sql
When asked for a password, enter the one you chose in step 5 of Create a Database Administrator, above. The import should take only a minute or two to finish. If you are using a custom export, you may encounter a few issues. For foreign key constraint errors, try adding "SET FOREIGN_KEY_CHECKS=0" at the start of your file. If you encounter the '\0' character, try setting the flag --binary-mode. You can also skip over records with errors using the -f flag.
UNNECESSARY:
mysql -u <username> -p -h localhost rt-math-1 <rt-math-1.sql
If you do an import of rt-math-1 it may take an hour or more.
When you use the Inventory application, it will run queries and updates against the database. Those queries and updates require user credentials. You will need to define those credentials by adding a row to the users table in the equipment database. Follow these steps.
Column | Value |
---|---|
userid | your WatIAM user id |
expires | a date about one year in the future (yyyy-mm-dd) |
unit | "CS" |
flags | "wm" |
Earlier, at The db-passwords.inc File, we put the db-passwords.inc file in a safe, non-web-accessible location. We now need to tell MySQL where to find it.
cp /var/www/inv/constants.php.template /var/www/inv/constants.php
Constant | Value |
---|---|
'DEV_PASSWORD_PATH' | '/home/<username>/private/db-passwords.inc' (where <username> is your Linux user name) |
'SCHOOL_ENVIRONMENT' | 'cs' |
'DB_USED' | 'LocalHost Database' |
Set write permission for MySQL on certain directories by running a set-up script.
/var/www/inv
directory.
. setup
Just to verify that the system is running:
sudo service apache2 restart
http://localhost/inv
.
OpenDCIM is used for the server room inventory mapping which is now built into inventory. See the InventoryFields page for basic details about OpenDCIM. While it is not required to use inventory, it is a feature of inventory and should be installed with inventory. To install OpenDCIM you'll need to follow the instructions included on the git repo we have for OpenDCIM. You can find the repository at https://git.uwaterloo.ca/cscf/open-dcim . It should be noted that you do not want OpenDCIM installed in the same location as inventory. For example if you installed inventory in /var/www/inventory/ you may want to install OpenDCIM in a location like /var/www/openDCIM/. OpenDCIM works with inventory via an API and has a separate web interface much like nagios.
Once OpenDCIM is setup you'll need to alter the inventory configuration in constants.php for the following constant: OPEN_DCIM_BASE_URL. This is simply the base URL you'd use to access the OpenDCIM interface from an external source. The URL set here is the base used to construct the API calls inventory makes to OpenDCIM.
The way in which we are storing OpenDCIM has some pros and cons. It is very easy to deploy OpenDCIM as it is all stored in a git repo that can easily be cloned and used. A con though is that updating is slightly more work as our files are mixed in with the core OpenDCIM files. Overall, we minimize differences with the core code; however we have some added files for the API, as well as a few class files that are modified to add additional functionality for the API. We have a custom_auth.php file that handles authentication, and the main db.inc.php file was modified to "require" our passwords file and the custom auth file.
It is still possible though to update without too much pain since git is very good at dealing with these kinds of situations. Git allows us to have "remotes" for one git repo. I will outline the steps below of how to update. For these steps I assume you are already cd'ed into the OpenDCIM directory.
Add in a new git remote that goes to the OpenDCIM Github repo:
git remote add dev https://github.com/samilliken/openDCIM.git
#
Great, now if we did a git pull dev master
we would be able to grab all of OpenDCIM's changes. However this will cause a lot of merge conflicts. I suggest trying out git pull dev master
and seeing if you can resolve the conflicts. Another option is to just tell git to use all of the OpenDCIM files as the "correct" files to use in the case of a merge conflict, however this could overwrite some of our custom changes. However if this is not a concern the command below will accomplish this:
git pull -s recursive -X theirs dev master
The above command essentially does the normal pull, but in the case of merge conflicts it uses OpenDCIM's repo from Github as the authoritative one and resolves the merge conflicts by using their changes. But again, be careful as this could overwrite some of our changes we made to the OpenDCIM files so you cannot always use this command.
If you have any problems where git is complaining that you have untracked or uncommitted files then you will need to deal with these for the git pull to work. In my case there were a lot of locale files that were causing issues. You will need to figure out on your own the resolutions to the problems that occur, just make sure you deal appropriately with the db.config.inc
file as this file may appear in a list of untracked files, but be a required file as it stores your database config settings.
Due to how this git pull works you may end up with the install file added back into your set of files which may cause OpenDCIM to keep redirecting to the installer. You'll need to delete the install file via:
rm -f install.php
At this point you should be all updated code wise, however there is one more step. Your database is likely using an out of date schema now. OpenDCIM is a little odd for how they handle updating the database to the new versions. They have an SQL file that is used to convert every version to the next one. Take a look at the sql files to see what I mean:
ls db*.sql
You'll notice a lot of files. How do you know which SQL changes to apply? Simple. If you are upgrading from version 4.2 to version 4.3 I would run the SQL commands in the db-4.2-to-4.3.sql
file on the database. Now if you upgraded through multiple versions you'll need to run in order through all of the files. So if I was going from 4.2 to 4.4 I would need to run the migrations from 4.2 to 4.3 and then 4.3 to 4.4.
Once you've applied these SQL changes you should be ready to use OpenDCIM with the new version. I suggest with the database updates you make a backup of the database prior to making the SQL changes, just in case. Also once done all the updating it is a good idea to verify that OpenDCIM is working properly and that all of the API is working properly in inventory.
Use the following commands to do a little housekeeping.
Command | Function |
---|---|
sudo apt-get clean | Clean up the apt cache |
sudo apt-get update | Update the package index with the latest changes in repositories |
sudo apt-get autoremove | Remove packages that were automatically installed to satisfy dependencies but are no longer needed |
<?php phpinfo(); ?>
Testing of the inventory application is very important. We have automated tests using selenium that test the application. Any new features or changes in the functionality of a feature requires new tests or modification of old tests. They must be regularly tested to make sure there are no bugs in the application.
To install selenium and other requirements as well as examples of how to write tests, go to InventoryDeveloperTestPlan.
sudo apt-get install nodejs-legacy
sudo apt-get install npm
sudo npm install -g jshint
sudo npm install -g csslint
"paths": { "linux": [ "/usr/local/lib/node_modules/jshint/bin", "/usr/local/lib/node_modules/csslint/bin", "/usr/bin/php -l" ], "osx": [], "windows": [] }
You will be using the command-line tool ssh to connect to other linux machines, such as linux.cs.uwaterloo.ca, which mounts the shared directories where our production web files are stored. You can find an intro to SSH here.
I | Attachment | History | Action | Size | Date | Who | Comment |
---|---|---|---|---|---|---|---|
![]() |
ChooseDatabase.png | r1 | manage | 28.6 K | 2015-11-30 - 11:54 | JeffGuild | Screen shot: choosing a database for myPhpAdmin |
![]() |
ChooseWebServer.png | r2 r1 | manage | 13.8 K | 2015-11-30 - 11:46 | JeffGuild | Screen shot: choosing a web server to run phpMyAdmin |
![]() |
db-passwords.inc | r4 r3 r2 r1 | manage | 1.1 K | 2021-02-25 - 15:42 | BrianJiang | template password file - not included in repository. |
![]() |
inventory.sql | r2 r1 | manage | 104.7 K | 2021-02-23 - 10:18 | BrianJiang | Sample schema with necessary data inserted. |