Getting Started - shmolyneaux/SquareJam GitHub Wiki

This guide is intended as a first step introduction to setting up SnakeCharmer in a development environment.

The following guide should take less than 30 minutes to complete.

Setup

To start using SnakeCharmer you first need to retrieve a copy of SnakeCharmer and put it somewhere in your file system. Next you will need to create a new user. The default name for this user is pstorage. To create a new user, enter the following in a terminal:

sudo useradd pstorage

The next step is to generate a certificate for use with HTTPS with the command while in your SnakeCharmer directory:

openssl req -new -x509 -keyout server.pem -out server.pem -days 365 -nodes

The generated server.pem file should be in the same location as the SnakeCharmer.py and storserv.py scripts.

Next, a couple changes need to be made to the configuration files. In storserv_config.py we need to set the location of the database. The DATA_PATH variable must direct to the storserv_data directory. The DATA_PATH must change from this:

    DATA_PATH = os.path.join(RUN_PATH,'/usr/local/lib/SnakeCharmer/6.0/storserv_data');

To something like this:

    DATA_PATH = "/example/use/the/actual/location/of/SnakeCharmer/storserv_data";

In the SnakeCharmer_config.py file we must set fpem to the location of the certificate file we generated in a previous step (the location of server.pem).

Finally, before running the python scripts, we must set the server address in SnakeCharmer.py. At the bottom of the script there are two separate places where the server_address is defined. This must be changed to the following:

server_address = ('0.0.0.0', SnakeCharmer_config.HTTP_PORT); #(address, port)

and

server_address = ('0.0.0.0', SnakeCharmer_config.HTTPS_PORT); #(address, port)

Running the Scripts

Before we can run the scripts a version of python 3 is required. Using apt we can get it with the following command:

sudo apt-get install python3-dev

Next, we must start storserv and SnakeCharmer:

sudo python3.2 storserv.py

storserv Terminal

python3.2 SnakeCharmer.py

SnakeCharmer Terminal

And recompile the methods contained in the database using compile_methods.py (note for Dr. Kremer: you may have an older version that is more verbose than it needs to be (it was the first thing I made in python)):

python3.2 compile_methods.py

It will ask for the root password. This is the root password for the database. The default password is toor.

Now we can begin to use stosh. You should read that article if you want to have a greater understanding of how to user stosh. Type the following in a terminal to begin using stosh:

python3.2 stosh.py

If this is a fresh install of SnakeCharmer you should enter the following text into stosh (Note: toor is entered as the password to switch to the root user):

su root
toor
cd Server
cd WebSites
make Object _0_0_0_0
cd _0_0_0_0
make Object index
cd index
make Method html

stosh Terminal

If it is not a fresh install the root password may have changed, and some of these objects may have already been created. Use ls in stosh to check if attributes have already been created. Go to stosh for more details.

Now, we must modify the method we just created to produce a web page. In stosh type:

edit html

This will prompt you for the editor you would like to use. Examples include vim, nano, and gedit. Inside your editor type in the following and save:

def html( self, req ):
  req.content_type = "text/html";
  req.content = """
<html>
  <head>
    <title>Example Page</title>
  </head>
  <body>
    <h1>Hello World!</h1>
  </body>
</html>""";

Edit HTML

Admire Your Handiwork

At this point you are able to open your web browser and navigate to the web page you just created. Set the URL of your browser to: https://0.0.0.0:8001

You should get a warning which states that the website's security certificate is not trusted, but most browsers will let you proceed anyways. This is because the certificate we generated at the beginning is not signed by a trusted party, or is for a different domain.

Result

After following these steps you should get the following result:

Hello World!

![Hello World!](http://i.imgur.com/WRYcR4y.png)

Before proceeding on your own you should read the Getting Started Explanation to get a greater understanding of how SnakeCharmer works.

⚠️ **GitHub.com Fallback** ⚠️