From 743618efd9dc09a0c3c923cccc77644124b9415a Mon Sep 17 00:00:00 2001 From: AjmalCybro Date: Fri, 28 Jun 2024 16:27:46 +0530 Subject: [PATCH] Jun 21 [UPDT] Updated 'access_restriction_by_ip' --- access_restriction_by_ip/__manifest__.py | 6 +- access_restriction_by_ip/controllers/main.py | 14 +- .../models/allowed_ips.py | 3 +- .../static/description/index.html | 209 +++++++++--------- .../static/src/js/widget.js | 33 +++ 5 files changed, 156 insertions(+), 109 deletions(-) create mode 100644 access_restriction_by_ip/static/src/js/widget.js diff --git a/access_restriction_by_ip/__manifest__.py b/access_restriction_by_ip/__manifest__.py index 08c14e97b..07f8f9133 100644 --- a/access_restriction_by_ip/__manifest__.py +++ b/access_restriction_by_ip/__manifest__.py @@ -31,8 +31,12 @@ 'security/ir.model.access.csv', 'views/allowed_ips_view.xml', ], + 'assets': { + 'web.assets_backend': [ + '/access_restriction_by_ip/static/src/js/widget.js', + ], + }, 'images': ['static/description/banner.png'], 'installable': True, 'auto_install': False, } - diff --git a/access_restriction_by_ip/controllers/main.py b/access_restriction_by_ip/controllers/main.py index e0a79908c..152ee3036 100644 --- a/access_restriction_by_ip/controllers/main.py +++ b/access_restriction_by_ip/controllers/main.py @@ -34,10 +34,8 @@ class Home(main.Home): request.params['login_success'] = False if request.httprequest.method == 'GET' and redirect and request.session.uid: return request.redirect(redirect) - if not request.uid: request.uid = odoo.SUPERUSER_ID - values = request.params.copy() try: values['databases'] = http.db_list() @@ -85,5 +83,15 @@ class Home(main.Home): request.uid = old_uid if e.args == odoo.exceptions.AccessDenied().args: values['error'] = _("Wrong login/password") - return request.render('web.login', values) + + @http.route('/get_ip', auth='user', type='json') + def get_ip(self): + ip_address = request.httprequest.environ['REMOTE_ADDR'] + ip_addresses = [] + for ips in request.env.user.allowed_ips: + ip_addresses.append(ips.ip_address) + if ip_addresses: + if ip_address not in ip_addresses: + return False + return True diff --git a/access_restriction_by_ip/models/allowed_ips.py b/access_restriction_by_ip/models/allowed_ips.py index 105e2a2f3..2d0f0ef18 100644 --- a/access_restriction_by_ip/models/allowed_ips.py +++ b/access_restriction_by_ip/models/allowed_ips.py @@ -17,7 +17,7 @@ # If not, see . # ############################################################################## -from odoo import models, fields +from odoo import api, models, fields class ResUsersInherit(models.Model): @@ -31,3 +31,4 @@ class AllowedIPs(models.Model): users_ip = fields.Many2one('res.users', string='IP') ip_address = fields.Char(string='Allowed IP') + diff --git a/access_restriction_by_ip/static/description/index.html b/access_restriction_by_ip/static/description/index.html index 5930e3a01..0742276e8 100644 --- a/access_restriction_by_ip/static/description/index.html +++ b/access_restriction_by_ip/static/description/index.html @@ -1,18 +1,17 @@ -
+ style="border-bottom: 1px solid #d5d5d5;">
+ style="background-color: #7C7BAD !important; color: #fff !important; font-weight: 600 !important; padding: 5px 15px 8px !important; margin: 0 5px !important;"> Community
+ style="background-color: #875A7B !important; color: #fff !important; font-weight: 600 !important; padding: 5px 15px 8px !important; margin: 0 5px !important;"> Enterprise
@@ -24,35 +23,35 @@
+ style="padding: 4rem 1rem !important; background-color: #714B67 !important; height: 600px !important; border-radius: 20px !important;">

+ style="font-family: 'Montserrat', sans-serif !important; font-weight: 600 !important; color: #FFFFFF !important; font-size: 3.5rem !important; text-align: center !important;"> Access Restriction By IP

