why is javascript so bad

who knows
This commit is contained in:
MallocNull 2014-07-11 16:03:57 -05:00
parent 981327c4af
commit 2cfef93e01
17 changed files with 465 additions and 101 deletions

2
.gitignore vendored
View file

@ -2,7 +2,7 @@
## Temporary Exclusions ## Temporary Exclusions
################# #################
conn.php conn.php
_G.cs dbinfo.txt
.idea/ .idea/
################# #################

View file

@ -17,8 +17,22 @@ namespace bot {
class Bot { class Bot {
static string tmp; static string tmp;
static List<NavigationNode> navigationList = new List<NavigationNode>();
static List<Response> responseList = new List<Response>(); static List<Response> responseList = new List<Response>();
public static void loadNavigationList() {
navigationList = new List<NavigationNode>();
var r = Query.Reader("SELECT * FROM `navigate`", _G.conn);
while(r.Read()) {
navigationList.Add(new NavigationNode(
r.GetInt32("findtype"),
r.GetString("locator"),
r.GetInt32("action"),
r.GetString("parameter")));
}
r.Close();
}
public static void loadResponseList() { public static void loadResponseList() {
responseList = new List<Response>(); responseList = new List<Response>();
var r = Query.Reader("SELECT * FROM `responses`", _G.conn); var r = Query.Reader("SELECT * FROM `responses`", _G.conn);
@ -33,10 +47,12 @@ namespace bot {
} }
static void Main(string[] args) { static void Main(string[] args) {
_G.conn = new MySqlConnection("SERVER="+ _G.serveraddr +";DATABASE="+ _G.dbname +";UID="+ _G.dbuser +";PASSWORD="+ _G.dbpass +";"); _G.loadDatabaseInfo();
_G.conn.Open(); _G.conn = _G.spawnNewConnection();
_G.errconn = _G.spawnNewConnection();
_G.loadConfig(); _G.loadConfig();
loadResponseList();
tmp = "DELETE FROM resptypes WHERE "; tmp = "DELETE FROM resptypes WHERE ";
foreach(Type t in ResponseCaller.getResponseTypes()) { foreach(Type t in ResponseCaller.getResponseTypes()) {
@ -62,9 +78,11 @@ namespace bot {
tmp = tmp.Substring(0, tmp.Length - 5); tmp = tmp.Substring(0, tmp.Length - 5);
Query.Quiet(tmp, _G.conn); Query.Quiet(tmp, _G.conn);
_G.updateHeartbeat(); _G.driver = new FirefoxDriver();
foreach(NavigationNode node in navigationList)
node.performNavigation(_G.driver);
_G.startThread(_G.pulseThread); _G.startThread(Pulse.pulseThread);
Console.WriteLine(_G.propername +" has started successfully."); Console.WriteLine(_G.propername +" has started successfully.");

View file

@ -14,9 +14,9 @@ namespace bot {
conditionTypes = Assembly.GetExecutingAssembly().GetTypes().Where(t => String.Equals(t.Namespace, "bot.conditions", StringComparison.Ordinal)).ToArray(); conditionTypes = Assembly.GetExecutingAssembly().GetTypes().Where(t => String.Equals(t.Namespace, "bot.conditions", StringComparison.Ordinal)).ToArray();
} }
public static bool checkCondition(String conditionName, string check, string parameter) { public static bool checkCondition(String conditionName, Message msg, string parameter) {
loadConditionTypes(); loadConditionTypes();
return (bool)conditionTypes.First(t => t.Name == conditionName).GetMethod("performCheck").Invoke(null, new Object[] { (object)parameter }); return (bool)conditionTypes.First(t => t.Name == conditionName).GetMethod("performCheck").Invoke(null, new Object[] { (object)msg, (object)parameter });
} }
public static Type[] getConditions() { public static Type[] getConditions() {

View file

@ -27,12 +27,66 @@ namespace bot {
INDEXSELECT INDEXSELECT
}; };
findTypes findtype;
string locator;
actionTypes action;
string parameter;
public NavigationNode() { } public NavigationNode() { }
public void performNavigation(FirefoxDriver d) { public NavigationNode(int ft, string l, int a, string p) {
findtype = (findTypes)ft;
locator = l;
action = (actionTypes)a;
parameter = p;
}
public bool performNavigation(FirefoxDriver d) {
IWebElement e = null;
try {
switch(findtype) {
case findTypes.GOTOURL:
d.Navigate().GoToUrl(locator);
break;
case findTypes.BYLINKTEXT:
e = (new WebDriverWait(d, new TimeSpan(0, 0, 900)).Until(ExpectedConditions.ElementExists(By.LinkText(locator))));
break;
case findTypes.BYID:
e = (new WebDriverWait(d, new TimeSpan(0, 0, 900)).Until(ExpectedConditions.ElementExists(By.Id(locator))));
break;
case findTypes.BYNAME:
e = (new WebDriverWait(d, new TimeSpan(0, 0, 900)).Until(ExpectedConditions.ElementExists(By.Name(locator))));
break;
case findTypes.BYCLASS:
e = (new WebDriverWait(d, new TimeSpan(0, 0, 900)).Until(ExpectedConditions.ElementExists(By.ClassName(locator))));
break;
case findTypes.BYTAG:
e = (new WebDriverWait(d, new TimeSpan(0, 0, 900)).Until(ExpectedConditions.ElementExists(By.TagName(locator))));
break;
}
} catch(Exception err) {
_G.logError("Failed to find element "+ locator +" "+ findtype.ToString());
return false;
}
if(e != null) {
switch(action) {
case actionTypes.CLICK:
e.Click();
break;
case actionTypes.TYPE:
e.SendKeys(parameter);
break;
case actionTypes.TEXTSELECT:
(new SelectElement(e)).SelectByText(parameter);
break;
case actionTypes.INDEXSELECT:
(new SelectElement(e)).SelectByIndex(Int32.Parse(parameter));
break;
}
}
return true;
} }
} }
} }

46
bot/bot/Pulse.cs Normal file
View file

@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace bot {
class Pulse {
public static void updateHeartbeat() {
string beat = _G.getLocalTimeFromUTC().ToString();
Query.Quiet("UPDATE `updater` SET `heartbeat`='" + beat + "' WHERE `id`=1", _G.conn);
}
public static void checkUpdates() {
var r = Query.Reader("SELECT * FROM `updater` WHERE `id`=1", _G.conn);
r.Read();
bool[] tmp = new bool[] { r.GetBoolean("responses"), r.GetBoolean("autonomous"), r.GetBoolean("config") };
r.Close();
if(tmp[0]) {
Bot.loadResponseList();
Query.Quiet("UPDATE `updater` SET `responses`=0 WHERE `id`=1", _G.conn);
}
if(tmp[1]) {
// TODO implement update when autonomous is added
Query.Quiet("UPDATE `updater` SET `autonomous`=0 WHERE `id`=1", _G.conn);
}
if(tmp[2]) {
_G.loadConfig();
Query.Quiet("UPDATE `updater` SET `config`=0 WHERE `id`=1", _G.conn);
}
}
public static void pulseThread() {
DateTime t = new DateTime(0);
while(true) {
if((DateTime.Now - t).TotalSeconds > 30) {
updateHeartbeat();
checkUpdates();
t = DateTime.Now;
Console.WriteLine("pulsed");
}
}
}
}
}

View file

@ -1,8 +1,4 @@
/* using System;
* MODIFY THIS FILE TO FIT YOUR SERVER'S CONFIGURATION!
*/
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -18,14 +14,16 @@ using MySql.Data.MySqlClient;
using System.Threading; using System.Threading;
namespace bot { namespace bot {
static class _GG { static class _G {
const string serveraddr = "ADDR"; static string[] dbinfo = new string[4];
const string dbuser = "NAME";
const string dbpass = "PWD";
const string dbname = "DATABASE_NAME";
static List<Thread> runningThreads = new List<Thread>(); static List<Thread> runningThreads = new List<Thread>();
public static FirefoxDriver driver;
/*
* TODO cross-thread driver protection
*/
public static string timezone = "+00:00"; public static string timezone = "+00:00";
public static bool observeDST = false; public static bool observeDST = false;
public static string username = ""; public static string username = "";
@ -34,6 +32,19 @@ namespace bot {
public static int defaultCooldown = 300; public static int defaultCooldown = 300;
public static MySqlConnection conn; public static MySqlConnection conn;
public static MySqlConnection errconn;
public static bool loadDatabaseInfo() {
try {
System.IO.StreamReader r = new System.IO.StreamReader("dbinfo.txt");
for(int i = 0; i < 4; i++)
dbinfo[i] = r.ReadLine();
} catch(Exception e) {
Environment.FailFast("Error attempting to read from dbinfo.txt: "+e.Message+"\n\nProper format:\nSERVER ADDRESS\nUSERNAME\nPASSWORD\nDATABASE_NAME");
return false;
}
return true;
}
public static bool isDaylightSavings() { public static bool isDaylightSavings() {
return (observeDST) ? TimeZoneInfo.GetSystemTimeZones().First(o => o.DisplayName.ToLower().Contains("central time")).IsDaylightSavingTime(DateTime.UtcNow) : false; return (observeDST) ? TimeZoneInfo.GetSystemTimeZones().First(o => o.DisplayName.ToLower().Contains("central time")).IsDaylightSavingTime(DateTime.UtcNow) : false;
@ -47,11 +58,6 @@ namespace bot {
return (new DateTimeOffset(utcTime)).ToOffset(TimeSpan.Parse(timezone).Add(TimeSpan.FromHours(isDaylightSavings() ? 1 : 0))).DateTime; return (new DateTimeOffset(utcTime)).ToOffset(TimeSpan.Parse(timezone).Add(TimeSpan.FromHours(isDaylightSavings() ? 1 : 0))).DateTime;
} }
public static void updateHeartbeat() {
string beat = getLocalTimeFromUTC().ToString();
Query.Quiet("UPDATE `updater` SET `heartbeat`='" + beat + "' WHERE `id`=1", conn);
}
public static void loadConfig() { public static void loadConfig() {
var r = Query.Reader("SELECT * FROM `config` WHERE `id`=1", conn); var r = Query.Reader("SELECT * FROM `config` WHERE `id`=1", conn);
r.Read(); r.Read();
@ -61,31 +67,23 @@ namespace bot {
timezone = r.GetString("timezone"); timezone = r.GetString("timezone");
observeDST = r.GetBoolean("dst"); observeDST = r.GetBoolean("dst");
r.Close(); r.Close();
Bot.loadNavigationList();
} }
public static void checkUpdates() { public static MySqlConnection spawnNewConnection() {
var r = Query.Reader("SELECT * FROM `updater` WHERE `id`=1", conn); MySqlConnection tmp;
r.Read(); try {
if(r.GetBoolean("responses")) tmp = new MySqlConnection("SERVER=" + dbinfo[0] + ";DATABASE=" + dbinfo[3] + ";UID=" + dbinfo[1] + ";PASSWORD=" + dbinfo[2] + ";");
Bot.loadResponseList(); tmp.Open();
//if(r.GetBoolean("autonomous")) TODO implement with autonomous } catch(Exception e) {
Environment.FailFast("Could not open database connection!");
if(r.GetBoolean("config")) return null;
loadConfig();
r.Close();
}
public static void pulseThread() {
DateTime t = new DateTime(0);
while(true) {
if((DateTime.Now - t).TotalSeconds > 30) {
updateHeartbeat();
checkUpdates();
t = DateTime.Now;
Console.WriteLine("pulsed");
}
} }
return tmp;
}
public static void logError(string err) {
(new MySqlCommand("INSERT INTO `error` (`time`,`msg`) VALUES ('"+ getLocalTimeFromUTC() +" UTC"+ timezone +"','"+err+"')", errconn)).ExecuteNonQuery();
} }
public delegate void threadFunc(); public delegate void threadFunc();

View file

@ -92,8 +92,9 @@
<Compile Include="Bot.cs" /> <Compile Include="Bot.cs" />
<Compile Include="Condition.cs" /> <Compile Include="Condition.cs" />
<Compile Include="ConditionChecker.cs" /> <Compile Include="ConditionChecker.cs" />
<Compile Include="conditions\contains.cs" /> <Compile Include="conditions\msgcontains.cs" />
<Compile Include="NavigationNode.cs" /> <Compile Include="NavigationNode.cs" />
<Compile Include="Pulse.cs" />
<Compile Include="Query.cs" /> <Compile Include="Query.cs" />
<Compile Include="responses\jumble.cs" /> <Compile Include="responses\jumble.cs" />
<Compile Include="responses\replace.cs" /> <Compile Include="responses\replace.cs" />
@ -104,12 +105,14 @@
<Compile Include="Response.cs" /> <Compile Include="Response.cs" />
<Compile Include="responses\sendmsg.cs" /> <Compile Include="responses\sendmsg.cs" />
<Compile Include="ResponseCaller.cs" /> <Compile Include="ResponseCaller.cs" />
<Compile Include="_GG.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="App.config" /> <None Include="App.config" />
</ItemGroup> </ItemGroup>
<ItemGroup /> <ItemGroup>
<Content Include="dbinfo.txt" />
<Content Include="dbinfo_generic.txt" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets. Other similar extension points exist, see Microsoft.Common.targets.

View file

@ -1,17 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace bot.conditions {
class contains {
static public string[] getInfo() {
return new string[] {typeof(contains).Name, "contains"};
}
static public bool performCheck(string check, string parameter) {
return check.Contains(parameter);
}
}
}

View file

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace bot.conditions {
class msgcontains {
static public string[] getInfo() {
return new string[] {typeof(msgcontains).Name, "message contains"};
}
static public bool performCheck(Message msg, string parameter) {
return msg.msg.Contains(parameter);
}
}
}

View file

@ -0,0 +1,4 @@
ADDR
NAME
PWD
DATABASE_NAME

View file

@ -29,6 +29,30 @@ if($_POST["changeConfig"]) {
} }
} }
function select() {
echo "selected='selected'";
}
if($_POST["updateNav"]) {
mysql_query("TRUNCATE `navigate`");
mysql_query("ALTER TABLE `navigate` AUTO_INCREMENT=1");
for($rowCount = 0;;$rowCount++) {
$r = $rowCount + 1;
if(!isset($_POST["r".($rowCount+1)."c1"])) break;
if($_POST['r'.$r.'c1'] == 0) {
if(substr($_POST['r'.$r.'c2'], 0, 4) != "http")
$_POST['r'.$r.'c2'] = "http://". $_POST['r'.$r.'c2'];
}
mysql_query("INSERT INTO `navigate` (`findtype`,`locator`,`action`,`parameter`)
VALUES (
". $_POST['r'.$r.'c1'] .",
'". mysql_real_escape_string(trim($_POST['r'.$r.'c2'])) ."',
'". $_POST['r'.$r.'c3'] ."',
'". mysql_real_escape_string(trim($_POST['r'.$r.'c4'])) ."'
)");
}
}
$rowCount = mysql_num_rows(mysql_query("SELECT * FROM `navigate`")); $rowCount = mysql_num_rows(mysql_query("SELECT * FROM `navigate`"));
include("header.php"); ?> include("header.php"); ?>
@ -67,24 +91,23 @@ include("header.php"); ?>
document.getElementById("navContainer").innerHTML = ""; document.getElementById("navContainer").innerHTML = "";
for(i = 0; i < tmp.length; i++) { for(i = 0; i < tmp.length; i++) {
if(tmp[i].getAttribute("id") != "r"+(i+1)) { tmp[i].setAttribute("id","r"+(i+1));
tmp[i].setAttribute("id","r"+(i+1)); tmp[i].innerHTML = (i+1) + tmp[i].innerHTML.substr(tmp[i].innerHTML.indexOf("."));
tmp[i].innerHTML = (i+1) + tmp[i].innerHTML.substr(tmp[i].innerHTML.indexOf(".")); var tmpc = tmp[i].children;
var tmpc = tmp[i].children; for(j = 0; j < 7; j++) {
for(j = 0; j < 4; j++) { tmpc[j].setAttribute("id","r"+(i+1)+"c"+(j+1));
tmpc[j].setAttribute("id","r"+(i+1)+"c"+(j+1)); tmpc[j].setAttribute("name","r"+(i+1)+"c"+(j+1));
tmpc[j].setAttribute("name","r"+(i+1)+"c"+(j+1)); if(j%2==0 && j < 4) {
if(j%2==0 && j < 4) { tmpc[j].selectedIndex = (j==0)?selectedValues[i*4]:selectedValues[i*4+2];
tmpc[j].selectedIndex = (j==0)?selectedValues[i*4]:selectedValues[i*4+2]; tmpc[j].setAttribute("onchange","handleColumnChange("+(i+1)+","+(j+1)+");");
tmpc[j].setAttribute("onchange","handleColumnChange("+(i+1)+","+(j+1)+");"); } else if(j < 4) {
} else if(j < 4) { tmpc[j].value = (j==1)?selectedValues[i*4+1]:selectedValues[i*4+3];
tmpc[j].value = (j==1)?selectedValues[i*4+1]:selectedValues[i*4+3]; } else if(j == 4) {
} else if(j == 4) tmpc[j].setAttribute("onclick","handleRowUp("+(i+1)+");");
tmpc[j].setAttribute("onchange","handleRowUp("+(i+1)+");"); } else if(j == 5) {
else if(j == 4) tmpc[j].setAttribute("onclick","handleRowDown("+(i+1)+");");
tmpc[j].setAttribute("onchange","handleRowDown("+(i+1)+");"); } else if(j == 6) {
else if(j == 4) tmpc[j].setAttribute("onclick","handleRowDelete("+(i+1)+");");
tmpc[j].setAttribute("onchange","handleRowDelete("+(i+1)+");");
} }
} }
document.getElementById("navContainer").appendChild(tmp[i]); document.getElementById("navContainer").appendChild(tmp[i]);
@ -93,19 +116,49 @@ include("header.php"); ?>
function handleRowUp(r) { function handleRowUp(r) {
if(r != 1) { if(r != 1) {
var data = Array();
var child = document.getElementById("r"+r); var child = document.getElementById("r"+r);
data[0] = child.children[0].selectedIndex; var clone = child.cloneNode(true);
data[0] = child.children[0].selectedIndex; clone.children[0].selectedIndex = child.children[0].selectedIndex;
data[0] = child.children[0].selectedIndex; clone.children[1].value = child.children[1].value;
data[0] = child.children[0].selectedIndex; clone.children[2].selectedIndex = child.children[2].selectedIndex;
var clone = child.cloneNode(); clone.children[3].value = child.children[3].value;
document.getElementById("navContainer").removeChild(); document.getElementById("navContainer").removeChild(child);
document.getElementById("navContainer").insertBefore(clone, document.getElementById("r"+(r-1)));
redrawTable();
} }
} }
function handleRowDown(r) {
if(r != rowCount) {
var child = document.getElementById("r"+r);
var clone = child.cloneNode(true);
clone.children[0].selectedIndex = child.children[0].selectedIndex;
clone.children[1].value = child.children[1].value;
clone.children[2].selectedIndex = child.children[2].selectedIndex;
clone.children[3].value = child.children[3].value;
document.getElementById("navContainer").removeChild(child);
document.getElementById("navContainer").insertBefore(clone, document.getElementById("r"+(r+2)));
redrawTable();
}
}
function handleRowDelete(r) {
rowCount--;
if(rowCount == 0) {
document.getElementById("navSubmit").style.display = "none";
document.getElementById("addSelect").remove(3);
document.getElementById("addSelect").remove(2);
document.getElementById("addPosition").style.display = "none";
}
var test = document.getElementById("navContainer").removeChild(document.getElementById("r"+r));
redrawTable();
populateRowDropdown();
}
function handleAddRow() { function handleAddRow() {
if(rowCount == 0) { if(rowCount == 0) {
document.getElementById("navSubmit").style.display = "block";
var element = document.createElement("option"); var element = document.createElement("option");
element.text = "after"; element.text = "after";
document.getElementById("addSelect").add(element); document.getElementById("addSelect").add(element);
@ -188,12 +241,12 @@ include("header.php"); ?>
UTC UTC
<select name="tzSign"> <select name="tzSign">
<option value="+">+</option> <option value="+">+</option>
<option value="-"<?php if(substr($config->timezone, 0, 1) == "-") { ?> selected="true"<?php } ?>>-</option> <option value="-"<?php if(substr($config->timezone, 0, 1) == "-") { ?> selected="selected"<?php } ?>>-</option>
</select> </select>
<input type="text" name="tzHour" maxlength="2" value="<?php echo substr($config->timezone, 1, 2); ?>" style="width:20px;" /> <input type="text" name="tzHour" maxlength="2" value="<?php echo substr($config->timezone, 1, 2); ?>" style="width:20px;" />
: :
<input type="text" name="tzMins" maxlength="2" value="<?php echo substr($config->timezone, 4); ?>" style="width:20px;" /> <input type="text" name="tzMins" maxlength="2" value="<?php echo substr($config->timezone, 4); ?>" style="width:20px;" />
<br /><abbr title="Daylight Savings Time?">DST?</abbr> <input type="checkbox" name="dst"<?php if($config->dst) { ?> checked="true"<?php } ?> /> <br /><abbr title="Daylight Savings Time?">DST?</abbr> <input type="checkbox" name="dst"<?php if($config->dst) { ?> checked="checked"<?php } ?> />
</td></tr> </td></tr>
<tr><td style="text-align: right;">Chat Username:</td><td><input type="text" name="username" value="<?php echo $config->username; ?>" /></td></tr> <tr><td style="text-align: right;">Chat Username:</td><td><input type="text" name="username" value="<?php echo $config->username; ?>" /></td></tr>
<tr><td style="text-align: right;">Bot Name:</td><td><input type="text" name="name" value="<?php echo $config->name; ?>" /></td></tr> <tr><td style="text-align: right;">Bot Name:</td><td><input type="text" name="name" value="<?php echo $config->name; ?>" /></td></tr>
@ -206,9 +259,37 @@ include("header.php"); ?>
<fieldset class="wide"> <fieldset class="wide">
<legend>Navigation Instructions</legend> <legend>Navigation Instructions</legend>
<p style="margin-top: 0;">In order for the bot to work, it needs to know how to both log into the website and get into the chat. The following is a user-defined method for the bot to perform this task.</p> <p style="margin-top: 0;">In order for the bot to work, it needs to know how to both log into the website and get into the chat. The following is a user-defined method for the bot to perform this task.</p>
<span id="navContainer"> <form method="post" action="">
<span id="navContainer">
</span> <?php
$q = mysql_query("SELECT * FROM `navigate`");
while($row = mysql_fetch_object($q)) { ?>
<p id="r<?php echo $row->id; ?>">
<?php echo $row->id; ?>.
<select name='r<?php echo $row->id; ?>c1' id='r<?php echo $row->id; ?>c1' onchange='handleColumnChange(<?php echo $row->id; ?>,1);'>
<option value='0' <?php if($row->findtype == 0) select(); ?>>Go to URL</option>
<option value='1' <?php if($row->findtype == 1) select(); ?>>Find element by link text</option>
<option value='2' <?php if($row->findtype == 2) select(); ?>>Find element by ID</option>
<option value='3' <?php if($row->findtype == 3) select(); ?>>Find element by name</option>
<option value='4' <?php if($row->findtype == 4) select(); ?>>Find element by class</option>
<option value='5' <?php if($row->findtype == 5) select(); ?>>Find element by tag name</option>
</select>
<input type='text' name='r<?php echo $row->id; ?>c2' id='r<?php echo $row->id; ?>c2' value="<?php echo $row->locator; ?>" />
<select name='r<?php echo $row->id; ?>c3' id='r<?php echo $row->id; ?>c3' onchange='handleColumnChange(<?php echo $row->id; ?>,3);' <?php if($row->findtype == 0) { ?>style='display: none;'<?php } ?>>
<option value='0' <?php if($row->action == 0) select(); ?>>and click it.</option>
<option value='1' <?php if($row->action == 1) select(); ?>>and type</option>
<option value='2' <?php if($row->action == 2) select(); ?>>and select the value</option>
<option value='3' <?php if($row->action == 3) select(); ?>>and select the index</option>
</select>
<input type='text' name='r<?php echo $row->id; ?>c4' id='r<?php echo $row->id; ?>c4' <?php if($row->findtype == 0 || $row->action == 0) { ?>style='display: none;'<?php } ?> value="<?php echo $row->parameter; ?>" />
<img src='img/arrow_up.png' class='fakelink' style='vertical-align: text-bottom;' onclick='' />
<img src='img/arrow_down.png' class='fakelink' style='vertical-align: text-bottom;' onclick='' />
<img src='img/delete.png' class='fakelink' style='vertical-align: text-bottom;' onclick='' />
</p>
<?php } ?>
</span>
<p id="navSubmit"<?php if($rowCount == 0) { ?> style="display: none;" <?php } ?>><input type="submit" value="Update Navigation" name="updateNav" /></p>
</form>
<p style="margin-bottom: 0">Add instruction <p style="margin-bottom: 0">Add instruction
<select id="addSelect" onchange="handleAddSelectChange();"> <select id="addSelect" onchange="handleAddSelectChange();">
<option selected="selected">at the end</option> <option selected="selected">at the end</option>
@ -234,5 +315,6 @@ include("header.php"); ?>
} }
} }
populateRowDropdown(); populateRowDropdown();
redrawTable();
</script> </script>
<?php include("footer.php"); ?> <?php include("footer.php"); ?>

View file

@ -18,6 +18,7 @@
<?php if($request == "config") { ?>Configuration<?php } else { ?><a href="config.php">Configuration</a><?php } ?> | <?php if($request == "config") { ?>Configuration<?php } else { ?><a href="config.php">Configuration</a><?php } ?> |
<?php if($request == "resp") { ?>Responses<?php } else { ?><a href="resp.php">Responses</a><?php } ?> | <?php if($request == "resp") { ?>Responses<?php } else { ?><a href="resp.php">Responses</a><?php } ?> |
<?php if($request == "auto") { ?>Autonomous<?php } else { ?><a href="auto.php">Autonomous</a><?php } ?> | <?php if($request == "auto") { ?>Autonomous<?php } else { ?><a href="auto.php">Autonomous</a><?php } ?> |
<?php if($request == "admin") { ?>Admin Access<?php } else { ?><a href="admin.php">Admin Access</a><?php } ?> |
<a href="jews.php">Logout</a> <a href="jews.php">Logout</a>
</h4> </h4>
</center> </center>

BIN
www/img/add.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 733 B

View file

@ -45,8 +45,17 @@ if($_GET["jew"] == "true")
echo " UTC". $config->timezone ."". (($config->dst)?" in accordance to daylight savings.":"disregarding daylight savings."); echo " UTC". $config->timezone ."". (($config->dst)?" in accordance to daylight savings.":"disregarding daylight savings.");
?> ?>
</fieldset> </fieldset>
<?php <br />
?> <fieldset class="wide">
<legend>Error Log</legend>
<a href="jews.php?do=cerrs">Clear Error List</a>
<?php
$q = mysql_query("SELECT * FROM `error` ORDER BY `id` DESC");
while($err = mysql_fetch_object($q)) {
echo "<p class='error'>". $err->time ." - ". $err->msg ."</p>";
}
?>
</fieldset>
</center> </center>
<?php include("footer.php"); ?> <?php include("footer.php"); ?>
<?php } ?> <?php } ?>

View file

@ -1,5 +1,15 @@
<?php <?php
session_start(); include("conn.php");
session_destroy();
header("Location: index.php"); if(!$_GET["do"]) {
session_start();
session_destroy();
header("Location: index.php");
} else {
if($_GET["do"] = "cerrs") {
mysql_query("TRUNCATE `error`");
mysql_query("ALTER TABLE `error` AUTO_INCREMENT=1");
header("Location: index.php");
}
}
?> ?>

129
www/resp.php Normal file
View file

@ -0,0 +1,129 @@
<?php include("conn.php");
include("header.php"); ?>
<script type="text/javascript">
function handleRespChange() {
document.getElementById("respDesc").innerHTML = document.getElementById(""+document.getElementById("resptype").selectedIndex).innerHTML;
}
function redrawList() {
var selectedValues = Array();
var tmpr = document.getElementById("ifholder").children;
var tmp = Array();
for(i = 0; i < tmpr.length; i++) {
selectedValues[i*4] = tmpr[i].children[0].selectedIndex;
selectedValues[i*4+1] = tmpr[i].children[1].selectedIndex;
selectedValues[i*4+2] = tmpr[i].children[2].value;
if(tmpr[i].children.length == 7)
selectedValues[i*4+3] = tmpr[i].children[3].selectedIndex;
else
selectedValues[i*4+3] = -1;
tmp[i] = tmpr[i].cloneNode(true);
}
document.getElementById("ifholder").innerHTML = "";
for(i = 0; i < tmp.length; i++) {
tmp[i].setAttribute("id","if"+(i+1));
var tmpc = tmp[i].children;
tmpc[0].name = "if"+ (i+1) +"group";
tmpc[0].selectedIndex = selectedValues[0];
tmpc[1].name = "if1"
document.getElementById("navContainer").appendChild(tmp[i]);
}
}
function addCondition() {
var cond = document.createElement("span");
cond.setAttribute("id","if1");
cond.setAttribute("class","block")
cond.innerHTML = '<select name="if1group">' +
'<?php for($i = 1; $i < 10; $i++) echo "<option value=\"$i\">$i</option>"; ?>' +
'</select>' +
' <select name="if1cond">' +
'<?php $q = mysql_query("SELECT * FROM `conditions`"); while($cond = mysql_fetch_object($q)) { echo "<option value=\"". $cond->id ."\">". $cond->friendlyname ."</option>"; } ?>' +
'</select>' +
' <input type="text" name="if1param" />' +
' <img src="img/arrow_up.png" class="fakelink" style="vertical-align: text-bottom;" onclick="handleRowUp(1);" />' +
' <img src="img/arrow_down.png" class="fakelink" style="vertical-align: text-bottom;" onclick="handleRowDown(1);" />' +
' <img src="img/delete.png" class="fakelink" style="vertical-align: text-bottom;" onclick="handleRowDelete(1);" />'
document.getElementById("ifholder").appendChild(cond);
//redrawList();
}
</script>
<center>
<fieldset class="wide" style="padding-bottom: 0;">
<?php if(!$_GET["do"]) { ?>
<legend>Response List</legend>
<p style="margin-top: 0;"><a href="resp.php?do=new">New Response</a></p>
<?php } else if($_GET["do"]=="new") { ?>
<legend>Create New Response</legend>
<p>
If
<span id="ifholder">
<span id="if1" class="block">
<select name="if1group">
<?php
for($i = 1; $i < 10; $i++)
echo "<option value=\"$i\">$i</option>";
?>
</select>
<select name="if1cond">
<?php
$q = mysql_query("SELECT * FROM `conditions`");
while($cond = mysql_fetch_object($q)) {
echo "<option value='". $cond->id ."'>". $cond->friendlyname ."</option>";
}
?>
</select>
<input type="text" name="if1param" />
<img src='img/arrow_up.png' class='fakelink' style='vertical-align: text-bottom;' onclick='handleRowUp(1);' />
<img src='img/arrow_down.png' class='fakelink' style='vertical-align: text-bottom;' onclick='handleRowDown(1);' />
<img src='img/delete.png' class='fakelink' style='vertical-align: text-bottom;' onclick='handleRowDelete(1);' />
</span>
</span>
<span class="block">
<a href="javascript:addCondition();">Add Condition</a>
</span>
</p>
<p>
then
<select name="resptype" id="resptype" onchange="handleRespChange();">
<?php
$q = mysql_query("SELECT * FROM `resptypes`");
$descarr = array();
for($i = 0;;$i++) {
$type = mysql_fetch_object($q);
if(!$type) break;
echo "<option value='". $type->id ."'>". $type->friendlyname ."</option>";
$descarr[$i] = $type->description;
}
?>
</select>
<?php
$i = 0;
foreach($descarr as $desc) {
echo "<p style='display:none;' id='$i'>". $desc ."</p>";
$i++;
}
?>
</p>
<p>
<span class="block" id="respDesc">
<?php echo $descarr[0]; ?>
</span>
<span class="block">Parameters:
<center>
<textarea name="parameters" rows="8" style="width:95%;"></textarea>
</center></span>
</p>
<p>
<input type="submit" name="addResponse" value="Add Response" />
&nbsp;&nbsp;&nbsp;&nbsp;
<input type="button" value="Cancel" onclick="window.location.href = 'resp.php';" />
</p>
<?php } else if($_GET["do"]=="edit") { ?>
<legend>Edit Response</legend>
<?php } ?>
</fieldset>
</center>
<?php include("footer.php"); ?>

View file

@ -24,4 +24,14 @@ body {
.fakelink:hover { .fakelink:hover {
cursor: pointer; cursor: pointer;
}
.error {
/*font-weight: bold;*/
}
.block {
display: block;
margin-top: 10px;
margin-bottom: 10px;
} }