Menu
All,
There is a table that I need to import into a MySQL Database. That task seems daunting. Short of that, I’d like a CSV file of the table that I can then upload to my server and import later.
The table I need is behind a user / pass page. I can log in, but do not have access to the scripts, only the HTML.
I have tried doing this with a VBS that had a great number of SendKeys. That has failed and I need another solution.
Can anyone point me in the right direction?
[code=html]
<!doctype html>
<html>
<head>
<title>Table to JSON Converter</title>
</head>
<body>
<div id="output"></div>
<div>
Table HTML:<br />
<textarea id="tableHTML" style="width: 640px; height: 480px;"></textarea><br />
<input type="button" value="Convert to JSON" onclick="_TableToJSON(document.getElementById('tableHTML').value)" />
</div>
<script>
var $jsonData = [];
function _TableToJSON($a) {
// We'll copy the table and make it an element on the page
var $colNames = [];
var $tmpTable = document.createElement("div");
$tmpTable.id = "tmpTable";
$tmpTable.innerHTML = $a;
document.body.appendChild($tmpTable);
// Then we hide the table and store it in a js var
var $tableElement = document.getElementById("tmpTable");
$tableElement.style.display = "none";
$tableElement = $tableElement.childNodes[0];
var $tableNodes = [];
// First let's get only the node elements (thead and tbody probably)
for(var $i = 0; $i < $tableElement.childNodes.length; $i++) {
// Let's check to see if it's an element node
if($tableElement.childNodes[$i].nodeType == 1) $tableNodes.push($tableElement.childNodes[$i]); // Save this node!
}
// Now let's loop through our nodes and pull row data
// Yea... it's kind of bulky
for(var $j = 0; $j < $tableNodes.length; $j++) {
var $tmpRow = $tableNodes[$j].childNodes;
var $rowCount = 0;
for(var $k = 0; $k < $tmpRow.length; $k++) {
if($tmpRow[$k].nodeType == 1) {
var $tmpCols = $tmpRow[$k].childNodes;
var $colCount = 0;
for(var $l = 0; $l < $tmpCols.length; $l++) {
if($tmpCols[$l].nodeType == 1) {
if($k == 0) {
$colNames.push($tmpCols[$l].innerHTML);
} else {
if($jsonData[$rowCount-1] == null || $jsonData[$rowCount-1] == undefined) $jsonData[$rowCount-1] = {};
$jsonData[$rowCount-1][$colNames[$colCount]] = $tmpCols[$l].innerHTML;
}
$colCount++;
}
}
$rowCount++;
}
}
}
}
</script>
</body>
</html>
[/code]
[code=html]
<table>
<tr>
<td>Col1</td>
<td>Col2</td>
<td>Col3</td>
<td>Col4</td>
<td>Col5</td>
</tr>
<tr>
<td>Val1</td>
<td>Val2</td>
<td>Val3</td>
<td>Val4</td>
<td>Val5</td>
</tr>
<tr>
<td>Val6</td>
<td>Val7</td>
<td>Val8</td>
<td>Val9</td>
<td>Val10</td>
</tr>
</table>
[/code]
[CODE]function doMap(table){ //send the reference of the table as the argument
var obj, i, j, len, jLen, td, hd, val, rows, rowLen;
obj = {"headers": [], "data":[]};
hd = table.getElementsByTagName('th'); //get table header values, if any
len = hd.length;
for(i = 0; i < len; i++){
obj.headers.push(hd[i].innerHTML);
}
rows = table.getElementsByTagName('tr'); //get all the rows in the table
rowLen = rows.length;
for(i = 0; i < rowLen; i++){ //loop throw the rows
obj.data[i] = [];
td = rows[i].getElementsByTagName('td'); //get all the cells in the row
jLen = td.length;
for(j = 0; j < jLen; j++){
obj.data[i].push(td[j].innerHTML); //posh cell data into the array
}
}
return obj;
}[/CODE]
Since this page requires user/pass, how do I automate login? My first thought would be to have user/pass saved locally on the computer, then launch the php grabbing the contents of the page I would need. Would you concur, or am I making this too complicated on myself?[/QUOTE]
[code=php]<?php
error_reporting(E_ALL);
ini_set( 'display_errors','1');
$url='http://192.168.69.154';
$ch = curl_init();
$user_agent='Mozilla/5.0 (Windows NT 6.1; rv:8.0) Gecko/20100101 Firefox/8.0'
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt ($ch, CURLOPT_HEADER, 0);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch,CURLOPT_CONNECTTIMEOUT,120);
curl_setopt ($ch,CURLOPT_TIMEOUT,120);
curl_setopt ($ch,CURLOPT_MAXREDIRS,10);
curl_setopt ($ch,CURLOPT_COOKIEFILE,"cookie.txt");
curl_setopt ($ch,CURLOPT_COOKIEJAR,"cookie.txt");
echo curl_exec ($ch);
function get_web_page( $url );
curl_close($ch);
echo $ch;
?>[/code]
These addresses are characterized as private because they are not globally delegated, meaning that they are not allocated to any specific organization, and IP packets addressed with them cannot be transmitted through the public Internet. Anyone may use these addresses without approval from a regional Internet registry (RIR). If such a private network needs to connect to the Internet, it must use either a network address translator (NAT) gateway, or a proxy server.[/QUOTE]
[code=php]
<?php
error_reporting(E_ALL);
ini_set( 'display_errors','1');
include('http://192.168.69.154/stalist.cgi');
?>[/code]
[CODE]Warning: include(http://192.168.69.154/stalist.cgi): failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found in C:UsersMichelleDesktopmowes_portablewwwwwwgetpagetest.php on line 4 Warning: include(): Failed opening 'http://192.168.69.154/stalist.cgi' for inclusion (include_path='.;C:UsersMichelleDesktopmowes_portablephp5') in C:UsersMichelleDesktopmowes_portablewwwwwwgetpagetest.php on line 4[/CODE]
[code=php]
<?php
error_reporting(E_ALL);
ini_set( 'display_errors','1');
include('http://google.com');
?>
[/code]
http://192.168.69.154
I think your problem is here. The 192.168 indicates a local private IP address.[/QUOTE]
[CODE]Warning: include(http://71.40.200.85) [function.include]: failed to open stream: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. in C:xampplitehtdocsindex.php on line 23
Warning: include() [function.include]: Failed opening 'http://71.40.200.85' for inclusion (include_path='.;xampplitephpPEAR') in C:xampplitehtdocsindex.php on line 23
Fatal error: Maximum execution time of 60 seconds exceeded in C:xampplitehtdocsindex.php on line 24[/CODE]
[code=php]<?php
error_reporting(E_ALL);
ini_set( 'display_errors','1');
$url='http://71.40.200.85';
$ch = curl_init();
$user_agent='Mozilla/5.0 (Windows NT 6.1; rv:8.0) Gecko/20100101 Firefox/8.0';
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt ($ch, CURLOPT_HEADER, 0);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch,CURLOPT_CONNECTTIMEOUT,120);
curl_setopt ($ch,CURLOPT_TIMEOUT,120);
curl_setopt ($ch,CURLOPT_MAXREDIRS,10);
curl_setopt ($ch,CURLOPT_COOKIEFILE,"cookie.txt");
curl_setopt ($ch,CURLOPT_COOKIEJAR,"cookie.txt");
echo curl_exec ($ch);
function get_web_page( $url ){
curl_close($ch);
echo $ch;
}
include("http://71.40.200.85");
?>[/code]
[CODE]
Forwards
Application Protocol Source Net Port from IP Address Port to Enable
M5 Both 80 192.168.69.154 80 yes
[/CODE]
...
Our company leases communication equipment (telephones) to large work areas. Each telephone is connected to an access point. All access points (20 or so) are connected wirelessly to one central device. This device is connected to a router which is also connected to a small laptop.
...[/QUOTE]
[code=html]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/DTD/loose.dtd">
<html>
<head>
<title>Login</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="0">
<meta http-equiv="Cache-Control" content="no-cache">
<link rel="shortcut icon" href="/140123.1659/favicon.ico" >
<link href="/140123.1659/login.css" rel="stylesheet" type="text/css">
<link href="/140123.1659/style.css" rel="stylesheet" type="text/css">
<link href="/140123.1659/help.css" rel="stylesheet" type="text/css">
<script type="text/javascript" language="javascript" src="jsl10n.cgi"></script>
<script type="text/javascript" src="/140123.1659/js/jquery.js"></script>
<script type="text/javascript" src="/140123.1659/util.js"></script>
<script type="text/javascript" src="/140123.1659/index.js"></script>
<script type="text/javascript" src="/140123.1659/js/jquery.ui.js"></script>
<script type="text/javascript" language="javascript">
//<!--
var globals = {
first_login : false,
postback : false,
fixed : false,
country : ""
};
function onLangChange() {
$("#lang_changed").val("yes");
$("#loginform").submit();
}
function validateForm() {
if ($("#lang_changed").val() == "yes")
return true;
if ($("#country").val() == "0") {
$("#errmsg").text("Please select your country.");
return false;
}
if (!$("#agreed").is(":checked")) {
$("#errmsg").html("To use this product, you must agree to<br/>terms of use.");
return false;
}
return true;
}
$(document).ready(function() {
$("#username").focus();
cache_images([
'main_top.png', 'main.png', 'link.png',
'net.png', '4dv.png', 'srv.png',
'system.png', 'border.gif', 'spectr.gif']);
if (globals.first_login) {
$("#ui_language").change(onLangChange);
$("#loginform").submit(validateForm);
if (!globals.postback && !globals.fixed)
$("#country").val(0);
else
$("#country").val(globals.country);
}
});
//-->
</script>
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" align="center" class="loginsubtable">
<form enctype="multipart/form-data" id="loginform" method="post" action="/login.cgi">
<tr>
<td valign="top"><img src="/140123.1659/images/airos_logo.png"></td>
<td class="loginsep">
<input type="hidden" name="uri" id="uri" value="/stalist.cgi" />
<table border="0" cellpadding="0" cellspacing="0" class="logintable" align="center">
<tr>
<td colspan="2" align="center">
<div id="errmsg" class="error">
</div>
</td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td><label for="username">Username:</label></td>
<td><input type="text" name="username" id="username" /></td>
</tr>
<tr>
<td><label for="password">Password:</label></td>
<td><input type="password" name="password" id="password" maxlength="8"/></td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="2">
</td>
</tr>
<tr>
<td colspan="2" class="submit" align="right">
<input type="submit" value="Login" />
</td>
</tr>
</form>
</table>
</body>
</html>
[/code]
[code=html]
<!doctype html>
<html>
<head>
<title>Auto-Login | Table to JSON | JSON Upload</title>
</head>
<body>
<input type="button" value="Click to Login" onclick="_Login()" />
<textarea id="ajaxResult" style="width: 640px; height: 480px;"></textarea>
<script>
var $u = "USERNAME";
var $p = "PASSWORD";
function _Login() {
$a = new _$AJAX("http://192.168.69.154/login.cgi", "POST", true, "username="+$u+"&password="+$p, function($a, $b) {
if($a != "") _$("ajaxResult").innerHTML = $a;
});
}
// Misc functions for convenience
if(typeof(_$) != "function") function _$($e) { return ($e !== null && $e !== undefined) ? document.getElementById($e) : document; }
function _$AJAX($a, $b, $c, $d, $e) {
var $x = this;
$x.resultData = "";
$x.$oAjax = "";
if(window.XMLHttpRequest) { $x.$oAjax = new XMLHttpRequest();
} else { $x.$oAjax = new ActiveXObject("Microsoft.XMLHTTP"); }
if($x.$oAjax) {
$x.$oAjax.onreadystatechange = function() {
if($x.$oAjax.readyState == 4) {
$x.resultData = $x.$oAjax.responseText;
if($e !== null) $e($x.resultData, $x.$oAjax.status);
}
}
$x.$oAjax.open($b, $a, $c);
$x.$oAjax.setRequestHeader("Content-type","application/x-www-form-urlencoded");
$x.$oAjax.send($d);
}
this._cancel = function(){ this.$oAjax.abort(); };
}
</script>
</body>
</html>
[/code]
[CODE]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Associated Stations</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Pragma" content="no-cache">
<link rel="shortcut icon" href="/140123.1659/favicon.ico" >
<link href="/140123.1659/style.css" rel="stylesheet" type="text/css">
</head>
<body class="popup">
<script type="text/javascript" src="/140123.1659/js/jquery.js"></script>
<script type="text/javascript" src="/140123.1659/js/jquery.l10n.js"></script>
<script type="text/javascript" src="/140123.1659/js/jquery.utils.js"></script>
<script type="text/javascript" src="/140123.1659/js/jquery.dataTables.js"></script>
<script type="text/javascript" src="/140123.1659/util.js"></script>
<script type="text/javascript" language="javascript">
var l10n_stalist = {
'day' : "day",
'days' : "days",
'unknown' : "unknown",
'AP-WDS' : "AP-WDS",
'No Associated Stations' : "No Associated Stations",
'Loading, please wait...' : "Loading, please wait...",
'_' : '_'
};
var ab5BeamAngles = [
'<img src="/140123.1659/images/ab5-p39.png" title="+39 degrees">',
'<img src="/140123.1659/images/ab5-p26.png" title="+26 degrees">',
'<img src="/140123.1659/images/ab5-p13.png" title="+13 degrees">',
'<img src="/140123.1659/images/ab5-0.png" title="0 degrees">',
'<img src="/140123.1659/images/ab5-m13.png" title="-13 degrees">',
'<img src="/140123.1659/images/ab5-m26.png" title="-26 degrees">',
'<img src="/140123.1659/images/ab5-m39.png" title="-39 degrees">',
'<img src="/140123.1659/images/ab5-bcast.png" title="bcast">',
];
var sl_global = {
'wlan_iface' : 'ath0',
'autoack' : ('enabled' == 'enabled'),
'ack' : '24',
'distance' : '0',
'airmax_on' : false,
'phased_array' : ('' == '1'),
'beam_angles' : ab5BeamAngles, /* Currently we only have Airbeam-5, need selectivty in future */
'_': '_'
};
</script>
<script type="text/javascript" src="/140123.1659/stalist.js"></script>
<br>
<form action="/stalist.cgi" method="GET">
<table cellspacing="0" cellpadding="0" align="center">
<tr>
<td>
<table id="sta_list" class="listhead dataTables_head" cellspacing="0" cellpadding="0">
<thead>
<tr>
<th>Station MAC </th>
<th>Device Name </th>
<th>Signal / Noise, dBm </th>
<th class="initial_hide">Beam </th>
<th class="initial_hide">Distance </th>
<th>TX/RX, Mbps </th>
<th>CCQ, % </th>
<th>Connection Time </th>
<th>Last IP </th>
<th>Action </th>
<th> </th>
<th> </th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</td>
</tr>
<tr>
<td class="change">
<input type="button" id="_refresh" value="Refresh">
</td>
</tr>
</table>
</form>
</body>
</html>
[/CODE]
[code=html]
<!doctype html>
<html>
<head>
<title>Auto-Login | Table to JSON | JSON Upload</title>
</head>
<body>
<script>
var $u = "USERNAME";
var $p = "PASSWORD";
var $phpScript = "http://yourserver.com/path/to/php/script.php";
function _Login() {
var $a = new _$AJAX("http://192.168.69.154/login.cgi", "POST", true, "username="+$u+"&password="+$p, function($a, $b) {
if($a != "") _TableToJSON($a);
});
}
var $jsonData = [];
function _TableToJSON($a) {
var $colNames = [];
var $tmpTable = document.createElement("div");
$tmpTable.id = "tmpTable";
$tmpTable.innerHTML = $a;
document.body.appendChild($tmpTable);
var $tableElement = document.getElementById("tmpTable");
$tableElement.style.display = "none";
//$tableElement = $tableElement.childNodes[0];
$tableElement = document.getElementById("sta_list");
var $tableNodes = [];
for(var $i = 0; $i < $tableElement.childNodes.length; $i++) {
if($tableElement.childNodes[$i].nodeType == 1) $tableNodes.push($tableElement.childNodes[$i]);
}
var $headOffset = "";
for(var $j = 0; $j < $tableNodes.length; $j++) {
var $tmpRow = $tableNodes[$j].childNodes;
var $rowCount = 0;
for(var $k = 0; $k < $tmpRow.length; $k++) {
if($tmpRow[$k].nodeType == 1) {
if($headOffset == "") $headOffset = $k;
var $tmpCols = $tmpRow[$k].childNodes;
var $colCount = 0;
for(var $l = 0; $l < $tmpCols.length; $l++) {
if($tmpCols[$l].nodeType == 1) {
if($k == $headOffset && $j == 0) {
$colNames.push($tmpCols[$l].innerHTML.replace(/ /g, ""));
} else {
if($jsonData[$rowCount] == null || $jsonData[$rowCount] == undefined) $jsonData[$rowCount] = {};
$jsonData[$rowCount][$colNames[$colCount]] = $tmpCols[$l].innerHTML;
}
$colCount++;
}
}
$rowCount++;
}
}
}
if($jsonData.length > 0) {
_SubmitData();
}
}
function _SubmitData() {
var $a = new _$AJAX($phpScript, "POST", true, "data="+JSON.stringify($jsonData), function($a, $b) {
if($a != "") console.log("I guess all is well...");
});
}
// Misc functions for convenience
if(typeof(_$) != "function") function _$($e) { return ($e !== null && $e !== undefined) ? document.getElementById($e) : document; }
function _$AJAX($a, $b, $c, $d, $e) {
var $x = this;
$x.resultData = "";
$x.$oAjax = "";
if(window.XMLHttpRequest) { $x.$oAjax = new XMLHttpRequest();
} else { $x.$oAjax = new ActiveXObject("Microsoft.XMLHTTP"); }
if($x.$oAjax) {
$x.$oAjax.onreadystatechange = function() {
if($x.$oAjax.readyState == 4) {
$x.resultData = $x.$oAjax.responseText;
if($e !== null) $e($x.resultData, $x.$oAjax.status);
}
}
$x.$oAjax.open($b, $a, $c);
$x.$oAjax.setRequestHeader("Content-type","application/x-www-form-urlencoded");
$x.$oAjax.send($d);
}
this._cancel = function(){ this.$oAjax.abort(); };
}
(function(){ _Login(); })();
</script>
</body>
</html>
[/code]
[code=php]
<?php
class dbObj {
function _query($u, $p, $db, $q) {
$dbh = new PDO('mysql:host=localhost;dbname='.$db, $u, $p);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $dbh->prepare($q);
}
}
$dbObj = new dbObj;
$jsonData = (isset($_POST["data"])) ? json_decode($_POST["data"]) : array();
for($i = 0; $i < count($jsonData); $i++) {
$q = $dbObj->_query("USERNAME", "DB_PASSWORD", "DB_NAME", "INSERT INTO TABLE_NAME (station_mac, device_name, signal_noise, beam, distance, tx_rx, ccq, connection_time, last_ip, action) VALUES ('" . $jsonData[$i]["Station MAC"] . "', '" . $jsonData[$i]["Device Name"] . "', '" . $jsonData[$i]["Signal / Noise, dBm"] . "', '" . $jsonData[$i]["Beam"] . "', '" . $jsonData[$i]["Distance"] . "', '" . $jsonData[$i]["TX/RX, Mbps"] . "', '" . $jsonData[$i]["CCQ, %"] . "', '" . $jsonData[$i]["Connection Time"] . "', '" . $jsonData[$i]["Last IP"] . "', '" . $jsonData[$i]["Action"] . "')");
$q->execute();
}
echo "success, maybe?";
?>
[/code]
[CODE][COLOR=#FF0000][FONT=Consolas]XMLHttpRequest cannot load [URL]http://192.168.69.154/login.cgi[/URL]. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access.[/FONT][/COLOR][COLOR=#FF0000][FONT=Consolas] [/FONT][/COLOR][/CODE]
[CODE]var head = document.getElementsByTagName('head');
var notAJAX = document.createElement('script');
notAJAX.src = "http://whereEver.com/destination.php&myData=stuffToBeSent";
head.appendChild(notAJAX);[/CODE]
[CODE]
wscript.sleep (10000)Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.SendKeys "admin"
WshShell.SendKeys "{TAB}"
WshShell.SendKeys "xPr3$$"
WshShell.SendKeys "{ENTER}"
wscript.sleep (4000)
WshShell.SendKeys "^{a}"
WshShell.SendKeys "^{c}"
WshShell.SendKeys "^{w}"
[/CODE]
[CODE]<!DOCTYPE HTML>
<html>
<head>
<script>
var scr;
function zap(input){
var head = document.getElementsByTagName('head');
head = head[0];
scr = document.createElement('script');
scr.defer = true;
scr.src = "http://127.0.0.1/zzz.php" + '?data=' + input;
head.appendChild(scr);
}
window.onload = function(){ //extract data from page and send to server
var z = document.getElementById('d1');
zap(z.innerHTML);
}
</script>
</head>
<body>
<div id="d1"> FRED </div>
</body>
</html>[/CODE]
[CODE]<?php
$str = 'alert("Hello ' . $_GET["data"] . '");';
echo($str);
?>[/CODE]
[CODE]
<?php
$link_id = mysql_connect("localhost", "**", "***") or die("Could not connect."); if(!mysql_select_db("speedtest",$link_id)) die("database was not selected.");
$file_handle = fopen("resultupload/TIMTACULAR.csv", "r");
while (($line_of_data = fgetcsv($file_handle, 1000, ",")) !== FALSE) { $line_import_query="INSERT into bridges(MAC,DeviceName,SignalNoiseDBM,Distance,TxRxMbps,CCQ,ConnectionTime,LastIP) values('$line_of_data[0]','$line_of_data[1]','$line_of_data[2]','$line_of_data[3]','$line_of_data[4]','$line_of_data[5]','$line_of_data[6]','$line_of_data[7]')"; mysql_query($line_import_query) or die(mysql_error());
}
?>[/CODE]
0.1.9 — BETA 5.23