- User can access his account only from specified IP's + style="font-family: 'Montserrat', sans-serif !important; font-weight: 300 !important; color: #FFFFFF !important; font-size: 1.4rem !important; text-align: center !important;"> + User can access his account only from specified IP's

- +

+ style="font-family: 'Montserrat', sans-serif !important; font-weight: 600 !important; color: #714B67 !important; font-size: 1.5rem !important;"> Explore this module

+ style="background-color: #f5f2f5 !important; border-radius: 10px !important; margin: 1rem !important; padding: 1.5em !important; height: 100px !important;">

+ style="font-family: 'Montserrat', sans-serif !important; font-weight: 600 !important; color: #714B67 !important; font-size: 1.2rem !important;"> Overview

+ style="font-family: 'Roboto', sans-serif !important; font-weight: 400 !important; color: #714B67 !important; font-size: 0.9rem !important;"> Learn more about this module

@@ -64,13 +63,13 @@
+ style="background-color: #f5f2f5 !important; border-radius: 10px !important; margin: 1rem !important; padding: 1.5em !important; height: 100px !important;">

+ style="font-family: 'Montserrat', sans-serif !important; font-weight: 600 !important; color: #714B67 !important; font-size: 1.2rem !important;"> Features

+ style="font-family: 'Roboto', sans-serif !important; font-weight: 400 !important; color: #714B67 !important; font-size: 0.9rem !important;"> View features of this module

@@ -82,13 +81,13 @@
+ style="background-color: #f5f2f5 !important; border-radius: 10px !important; margin: 1rem !important; padding: 1.5em !important; height: 100px !important;">

+ style="font-family: 'Montserrat', sans-serif !important; font-weight: 600 !important; color: #714B67 !important; font-size: 1.2rem !important;"> Screenshots

+ style="font-family: 'Roboto', sans-serif !important; font-weight: 400 !important; color: #714B67 !important; font-size: 0.9rem !important;"> See key screenshots of this module

@@ -100,13 +99,13 @@
+ style="background-color: #f5f2f5 !important; border-radius: 10px !important; margin: 1rem !important; padding: 1.5em !important; height: 100px !important;">

+ style="font-family: 'Montserrat', sans-serif !important; font-weight: 600 !important; color: #714B67 !important; font-size: 1.2rem !important;"> Video

+ style="font-family: 'Roboto', sans-serif !important; font-weight: 400 !important; color: #714B67 !important; font-size: 0.9rem !important;"> Watch tutorial video on this module

@@ -121,15 +120,15 @@

+ style="font-family: 'Montserrat', sans-serif !important; font-weight: 600 !important; color: #714B67 !important; font-size: 1.5rem !important;"> Overview

- This module will restrict the users access to his account from specified IP address only + style="font-family: 'Roboto', sans-serif !important; font-weight: 400 !important; color: #282F33 !important; font-size: 1rem !important; line-height: 30px !important;"> + This module will restrict the users access to his account from specified IP address only

@@ -139,7 +138,7 @@

+ style="font-family: 'Montserrat', sans-serif !important; font-weight: 600 !important; color: #714B67 !important; font-size: 1.5rem !important;"> Features

@@ -150,10 +149,10 @@

+ style="font-family: 'Roboto', sans-serif !important; font-weight: 600 !important; color: #282F33 !important; font-size: 1.3rem !important;"> Admin Access

+ style="font-family: 'Roboto', sans-serif !important; font-weight: 400 !important; color: #282F33 !important; font-size: 1rem !important;"> Administrator can set a IP or a group of IP address for each users.

@@ -164,10 +163,10 @@

+ style="font-family: 'Roboto', sans-serif !important; font-weight: 600 !important; color: #282F33 !important; font-size: 1.3rem !important;"> User Restriction

+ style="font-family: 'Roboto', sans-serif !important; font-weight: 400 !important; color: #282F33 !important; font-size: 1rem !important;"> Users can access their account only from the specified IP's.

@@ -178,10 +177,10 @@

+ style="font-family: 'Roboto', sans-serif !important; font-weight: 600 !important; color: #282F33 !important; font-size: 1.3rem !important;"> Restricted Login

+ style="font-family: 'Roboto', sans-serif !important; font-weight: 400 !important; color: #282F33 !important; font-size: 1rem !important;"> Accessing system from a non-specified IP will restrict the user login.

