I created this method to create a text file as log for a page that has different buttons that call functions with parameters from different textfields:
function WriteToFile(data) {
var currentdate = new Date();
var datetime = "Time: " + currentdate.getDate() + "/" + (currentdate.getMonth()+1) + "/" + currentdate.getFullYear() + " # " + currentdate.getHours() + ":" + currentdate.getMinutes() + ":" + currentdate.getSeconds();
var fso = new ActiveXObject("Scripting.FileSystemObject");
var a = fso.OpenTextFile("C:\\logs\\log.txt", 8);
a.WriteLine(datetime);
a.WriteLine(data + "\n");
a.Close();
}
And it works perfectly fine when I'm using the C: drive. Unfonrtunately, this is to be used in production in a Z: drive so other people can use the page as well. When I copy it to the Z: drive and change this line:
var a = fso.OpenTextFile("C:\\logs\\log.txt", 8);
to the following:
var a = fso.OpenTextFile("Z:\\logs\\log.txt", 8);
it gives me an error saying:
Automation server can't create object
I am using IE8. Any ideas on what I'm doing wrong and how I can fix this?
Related
It works fine when document is opened in Acrobat, but does not work properly when the same PDF document is opened in web browser such as Google Chrome. this.closeDoc() is not getting executed in the Browser.
string path2 = #"D:\test\input.pdf";
string output = #"D:\test\output.pdf";
if (File.Exists(path2))
{
iText.Kernel.Pdf.PdfWriter writer = new iText.Kernel.Pdf.PdfWriter(output);
iText.Kernel.Pdf.PdfDocument pdfDocument = new iText.Kernel.Pdf.PdfDocument(new iText.Kernel.Pdf.PdfReader(path2) ,writer);
pdfDocument.AddNewPage();
String js = "var rightNow = new Date();"
+ "var endDate = new Date('2017-07-13');"
+ "if(rightNow.getTime() > endDate){"
+ "app.alert('This Document has expired, please contact us for a new one.',1);"
+ "this.closeDoc();}"
+ "else{}";
pdfDocument.GetCatalog().SetOpenAction(iText.Kernel.Pdf.Action.PdfAction.CreateJavaScript(js));
pdfDocument.Close();
}
Are you try "window.close()" ?
String js = "var rightNow = new Date();"
+ "var endDate = new Date('2017-07-13');"
+ "if(rightNow.getTime() > endDate){"
+ " app.alert('This Document has expired, please contact us for a new one.',1);"
+ " this.closeDoc(); "
+ " if(window){ window.close(); } "
+ "}"
+ "else{}";
I need to send HTTP request to AWS with signed request via Javascript. Sadly I cannot use the AWS SDK JS as its either for Node.js or browser, but I need to run it from Rhino JS environment.
seems I am doing something very wrong as I get whatever I do same result - AWS was not able to validate the provided access credentials.
:(
The code I am using is same as the one Amazons is using as example (but in Python). I am using only one external lib so I can use HMCA &SHA.
Any help is much appreciated (and needed as I am struggling for days by now...), so yeah - help!
Thanks is advance!
Cheers,
Joro
gs.include('jshashes');
var method = 'GET';
var service = 'ec2';
var host = 'ec2.amazonaws.com';
var region = 'us-east-1';
var endpoint = 'https://ec2.amazonaws.com';
var access_key = 'ACCESSKEY';
var secret_key = 'SECRET/KEY';
var request_parameters = 'AWSAccessKeyId' + access_key + 'Action=RunInstances&&ImageId=ami-b770fbd8';
function getSignatureKey(key, date, region, service){
var newKey = "AWS4" + key;
var kDate = new Hashes.SHA256().b64_hmac(newKey, date);
var kRegion = new Hashes.SHA256().b64_hmac(kDate, region);
var kService = new Hashes.SHA256().b64_hmac(kRegion, service);
var kSigning = new Hashes.SHA256().b64_hmac(kService, "aws4_request");
return kSigning;
}
var gdt = new GlideDateTime();
var datestamp = gdt.getDate().getByFormat('yyyyMMdd') + 'T' +
gdt.getTime().getByFormat('HHmmss') + 'Z';
var amzdate = gdt.getDate().getByFormat('yyyyMMdd')+"";
var canonical_uri = '/';
var canonical_querystring = request_parameters;
var canonical_headers = 'host:' + host + '\n' + 'x-amz-date:' + amzdate + '\n'
var signed_headers = 'host;x-amz-date';
var payload_hash = new Hashes.SHA256().hex("");
var canonical_request = method + '\n' + canonical_uri + '\n' + canonical_querystring + '\n' + canonical_headers + '\n' + signed_headers + '\n' + payload_hash;
var algorithm = 'AWS4-HMAC-SHA256';
var credential_scope = datestamp + '/' + region + '/' + service + '/' + 'aws4_request';
var string_to_sign = algorithm + '\n' + amzdate + '\n' + credential_scope + '\n' + new Hashes.SHA256().hex(canonical_request);
var signing_key = getSignatureKey(secret_key, datestamp, region, service);
//Python
//var signature = hmac.new(signing_key, (string_to_sign).encode('utf-8'), hashlib.sha256).hexdigest()
var signature = new Hashes.SHA256().hex_hmac(signing_key, string_to_sign);
var authorization_header = algorithm + ' ' + 'Credential=' + access_key + '/' + credential_scope + ', ' + 'SignedHeaders=' + signed_headers + ', ' + 'Signature=' + signature
var headers = {'x-amz-date':amzdate, 'Authorization':authorization_header}
var request_url = endpoint + '?' + canonical_querystring
var httpRequest = new GlideHTTPRequest(request_url);
httpRequest.setRequestHeader(headers);
var res = httpRequest.get();
gs.print(res.statusCode);
gs.print(res.allHeaders);
gs.print(res.body);
Check the URL construction. For one, the request_parameters have some missing and misplaced delimiters.
var request_parameters = 'AWSAccessKeyId=' + access_key +
'&Action=RunInstances&ImageId=ami-b770fbd8';
In addition to inspecting and testing the resulting URL, you might also try to simply the syntax to make it easier to check and update. Just as an example, the following
var credential_scope = datestamp + '/' + region + '/' + service + '/' + 'aws4_request';
var string_to_sign = algorithm + '\n' + amzdate + '\n' + credential_scope + '\n' + new Hashes.SHA256().hex(canonical_request);
could be written as follows (which seems easier to check to me):
var credential_scope = [
datestamp,
region,
service,
'aws4_request'
].join('/');
var string_to_sign = [
algorithm,
amzdate,
credential_scope,
new Hashes.SHA256().hex(canonical_request)
].join('\n');
I am having a problem when attempting to echo data in a php file to mobile Safari in iOS 7.1.2. Here is the php code:
function swapFlights()
{
var url;
redirect = 1;
airline = <?php echo 'PDT'; ?>;
url = "swap.php?date_one=" + date1 + "&flight_number_one=" + flight1 + "&dep_station_one=" + city1 + "&date_two=" + date2 + "&flight_number_two=" + flight2 + "&dep_station_two=" + city2 + "&redirect=" + redirect + "&airline=" + airline;
window.location.href = url;
}
In mobile Safari on iPhone 5S, the output is the following:
function swapFlights()
{
var url;
redirect = 1;
airline =
2cc1
PDT;
url = "swap.php?date_one=" + date1 + "&flight_number_one=" + flight1 + "&dep_station_one=" + city1 + "&date_two=" + date2 + "&flight_number_two=" + flight2 + "&dep_station_two=" + city2 + "&redirect=" + redirect + "&airline=" + airline;
window.location.href = url;
}
The seemingly random "2cc1" is interjected, and I cannot for the life of me figure out why. It causes a SyntaxError in the parsing of the JavaScript, rendering all of the JavaScript on the page unusable. In every other browser I've tried (desktop Safari, Firefox), the code is output correctly as one would expect:
function swapFlights()
{
var url;
redirect = 1;
airline = PDT;
url = "swap.php?date_one=" + date1 + "&flight_number_one=" + flight1 + "&dep_station_one=" + city1 + "&date_two=" + date2 + "&flight_number_two=" + flight2 + "&dep_station_two=" + city2 + "&redirect=" + redirect + "&airline=" + airline;
window.location.href = url;
}
Any ideas, or is this more likely a bug in mobile Safari itself? I've searched all over the internet, but can't seem to find any other instances of this problem.
Changing the php to:
redirect = 1;
<?php echo 'airline = PDT'; ?>;
results in the unknown characters being slightly different, and appearing earlier in the output:
redirect = 1;
2ccb
airline = PDT;
I should have specified that my goal is the replace the 'PDT' with the string variable $airline. I changed the variable to the literal 'PDT' thinking I may have had a problem with the datatype of the variable, but that wasn't the case.
I have a JavaScript code to get new time. But when i reload the page the time doesn't change instead it says 1/10/2014 10:57, how can i add a function for the time and date to detect and change
Below is the code I tried but its not working.
<script type="text/javascript">
(function () {
// using current UTC time from server as ref, display local time in div id="now"
var now = new Date();
now.setTime(1389322677492);
var nowstr = ""
+ (now.getMonth() + 1) + "/"
+ now.getDate() + "/"
+ ((now.getYear() < 1000) ? now.getYear() + 1900 : now.getYear()) + " "
+ now.getHours() + ":"
+ ((now.getMinutes() < 10) ? '0' + now.getMinutes() : now.getMinutes());
var el = document.getElementById("now");
el.appendChild(document.createTextNode(nowstr));
})();
</script>
Thanks for helping me.
Thats because you are explicitly setting it to 1389322677492 everytime. All you need to do is remove the line:
now.setTime(1389322677492);
For some reason this script won't work. I'm using express, socket.io, jade and node.js.
Here is the script:
var socket = io.connect();
function addMessage(msg)
{
var currentDate = new Date();
var dateTime = currentDate.getDate() + "/" +
(currentDate.getMonth() + 1) + "/" +
currentDate.getFullYear() + "#"
currentDate.getHours() + ":" +
currentDate.getMinutes() + ":" +
currentDate.getSeconds();
$("#historyView").append("<p>" + dateTime + " - " + msg + "</p>");
}
function sentMessage()
{
if ($("#arduinoInput").val() != "")
{
socket.emit("message", $("#arduinoInput").val());
addMessage($('#arduinoInput').val(), new Date().toISOString(), true);
$("#arduinoInput").val("");
}
}
socket.on("message", function(message){
addMessage(message);
});
$document.ready(function(){
$("#submit").click(function(){
sentMessage();
});
});
It doesn't even clear the text box. Here is the jade page:
doctype 5
html
head
title Arduino Controller 2
script(src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js")
script(src="/socket.io/socket.io.js");
script(src="script.js")
link(rel="stylesheet" type="text/css" href="style.css")
body
div.container
header
h1 Arduino Controller 2
center
div#historyView
input(type="text")#arduinoInput
button#submit Send
I've been trying to debug this for awhile. I'm running this on Mac OS X 10.9 if that helps.
Assuming you don't have any other code, this would be incorrect:
$document.ready();
It is likely you meant to attach a ready handler to the document, which should look like this:
$(document).ready();