[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Serverside Javascript

Posted on 2012-03-28
13
Medium Priority
?
217 Views
Last Modified: 2012-10-19
I've been working with javascript for a long time now and one thing I'd always disliked is the inability to be able to hide the code so you can protect your intellectual property when deploying scripts to a customer. The application framework I work within uses serverside javascript as it's scripting language. The framework is a web based application. When certain events occur in the framework such as a record update, insert or delete, I can add additional code into these steps to make other things happen similar to triggers in SQL. However, these additional functions that I can add are scripts written in javascript that run directly on the same server as the framework and as scripts they are easily readable. Obviously if I have created a component I don't necessarily want my customers, or potentially competitors, wanting to be able to see the code and use it. So, I'd like to be able to embed these functions in a code library or DLL. Any suggestions?

Thanks.
0
Comment
Question by:Lee Savidge
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 3
  • 2
  • +1
13 Comments
 
LVL 20

Expert Comment

by:BuggyCoder
ID: 37775916
there are loads of obfuscators available that makes it harder to read your code,  but there is nothing till date that hides your code:-

here is a link:-
http://www.javascriptobfuscator.com/

see these discussions as well:-
http://stackoverflow.com/questions/1660060/how-to-prevent-your-javascript-code-from-being-stolen-copied-and-viewed
0
 
LVL 7

Expert Comment

by:designatedinitializer
ID: 37775928
JavaScript runs on the browser, and you know it.
There are only 2 ways to run JavaScript into the browser:
1. One, is running it like we've all been doing. You can obfuscate it, but if it's readable by the browser it's also readable by the user.
2. The other, is by developing a browser plugin that users will need to install in their browsers.
That's been done before. There used to be these guys from a company named "Futuresplash" that (way back when) wrapped a little javascript animation library in a plugin. That eventually evolved into Flash.

Needless to say, your only hope (door number 2) is kinda cumbersome.
0
 
LVL 25

Author Comment

by:Lee Savidge
ID: 37775931
I know with Javascript the end response is that you can't hide your code. I know there are code obfuscators but you can decode them easily. I'm happy to rewrite the functions in C# and embed them in a DLL so they return the data I need as long as the functionality is hidden. For example many of my functions will return strings after processing, or booleans. These can easily be written in C# as a DLL. So how would I call that DLL from a javascript?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 25

Author Comment

by:Lee Savidge
ID: 37775935
Just so we're clear, the javascript does not run client side. It is serverside javascript. It is never sent to the browser.
0
 
LVL 20

Expert Comment

by:BuggyCoder
ID: 37775938
well you can always use AJAX to call a server side page, make your dll part of asp.net http handler and connect to that handler using AJAX. Here is an example:-

http://www.misfitgeek.com/2011/05/calling-web-service-page-methods-with-jquery/
http://brijbhushan.net/2011/05/29/call-httphandler-from-jquery-pass-data-and-retrieve-in-json-format/
0
 
LVL 5

Expert Comment

by:mvdeveloper
ID: 37775984
To be clear - what application framework are you using to support the serverside javascript?
0
 
LVL 25

Author Comment

by:Lee Savidge
ID: 37775987
I think I need to explain more here.

The framework is an ISAPI DLL that lives on the server in IIS. The javascript code exists inside that framework. The javascript code makes calls INTO that ISAPI DLL via it's standard object interface. This javascript is not/does not/will not exist anywhere on the client because it is called by the ISAPI DLL on the server to process data on the server. The page at the point this code runs, does not exist. I cannot do alerts because there is no place to display alerts as there is no page at this point. The code does not interact with the end page or browser. It exists BEFORE the page is built on the server in IIS and runs in IIS's memory space. That is where my code already exists. I would like to move the functions and rewrite them as C#. I can do that already. I can write the DLL. What I can't seem to find out is how to call that DLL that will live on the server from that script.

For example, my code may do this:

var oOrg = FW.GetRec("Org", "IDField=" + IDField);

This returns an object from the object interface of the ISAPI dll. At this point I have full access to that Organisation object because the GetRec function requests an Org object type and the search parameter is the unique ID. The ISAPI dll then searches the database on the same server for that record. I can then play around with my record like this:

oOrg.name = "new name";
oOrg.status = "deleted";
oOrg.save;

This will write the data back through the existing DLL. At this point, the HTTP response has not even started building the page to send back to the browser. That bit is fine and nothing will change there. However I have some code libraries which do things that the standard framework interface does not do. For example:

Date handling and conversions
Basic logic on iterating through multiple objects when the GetRec returns more than one object. The search parameter field doesn't necessarily have to be the ID field. I can do a partial name search ie "NameField like '%" + name + "%'"

This returns an array that I can iterate through. All of my custom functions I would like to have in my DLL. I can already convert the code to C#. That's simple. I'm just not clear on instantiating an object from a class in a DLL on the server.
0
 
LVL 5

Expert Comment

by:mvdeveloper
ID: 37776110
Ok I think I get the picture now.

In a sense, you're asking the wrong question .. javaScript is a scripting language, and so depends on the features provided to it in whatever context it is running. If, for example, you were running JS within Windows Scripting Host (WSH) you could instantiate a COM object and control that (e.g. System.FileScriptingObject for file access) but only because WSH makes that interface available. The JavaScript itself has no native means of doing that.

So the question is really, what features does your specific ISAPI DLL expose to support this?

If the DLL is itself allowing you to expose COM objects to your JavaScript - which seems likely from what you say above - then you can simply create a C# assembly and expose it for COM interop by either
a) going into the Assembly Properties and checking the Make Assembly COM Visible box, or b) by explicitly setting thye ComClass attribute on any class you wish to expose and using the GUIDGEN tool to set the class id and interface id.

