[shmookey] / portconf / install.py Repository:


UCC Code Repository

View of /portconf/install.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 110 - (download) (as text) (annotate)
Wed May 28 07:18:09 2008 UTC (2 years, 3 months ago) by shmookey
File size: 7554 byte(s)
various cleaning up and refining

#!/usr/bin/python

import cgi, cgitb, sys, os
import common

cgitb.enable ()


def ShowDefaultPage ():
	pageText = """
	<h1 id='ms_page_title'>Welcome to the Port Administration Configuration Tool (PACT)</h1>
	<p>Thanks for choosing PACT!<br>
	Before we can get started, we'll need to collect some information for the basic configuration
	of PACT. All of these questions are pretty vital, if you don't know the answers for them then
	perhaps you shouldn't be installing network manager software at all! That said, you can change
	these settings at any time should you feel the need to, we just need something to work with.
	These fields have been filled in with sane defaults where possible, but you can change them
	by clicking them.</p>
	<div class='block'>
	<h3>1.) Installation</h3>
	Ease of use has always been a primary objective for PACT, but there are some circumstances where
	for security reasons a drag-and-drop installation isn't suitable. If you choose to use a
	fragmented install, you'll have to provide paths to the locations of the parts you want to
	keep out of your public-html. We'll generate a script to move the relevant files to their
	new home called finalise-install.sh if you choose this option; you should run it as root. If you
	change these values, you can't finish the installation until you run this script.
	<b>Please note that in most situations it is perfectly okay to leave the paths alone.</b><br>
	<table border='0' cellpadding='2' cellspacing='0' class='rowset'>
	<tr><td><a style="cursor:pointer" class="var" id="pyciscopath">""" + os.path.abspath (os.path.dirname (sys.argv[0]) + "/pycisco/") + """</a></td><td>Path to PyCisco module, eg: <i>/usr/local/pycisco</i></td></tr>
	<tr><td><a style="cursor:pointer" class="var" id="pyaaapath">""" + os.path.abspath (os.path.dirname (sys.argv[0]) + "/pyaaa/") + """</a></td><td>Path to PyAAA module, eg: <i>/usr/local/pyaaa</i></td></tr>
	</table>
	</div>
	<div class='block'>
	<h3>2.) Database Configuration</h3>
	PACT uses PostgreSQL as a database backend for storing configuration, access-control and session 
	data. It can be used for authentication, but it doesn't have to be. You can't complete the
	installation until these are completed with valid values. Don't take it personally, we really
	do need them to keep your workplace secure!
	<table  border='0' cellpadding='2' cellspacing='0' class='rowset'>
	<tr><td><a style="cursor:pointer" class="var" id="dbhost">localhost</a></td><td>Hostname or IP address of PostgreSQL server.</td></tr>
	<tr><td><a style="cursor:pointer" class="var" id="dbport">5432</a></td><td>Port to connect through.</td></tr>
	<tr><td><a style="cursor:pointer" class="var" id="dbname">not set</a></td><td>Name of database for PACT to use (must already exist).</td></tr>
	<tr><td><a style="cursor:pointer" class="var" id="dbpref">pact_</a></td><td>Prefix to use for PACT tables, eg: <i>pact_</i>Users</td></tr>
	<tr><td><a style="cursor:pointer" class="var" id="dbuser">not set</a></td><td>User name to connect to the database with.</td></tr>
	<tr><td><a style="cursor:pointer" class="pw" id="dbpass">********</a></td><td>Password to connect to the database with.</td></tr>
	</table>
	</div>
	<div class='block'>
	<h3>3.) You're done!</h3>
	That's it! Click the link below to start the installation.<br>
	<div style="border-width:1px;border-style:solid;border-color:#cccccc;width:100%;text-align:center;padding:5px" id="status">
	Waiting for installation to start.<br />
	<a style="cursor:pointer;font-size:1.5em;font-weight:bold;text-align:center" class="testdetails">INSTALL</a>
	</div>
	</div>
	<input type='hidden' name='action' value='install' />
	<script type='text/javascript'>
	$(document).ready (function () {
		textFieldClick = function () {
			fieldid = $(this).attr ("id");
			$(this).attr ("class", fieldid + "Input");
			td = $(this).parents ("td");
			td.html ("<input type='text' value='" + $(this).text() + "' />");
			td.children ().focus ().blur (function () {
				newval = $(this).attr ("value");
				td = $(this).parents ("td");
				td.html ("<a style='cursor:pointer' class='var' id='" + fieldid + "'>Saving...</a>");
				td.children ().click (textFieldClick);
				td.children ().load ("update-install.py?action=setvar&name=" + fieldid + "&value=" + newval);
			});
		};
		pwFieldClick = function () {
			fieldid = $(this).attr ("id");
			$(this).attr ("class", fieldid + "Input");
			td = $(this).parents ("td");
			td.html ("<input type='password' value='" + $(this).text() + "' />");
			td.children ().focus ().blur (function () {
				newval = $(this).attr ("value");
				td = $(this).parents ("td");
				td.html ("<a style='cursor:pointer' class='pw' id='" + fieldid + "'>Saving...</a>");
				td.children ().click (textFieldClick);
				td.children ().load ("update-install.py?action=setvar&name=" + fieldid + "&value=" + newval);
			});
		};
		function ClearHighlights () {
			$("#dbhost").parents ("tr"). css ("color","black");
			$("#dbport").parents ("tr"). css ("color","black");
			$("#dbname").parents ("tr"). css ("color","black");
			$("#dbpref").parents ("tr"). css ("color","black");
			$("#dbuser").parents ("tr"). css ("color","black");
			$("#dbpass").parents ("tr"). css ("color","black");
		};
		function UpdateInstallStatus (errmess) {
			$("#status"). html (errmess + "<br /><a style='cursor:pointer;font-size:1.5em;font-weight:bold;text-align:center' class='testdetails'>RETRY</a>");
			$("a.testdetails").click (validateFieldClick);
		};
		validateFieldClick = function () {
			$.getScript ("update-install.py?action=validate", function () {
				ClearHighlights ();
				if (status == "NeedDBName") {
					$("#dbname").parents ("tr"). css ("color","red");
					UpdateInstallStatus ("Please provide a database name.");
				} else if (status == "NeedDBUser") {
					$("#dbuser").parents ("tr"). css ("color","red");
					UpdateInstallStatus ("Please provide a database username.");
				} else if (status == "NeedDBPass") {
					$("#dbpass").parents ("tr"). css ("color","red");
					UpdateInstallStatus ("Please provide a database password.");
				} else if (status == "NeedDBPort") {
					$("#dbport").parents ("tr"). css ("color","red");
					UpdateInstallStatus ("Please provide the correct database port.");
				} else if (status == "InvalidDatabaseSettings") {
					$("#dbuser").parents ("tr"). css ("color","red");
					$("#dbpass").parents ("tr"). css ("color","red");
					$("#dbname").parents ("tr"). css ("color","red");
					UpdateInstallStatus ("There was a problem with your username, password, or database name. Please check these values and try again.");
				} else if (status == "DatabaseError") {
					UpdateInstallStatus ("There was an unknown problem with the database. Please check that there are no existing tables or relations with the <i>" + $("#dbpref").html () + "</i> prefix.");
				} else if (status == "Success") {
					UpdateInstallStatus ("Installation sucessful.");
				}
			});
		};
		$("a.var").click (textFieldClick);
		$("a.pw").click (pwFieldClick);
		$("a.testdetails").click (validateFieldClick);
	});
	</script>
	"""
	return pageText

def GetSidebar ():
	sideText = """
		<dt><a href="index.html">Navigation</a></dt>
		<dd><ul>
		<li>Install</li>
		<li><a href="update-install.py?action=uninstall">Uninstall</a></li>
		</ul></dd>
	"""
	return sideText


pageBuffer = ""
pageBuffer += "Content-Type: text/html\n\n"
pageBuffer += common.GetHeader ("Install", GetSidebar ())
pageBuffer += ShowDefaultPage ()
pageBuffer += common.GetFooter ()

print pageBuffer

UCC Webmasters
ViewVC Help
Powered by ViewVC 1.0.5