@@ -192,10 +191,10 @@

+ style="font-family: 'Roboto', sans-serif !important; font-weight: 600 !important; color: #282F33 !important; font-size: 1.3rem !important;"> Warning

+ style="font-family: 'Roboto', sans-serif !important; font-weight: 400 !important; color: #282F33 !important; font-size: 1rem !important;"> A warning message will be displayed.

@@ -206,11 +205,12 @@

+ style="font-family: 'Roboto', sans-serif !important; font-weight: 600 !important; color: #282F33 !important; font-size: 1.3rem !important;"> Userwise IP

- If no IP is set to user means there is not any restriction by IP. IP Address for each users can be set from users form view

+ style="font-family: 'Roboto', sans-serif !important; font-weight: 400 !important; color: #282F33 !important; font-size: 1rem !important;"> + If no IP is set to user means there is not any restriction by IP. IP Address for each users can be + set from users form view

@@ -219,7 +219,7 @@

+ style="font-family: 'Montserrat', sans-serif !important; font-weight: 600 !important; color: #714B67 !important; font-size: 1.5rem !important;"> Screenshots

@@ -228,25 +228,26 @@ style="font-family: 'Roboto', sans-serif !important; font-weight: 600 !important; color: #282F33 !important; font-size: 1.3rem !important;"> Setting IP address for User

+ style="font-family: 'Roboto', sans-serif !important; font-weight: 400 !important; color: #282F33 !important; font-size: 1rem !important;"> Setting IP address for user from users form view

+ style="font-family: 'Roboto', sans-serif !important; font-weight: 400 !important; color: #282F33 !important; font-size: 1rem !important;"> User will be able to access his account only from this IP's

+ width="100%" height="auto"/>
- +

User accessing his account

- On accessing account from a non specified IP. + style="font-family: 'Roboto', sans-serif !important; font-weight: 400 !important; color: #282F33 !important; font-size: 1rem !important;"> + On accessing account from a non specified IP.(If the user is already logged in he/she will be logged out + after the first reload)

+ width="100%" height="auto"/>
@@ -254,15 +255,15 @@

+ style="font-family: 'Montserrat', sans-serif !important; font-weight: 600 !important; color: #714B67 !important; font-size: 1.5rem !important;"> Video

Cybrosys Cover Video + src="assets/screenshots/access_restriction_by_ip-youtube.png" alt="Cybrosys Cover Video" + style="max-width:100%">
@@ -270,10 +271,10 @@
@@ -322,8 +323,8 @@
+ style="border-top-left-radius:10px; border-top-right-radius:10px" + src="./assets/modules/shopify_image.png">
@@ -331,8 +332,8 @@
+ style="border-top-left-radius:10px; border-top-right-radius:10px" + src="./assets/modules/magento_image.png">
@@ -340,13 +341,13 @@
- + style="font-size:24px"> +
@@ -358,12 +359,12 @@

Our Services


+ style="border: 3px solid #714B67 !important; background-color: #714B67 !important; width: 80px !important; margin-bottom: 2rem !important;"/>
+ style="background-color: #1dd1a1 !important; border-radius: 15px !important; height: 80px; width: 80px;">
@@ -373,7 +374,7 @@
+ style="background-color: #ff6b6b !important; border-radius: 15px !important; height: 80px; width: 80px;">
@@ -383,7 +384,7 @@
+ style="background-color: #6462CD !important; border-radius: 15px !important; height: 80px; width: 80px;">
@@ -394,7 +395,7 @@
+ style="background-color: #ffa801 !important; border-radius: 15px !important; height: 80px; width: 80px;">
@@ -405,7 +406,7 @@
+ style="background-color: #54a0ff !important; border-radius: 15px !important; height: 80px; width: 80px;">
@@ -415,7 +416,7 @@
+ style="background-color: #6d7680 !important; border-radius: 15px !important; height: 80px; width: 80px;">
@@ -426,7 +427,7 @@
+ style="background-color: #786fa6 !important; border-radius: 15px !important; height: 80px; width: 80px;">
@@ -436,7 +437,7 @@
+ style="background-color: #f8a5c2 !important; border-radius: 15px !important; height: 80px; width: 80px;">
@@ -446,7 +447,7 @@
+ style="background-color: #e6be26 !important; border-radius: 15px !important; height: 80px; width: 80px;">
@@ -463,15 +464,15 @@

