JavaScript - Executing Commands On A Linux Box Via Javascript
I have been using Perl code for about 15 years and I develop/support Perl code used by engineers who run this code in Linux terminals. The code uses Tk as the user interface, which in turn executes Perl scripts.
We are looking into the possibility of putting the user interface in a web browser, which would (somehow) still run the same scripts on a Linux box. I can write a Perl script that, given a Linux machine name, user name and password, can open a connection to that machine and execute anything on that machine. My question: Can this sort of thing be done via a web page? This is posted in the JS forum because JS seems like it would provide the tools to create the type of interactive user interface I require. (I don't know a thing about JS, at the moment I'm trying to decide which language to use to implement my s/w, but first I need to determine if the language can do what I need.) Similar Tutorialsvar action = method+'sometexthere' submit eval('action') Hi, Here is something i was digging up but i stop after 3 hours of interpreting the code... (The code is inaccurate) What i was trying to get was load up a page and pass a javascript example: 1) load www.mysite.com 2) pass javascript using javascript: The problem that i'm facing is +action+ isn't define after the page was load up and i can't seem to validate by passing vars into the browser. example: javascript:document.write('<script>var desc = 10; var offx = 10; var offy = 10</script>') I'm a bit vague here, i will post more info later... Code: function displayResult() { var damn = document.getElementById("textyar").value; document.getElementById("oneforty").innerHTML = damn; var newDIV = document.createElement('div'); newDIV.className = "tweets"; var newspan =document.createElement('span'); newspan.className = "imagespanleft"; var img = document.createElement("IMG"); img.className="image"; img.src = "tweets/me.jpg"; newDIV.innerHTML = document.getElementById('textyar').value; document.getElementById('leftmaindiv').appendChild(newDIV).appendChild(newspan).appendChild(img); } this is the code , i m trying to create an interface like twitter where u put in text box and tweet appears below in problem is it is creating two divs instead of one , i tried insertbefore() as well but same behaviour plz ask any questions if u r still not clear i have this line in my code: PHP Code: echo '<a href="" onClick="yesnolist()">Free Chat</a>'; then at the top i have: Code: <? php //have some php here ?> <div class="innerContainer"> <head> <script type="text/JavaScript"> function yesnolist(val) { alert("lakjsd"); var e = confirm('Do you want to send a free chat request?'); if (e == true) { window.location.href = "http://www-rainbowcode-mobi/confirmfreechat.php"; window.location('http://www-rainbowcode-mobi/confirmfreechat.php'); return true; } else return false; } </script> </head> <span class="headings2">CONTACTS</span> //and more code after this echo '<a href="" onClick="yesnolist()">Free Chat</a>'; why is it not doing my onClick()?? please help? thanks Hi, I am new to programming and I am trying to write a code that will time how long it takes for you to write a word. First you input the word you would like to write, and than after you have pressed enter I want the program to "feel" when you start writing the word, at that point the timer should start. And then it shall know when you have completed the word and in that moment stop the timer. I have a built a timer that works fine, see startCounter() but i want it to be executed as i described above... This is the code: Code: <div> <div class="inputBox"> <input id="textBox" type="text" placeholder=" What word would you like to time?" onKeydown="Javascript: if (event.keyCode==13) hello();"> <input type="button" value="RushWrite" id="Btn" onclick="hello()"></input> <script> function hello() { if (textBox.value != "") { var wordInput = document.getElementById("textBox").value; document.getElementById("textBox").placeholder=" Let's RushWrite: "+wordInput; textBox.value = ""; document.getElementById("Btn").value="GoGo!"; document.getElementById("time").innerHTML="00.00"; }; } </script> <button id="time" type="text"></button> <script> function startCounter(){ var counter = 0; setInterval(function () { ++counter; document.getElementById("time").innerHTML=(counter); }, 1000); }; </script> <script> </script> </div> </div> Thankful for any advise! I'm attempting to run a small piece of code that will execute one of two source js files on my server. I have no problem creating the proper DOM script object with the proper type and conditional src value. However, when i add it to the document it does not seem to execute. I've tried adding it in two places, both using .appendChild(); myLocation.parentNode.appendChild(newScript); and document.getElementsByTagName("head")[0].appendChild(newScript); (myLocation is a calculated element representing the current script tag) In both these cases, the script tag is added to the document where I intended, but it does not appear to execute. The src has some doc writes in it and the tags the new script should generate right after itself are not there, as they are when I hard code the new sourced script tag into the document. All in all, my confusion comes from the fact that when I write a <script ... src="mysrc.js"></script> into my document, it behaves differently than when I have a script write an identical tag into the document in the same location. Also, fyi, I'm currently using Chrome (though I will require a multi-platform solution). Thanks for your time. I am doing a project in which I have to automatically download a file from a secured website by providing a username and password for which I am using "Selenium" with "Python 3.4.1" in Windows 7 x86_64 environment. The website is written using "JavaScript". And I don't have any practical working knowledge of JavaScript. I know Java but not JavaScript. So far, I have done this in Python: Code: from selenium import webdriver from selenium.webdriver.common.keys import Keys driver = webdriver.Firefox() driver.get("http://www.website_name.com") element_user_name = driver.find_element_by_id("userid") element_user_name.send_keys("user_name") element_passwd = driver.find_element_by_id("password") element_passwd.send_keys("some_passwd") elem = driver.find_element_by_id("submit") elem.send_keys(Keys.RETURN) After this code snippet, I am successfully directed to the home screen of the website. But now, I hit the snag. The source code of the website contains JavaScript functions which do not contain the code of the elements on the page which I want to manipulate. The main page contains code for user authentication, invalidate client and the likes of it. But when I right click on an element on the Home page, I get to see their source codes in a separate window (in Firefox 32). The source code of the element which I want to use "Favorites and Dashboards": Code: <!DOCTYPE html> <html id="ext-gen3" class=" ext-strict x-viewport" decorator="blank" webdriver="true"> <head></head> <body id="ext-gen4" class="ext-gecko3 cwc-view x-border-layout-ct" onload="cwc.getFrameworkWindow()"> <div id="cwc_header" class=" masthead x-border-panel" style="left: 0px; top: 0px; width: 1366px; height: 27px;"></div> <div id="cwcNavPanel" class=" x-panel cwc-navPanel x-border-panel" style="width: 220px; left: 0px; top: 56px;"> <div id="ext-gen17" class="x-panel-bwrap"> <div id="ext-gen18" class="x-panel-tbar x-panel-tbar-noheader" style="width: 220px;"></div> <div id="ext-gen19" class="x-panel-body x-panel-body-noheader" style="width: 220px; height: 323px;"> <div id="cwcAccordionNav" class=" x-panel x-panel-noborder" style="width: 218px;"> <div id="ext-gen48" class="x-panel-bwrap"> <div id="ext-gen49" class="x-panel-body x-panel-body-noheader x-panel-body-noborder" style="overflow: auto; width: 218px; height: 321px;" role="navigation"> <div id="ROOT/Favorites and Dashboards" class="x-panel x-panel-noborder x-tree" style="width: auto;"> <div id="ext-gen76" class="x-panel-header x-panel-header-noborder x-unselectable x-accordion-hd" style="cursor: pointer;" tabindex="0" role="tab" aria-expanded="true"></div> <div id="ext-gen77" class="x-panel-bwrap" style="display: block; visibility: visible; position: static; left: 0px; top: 0px; z-index: auto;"> <div id="ext-gen78" class="x-panel-body x-panel-body-noborder" style="width: auto; height: auto;"> <ul id="ext-gen79" class="x-tree-root-ct x-tree-arrows" role="group"> <div class="x-tree-root-node"> <li class="x-tree-node"></li> <li class="x-tree-node"></li> <li class="x-tree-node"></li> <li class="x-tree-node"></li> <li class="x-tree-node"></li> <li class="x-tree-node"></li> <li id="ext-gen447" class="x-tree-node"> <div id="ROOT/Favorites and Dashboards/6" class="x-tree-node-el x-unselectable x-tree-node-collapsed" unselectable="on" ext:tree-node-id="ROOT/Favorites and Dashboards/6"> <span class="x-tree-node-indent"></span> <img id="ext-gen94" class="x-tree-ec-icon x-tree-elbow-plus" src="/sm/default/s.gif" alt=""></img> <img class="x-tree-node-icon cwc-tree-noIcon-node" unselectable="on" src="/sm/default/s.gif" alt=""></img> <a id="ext-gen95" class="x-tree-node-anchor" tabindex="0" href="" role="treeitem" hidefocus="on" aria-expanded="false"> In this snippet, I want to click on "Favorites and Dashboards". How do I do it? Thanks for your help! Is it possible to merge the following? Code: document.getElementById("dimensionstext").style.color = "silver"; document.getElementById("dimensionstext").style.cursor = "pointer"; So, perhaps something like: Code: document.getElementById("dimensionstext").style.color = "silver"; style.cursor = "pointer"; what is the best way to count the seconds between each onkeyup to "autosave" without sending an ajax command after each key? id like my script to update after 2 seconds of no typing.... (yes, jquery is in use on the page) Code: function microtime (get_as_float) { var now = new Date().getTime() / 1000; var s = parseInt(now, 10); return (get_as_float) ? now : (Math.round((now - s) * 1000) / 1000) + ' ' + s; } var lastKeyUp=0; function saveChange(id,field,value){ thismicrotime=microtime(true); if(lastKeyUp == 0 || (thismicrotime-lastKeyUp) >= 2000000){ $.get("saveChange.php", { 'field': field, 'value': value, 'id': id }, function(data){ lastKeyUp=thismicrotime; }, 'xml' ); } } Code: <input type="text" name="field1" onkeyup="saveChange('2','field1',this.value);" /> i'd use onchange or onblur but that requires you to unfocus the field before it saves... I have a form that was created in Adobe Professional. I have hidden the toolbars on initial view of the form, however, the people using the form have discovered how to un-hide them. Is there any Java Script that I can add to the document that will disable certain menu commands (i.e. "Attach to E-mail")?
I am trying to create a simple auto-calculate function for a webpage. What should be happening: The 'onchange' command should pass the 'price' of the item to the function, the function should then cycle through all the dropdowns (or checkboxes or fields) and calculate the total. What is happening: It is only picking up the last checkbox. It seems that the 'for' loop only remembers the last item in the array. What am I doing wrong? How can I get the code to remember all the items? thanks, Code: <script language="JavaScript" type="text/javascript"> function calculateTotal(price) { var total = 0; var cList = ['sel1','sel2','sel3']; for (i=0;i<2;i++); var select = GetE(cList[i]); total+= price * (select.options[select.selectedIndex].value); GetE("totalShow").innerHTML = total.toFixed(2); } function GetE(id) {return document.getElementById(id); } </script> <html> <head></head><body> <form id="form1" name="form1" method="post" action=""> <select name="sel1" id="sel1" onchange="calculateTotal(100)"> <option value="0">0</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> </select><br><br> <select name="sel2" id="sel2" onchange="calculateTotal(200)"> <option value="0">0</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> </select><br><br> <select name="sel3" id="sel3" onchange="calculateTotal(300)"> <option value="0">0</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> </select><br><br> </form> <br>total <span id="totalShow">0.00</span> </body></html> i have this line: Code: echo $new_mail_cnt = '<script type="text/javascript">getMessages();</script>'; then have: Code: <script language="JavaScript" type="text/javascript"> var receiveReq = getXmlHttpRequestObject(); var mTimer; function getXmlHttpRequestObject() { if (window.XMLHttpRequest) { return new XMLHttpRequest(); } else if(window.ActiveXObject) { return new ActiveXObject("Microsoft.XMLHTTP"); } else { document.getElementById('p_status').innerHTML = 'Status: Cound not create XmlHttpRequest Object.' + 'Consider upgrading your browser.'; } } function getMessages() { receiveReq = getXmlHttpRequestObject(); if (receiveReq.readyState == 4 || receiveReq.readyState == 0) { receiveReq.open("POST", 'getMessage.php', true); receiveReq.onreadystatechange = handleReceiveMessage(); receiveReq.send(null); document.getElementById('new_messages').innerHTML = receiveReq.responseXML; //not sure here } mTimer = setTimeout('getMessage();',2000); } function handleReceiveMessage() { if (receiveReq.readyState == 4) { var chat_div = document.getElementById('div_chat'); var xmldoc = receiveReq.responseXML; var message_nodes = xmldoc.getElementsByTagName("message"); } } </script> all i need to do is update/refresh $new_mail_cnt so user can see when new messages come in, but getMessages() does not execute because no alerts pop up??? i dont understand please help? thank you i have this code: Code: if (($has_freechat1['confirmed'] == 1) && ($has_freechat2['confirmed'] == 1)) { $was_clicked = 0; ?> <a href="freechatcontacts.php?id=<?php echo $id_to.$was_clicked; ?>" class="charcoal_link" style="line-height: 20px;" name="message" id="message" onClick="return send('<?php echo $was_clicked;?> return false;')"> <?php echo $uniqueCode1?><span class="pink_text"><?php echo $uniqueCode2?></span><?php echo $uniqueCode3?> </a> <?php if ($was_clicked == 1) { ?> <tr> <td><input name="password" type="textarea" rows="10" cols="20" value="<?php echo $aCleanPost['message']['value']?>" /></td> </tr> <tr> <td><br /><input name="cmdSubmit" type="submit" value="Send" /><br/> </td> </tr> <?php } } then i have my JS:; and this is not executing because even though i clicked on my link, $was_clicked stays 0???? Code: <script type="text/JavaScript"> function send(val) { val = 1; //was clicked return val; } window.reload(); </script> what am i doing wrong please help? thank you See the code below, the alert is displayed when the page is loaded. It should only display when the image is moused over... Code: <script type="text/javascript"> addEvent(document.getElementById('snake'), "mouseover", fadeByid(this)); //This function attaches events to elements. function addEvent( elm, evt, fun ) { if ( elm.addEventListener ) { elm.addEventListener( evt, fun, false ); } else if ( elm.attachEvent ) { elm.attachEvent( 'on' + evt, fun ); } else { elm [ 'on' + evt ] = fun; } }; //Image fade, for the main front navigation function fadeByid(objId) { alert("wtf"); if (document.getElementById) { obj = document.getElementById(objId); opacity = obj.style.opacity; alert(opacity); if (opacity >= 100) { setOpacity(obj, opacity); opacity -= 10; window.setTimeout("fadeByid('"+objID+"','"+opacity+")", 100); } } } What's wrong with it? :/ Hi there! I set up a variable that should replace HTML code when run but it doesn't seem to be doing that... Here it is: Code: var finale = "document.getElementById(" + theid + ").innerHTML='test';"; eval("finale"); Any idea why? (My console isn't showing any issues) Thanks! Matt I have a secure server that I want users to be able to execute sinple .cmd files by clicking in a button on a web form. I am very new to this and kindly ask for some guidance. When I click on the button I get a error on page at the bottom of the window and the file the .cmd should create is not. Here is what I have so far: <HTML><HEAD><SCRIPT type="text/javascript" LANGUAGE="JavaScript"> function run(file) { var ws = new ActiveXObject("WScript.Shell"); ws.run(file); }</SCRIPT></HEAD> <BODY> <FORM name="Form1"><CENTER> <BR><img src="../icons/HelpDesk_logo.png" alt="OIT Support and Operations" height="100" Width="525"/> <BR> <H1>Reset Reader MGR in CS Gold </H1> <BR>This site is to be used only when all the readers contained in a single MGR have gone offline. Confirm this by using the Gold Reader Status screen.<BR><BR> <B> DO NOT USE THIS IF ALL READERS ARE OFFLINE. CALL PSIG STAFF ASAP!</B><BR><BR> Please select the appropriate MGR to bounce from the list below.<BR> Once you click the correct button please verify that the readers are now online using the Gold Reader Status screen.. If the readers do not come back online contact the AIS PSIG representative.<BR><BR> <B>ONLY CKICK THE BUTTON ONCE</B> <BR> <BR> <Input type="Button" name="Bounce Aero MGR" value="Bounce Aero MGR" onClick="run('D:\bounce_mgrs\BounceMGR2200-Aero.cmd')"/> <BR><BR> <Input type="Button" name="Bounce Copier MGR" value="Bounce Copier MGR" onClick="run('D:\bounce_mgrs\BounceMGR2400-Aero.cmd')"/> <BR><BR> <Input type="Button" name="Bounce Micros_Default MGR" value="Bounce Micros_Default MGR" onClick="run('D:\bounce_mgrs\BounceMGR2600-Aero.cmd')"/> <BR><BR> <Input type="Button" name="Bounce Micros_A MGR" value="Bounce Micros_A MGR" onClick="run('D:\bounce_mgrs\BounceMGR2800-Aero.cmd')"/> <BR><BR> <Input type="Button" name="Bounce Micros_B MGR" value="Bounce Micros_Bo MGR" onClick="run('D:\bounce_mgrs\BounceMGR3000-Aero.cmd')"/> <BR><BR> <Input type="Button" name="Bounce XML MGR" value="Bounce XML MGR" onClick="run('D:\bounce_mgrs\BounceMGR3400-Aero.cmd')"/> <BR><BR> <Input type="Button" name="Bounce Vending MGR" value="Bounce Vending MGR" onClick="run('D:\bounce_mgrs\BounceMGR3600-Aero.cmd')"/> </CENTER> </BODY> </FORM> </HTML> Thank you. Hi all, I'm a beginner in javascript so, i was trying to execute a single simple .js file that should retrieve a value from a sql server db and display it in a popup window like the following: var Statement = "SELECT coalesce(TotalWork,0) AS TotalWork FROM dual as x left outer join (SELECT 1 as Y,CONVERT(INT, SUM(MSP_TimesheetActual.ActualWorkBillable)) AS TotalWork FROM MSP_EpmResource LEFT OUTER JOIN MSP_TimesheetResource INNER JOIN MSP_TimesheetActual ON MSP_TimesheetResource.ResourceNameUID = MSP_TimesheetActual.LastChangedResourceNameUID ON MSP_EpmResource.ResourceUID = MSP_TimesheetResource.ResourceUID LEFT OUTER JOIN MSP_TimesheetPeriod INNER JOIN MSP_Timesheet ON MSP_TimesheetPeriod.PeriodUID = MSP_Timesheet.PeriodUID ON MSP_TimesheetResource.ResourceNameUID = MSP_Timesheet.OwnerResourceNameUID WHERE (MSP_EpmResource.ResourceNTAccount = 'INTERCOM\%username%') AND (MSP_TimesheetActual.TimeByDay BETWEEN MSP_TimesheetPeriod.StartDate AND MSP_TimesheetPeriod.EndDate) GROUP BY MSP_TimesheetPeriod.StartDate, MSP_TimesheetPeriod.EndDate HAVING (MSP_TimesheetPeriod.StartDate <= DATEADD(d, - 7, GETDATE())) AND (MSP_TimesheetPeriod.EndDate >= DATEADD(d, - 7, GETDATE()))) as y on x.x=y.Y"; var Connection = new ActiveXObject('ADODB.Connection'); var Recordset = new ActiveXObject('ADODB.Recordset'); var Shell = new ActiveXObject('WScript.Shell'); Connection.Open('Data Source={servername};Initial Catalog={database name};User ID={username};Password={password};Provider=SQLOLEDB'); Recordset.Open(Statement, Connection); Recordset.MoveFirst(); while (!Recordset.EOF) { Shell.Popup(Recordset('TotalWork'), 0, 'Message', 48); Recordset.MoveNext(); } Recordset.Close(); Connection.Close(); but for some reasons it returns 0 and while i'm trying to run the query on sql server it returns the correct value does anybody have an idea about where the error may be ?? thanks in advance Hello, I have stack of images arrange one behind another, when ever i click on them current image should flip down, image is flipping down but its parent container is staying at same position. Due to that i am not able to perform action on other images. i have chosen the option of providing lesser z index value to parent element so that it will not cause problem to perform event on other images. But still it is not working. I am able to add z index value but when running the code both flipping and adding z index to parent is executing at one time. Due to that animation is not coming in a right way. i want to know, How i can execute code one after another, example when flipping image is completed then only i want to add z index value to parent element (f1_container) SO that it will not cause problem for other images. Please help <div id="f1_container" class="f1_container"> <div id="f1_card" class="shadow"> <div class="front face"> <img src="img/8.jpg"/> </div> <div class="back face center"> <img src="img/1.jpg"/> </div> </div> </div> var flipImage=document.querySelectorAll('.shadow'); for(j=0; j<flipImage.length; j++){ var currentFlipImage=flipImage[j]; currentFlipImage.addEventListener('click', function(event){ var currentElement=event.currentTarget; //this should be executed first currentElement.style.webkitTransform='rotateX(-120deg)'; and this one should execute after flipping is completely done this.parentNode.style.zIndex=-100; },false); } hi. i'm using this script to replace text on a page loaded into another frame, called 'booker'. the script works when i use it on the same page, but i can't seem to get it to reference the other frame for some reason. it executed with 'body OnLoad' any ideas for what i'm doing wrong? thanks. Code: function myscript() { input = 'Membership'; output='Service Fee'; top.booker.document.body.innerHTML = top.booker.document.body.innerHTML.replace(input,output); I have three buttons on my form. The user has to be logged in for the buttons to do anything. Is it possible to get an alert to popup on the form page without the form action occuring? If so, how do I go about it?
Hey. I'm working on a simple slideshow made with jQuery, and i need some help now. What i'm trying to do now, is to make it change image every X second. I know how to change image, but i'm kind of stuck trying to find out how to make it "do something" every Xth second... i hope you understand what i mean. Here's an example: (obviously not working..) Code: function slideSwitch() { //change image... } setInterval(slideSwitch, 5000); //make the function slideSwitch execute every 5th second. If anyone could help me out here, i'd really appreciate it! Also, is there any "else if" function in jQuery? Like in for example PHP, you can use "if", "else if" and "else".. like this: Code: if(){ }else if(){ }else { } So is there any function like that? I googled it, and i found out i have to use some kind of plugin for it to work? How do i use it? Thanks in advance, -Nike |