bkruse: trunk r1285 - in /trunk: ./ config/ config/scripts/ scripts/

SVN commits to the Asterisk-GUI project asterisk-gui-commits at lists.digium.com
Wed Aug 1 15:40:06 CDT 2007


Author: bkruse
Date: Wed Aug  1 15:40:06 2007
New Revision: 1285

URL: http://svn.digium.com/view/asterisk-gui?view=rev&rev=1285
Log:
[1] Support for a CDR Viewer (bbryant) (cdr.html) [2] Adding CDR Configuration Page (currently commented out inside cfgbasic.html, because of some errors) [3] Updated todo.txt for a revision string inside the gui context idea (pari) [4] Added some tooltips for the CDR viewer page [5] Added a couple php like functions into astman.js (bbryant) which are very useful

Added:
    trunk/config/cdr.html
    trunk/config/cdr_conf.html
    trunk/scripts/mastercsvexists
Modified:
    trunk/config/cfgbasic.html
    trunk/config/scripts/astman.js
    trunk/config/scripts/tooltip.js
    trunk/todo.txt

Added: trunk/config/cdr.html
URL: http://svn.digium.com/view/asterisk-gui/trunk/config/cdr.html?view=auto&rev=1285
==============================================================================
--- trunk/config/cdr.html (added)
+++ trunk/config/cdr.html Wed Aug  1 15:40:06 2007
@@ -1,0 +1,180 @@
+<script type="text/javascript" src="scripts/prototype.js"></script>
+<script type="text/javascript" src="scripts/astman.js"></script>
+<link href="stylesheets/schwing.css" media="all" rel="Stylesheet" type="text/css" />
+<style type="text/css">
+	#page_header {
+		font-size : 12px;
+		padding : 4px 6px 4px 6px;
+		border-style : solid none solid none;
+		border-top-color : #BDC7E7;
+		border-bottom-color : #182052;
+		border-width : 1px 0px 1px 0px;
+		background-color : #ef8700;
+		margin-bottom: 10px;
+		color : #ffffff;
+	}
+
+	.header {
+		color: #6b79a5;
+		font-family: Arial;
+		font-weight: bold;
+		font-size: 25px;
+	}
+
+
+	#tr0 {
+		background-color: #efaa50;
+		color: white;
+		font-weight: bold;
+	}
+
+	#tr1 {
+		background-color: #6b79a5;
+		color: white;
+		font-weight: bold
+	}
+
+	#tr2 {
+		background-color: white;
+		color: black;
+		text-decoration: underline;
+	}
+
+	#tr0 td, #tr1 td, #tr2 td {
+		font-size: xx-small;
+	}
+
+	#cdr_content {
+		overflow: scroll;
+	}
+
+	.info {
+		font-size: small;
+		color: #6b79a5;
+	}
+</style>
+<script type="text/javascript">
+//<![CDATA[
+	var backend = "cvs";
+	var records = [];
+	var viewCount = 10;
+	var offset = 0;
+	var fields = [
+		"",
+		"Account Code", "Source", "Destination", "Dest. Context",
+		"Caller ID", "Channel", "Dest. Channel", "Last app.",
+		"Last data", "Start time", "Answer Time", "End Time",
+		"Duration", "Billable seconds", "Disposition", "AMA flags", 
+		"Unique ID", "Log userfield"
+	];
+
+	function nextPage() {
+		if (records.length > offset + viewCount)
+			offset += viewCount;
+		loadRecords();
+	}
+
+	function prevPage() {
+		if (offset) offset -= viewCount;
+		if (offset < 0) offset = 0;
+		loadRecords();
+	}
+
+	function loadRecords() {
+		var c = viewCount;
+
+		clearContent();
+
+		_$("info").innerHTML = "Viewing " + (offset+1) + "-" + (offset+viewCount) + " of " + records.length;
+
+		var tr = document.createElement("tr");
+		tr.id = "tr2";
+
+		for(var i=0;i<=records[offset].length;i++) {
+			var td = document.createElement("td");
+			td.appendChild(document.createTextNode(fields[i]));
+			tr.appendChild(td);
+		}
+
+		_$("cdr_content").appendChild(tr);
+
+		for(var i=0;c--&&isset(records[i+offset]);i++) {
+			var tr = document.createElement("tr");
+			tr.id = "tr"+(i%2);
+			var r = records[i+offset];
+			
+			for(var j=-1;j<r.length;j++) {
+				var td = document.createElement("td");
+				if (j < 0)
+					var l = offset+i+1;
+				else
+					var l = r[j].toString().replace(/^[\"]{1}/, "").replace(/[\"]{1}$/, "");
+				td.appendChild(document.createTextNode(l));
+				tr.appendChild(td);
+			}
+
+			_$("cdr_content").appendChild(tr);
+		}
+	}
+
+	function clearContent() {
+		while(_$("cdr_content").childNodes.length) {
+			_$("cdr_content").removeChild(
+				_$("cdr_content").childNodes[0]
+			);
+		}
+	}
+
+	window.onload = function() {
+		setWindowTitle("CDR viewer (" + backend + ")");
+		parent.loadscreen(this);
+
+		config2json("cdr.conf", 1, function(config) {
+			if (isset(config.enable) && !ast_true(config.enable))
+				this.location.href = "cdr_conf.html?needssetup";
+		});
+
+		parent.astmanEngine.run_tool("sh " + asterisk_scriptsFolder + "mastercsvexists", function (){
+			new Ajax.Request("/asterisk/static/Master.csv", {
+				method : "get",
+				asynchronous : true,
+				onComplete : function(c) {
+					records = c.responseText.split("\n");
+					for(var i=0;i<records.length;i++)
+						records[i] = records[i].split(",");
+					loadRecords();
+				},
+				onFailure : function() {
+					gui_alert("Sorry, it appears that you're not using > version 1.4 of asterisk, " +
+							  "or you're on an appliance. Only configuring CDRs is available at this time.");
+					this.location.href = "cdr_conf.html";
+				},
+			});
+		});
+	}
+//]]>
+</script>
+<body>
+  <div id="page_header">
+    <span style="margin-left: 4px"><strong>CDR viewer</strong></span>&nbsp;
+	<img src="images/refresh.png" alt=" Refresh " onclick="javascript: this.location.href=this.location.href" />
+  </div>
+  <div class="header">
+    CDR viewer
+    <a href="#" onclick="javascript: prevPage();">&lt;&lt; prev</a>
+    <a href="#" onclick="javascript: nextPage();">next &gt;&gt;</a>
+  </div>
+  <div style="float: right; font-size: medium; color: #6b79a5;">
+    View:
+    <select tip="en,cdr,0" onchange="javascript: viewCount=parseInt(this.value);loadRecords();">
+      <option value="10">10</option>
+      <option value="25">25</option>
+      <option value="50">50</option>
+      <option value="100">100</option>
+    </select>
+  </div> 
+  <div id="info" class="info"></div><div class="info"> (most recent first) <a href="cdr_conf.html" target="_self">Configure CDRs</a></div>
+  <div style="width: 500px; position: relative; left: 10px; height: 320px; overflow: auto;" id="cdr_content_container">
+    <table id="cdr_content"></table>
+  </div>
+</body>

Added: trunk/config/cdr_conf.html
URL: http://svn.digium.com/view/asterisk-gui/trunk/config/cdr_conf.html?view=auto&rev=1285
==============================================================================
--- trunk/config/cdr_conf.html (added)
+++ trunk/config/cdr_conf.html Wed Aug  1 15:40:06 2007
@@ -1,0 +1,362 @@
+<script type="text/javascript" src="scripts/prototype.js"></script>
+<script type="text/javascript" src="scripts/astman.js"></script>
+<script type="text/javascript" src="scripts/tooltip.js"></script>
+<link href="stylesheets/schwing.css" media="all" rel="Stylesheet" type="text/css" />
+<style type="text/css">
+	#page_header {
+		font-size : 12px;
+		padding : 4px 6px 4px 6px;
+		border-style : solid none solid none;
+		border-top-color : #BDC7E7;
+		border-bottom-color : #182052;
+		border-width : 1px 0px 1px 0px;
+		background-color : #ef8700;
+		color : #ffffff;
+	}
+
+	#dialog {
+		border: 1px solid blue;
+		background-color: #0000af;
+		text-indent: 20px;
+		position: absolute;
+		z-index: 50;
+		top: 0px;
+		left: 0px;
+	}
+
+	.header {
+		color: #6b79a5;
+		font-family: Arial;
+		font-weight: bold;
+		font-size: 25px;
+	}
+
+	.header a {
+		text-decoration: underline;
+		font-weight: normal;
+		font-size: 10px;
+	}
+
+	.header a:hover {
+		text-decoration: none;
+	}
+
+	.mainTable_top {
+		border-top: 1px groove gray;
+		border-left: 1px groove gray;
+		border-right: 1px groove gray;
+		border-bottom: none;
+
+		position: relative;
+		left: 20px;
+		width: 444px;
+
+		margin-top: 10px;
+		margin-bottom: 0px;
+	}
+
+	.mainTable_middle {
+		border-top: none;
+		border-bottom: none;
+		border-left: 1px groove gray;
+		border-right: 1px groove gray;
+
+		position: relative;
+		left: 20px;
+		width: 444px;
+
+		margin: 0 0 0 0;
+	}
+
+	.mainTable_bottom {
+		border-top: none;
+		border-left: 1px groove gray;
+		border-bottom: 1px groove gray;
+		border-right: 1px groove gray;
+
+		position: relative;
+		left: 20px;
+		width: 444px;
+
+		margin-top: 0;
+		margin-bottom: 10px;
+	}
+
+	input {
+		width: 50px;
+	}
+</style>
+<script type="text/javascript">
+//<![CDATA[
+	var needssetup = false;
+
+	var configObjs = [
+		"enable", 
+		"batch",
+		"size",
+		"time",
+		"safeshutdown",
+		"csv_enable",
+		"csv_usegmtime",
+		"csv_loguniqueid",
+		"csv_loguserfield"
+	];
+
+	var cdrconfig = {
+		enable : true,
+		batch : false,
+		size : 100,
+		time : 300,
+		scheduleronly : false,
+		safeshutdown : true,
+		endbeforehexten : false,
+		csv_enable : false,
+		csv_usegmtime : true,
+		csv_loguniqueid : true,
+		csv_loguserfield : true,
+	};
+
+	function showBackendConfig(backend) {
+		var divs = document.getElementsByName("div");
+
+		for(var i=0;i<divs.length;i++) {
+			if (divs[i].id.match("_config$"))
+				divs[i].style.display = "none";
+		}
+
+		if (isset(_$(backend + "_config"))) {
+			_$(backend + "_config").display = "block";
+			return;
+		}
+
+		gui_alert("CDR backend \"" + backend +"\" does not have a config section.");
+		_$("backends").options[0].selected = true;
+	}
+
+	window.onload = function() {
+		parent._$("mainscreen").width = 798;
+
+		setWindowTitle("CDR Configuration");
+
+		ASTGUI.events.add(document, "mouseover", show_tooltip);
+
+		if (this.location.href.match("needssetup"))
+			needssetup = true;
+
+		loadCDRs();
+
+		parent.loadscreen(this);
+	}
+
+	function loadConfigToHTML() {
+		for (var i in configObjs) {
+			if (!configObjs.propertyIsEnumerable(i))
+				continue;
+			if (!isset(cdrconfig[configObjs[i]]) || !(_$(configObjs[i]))) {
+				gui_alert("Warning: config variable \"" + i + "\" " +
+						  "configured, but does exist in either cdrconfig or html.");
+				configObjs.splice(i, 1);
+				continue;
+			}
+
+			if (_$(configObjs[i]).options)
+				_$(configObjs[i]).options[!cdrconfig[configObjs[i]]].selected = true;
+			else
+				_$(configObjs[i]).value = parseInt(cdrconfig[configObjs[i]]);
+
+			if (isset(tooltips["cdr"].en[i]))
+				_$(configObjs[i]).setAttribute("tip", "en,cdr," + i);
+
+			_$(configObjs[i]).disabled = false;
+		}
+
+		if (cdrconfig.batch)
+			_$("batch_options").style.display = "block";
+
+		_$("backends").disabled = false;
+	}
+
+	function readConfigFromHTML() {
+		for (var i in configObjs) {
+			if (!configObjs.propertyIsEnumerable(i))
+				continue;
+			if (configObjs[i].options)
+				cdrconfig[configObjs[i]] = ast_true(_$(configObjs[i]).value);
+			else
+				cdrconfig[configObjs[i]] = parseInt(_$(configObjs[i]).value);
+		}
+	}
+
+	function applyChanges() {
+		readConfigFromHTML();
+
+		if (cdrconfig.enable)
+			needssetup = false;
+
+		for (var i in cdrconfig) {
+			var context = "general";
+
+			if (!cdrconfig.propertyIsEnumerable(i))
+				continue;
+
+			if ((i = i.split("_"))[1]) {
+				context = i[0];
+				i = i[1];
+			}
+
+			makerequest(
+				"u", "cdr.conf", 
+				build_action("append", 0, context, i, cdrconfig[configObjs[i]].toString()),
+				function(ignore) { return true; }
+			);
+		}
+	}
+
+	function viewCDRs() {
+		if (needssetup) {
+			gui_alert("You don't have CDRs setup yet, you might want to enable that first.");
+			return;
+		}
+
+		this.location.href = 'cdr.html';
+	}
+
+	function loadCDRs() {
+		config2json("cdr.conf", 1, function(config) {
+			if (isset(config.general.enable))
+				cdrconfig.enable = ast_true(config.general.enable);
+			if (isset(config.general.batch))
+				cdrconfig.batch = ast_true(config.general.batch);
+			if (isset(config.general.size))
+				cdrconfig.size = parseInt(config.general.size);
+			if (isset(config.general.time))
+				cdrconfig.time = parseInt(config.general.time);
+			if (isset(config.general.sceduleronly))
+				cdrconfig.scheduleronly = ast_true(config.general.scheduleronly);
+			if (isset(config.general.safeshutdown))
+				cdrconfig.safeshutdown = ast_true(config.general.safeshutdown);
+			if (isset(config.general.endbeforehexten))
+				cdrconfig.endbeforehexten = ast_true(config.generael.endbeforehexten);
+
+			if (isset(config.csv)) {
+				cdrconfig.cvs_enable = true;
+
+				if (config.csv.usegmtime)
+					cdrconfig.csv_usegmtime = ast_true(config.csv.usegmtime);
+				if (config.csv.loguniqueid)
+					cdrconfig.csv_loguniqueid = ast_true(config.csv.loguniqueid);
+				if (config.csv.loguserfield)
+					cdrconfig.csv_loguserfield = ast_true(config.csv.loguserfield);
+			}
+
+			loadConfigToHTML();
+		});
+	}
+//]]>
+</script>
+<body id="foo">
+  <div id="page_header">
+    <span style="margin-left: 4px;"><strong>CDR Configuration</strong></span>
+    <span style="cursor: pointer;">
+      <img src="images/refresh.png" alt=" Refresh " onclick="window.location.href = window.location.href;" />
+    </span>
+  </div>
+  <div class="mainscreenContentBox" style="width: 500px; margin-left: 20px;">
+    <div class="header">
+      CDR Configuration options 
+      <a href="#" onclick="javascript: viewCDRs();">(View CDRs)</a>
+    </div>
+    <table class="mainTable_top" cellpadding="2">
+      <tr>
+        <td width="130px">Enabled: </td>
+        <td>
+          <select id="enable" disabled>
+            <option value="true">Yes</option>
+            <option value="false">No</option>
+          </select>
+        </td>
+      </tr>
+      <tr>
+        <td>Batch mode: </td>
+        <td>
+          <select id="batch" disabled onchange="javascript: _$('batch_options').style.display = (ast_true(this.value)) ? 'block':'none';">
+            <option value="true">Yes</option>
+            <option value="false" selected>No</option>
+          </select>
+        </td>
+      </tr>
+    </table>
+    <table class="mainTable_middle" id="batch_options" style="display: none">
+      <tr>
+        <td width="130px">&nbsp; Batch <small>(max queue size)</small>: </td>
+        <td><input type="text" id="size" disabled></td>
+      </tr>
+      <tr>
+          <td>&nbsp; Batch <small>(max queue time)</small>: </td>
+          <td><input type="text" id="time" disabled></td>
+      </tr>
+    </table>
+    <table class="mainTable_middle">
+      <tr>
+        <td width="130px">Backends: </td>
+        <td>
+          <select id="backends" onchange="javascript: if(this.value.length) showBackendConfig(this.value);">
+            <option value=""></option>
+            <option value="csv">csv</option>
+          </select>
+        </td>
+      </tr>
+    </table>
+    <table class="mainTable_middle" id="csv_config" style="display: none;">
+      <tr>
+        <td width="130px">Enabled: </td>
+        <td>
+          <select id="csv_enable" disabled>
+            <option value="true">Yes</option>
+            <option value="false">No</option>
+          </select>
+        </td>
+      </tr>
+      <tr>
+        <td>Use GMT: </td>
+        <td>
+          <select id="csv_usegmtime" disabled>
+            <option value="true">Yes</option>
+            <option value="false">No</option>
+          </select>
+        </td>
+      </tr>
+      <tr>
+        <td>Log unique id: </td>
+        <td>
+          <select id="csv_loguniqueid" disabled>
+            <option value="true">Yes</option>
+            <option value="false">No</option>
+          </select>
+        </td>
+      </tr>
+      <tr>
+        <td>Log user field: </td>
+        <td>
+           <select id="csv_loguserfield" disabled>
+            <option value="true">Yes</option>
+            <option value="false">No</option>
+          </select>
+        </td>
+      </tr>
+    </table>
+    <table class="mainTable_bottom">
+      <tr>
+        <td width="130px">Safe shutdown: </td>
+        <td>
+          <select id="safeshutdown" disabled>
+            <option value="true">Yes</option>
+            <option value="false">No</option>
+          </select>
+        </td>
+      </tr>
+    </table>
+    <button onclick="javascript: applyChanges();">Apply Changes</button>
+	<button onclick="javascript: viewCDRs();">View CDRs</button>
+  </div>
+</body>

