Cisco room kit macro - Javascript - javascript

This may be a long shot asking here, but I've been tasked with creating a macro for a Cisco room kit.
I have very limited knowledge in JavaScript but can understand simple concepts.
The macro needs to auto connect the video input instead of having to tap share on the controller.
This is what I have so far:
const xapi = require('xapi');
const value = 'AutoShare';
//function value('OnConnect')
xapi.config.set('Video Input Connector 2 PresentationSelection', value);
This performs no action.
I'm using the api reference guide here:
https://www.cisco.com/c/dam/en/us/td/docs/telepresence/endpoint/ce915/collaboration-endpoint-software-api-reference-guide-ce915.pdf
This is the relevant section
And the limited information in the macro tutorial:
macro configuration
But I can't really make sense of formatting or where I'm going wrong / other relevant JavaScript I'm leaving out.
If anybody has any idea to point me in the right track, I'd greatly appreciate it.

Related

How to select text in an Outlook mail using the office.js API

I am implementing a Webapp that helps users to find alternatives for specific words.
One way people can access this data should be via Office AddIns (using Office.js) that select critical words on button press, let the users choose an alternative (provided by the API of my Webapp), and replaces the content within the selection upon a second button press. Think of it as a custom spell checker/ mini Grammarly for a specific purpose.
So the first thing is, I need to select a certain text area/range within the document/mail (bacically simulating Ctrl-F). Sadly I haven't found this specific API-call within the documentation for Outlook AddIns. Only Body.getAsync and Body.setAsync but if possible at all, I don't want to replace the whole text.
FYI: The same is easily doable for MS Word via :
Word.run(function (context) {
const ranges = context.document.body.search('office.js is stupid')
const range = ranges.getFirst()
range.select()
const alternative = 'office.js is awesome' //Faked user interaction
range.insertHtml(alternative, 'Replace')
})
What would be the equivalent for Outlook?
FYI: I have checked multiple sources but I was most disappointed that I didn't find the answer here: https://learn.microsoft.com/en-us/javascript/api/outlook/office.body?view=outlook-js-preview
Also, I take it as a bad sign that Grammarly doesn't provide an Outlook Addin in the Microsoft AppSource O365 Store.
Edit: Well, not looking good.
Edit 2: Maybe not so important, but does someone know why there is no:
window.Outlook.run(async context =>{
//[...]
await context.sync()
}
)
This is not possible today. We track Outlook add-in feature requests on our user-voice page.
It looks like the feature you want has been requested by others already. Please upvote the existing request. Feature requests on user-voice are considered when we go through our planning process.

Run local JavaScript functions from Python 3

So, I'm teaching myself various AI techniques, and I figured the best way to do so would be to create my own Python bot which can play the game Pokemon using an online open-source Pokemon simulator.
The issue is that this simulator has all its source code written in JavaScript, whereas my bot uses Python. At first, I solved the problem of grabbing the full list of valid Pokemon and such by simply downloading the server's .js files, which (handily) contained all valid Pokemon/moves as JSON objects that I could easily import into Python. This was all well and good when I just needed Pokemon names and such, but now that I'm building out the actual engine I've discovered that it uses these same JSON files for its actual gameplay code.
For example, here's the Pokemon "Ability" Aftermath. Pay attention to onAfterDamage:
"aftermath": {
desc: "If this Pokemon is knocked out with a contact move, that move's user loses 1/4 of its maximum HP, rounded down. If any active Pokemon has the Damp Ability, this effect is prevented.",
shortDesc: "If this Pokemon is KOed with a contact move, that move's user loses 1/4 its max HP.",
id: "aftermath",
name: "Aftermath",
onAfterDamageOrder: 1,
onAfterDamage: function (damage, target, source, move) {
if (source && source !== target && move && move.flags['contact'] && !target.hp) {
this.damage(source.maxhp / 4, source, target);
}
},
rating: 2.5,
num: 106,
}
As you can see, onAfterDamage is a JavaScript function, one that I can't easily call from Python (to my knowledge). So now I'm at a crossroads:
Stop grabbing the .js files from the server and write my own code entirely in Python, essentially "translating" the JavaScript code myself.
Rewrite my entire bot in JavaScript instead of Python, although I'm far less experienced and comfortable in JavaScript.
Find a way to run the JavaScript code I'm downloading from the server from within my Python bot, calling arbitrary functions from within the code and returning the results.
Option 1 has the issue of rapidly becoming out of date -- when new Pokemon mechanics are introduced or new Pokemon are created, I wouldn't get it "for free" -- I'd have to figure out what changed and implement the changes myself.
I'd like to avoid Option 2 just because I'm not very comfortable writing JavaScript -- it's something I've dabbled with in the past, but it's far from my favorite language and not something I want to deal with when it's not the primary focus of my project.
I realize that Option 3 is a pretty massive security risk -- while I'm reasonably sure that a man-in-the-middle attack won't happen to a bot that likely nobody will ever use but myself, I'm still just downloading random JavaScript from a server somewhere and trying to execute it.
I've seen things like PyExecJS, but they're no longer maintained, and I haven't really seen anyone recommending a good replacement for them. PyExecJS's functionality is exactly what I'm looking for (namely the function execjs.eval(js_code)), but I'm not sure I want to use something that's reached EOL. I've seen the answers here, but they don't recommend any replacements for PyExecJS; they only show that user that they're using it wrong.
I've also seen people suggest Selenium or running a headless browser, but I'm not sure if I want to deal with all that extra overhead. The very first programming project I ever did outside of school was very similar to this, and I wound up coding it in Java using Selenium. I wasn't happy with that experience, and I'm not looking forward to having to do it again, especially when I only need to execute JavaScript I already have downloaded locally.
Am I completely off-base here? Is there another approach I should take, or should I just get to work translating all this JS code to Python by hand?
Ideally you could run your .js-file from cli just like any other executable. With node -e you can execute your JavaScript code on cli.
Relating to this post https://stackoverflow.com/a/450329/6478277 you could similarly run your script with your local node.
node -e "function func(){console.log(123)};func();"
From a file
print subprocess.check_output(['node -e "require(\"./file.js\").test()"'])
Where file.js could be something like
module.exports = {
test: () => console.log(123),
}

