!C99Shell v. 2.0 [PHP 7 Update] [25.02.2019]!

Software: Apache/2.4.18 (Ubuntu). PHP/7.0.33-0ubuntu0.16.04.16 

uname -a: Linux digifus 3.13.0-57-generic #95-Ubuntu SMP Fri Jun 19 09:28:15 UTC 2015 x86_64 

uid=33(www-data) gid=33(www-data) groups=33(www-data) 

Safe-mode: OFF (not secure)

/var/www/FlaskAppTest/ahab/   drwxr-xr-x
Free 10.22 GB of 29.4 GB (34.77%)
Home    Back    Forward    UPDIR    Refresh    Search    Buffer    Encoder    Tools    Proc.    FTP brute    Sec.    SQL    PHP-code    Update    Feedback    Self remove    Logout    


Viewing file:     app.py (7.68 KB)      -rw-r--r--
Select action/file-type:
(+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
from flask import Flask
from flask.ext.api import status


from json import dumps
from json import loads
from flask import request
from flask import Response
import database_functions
import utils
from flask.ext.cors import CORS

app = Flask(__name__)
# enable cross domain request
CORS(app)

flask_debug = True

    
# API REST PRODUCTS ###############
@app.route('/product', methods=['GET'])
def get_product_list():
    ''' return foreach product {id, name, description, price, qr} '''
    return dumps(database_functions.get_all_products())


@app.route('/product', methods=['POST'])
def add_product():
    ''' data: ex. { 'id' : null, 'name': 'product', 'description': 'a product named product',
            'price': 0.5, , 'seller_price' : 1.0, 'count': 2, 'photo': <base_64>}
    '''
    json_request = loads(request.data)
    name = json_request['name'].replace("'", "").replace("%20", " ")
    description = json_request['description'].replace("'", "").replace("%20", " ")
    price = json_request['price']
    seller_price = json_request['seller_price']
    count = json_request['count']
    model = json_request['model'].replace("'", "").replace("%20", " ")

    category = json_request['category'].replace("'", "").replace("%20", " ")

    supplier = json_request['supplier'].replace("'", "").replace("%20", " ")

    code = json_request['code']

    #print name, description, price, seller_price, count, model, category, supplier, code
    if ('photo' in json_request and json_request['photo'] is not None):
        image =    utils.decode_and_save_image(json_request['photo'], name)
        database_functions.insert_product(name, description, price, seller_price, count, model, category, supplier, code, image)
    else:
        database_functions.insert_product(name, description, price, seller_price, count, model, category, supplier, code)
    
    return "Producto creado"

@app.route('/product/<string:product_id>', methods=['PUT'])
def update_product(product_id):
    json_request = loads(request.data)
    name = json_request['name'].replace("'", "").replace("%20", " ")
    description = json_request['description'].replace("'", "").replace("%20", " ")
    price = json_request['price']
    seller_price = json_request['seller_price']
    count = json_request['count']
    model = json_request['model'].replace("'", "").replace("%20", " ")

    category = json_request['category'].replace("'", "").replace("%20", " ")

    supplier = json_request['supplier'].replace("'", "").replace("%20", " ")

    code = json_request['code']

    #print name, description, price, seller_price, count, model, category, supplier, code
    if ('photo' in json_request and json_request['photo'] is not None):
        image =    utils.decode_and_save_image(json_request['photo'], name)
        database_functions.update_product(name, description, price, seller_price, count, model, category, supplier, code, image)
    else:
        database_functions.update_product(name, description, price, seller_price, count, model, category, supplier, code)
    
    return "Producto actualizado correctamente"

@app.route('/product/<string:product_id>', methods=['GET'])
def get_product_detail(product_id):
    return dumps(database_functions.get_product_by_name(product_id))

@app.route('/product/<string:product_id>/qr', methods=['GET'])
def get_qrcode(product_id):
    from flask import send_file
        filename = database_functions.get_qr_filename_from_product(product_id)
        # TODO: Verify filename is not None
    return send_file(filename, mimetype='image/png')

@app.route('/product/<string:product_id>/photo', methods=['GET'])
def get_product_photo(product_id):
    from flask import send_file
    photo = database_functions.get_photo_from_product(product_id)
    filename = '/var/www/FlaskAppTest/images/NotAvailable300.png'
    if photo != "None" and photo is not None:
        filename = utils.image_store_folder + "/" + photo
    return send_file(filename, mimetype='image/png')

@app.route('/product/<string:product_id>/photo_base_64', methods=['GET'])
def get_product_photo_base_64(product_id):
    from flask import send_file
    import base64
    photo = database_functions.get_photo_from_product(product_id)
    filename = utils.image_store_folder + "/" + photo
    if photo == "None":
        filename = '/var/www/FlaskAppTest/images/NotAvailable300.png'
    with open(filename, "rb") as image_file:
        encoded_string = base64.b64encode(image_file.read())
    return dumps({ 'photo': encoded_string })

@app.route('/product/<string:product_id>/photo', methods=['PUT', 'POST'])
def update_product_photo(product_id):
    image =    utils.decode_and_save_image(json_request['photo'], product_id)
    database_functions.update_product_photo(product_id, image)
    return Response("Photo updated", status=200, mimetype='application/json')

######################

# API REST ORDERS ########################
@app.route('/order', methods=['POST'])
def create_order():
        ''' {
            "id": null,
            "seller_id": "seller 1",
            "client": "client_id",
            "products": [
                {
                    "name": "product1",
                    "count": 5
                },
                ...
             ]
            }
        '''
        json_request = loads(request.data)

        seller_id = json_request['seller_id']
        client_id = json_request['client_id']
        products = json_request['products'] 
    database_functions.insert_order(seller_id, client_id, products)
    return Response("Orden creada", status=200, mimetype='application/json')

@app.route('/order', methods=['GET'])
def get_orders():
    return dumps(database_functions.get_all_orders())
#########################

# API REST CLIENTS #####################
@app.route('/client', methods=['GET'])
def get_all_clients():
    # return foreach client {id, name, business_name , address, cuit, city, iva, mail }
    clients = database_functions.get_all_clients()
    # Avoid to convert unicode string. Clients has characters no ascii
    json = dumps(clients, ensure_ascii=False)
    return json

@app.route('/client', methods=['POST'])
def add_new_client():
    ''' data: ex. { 'name': 'client', 'bussiness_name': 'client SRL', 'address': 'client addres 1234',
                     'city' : 'client city', 'phone': '0800000', 'cuit': '20-client-3', 'mail': 'client@client.com', 'iva': 'responsable inscripto',
                     'observation': '', 'expresso': ''}
    '''
    json_request = loads(request.data)
    name = json_request['name']
    #business_name = json_request['business_name']
    address = json_request['address']
    #city = json_request['city']
    phone  = json_request['phone']
    cuit = ''
    if 'cuit' in json_request:
        cuit = json_request['cuit']

    mail = json_request['mail']
    #expresso = json_request['expresso']  
    #database_functions.insert_client(name, business_name, address, city, phone, cuit, mail, expresso)
    database_functions.insert_client(name, address, phone, cuit, mail)
    return Response("Cliente creado", status=200, mimetype='application/json')

@app.route('/client/<string:client_bussines_name>', methods=['GET'])
def get_client(client_bussines_name):
    return dumps(database_functions.get_client_by_business_name(client_bussines_name))

####################################

# API REST MODELS ###############3

@app.route('/model', methods=['GET'])
def get_models():
    return dumps(database_functions.get_models())

# API REST CATEGORIES ###############3

@app.route('/category', methods=['GET'])
def get_categories():
    return dumps(database_functions.get_categories())

# API REST SUPPLIERS ###############3

@app.route('/supplier', methods=['GET'])
def get_supplier():
    return dumps(database_functions.get_suppliers())

if __name__ == '__main__':
    app.run('0.0.0.0', debug=flask_debug)

:: Command execute ::

Enter:
 
Select:
 

:: Search ::
  - regexp 

:: Upload ::
 
[ Read-Only ]

:: Make Dir ::
 
[ Read-Only ]
:: Make File ::
 
[ Read-Only ]

:: Go Dir ::
 
:: Go File ::
 

--[ c99shell v. 2.0 [PHP 7 Update] [25.02.2019] maintained by KaizenLouie | C99Shell Github | Generation time: 0.006 ]--