Modified: trunk/config/cfgbasic.html
URL: http://svn.digium.com/view/asterisk-gui/trunk/config/cfgbasic.html?view=diff&rev=1285&r1=1284&r2=1285
==============================================================================
--- trunk/config/cfgbasic.html (original)
+++ trunk/config/cfgbasic.html Wed Aug  1 15:40:06 2007
@@ -176,6 +176,8 @@
 	newpanel( ["Graphs", "graphs.html", "View Graphs of your System Information."]);
 	newpanel( ["System Info", "sysinfo.html", "System Information."]);
 	newpanel( ["Asterisk Logs", "syslog.html", "Asterisk Log messages."]);
+	// newpanel( ["CDR Configuration", "cdr_conf.html", "CDR Engine Configuration."]); // Uncomment when cdr_conf.html is finished, there are still some errors. 
+	newpanel( ["CDR Reader", "cdr.html", "Read all your call records from Asterisk."]);
 	newpanel( ["File Editor", "feditor.html", "Edit Asterisk Config Files"]);
 	newpanel( ["Asterisk CLI", "cli.html", "Asterisk Command Line Interface"]);
 	newpanel( ["GUI Access", "http_options.html", "GUI Access settings."]);

Modified: trunk/config/scripts/astman.js
URL: http://svn.digium.com/view/asterisk-gui/trunk/config/scripts/astman.js?view=diff&rev=1285&r1=1284&r2=1285
==============================================================================
--- trunk/config/scripts/astman.js (original)
+++ trunk/config/scripts/astman.js Wed Aug  1 15:40:06 2007
@@ -42,6 +42,38 @@
 var TIMERULES_CATEGORY = 'timebasedrules';
 var isIE = false;
 if(document.attachEvent){ isIE= true; }
