huashengdun / webssh

:seedling: Web based ssh client
https://webssh.huashengdun.org/
MIT License
4.57k stars 1.3k forks source link

Encountered unknown tag 'module' #51

Closed aetasoul closed 5 years ago

aetasoul commented 5 years ago

Hi,

I'm trying to implement this web shell to my flask website. I have imported this project into mine.

When I execute the server all load correctly, after that I press the button SSH that call the ssh page (the index.html of this project) and I recive this error:


{% module xsrf_form_html() %}
TemplateSyntaxError: Encountered unknown tag 'module'.

That is refered to line 61 of index.html:

            {% module xsrf_form_html() %}
            <button type="submit" class="btn btn-primary">Connect</button>
            <button type="reset" class="btn btn-danger">Reset</button>
</form>

Removing the {% module xsrf_form_html() %} the page load correctly but nothing work about the ssh connection.

This is the code that call the page:

@app.route('/ssh_page', methods = ['POST', 'GET'])
def ssh_page():

    return render_template(
        'ssh_modal.html'
    )

Someone know how to solve this please?

Thanks in advance.

huashengdun commented 5 years ago

Hi,

I guess you let flask handle the request. Flask uses a different template system and doesn't know the tag "module", so you get the "unknown tag" error. You need to let tornado (wssh) handle the request.

aetasoul commented 5 years ago

Ok, I understand what you mean. But I have never used tornado before and this is the first time that I use Flask.

So, can you help me to implement this request?

I have a file init.py where I create the app object as Flask(): app = Flask(__name__)

After that I have a file called views.py that contains the route to the webssh page.

@app.route('/ssh_modal', methods = ['POST', 'GET'])
def ssh_modal():

    return render_template(
        'ssh_modal.html'
    )

This is the page where I have the button that call the webssh page.

<form action="{{ url_for('ssh_modal') }}" method="POST">
    <button class="btn btn-default" type="submit" name="details" value=" {{ ip }}, {{ key }} " href="">SSH Connection</button>
</form>

I have to implement the handle request using tornado in the views.py file?

huashengdun commented 5 years ago

A simple way is you can use flask to render a page containing an iframe element which renders the webssh page.

huashengdun commented 5 years ago

Example like this,

@app.route('/ssh_modal', methods = ['GET'])
def ssh_modal():

    return render_template(
        'ssh_modal.html'
    )

ssh_modal.html,

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title></title>
</head>
<body>
   <iframe src="http://webssh-page-url"></iframe> 
</body>
</html>
aetasoul commented 5 years ago

Ok with the iframe is working correctly.

What happends when you press the "Connect" button? Maybe I can implement directly the connection and the terminal to my web application without your page.

huashengdun commented 5 years ago

I am going to close this issue. If you meet any problem as you continuing your implementation, please open another issue here.