summaryrefslogtreecommitdiff
path: root/python-django-adminrestrict.spec
blob: 9ed9800b173d8aa57922450b2f9ac6e6ad3656f0 (plain)
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
%global _empty_manifest_terminate_build 0
Name:		python-django-adminrestrict
Version:	3.1
Release:	1
Summary:	Restrict admin pages using simple IP address rules
License:	MIT
URL:		https://github.com/robromano/django-adminrestrict
Source0:	https://mirrors.aliyun.com/pypi/web/packages/ec/83/5d21fe47e9ea3fd2a77a4e34c27ae5b0c7715fa84f6a43755470aa0ea07f/django-adminrestrict-3.1.tar.gz
BuildArch:	noarch


%description
# Django Admin Restrict

[![build-status-image]][travis]
[![coverage-status-image]][codecov]
[![pypi-version]][pypi]

**Restrict admin pages using simple IP address rules.**

## Overview

``django-adminrestrict`` secures access to the Django admin pages. It works 
by blocking requests for the admin page path unless the requests come from 
specific IP addresses, address ranges or domains that you specify in 
a model. 


## Requirements

``django-adminrestrict`` requires Django 1.4 or later.  The
application is intended improve the security around the Django admin
login pages.

## Installation

Download and install ``django-adminrestrict`` using **one** of the following methods:

### pip

You can install the latest stable package running this command:

    $ pip install django-adminrestrict

### Setuptools

You can install the latest stable package running:

    $ easy_install django-adminrestrict

## Python 3.0 Only

`adminrestrict` requires Python 3.x and no longer supports Python 2.x.

## Development

You can contribute to this project forking it from github and sending pull requests.


## Configuration

First of all, you must add this project to your list of ``INSTALLED_APPS`` in
``settings.py``

    INSTALLED_APPS = (
        'django.contrib.admin',
        'django.contrib.auth',
        'django.contrib.contenttypes',
        'django.contrib.sessions',
        'django.contrib.sites',
        ...
        'adminrestrict',
        ...
    )

Next, install the ``AdminPagesRestrictMiddleware`` middleware:

    MIDDLEWARE_CLASSES = (
        'django.middleware.common.CommonMiddleware',
        'django.contrib.sessions.middleware.SessionMiddleware',
        'django.contrib.auth.middleware.AuthenticationMiddleware',
        'adminrestrict.middleware.AdminPagesRestrictMiddleware',
    )


Create the appropriate tables in your database that are necessary for operation.

For django(<1.7), run ``python manage.py syncdb``.

For django(>=1.7), run ``python manage.py makemigrations adminrestrict; python manage.py migrate``. 

IMPORTANT: When the package is configured in your project, an empty table called `AllowedIP`
will be created in your database. If this table is empty or has one record with
a "\*" the package will not restrict any IPs. If you want to add specific restrictions
please go to the next section.

## Usage

Using ``django-adminrestrict`` is extremely simple.  Once you install the application
and the middleware, all you need to do is update the allowed IP addresses `AllowedIP`
section of the admin pages.

### Adding allowed IP addresses

Login to the admin pages and browse to the Adminrestrict app, and
start creating recorded in the `AllowedIP` table.  Just type in the IP
addresses and save them. These will be single IPv4 addresses that are
permitted to access the pages.


### Managing allowed IP addresses from command line

Use the management commands to add and remove allowed IP addresses from the command line:

``python manage.py addadminip 10.10.10.10``

``python manage.py removeadminip 10.10.10.10``


### Adding allowed IP addresses with wildcards

Create a `AllowedIP` entries ending with a "\*" to any IPs that start
with the specified pattern. For example, adding `192.*` would allow
addreses starting matching 192.*.*.* to access the admin pages.

### Adding allowed IP addresses using CIDR ranges

Create a `AllowedIP` entries denoted in CIDR notation, to indicate a range 
of IP addresses that would be allowed to login/access the admin pages.
For example, a CIDR range with a suffix indicating the number of bits 
of the prefix, such as `192.0.2.0/24` for IPv4 or `2001:0db8:85a3:0000::/64` for IPv6 would indicate an 
entire subnet allowed to access the admin pages.
### Adding allowed IP addresses using domain names

Create `AllowedIP` records with domain names starting with a lower-case or upper-case character. These domain names' corresponding IP addresses
will be allowed to access the admin pages. Recommended use case: dynamic 
DNS domain names.

### Adding * to disable all restrictions

Create a single `AllowedIP` record with "\*" as the IP address, to
temporarily disable restrictions. In this way, you do not have to
modify settings.py and remove the middleware if you need to disable.

Having at least one `AllowedIP` record with * as the IP address
effectively disables all restrictions.

## Advanced Settings

There are a few advanced settings that can be engaged by adding them
to your project's `settings.py` file:

`ADMINRESTRICT_BLOCK_GET=True` will block all GET requests to admin urls.  By default, `adminrestrict` only blocks the POST method to block logins only, which is usually sufficient, because GET will redirect to the login page anyway. 

`ADMINRESTRICT_ENABLE_CACHE=True` will cause `adminrestrict` to cache some of the IP addresses retrieved from the AllowedIP model to reduce read query load on your database.  When any update gets made to AllowedIP models, the cache is auto-refreshed. 

`ADMINRESTRICT_DENIED_MSG="Custom denied msg."` will let you set the response body of the 403 HTTP 
result when a request is denied. By default, the message is **"Access to admin is denied."**

`ADMINRESTRICT_ALLOW_PRIVATE_IP=True` will allow all private IP addresses to access
the admin pages, regardless of whether the request IP matches any pattern or IP address
in the AllowedIP model.  Note: private IP addresses are those which comply with [RFC1918](https://tools.ietf.org/html/rfc1918).

[build-status-image]: https://secure.travis-ci.org/robromano/django-adminrestrict.svg?branch=master
[travis]: https://travis-ci.org/robromano/django-adminrestrict?branch=master
[pypi-version]: https://badge.fury.io/py/django-adminrestrict.svg
[pypi]: https://pypi.org/project/django-adminrestrict/
[coverage-status-image]: https://img.shields.io/codecov/c/github/robromano/django-adminrestrict/master.svg
[codecov]: https://codecov.io/github/robromano/django-adminrestrict?branch=master

%package -n python3-django-adminrestrict
Summary:	Restrict admin pages using simple IP address rules
Provides:	python-django-adminrestrict
BuildRequires:	python3-devel
BuildRequires:	python3-setuptools
BuildRequires:	python3-pip
%description -n python3-django-adminrestrict
# Django Admin Restrict

[![build-status-image]][travis]
[![coverage-status-image]][codecov]
[![pypi-version]][pypi]

**Restrict admin pages using simple IP address rules.**

## Overview

``django-adminrestrict`` secures access to the Django admin pages. It works 
by blocking requests for the admin page path unless the requests come from 
specific IP addresses, address ranges or domains that you specify in 
a model. 


## Requirements

``django-adminrestrict`` requires Django 1.4 or later.  The
application is intended improve the security around the Django admin
login pages.

## Installation

Download and install ``django-adminrestrict`` using **one** of the following methods:

### pip

You can install the latest stable package running this command:

    $ pip install django-adminrestrict

### Setuptools

You can install the latest stable package running:

    $ easy_install django-adminrestrict

## Python 3.0 Only

`adminrestrict` requires Python 3.x and no longer supports Python 2.x.

## Development

You can contribute to this project forking it from github and sending pull requests.


## Configuration

First of all, you must add this project to your list of ``INSTALLED_APPS`` in
``settings.py``

    INSTALLED_APPS = (
        'django.contrib.admin',
        'django.contrib.auth',
        'django.contrib.contenttypes',
        'django.contrib.sessions',
        'django.contrib.sites',
        ...
        'adminrestrict',
        ...
    )

Next, install the ``AdminPagesRestrictMiddleware`` middleware:

    MIDDLEWARE_CLASSES = (
        'django.middleware.common.CommonMiddleware',
        'django.contrib.sessions.middleware.SessionMiddleware',
        'django.contrib.auth.middleware.AuthenticationMiddleware',
        'adminrestrict.middleware.AdminPagesRestrictMiddleware',
    )


Create the appropriate tables in your database that are necessary for operation.

For django(<1.7), run ``python manage.py syncdb``.

For django(>=1.7), run ``python manage.py makemigrations adminrestrict; python manage.py migrate``. 

IMPORTANT: When the package is configured in your project, an empty table called `AllowedIP`
will be created in your database. If this table is empty or has one record with
a "\*" the package will not restrict any IPs. If you want to add specific restrictions
please go to the next section.

## Usage

Using ``django-adminrestrict`` is extremely simple.  Once you install the application
and the middleware, all you need to do is update the allowed IP addresses `AllowedIP`
section of the admin pages.

### Adding allowed IP addresses

Login to the admin pages and browse to the Adminrestrict app, and
start creating recorded in the `AllowedIP` table.  Just type in the IP
addresses and save them. These will be single IPv4 addresses that are
permitted to access the pages.


### Managing allowed IP addresses from command line

Use the management commands to add and remove allowed IP addresses from the command line:

``python manage.py addadminip 10.10.10.10``

``python manage.py removeadminip 10.10.10.10``


### Adding allowed IP addresses with wildcards

Create a `AllowedIP` entries ending with a "\*" to any IPs that start
with the specified pattern. For example, adding `192.*` would allow
addreses starting matching 192.*.*.* to access the admin pages.

### Adding allowed IP addresses using CIDR ranges

Create a `AllowedIP` entries denoted in CIDR notation, to indicate a range 
of IP addresses that would be allowed to login/access the admin pages.
For example, a CIDR range with a suffix indicating the number of bits 
of the prefix, such as `192.0.2.0/24` for IPv4 or `2001:0db8:85a3:0000::/64` for IPv6 would indicate an 
entire subnet allowed to access the admin pages.
### Adding allowed IP addresses using domain names

Create `AllowedIP` records with domain names starting with a lower-case or upper-case character. These domain names' corresponding IP addresses
will be allowed to access the admin pages. Recommended use case: dynamic 
DNS domain names.

### Adding * to disable all restrictions

Create a single `AllowedIP` record with "\*" as the IP address, to
temporarily disable restrictions. In this way, you do not have to
modify settings.py and remove the middleware if you need to disable.

Having at least one `AllowedIP` record with * as the IP address
effectively disables all restrictions.

## Advanced Settings

There are a few advanced settings that can be engaged by adding them
to your project's `settings.py` file:

`ADMINRESTRICT_BLOCK_GET=True` will block all GET requests to admin urls.  By default, `adminrestrict` only blocks the POST method to block logins only, which is usually sufficient, because GET will redirect to the login page anyway. 

`ADMINRESTRICT_ENABLE_CACHE=True` will cause `adminrestrict` to cache some of the IP addresses retrieved from the AllowedIP model to reduce read query load on your database.  When any update gets made to AllowedIP models, the cache is auto-refreshed. 

`ADMINRESTRICT_DENIED_MSG="Custom denied msg."` will let you set the response body of the 403 HTTP 
result when a request is denied. By default, the message is **"Access to admin is denied."**

`ADMINRESTRICT_ALLOW_PRIVATE_IP=True` will allow all private IP addresses to access
the admin pages, regardless of whether the request IP matches any pattern or IP address
in the AllowedIP model.  Note: private IP addresses are those which comply with [RFC1918](https://tools.ietf.org/html/rfc1918).

[build-status-image]: https://secure.travis-ci.org/robromano/django-adminrestrict.svg?branch=master
[travis]: https://travis-ci.org/robromano/django-adminrestrict?branch=master
[pypi-version]: https://badge.fury.io/py/django-adminrestrict.svg
[pypi]: https://pypi.org/project/django-adminrestrict/
[coverage-status-image]: https://img.shields.io/codecov/c/github/robromano/django-adminrestrict/master.svg
[codecov]: https://codecov.io/github/robromano/django-adminrestrict?branch=master

%package help
Summary:	Development documents and examples for django-adminrestrict
Provides:	python3-django-adminrestrict-doc
%description help
# Django Admin Restrict

[![build-status-image]][travis]
[![coverage-status-image]][codecov]
[![pypi-version]][pypi]

**Restrict admin pages using simple IP address rules.**

## Overview

``django-adminrestrict`` secures access to the Django admin pages. It works 
by blocking requests for the admin page path unless the requests come from 
specific IP addresses, address ranges or domains that you specify in 
a model. 


## Requirements

``django-adminrestrict`` requires Django 1.4 or later.  The
application is intended improve the security around the Django admin
login pages.

## Installation

Download and install ``django-adminrestrict`` using **one** of the following methods:

### pip

You can install the latest stable package running this command:

    $ pip install django-adminrestrict

### Setuptools

You can install the latest stable package running:

    $ easy_install django-adminrestrict

## Python 3.0 Only

`adminrestrict` requires Python 3.x and no longer supports Python 2.x.

## Development

You can contribute to this project forking it from github and sending pull requests.


## Configuration

First of all, you must add this project to your list of ``INSTALLED_APPS`` in
``settings.py``

    INSTALLED_APPS = (
        'django.contrib.admin',
        'django.contrib.auth',
        'django.contrib.contenttypes',
        'django.contrib.sessions',
        'django.contrib.sites',
        ...
        'adminrestrict',
        ...
    )

Next, install the ``AdminPagesRestrictMiddleware`` middleware:

    MIDDLEWARE_CLASSES = (
        'django.middleware.common.CommonMiddleware',
        'django.contrib.sessions.middleware.SessionMiddleware',
        'django.contrib.auth.middleware.AuthenticationMiddleware',
        'adminrestrict.middleware.AdminPagesRestrictMiddleware',
    )


Create the appropriate tables in your database that are necessary for operation.

For django(<1.7), run ``python manage.py syncdb``.

For django(>=1.7), run ``python manage.py makemigrations adminrestrict; python manage.py migrate``. 

IMPORTANT: When the package is configured in your project, an empty table called `AllowedIP`
will be created in your database. If this table is empty or has one record with
a "\*" the package will not restrict any IPs. If you want to add specific restrictions
please go to the next section.

## Usage

Using ``django-adminrestrict`` is extremely simple.  Once you install the application
and the middleware, all you need to do is update the allowed IP addresses `AllowedIP`
section of the admin pages.

### Adding allowed IP addresses

Login to the admin pages and browse to the Adminrestrict app, and
start creating recorded in the `AllowedIP` table.  Just type in the IP
addresses and save them. These will be single IPv4 addresses that are
permitted to access the pages.


### Managing allowed IP addresses from command line

Use the management commands to add and remove allowed IP addresses from the command line:

``python manage.py addadminip 10.10.10.10``

``python manage.py removeadminip 10.10.10.10``


### Adding allowed IP addresses with wildcards

Create a `AllowedIP` entries ending with a "\*" to any IPs that start
with the specified pattern. For example, adding `192.*` would allow
addreses starting matching 192.*.*.* to access the admin pages.

### Adding allowed IP addresses using CIDR ranges

Create a `AllowedIP` entries denoted in CIDR notation, to indicate a range 
of IP addresses that would be allowed to login/access the admin pages.
For example, a CIDR range with a suffix indicating the number of bits 
of the prefix, such as `192.0.2.0/24` for IPv4 or `2001:0db8:85a3:0000::/64` for IPv6 would indicate an 
entire subnet allowed to access the admin pages.
### Adding allowed IP addresses using domain names

Create `AllowedIP` records with domain names starting with a lower-case or upper-case character. These domain names' corresponding IP addresses
will be allowed to access the admin pages. Recommended use case: dynamic 
DNS domain names.

### Adding * to disable all restrictions

Create a single `AllowedIP` record with "\*" as the IP address, to
temporarily disable restrictions. In this way, you do not have to
modify settings.py and remove the middleware if you need to disable.

Having at least one `AllowedIP` record with * as the IP address
effectively disables all restrictions.

## Advanced Settings

There are a few advanced settings that can be engaged by adding them
to your project's `settings.py` file:

`ADMINRESTRICT_BLOCK_GET=True` will block all GET requests to admin urls.  By default, `adminrestrict` only blocks the POST method to block logins only, which is usually sufficient, because GET will redirect to the login page anyway. 

`ADMINRESTRICT_ENABLE_CACHE=True` will cause `adminrestrict` to cache some of the IP addresses retrieved from the AllowedIP model to reduce read query load on your database.  When any update gets made to AllowedIP models, the cache is auto-refreshed. 

`ADMINRESTRICT_DENIED_MSG="Custom denied msg."` will let you set the response body of the 403 HTTP 
result when a request is denied. By default, the message is **"Access to admin is denied."**

`ADMINRESTRICT_ALLOW_PRIVATE_IP=True` will allow all private IP addresses to access
the admin pages, regardless of whether the request IP matches any pattern or IP address
in the AllowedIP model.  Note: private IP addresses are those which comply with [RFC1918](https://tools.ietf.org/html/rfc1918).

[build-status-image]: https://secure.travis-ci.org/robromano/django-adminrestrict.svg?branch=master
[travis]: https://travis-ci.org/robromano/django-adminrestrict?branch=master
[pypi-version]: https://badge.fury.io/py/django-adminrestrict.svg
[pypi]: https://pypi.org/project/django-adminrestrict/
[coverage-status-image]: https://img.shields.io/codecov/c/github/robromano/django-adminrestrict/master.svg
[codecov]: https://codecov.io/github/robromano/django-adminrestrict?branch=master

%prep
%autosetup -n django-adminrestrict-3.1

%build
%py3_build

%install
%py3_install
install -d -m755 %{buildroot}/%{_pkgdocdir}
if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi
if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi
if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi
if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi
pushd %{buildroot}
if [ -d usr/lib ]; then
	find usr/lib -type f -printf "\"/%h/%f\"\n" >> filelist.lst
fi
if [ -d usr/lib64 ]; then
	find usr/lib64 -type f -printf "\"/%h/%f\"\n" >> filelist.lst
fi
if [ -d usr/bin ]; then
	find usr/bin -type f -printf "\"/%h/%f\"\n" >> filelist.lst
fi
if [ -d usr/sbin ]; then
	find usr/sbin -type f -printf "\"/%h/%f\"\n" >> filelist.lst
fi
touch doclist.lst
if [ -d usr/share/man ]; then
	find usr/share/man -type f -printf "\"/%h/%f.gz\"\n" >> doclist.lst
fi
popd
mv %{buildroot}/filelist.lst .
mv %{buildroot}/doclist.lst .

%files -n python3-django-adminrestrict -f filelist.lst
%dir %{python3_sitelib}/*

%files help -f doclist.lst
%{_docdir}/*

%changelog
* Thu Jun 08 2023 Python_Bot <Python_Bot@openeuler.org> - 3.1-1
- Package Spec generated