Zapier Python or Javascript Code for Twitter HTML

I'm using Zapier to run a search on Twitter, create a daily digest of results (Zapier Digest), and send the digest to a mailing list (Mailgun). I seek to format the Tweets similar to Twitter's own emails where the tweet isn't text but HTML where any user mention (#name, corresponding URL is https://twitter.com/[NAME]) and URL in the tweet are actual links. (I don't want the conversion for any hashtags.)
This search, extract, and replace (with added HTML) isn't that hard. But it's too much for Zapier's simple Formatter text functions. So I turned to the Zapier Code action, thinking I could borrow code as I'm not a hardcore coder.
I found Python code as below (and others at that site). After a couple hours of testing I've given up on being able to successfully adapt it for use in Zapier Code. Zapier has limitations on how it uses Python. Their documentation on it is primitive.
Could someone here familiar with Zapier help me with converting that (or similar) code so I could run it on Zapier Python or Javascript? I truly would appreciate it.
Thank you,
Marc
https://coderwall.com/p/wdtkhw/convert-links-username-mentions-and-hashtags-in-a-tweet
function twitterify($ret) {
$ret = preg_replace("#(^|[\n ])([\w]+?://[\w]+[^ \"\n\r\t< ]*)#", "\\1\\2", $ret);
$ret = preg_replace("#(^|[\n ])((www|ftp)\.[^ \"\t\n\r< ]*)#", "\\1\\2", $ret);
$ret = preg_replace("/#(\w+)/", "#\\1", $ret);
$ret = preg_replace("/#(\w+)/", "#\\1", $ret);
return $ret;
}
David here, from the Zapier Platform team.
Marc, your main problem is that you're using a PHP snippet in our Python interpreter, which is probably why it's giving you trouble. If you have specific questions or there's something we can improve about our documentation, definitely let me know!
I'd check out the python re.sub() function instead. There's a great answer about it here. You'll also want to be able test your regex, for which there's a great site (as there are some sleight differences between PHP and Python regex. There's also a great language resource here if you want to learn more about the Python language.
​Let me know if you've got any other questions!
David,
Regarding documentation, the help page is oriented to someone who has Python or Javascript experience. I don't. The following would help.
In-code commenting. For the most part, the help just says here's what an example does and shows the code. It doesn't explain what each line of code does.
The help virtually skips to advanced examples, such as comma
separated lists. More basic examples would provide firmer ground
for newbies like me.
I continued testing and came up with the following code for Zapier Python, based on the snippet above. While it executed without error (progress!), it made no change to the #user or URL in the input data test tweet.
Marc
import re
tweetHTML = re.sub('/#(\w+)/', '#\\1', input_data ['tweet'])
tweetHTML = re.sub('#(^|[\n ])([\w]+?://[\w]+[^ \"\n\r\t< ]*)#', '\\1\\2', tweetHTML)
tweetHTML = re.sub('#(^|[\n ])((www|ftp)\.[^ \"\t\n\r< ]*)#', '\\1\\2', tweetHTML)
return {'tweetHTML': tweetHTML}

Run exe file with jQuery or JavaScript

I want to know if there is a way to open a exe file from client side with jQuery or JavaScript.
I tried with windows.open("..") but it didn't work.
First off, Dalorzo is correct - you cannot escape the sandbox of a browser without earning lots of money. Recently Pinky Pie won over $60k from Google for performing such a task on Google Chrome.
http://blog.chromium.org/2012/05/tale-of-two-pwnies-part-1.html
However, sometimes I ask questions to try to find out-of-the-box solutions, so I'm assuming that you have a legitimate use-case for this question. I can help you think of a "hack" solution if you have a legitimate use for this. I'll probably get downvoted to oblivion for this response, but theoretically you could do this...
Back in college, I took a computer forensics class in which I wrote a chat web application which would forensically clean a user's computer from having ever accessed the chat webpage. This was done through the user running an executable they could download from the site. However, I wanted to have the users to not have to run the executable every time so I wanted a sandbox escape like you're asking about.
It's messy, but if your users are a participating party they can modify their computer to allow executables to be run from Chrome webpages.
Please Note: This will make your computer less secure, I only ever did it on Virtual Machines or Lab Machines. Reconsider whether you actually wanna try this or not.
Step One: Create a Chrome custom browser:
This is the python that I eventually compiled to a packed *.exe that accomplished creating a Google Chrome custom browser.
import sqlite3 as lite
con = lite.connect('C:\Users\USERNAME\AppData\Local\Google\Chrome\User Data\Default\Web Data')
c = con.cursor()
#idmax = c.execute('SELECT MAX(id) FROM keywords')
#c.execute("INSERT INTO keywords VALUES('cleanupeverybodyeverywhere','cleanupeverybodyeverywhere','','forensichat://C:>Windows>System32>calc.exe',0,'',0,0,'',0,'',0,0,'',0,'','','','','','','','','')")
c.execute("SELECT * FROM keywords WHERE short_name='cleanupeverybodyeverywhere'")
foo = c.fetchall()
if foo == []:
c.execute("INSERT INTO keywords (short_name,keyword,url,favicon_url) VALUES ('cleanupeverybodyeverywhere','cleanupeverybodyeverywhere','forensichat://C:>Windows>System32>calc.exe','')")
con.commit()
con.close()
Note that now when I open a Chrome tab and use the custom browser cleanupeverybodyeverywhere to run the key forensichat and it will open calc.exe as proof of concept.
Step Two: Modify your Windows Registry:
import _winreg as wreg
import getpass
user = getpass.getuser()
key = wreg.CreateKey(wreg.HKEY_CLASSES_ROOT, '')
wreg.SetValue(key,'forensichat',wreg.REG_SZ,'URL:forensichat Protocol')
# Create new subkey
kkey = wreg.CreateKey(wreg.HKEY_CLASSES_ROOT, 'forensichat')
wreg.SetValueEx(kkey, 'URL Protocol', 0, wreg.REG_SZ,'')
# Create new value
wreg.CreateKey(wreg.HKEY_CLASSES_ROOT,"forensichat\shell")
nkey = wreg.CreateKey(wreg.HKEY_CLASSES_ROOT,"forensichat\shell\open")
wreg.SetValue(nkey,"command",wreg.REG_SZ,'C:\Users\\'+user+'\Downloads\\forensicleaner.exe')
key.Close()
Note that I'm creating a key called forensichat which will run the exe found in the user's Downloads folder.
Of course, I ended up cleaning this all up and packing it so Anti-Virus wouldn't flag it, next thing I know Google Chrome has marked the site lol. It's still up if you wanna check it out - check Secure Chat and Repeat Customer. Chrome will flag it, but there's obviously ways around that.

SAPUI5 Logout Event with Javascript

I am currently working on a SAP XS application. Using the provided API, I want to log off my user on the website. Im totally new on Javascript to please dont mind the probable ease of my question.
The API (https://sapui5.hana.ondemand.com/sdk/docs/api/symbols/sap.ui.commons.ApplicationHeader.html#event:logoff) provides the method "fireLogoff". But before that I have to add "attachLogoff" to the applicationheader in my application right?
My faulty method looks like this:
oAppHeader.attachLogoff(function logout(oEvent) {this.fireLogOff();});
Thank you a lot for helping a noob in this matter.
fireLogOff calls a function assigned to logOff. So you need to write your own code for SAP HANA API that makes user to log off. Or you can just close browser tab:
oAppHeader.attachLogoff(function(){window.close();});

Categories