Scripster - Razie's ScriptPad

Interactive access to the application's objects

I think that all apps must alllow scripted/programatic access to their objects.

I created a simple interactive gate to acces the scala parser in any scala/java process. It only uses one port and supports telnet, http and swing:

scalap.png

The graphics are based on my [[20widgets]] project, with the addition of a ScriptPad widget.

Content assist is only available in the telnet and web versions.

There is (usually up-and-running :)) online demo version running at http://scripster.razie.com or use "telnet demo.razie.com 4445".

Installing and running

Need to download:

Run the example with this command line (replace /host/bin/scala with your $SCALA_HOME) :

java -classpath ./scripster-dist.jar:./jline-0_9_5.jar:/host/bin/scala/lib/scala-library.jar:/host/bin/scala/lib/scala-compiler.jar:/host/bin/scala/lib/scala-swing.jar razie.scripster.MainSwingScripster

The web sessions are limited. Each consumes a parser instance and lots of memory. To limit them, these system properties *should* work:

  • -Dscripster.sessions.life=180 , the life of a session in seconds, since last usage
  • -Dscripster.sessions.max=12 , the maximum number of sessions

Embedding

To use it in your process, put these jars in your classpath and use this:

razie.scripster.Scripster.create(4445)

where 4445 is the port you want to use, see the razie.scripster.MainScripster for an example. To enable the swing version, use the swing jars as well and see the razie.scripster.MainSwingScripster class for an example.

A LightServer will be started on that port, which can serve from classpath only. If your classpath includes local directories, it will serve those too.

For further tweaking, look at the code yourself, at http://github.com/razie/scripster

If you want to keep in touch with the evolution of scripster or my other related endeavours, subscribe to the RSS feed or Twitter.

Using

Telnet

To use the telnet, just open a telnet session to the port you opened, default being 4445. It will switch the client to character mode.

Every time you hit enter, it will run that line as an expression and print the resulting value, if any. If the expression is multi-line, it will not run it but wait for you to enter more lines and the final expression will run when it's complete. The scala Parser is smart that way.

To use content assist, use TAB. It will "popup" a list of options. You can select an option with it's number or just keep on typing.

To ditch the current line, use ^C. Here's an example session:

~/w/scripster\> telnet localhost 4445 
Trying ::1... 
Connected to razubuntu. 
Escape character is '^]'. 
lava 
<console>:6: error: not found: value lava 
       lava 
       ^ 
java.lang.Syste                                                       <-- TAB 
--> Selection: 
      1) System 
      2) SystemClassLoaderAction 
      0)  - quit selection 
java.lang.Syste                                                        <-- 2 
java.lang.SystemClassLoaderAction 
<console>:6: error: object SystemClassLoaderAction cannot be accessed in package java.lang 
       java.lang.SystemClassLoaderAction 
                 ^

NOTE that each telnet session is indepdendent, i.e. the objects defined in one will not be visible in others.

To end a session, either kill the client or type "quit".

Web

webpad.png

Go to http://localhost:4445/scripting/session - it will start a new scripting session. Type expressions in the upper pad and use the link to run the selection. If any text is selected in the pad, that's what it will execute, otherwise the contents of the entire pad are executed.

The script pad is a fork of the CodeMirror project: http://github.com/razie/CodeMirror.

If you want to mess with the styles, these are all in the jar file. Analyze the page to see which style you want to mess with and you shall find them in a /public folder in the jar file. Just pull them out, edit them and then put them in the classpath…or back in the jar file.

The results are displayed in the bottom.

The simple web server included here is actually Razie's embedded light SOA [[HttServer]], so you can even write annotated services. This particular server has been modified to support both http and telnet, so you don't need separate ports.

NOTE that each web session is indepdendent, i.e. the objects defined in one will not be visible in others. If you refresh the page, you get a new session.

Swing

swingpad.png

Similar to the web pad, for now it's just a placeholder. We may get a full blown and smart Swing script pad soon…or not :)

The swing pad is a fork of the JSyntaxPane project http://code.google.com/p/jsyntaxpane/

NOTE that each swing dialog session is indepdendent, i.e. the objects defined in one will not be visible in others.

Security

There isn't much security built-in, so clients have full access to code, as if they are on the same server, so be VERY careful.

I run a live demo and I use java security for that. Here's the command line switches and the policy file I use (disable writing to files only).

java -Djava.security.manager -Djava.security.policy=./policyfile ...

demo@cloud:~/scripster$ cat policyfile 

grant {

  permission java.io.FilePermission "<<ALL FILES>>", "read";

  permission java.net.NetPermission "setDefaultAuthenticator";
  permission java.net.NetPermission "requestPasswordAuthentication";

  permission java.util.PropertyPermission "*", "read, write";

  permission java.net.SocketPermission "*:1024-", "listen, accept, resolve";

  permission java.lang.reflect.ReflectPermission "*";

  permission java.lang.RuntimePermission "*";
};

Customization

To customize certain features, put these files in the classpath, before the scripster.jar:

  • /public/scripster.html for the web version notice at the bottom
  • /public/scriptpad-code.css for the web version colors (syntax coloring). the default is based on the dw_orange scheme for vim, which is my favorite
  • /public/scriptpad.css for the web version content assist popup colors
  • /public/style.css for the general web look and feel

For serious hacking, you can replace the /public/scriptpad.js in the classpath with a version where you mess with the DOM.

These files can be found in the scripster distribution jar file. Remember that the web server embedded in scripster can only serve files from the classpath (I hope so anyways) so be careful with what classpath you're setting. For instance adding "/" or "." to the classpath gives access to those files…

Roadmap

TODOs:

Status Priority Cost Description
? L L remote swing - detach the swing from the actual server
done H M content assisst in web version
? H M validate behavior against REPL
? H M scope access to only objects in context - no classpath access (i.e. java.io.File etc)
? H M SSL

Version history

http://wiki.github.com/razie/scripster/versions

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License