• Products
  • Get started
  • Documentation
  • Resources

Marid's proxy and web server functionalities

Marid Proxy Server Users

OEC does not have proxy server functionality. If you are using Marid's proxy server functionality, you should use other proxy server solutions. For reference, here is the list of common tools that can be used for this purpose: FreeProxy, Squid, Nginx, Wingate, TinyProxy, Ultrasurf, Privoxy, Polipo, Apache Traffic Server...

Marid Web Server Users

OEC does not have web server functionality. The following tutorial is a basic demonstration of achieving the same functionality by using DjangoServer. It is a free and open source web framework.

  1. Install Django server:

    pip install Django==2.2.5

     

  2. Create a project to serve your script server:

    django-admin startproject oecserver

     

  3. Create scripts folder under the project that you created at step 2 and add the scripts that you want to execute under this folder. For this example, 

    hello.py

     is added under the scripts folder which prints "Hello World!" to the console.

     

  4. Create 

    views.py

     under the project folder. views.py contains the following lines of codes:

     

view.py

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 from django.views.decorators.csrf import csrf_exempt from django.http import HttpResponse import json,requests from subprocess import Popen, PIPE, STDOUT def hello(): command = ["python3","oecserver/scripts/hello.py","create" ] try: process = Popen(command, stdout=PIPE, stderr=STDOUT) output = process.stdout.read() exitstatus = process.poll() if (exitstatus==0): return {"status": "Success", "output":str(output)} else: return {"status": "Failed", "output":str(output)} except Exception as e: return {"status": "failed", "output":str(e)} @csrf_exempt def execute(request): data = hello() response = HttpResponse(json.dumps(data) , content_type='application/json', status=200) return response

 

execute

 method is the main method that handles the HTTP requests. It calls 

hello

 method to execute the script and adds the result of the execution to the HTTP response. You can run any executable or script implemented with other languages with the same approach above.

 

  1. Manipulate urls.py to bind your script with URLs:

urls.py

1 2 3 4 5 6 7 8 9 10 11 from django.contrib import admin from django.urls import path from django.conf.urls import url from django.contrib import admin from django.views import generic from oecserver.views import execute #added urlpatterns = [ path('admin/', admin.site.urls), url(r'^hello_api$', execute) ]

 

hello_api

 is the URL you bind and 

execute

 is name of the main method implemented at 

views.py

.

 

  1. Start your server. You can change the host and port number by manipulating the last parameter of the following command:

    python ./manage.py runserver 0.0.0.0:8000

     

  2. You can execute the command below to test your server:

    curl -i -X POST localhost:8000/hello_api -d '{"anyData":"data"}'

     

response

1 2 3 4 5 6 7 8 HTTP/1.1 200 OK Date: Mon, 16 Sep 2019 14:20:16 GMT Server: WSGIServer/0.2 CPython/3.7.0 Content-Type: application/json X-Frame-Options: SAMEORIGIN Content-Length: 54 {"status": "Success", "output": "b'Hello, World!\\n'"}

The example above is just a basic starter tutorial for the migration. You can check Django's website for more features and details. By using Django and Python SDK (or any other SDK or script of your choice), the same behavior can be achieved.

Last modified on Mar 23, 2021
Cached at 11:43 AM on Jul 30, 2021 |

Additional Help

Ask the Community