+
+/* Some useful functions */
+function isset(obj) {
+	if (typeof obj != "object")
+		return (typeof obj != "undefined");
+	for (var i in obj)
+		return true;
+	return false;
+}
+
+function trim(str) {
+	return str.replace(/^[\s]+/, "").replace(/[\s]+$/, "");
+}
+
+Array.prototype.contains = function(str) {
+	for (var i in this)
+		if(str == this[i])
+			return true;
+	return false;
+}
+
+function ast_true(str) {
+	return [
+		"yes", "true", "y", "t", "1", "on"
+	].contains(trim(str.toLowerCase()));
+}
+
+function ast_false(str) {
+	return [
+		"no", "false", "n", "f", "0", "off"
+	].contains(trim(str.toLowerCase()));
+}
 
 var ASTGUI = { // the idea is to eventually move all the global variables and functions into this one object so that the global name space is not as cluttered as it is now.
 	dialog : {

Modified: trunk/config/scripts/tooltip.js
URL: http://svn.digium.com/view/asterisk-gui/trunk/config/scripts/tooltip.js?view=diff&rev=1285&r1=1284&r2=1285
==============================================================================
--- trunk/config/scripts/tooltip.js (original)
+++ trunk/config/scripts/tooltip.js Wed Aug  1 15:40:06 2007
@@ -318,3 +318,9 @@
 	tooltips['http_options'].en[0] = "" ;
 	tooltips['http_options'].en[1] = "<B>Bind IP:</B> GUI will be available only on this IP address, if not sure please enter the LAN IP address. If you want the GUI to be available on all interfaces - enter 0.0.0.0" ;
 	tooltips['http_options'].en[2] = "<B>Port:</B> Please enter the port number on which you want to access the GUI." ;
+
+
+// 	Tooltips for the CDR reader page.
+	tooltips['cdr'] = new Object;
+	tooltips['cdr'].en = new Array;
+	tooltips['cdr'].en[0] = "<B>View:</B> Select how many call detail records to read at once.." ;

Added: trunk/scripts/mastercsvexists
URL: http://svn.digium.com/view/asterisk-gui/trunk/scripts/mastercsvexists?view=auto&rev=1285
==============================================================================
--- trunk/scripts/mastercsvexists (added)
+++ trunk/scripts/mastercsvexists Wed Aug  1 15:40:06 2007
@@ -1,0 +1,17 @@
+#!/bin/bash
+
+MASTERCSV="/var/log/asterisk/cdr-csv/Master.csv"
+STATICHTTP="/var/lib/asterisk/static-http/"
+
+if [ `whoami` != "root" ]; then
+	echo "Error: You must be root to run this script."
+	exit 1
+fi
+
+if [ -f /var/log/asterisk/cdr-csv/Master.csv ]; then
+	if [ ! -f $STATICHTTP`basename $MASTERCSV` ]; then
+		ln -s $MASTERCSV /var/lib/asterisk/static-http/`basename $MASTERCSV`
+	fi
+fi
+
+exit

Modified: trunk/todo.txt
URL: http://svn.digium.com/view/asterisk-gui/trunk/todo.txt?view=diff&rev=1285&r1=1284&r2=1285
==============================================================================
--- trunk/todo.txt (original)
+++ trunk/todo.txt Wed Aug  1 15:40:06 2007
@@ -15,7 +15,7 @@
 
 * Call Forwarding
 
-* CDR support
+* CDR Configuration page from patch http://bugs.digium.com/view.php?id=10306 (bbryant)
 
 * Label/Tag/Name Analog Channels for presentation in GUI
 
@@ -36,6 +36,8 @@
 
 * Ability to download config backup files and restore them via file uploads
 
+* Add the GUI version string inside extensions.conf, so the setup wizard can decide if it needs to update the guitools context.
+
 Completed
 ----------
 * Operator Extension
@@ -55,3 +57,5 @@
 * Agent logout Extension
 
 * To fix call parking, give it an option to allow if the user wants people to be able to access the parking lot per numberplan
+
+* CDR support (Reader) (Thanks bbryant)




More information about the asterisk-gui-commits mailing list