Our Industries


+ style="border: 3px solid #714B67 !important; background-color: #714B67 !important; width: 80px !important; margin-bottom: 2rem !important;"/>
+ style="background-color: #f6f8f9 !important; border-radius: 10px; padding: 2rem !important; height: 250px !important;">
+ style="font-family: Montserrat, sans-serif !important; color: #000 !important; font-weight: bold;"> Trading

@@ -483,10 +484,10 @@

+ style="background-color: #f6f8f9 !important; border-radius: 10px; padding: 2rem !important; height: 250px !important;">
+ style="font-family: Montserrat, sans-serif !important; color: #000 !important; font-weight: bold;"> POS

@@ -498,11 +499,11 @@

+ style="background-color: #f6f8f9 !important; border-radius: 10px; padding: 2rem !important; height: 250px !important;"> + width="48px">
+ style="font-family: Montserrat, sans-serif !important; color: #000 !important; font-weight: bold;"> Education

@@ -513,11 +514,11 @@

+ style="background-color: #f6f8f9 !important; border-radius: 10px; padding: 2rem !important; height: 250px !important;"> + width="48px">
+ style="font-family: Montserrat, sans-serif !important; color: #000 !important; font-weight: bold;"> Manufacturing

@@ -528,10 +529,10 @@

+ style="background-color: #f6f8f9 !important; border-radius: 10px; padding: 2rem !important; height: 250px !important;">
+ style="font-family: Montserrat, sans-serif !important; color: #000 !important; font-weight: bold;"> E-commerce & Website

@@ -543,10 +544,10 @@

+ style="background-color: #f6f8f9 !important; border-radius: 10px; padding: 2rem !important; height: 250px !important;">
+ style="font-family: Montserrat, sans-serif !important; color: #000 !important; font-weight: bold;"> Service Management

@@ -557,11 +558,11 @@

+ style="background-color: #f6f8f9 !important; border-radius: 10px; padding: 2rem !important; height: 250px !important;"> + width="48px">
+ style="font-family: Montserrat, sans-serif !important; color: #000 !important; font-weight: bold;"> Restaurant

@@ -572,10 +573,10 @@

+ style="background-color: #f6f8f9 !important; border-radius: 10px; padding: 2rem !important; height: 250px !important;">
+ style="font-family: Montserrat, sans-serif !important; color: #000 !important; font-weight: bold;"> Hotel Management

@@ -597,26 +598,26 @@

Need Help?


+ style="border: 3px solid #714B67 !important; background-color: #714B67 !important; width: 80px !important; margin-bottom: 2rem !important;"/>
+ style="max-width:1540px; margin: 0 auto 2rem auto;">
@@ -630,12 +631,12 @@
- +

+ style="margin-top: 3rem;background: linear-gradient(90deg, rgba(2,0,36,0) 0%, rgba(229,229,229,1) 33%, rgba(229,229,229,1) 58%, rgba(0,212,255,0) 100%); height: 2px; border-style: none;">
diff --git a/access_restriction_by_ip/static/src/js/widget.js b/access_restriction_by_ip/static/src/js/widget.js new file mode 100644 index 000000000..8c076176c --- /dev/null +++ b/access_restriction_by_ip/static/src/js/widget.js @@ -0,0 +1,33 @@ +/** @odoo-module **/ +import SystrayMenu from 'web.SystrayMenu'; +import Widget from 'web.Widget'; +var ajax = require('web.ajax'); +var core = require('web.core'); +var qweb = core.qweb; + +var GetUser = Widget.extend({ + /** + function run before loading the page to call methode "get_idle_time" + */ + willStart: function() { + var self = this; + return this._super().then(function() { + self.get_user(); + }); + }, + /** + Getting minutes through python for the corresponding user in the backend + */ + get_user: function() { + var self = this + var now = new Date().getTime(); + ajax.rpc('/get_ip').then(function(data) { + console.log(data) + if (data == false){ + location.replace("/web/session/logout") + } + }) + }, +}); +SystrayMenu.Items.push(GetUser); +export default GetUser; \ No newline at end of file