But you need to contact whoever developed the ISAPI DLL you are using to find out what that supports. The JavaScript is only automating that.
0
 
LVL 25

Author Comment

by:Lee Savidge
ID: 37776183
The ISAPI dll is not what I want to interact with. I can already do that because the interface is already created for me. I have additional functions which work well as SSJS and I can easily convert to C#. These functions take a string and return a processed string. There are plenty of others. It's just a library of functions that I find useful.

For example, I can make a connection to a database using SSJS with code like this:

var rs = new ActiveXObject("ADODB.Recordset")
var conn = new ActiveXObject("ADODB.Connection")

I can create a COM object myself in C# that contains equivalent functions to what my existing javascript library contains.

My code library contains functions like:

RemoveNonNumeric(inputString)
ProperCase(inputString)
ProcessLimited(inputString)
ProcessQuotes(inputString)

All of them take an input and return a string. This can be done in javascript, or if I were creating a Windows app, I may have a FunctionsLib class that contained a bunch of public functions that did the same as these examples above. If I created the FunctionLib class in C# and made the functions plublic I would call them in a way similar to this:

string sOut = "";
FunctionLib oFL = new FunctionLib();
sOut = oFL.ProcessQuotes(inputString);

If I were to do this from serverside javascript where I had registered the FunctionLib.dll, how would I call that from the javascript on the server?
0
 
LVL 5

Accepted Solution

by:
mvdeveloper earned 1000 total points
ID: 37776262
Since your SSJS has ActiveXObject,

var funcLib = new ActiveXObject("myAssembly.myClass");

Once you've exposed your C# class for com.
0
 
LVL 25

Author Comment

by:Lee Savidge
ID: 37826905
I will be testing this sometime this week. Thanks for the suggestions so far.
0
 
LVL 25

Author Comment

by:Lee Savidge
ID: 38007155
Other project work has got in the way of this. I have not yet managed to try this out. When I do I will update the question. Apologies for the delay.
0
 
LVL 25

Author Closing Comment

by:Lee Savidge
ID: 38514935
I got this working in the end. Finally had time to try it.

Many thanks.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question