Rework Dirs
This commit is contained in:
0
Web Development & Frameworks/Django/db.sqlite3
Normal file
0
Web Development & Frameworks/Django/db.sqlite3
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
3
Web Development & Frameworks/Django/info/admin.py
Normal file
3
Web Development & Frameworks/Django/info/admin.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
6
Web Development & Frameworks/Django/info/apps.py
Normal file
6
Web Development & Frameworks/Django/info/apps.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class InfoConfig(AppConfig):
|
||||
default_auto_field = "django.db.models.BigAutoField"
|
||||
name = "info"
|
||||
3
Web Development & Frameworks/Django/info/models.py
Normal file
3
Web Development & Frameworks/Django/info/models.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
24
Web Development & Frameworks/Django/info/serializers.py
Normal file
24
Web Development & Frameworks/Django/info/serializers.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from rest_framework import serializers
|
||||
|
||||
class MemoryInfoSerializer(serializers.Serializer):
|
||||
total = serializers.IntegerField()
|
||||
available = serializers.IntegerField()
|
||||
percent = serializers.FloatField()
|
||||
used = serializers.IntegerField()
|
||||
free = serializers.IntegerField()
|
||||
active = serializers.IntegerField()
|
||||
inactive = serializers.IntegerField()
|
||||
buffers = serializers.IntegerField()
|
||||
cached = serializers.IntegerField()
|
||||
shared = serializers.IntegerField()
|
||||
|
||||
|
||||
class CpuInfoSerializer(serializers.Serializer):
|
||||
info = serializers.FloatField()
|
||||
|
||||
class HardInfoSerializer(serializers.Serializer):
|
||||
total = serializers.IntegerField()
|
||||
used = serializers.IntegerField()
|
||||
free = serializers.IntegerField()
|
||||
percent = serializers.FloatField()
|
||||
|
||||
3
Web Development & Frameworks/Django/info/tests.py
Normal file
3
Web Development & Frameworks/Django/info/tests.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
7
Web Development & Frameworks/Django/info/urls.py
Normal file
7
Web Development & Frameworks/Django/info/urls.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from django.urls import path
|
||||
from .views import *
|
||||
urlpatterns = [
|
||||
path("memory", MemoryInfoView.as_view(),name="memory"),
|
||||
path("cpu", CpuInfoView.as_view(),name="cpu"),
|
||||
path("hard",HardInfoView.as_view(),name='hard'),
|
||||
]
|
||||
34
Web Development & Frameworks/Django/info/views.py
Normal file
34
Web Development & Frameworks/Django/info/views.py
Normal file
@@ -0,0 +1,34 @@
|
||||
from django.shortcuts import render
|
||||
from rest_framework.views import APIView
|
||||
from rest_framework.response import Response
|
||||
from .serializers import *
|
||||
import psutil
|
||||
import os
|
||||
# Create your views here.
|
||||
|
||||
class MemoryInfoView(APIView):
|
||||
def get(self, request, *args, **kwargs):
|
||||
memo_info = psutil.virtual_memory()._asdict()
|
||||
seri = MemoryInfoSerializer(data=memo_info)
|
||||
if seri.is_valid():
|
||||
return Response(seri.data)
|
||||
return Response(seri.errors,status=400)
|
||||
|
||||
|
||||
class CpuInfoView(APIView):
|
||||
def get(self, request, *args, **kwargs):
|
||||
cpu_info = psutil.cpu_percent()
|
||||
info = {"info":cpu_info}
|
||||
seri= CpuInfoSerializer(data=info)
|
||||
if seri.is_valid():
|
||||
return Response(seri.data)
|
||||
return Response(seri.errors,status=400)
|
||||
|
||||
class HardInfoView(APIView):
|
||||
def get(self,request,*args,**kwargs):
|
||||
hard_info = psutil.disk_usage(os.getcwd())._asdict()
|
||||
seri = HardInfoSerializer(data=hard_info)
|
||||
if seri.is_valid():
|
||||
return Response(seri.data)
|
||||
return Response(seri.errors,status=400)
|
||||
|
||||
22
Web Development & Frameworks/Django/manage.py
Executable file
22
Web Development & Frameworks/Django/manage.py
Executable file
@@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env python
|
||||
"""Django's command-line utility for administrative tasks."""
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
||||
def main():
|
||||
"""Run administrative tasks."""
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "sysinfo.settings")
|
||||
try:
|
||||
from django.core.management import execute_from_command_line
|
||||
except ImportError as exc:
|
||||
raise ImportError(
|
||||
"Couldn't import Django. Are you sure it's installed and "
|
||||
"available on your PYTHONPATH environment variable? Did you "
|
||||
"forget to activate a virtual environment?"
|
||||
) from exc
|
||||
execute_from_command_line(sys.argv)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
40
Web Development & Frameworks/Django/sys_info.md
Normal file
40
Web Development & Frameworks/Django/sys_info.md
Normal file
@@ -0,0 +1,40 @@
|
||||
جمعآوری اطلاعات سیستم با استفاده از Django و Django Rest Framework
|
||||
مقدمه
|
||||
در این پروژه، از Django و Django Rest Framework استفاده شدهاست تا اطلاعاتی از سیستم مانند CPU، حافظه و ... جمعآوری شود.
|
||||
|
||||
راهاندازی
|
||||
نصب مورد نیازها
|
||||
برای نصب وابستگیهای مورد نیاز:
|
||||
|
||||
bash
|
||||
Copy code
|
||||
pip install -r requirements.txt
|
||||
راهاندازی دیتابیس
|
||||
برای مهاجرت دیتابیس، دستورات زیر را اجرا کنید:
|
||||
|
||||
bash
|
||||
Copy code
|
||||
python manage.py makemigrations
|
||||
python manage.py migrate
|
||||
اجرای سرور
|
||||
برای اجرای سرور توسط Django:
|
||||
|
||||
bash
|
||||
Copy code
|
||||
python manage.py runserver
|
||||
API ها
|
||||
دریافت اطلاعات CPU
|
||||
|
||||
URL: /api/cpu_info/
|
||||
روش: GET
|
||||
خروجی: اطلاعات مربوط به CPU
|
||||
دریافت اطلاعات حافظه
|
||||
|
||||
URL: /api/memory_info/
|
||||
روش: GET
|
||||
خروجی: اطلاعات مربوط به حافظه
|
||||
... (و همین طور برای سایر API ها)
|
||||
|
||||
جمعبندی
|
||||
این پروژه به شما امکان میدهد تا با استفاده از یک وب API ساده، اطلاعات مختلف سیستم را مشاهده کنید.
|
||||
|
||||
BIN
Web Development & Frameworks/LaravelAPI/LearnAPI.zip
Normal file
BIN
Web Development & Frameworks/LaravelAPI/LearnAPI.zip
Normal file
Binary file not shown.
77
Web Development & Frameworks/LaravelOnNginx/LaravelOnNginx
Normal file
77
Web Development & Frameworks/LaravelOnNginx/LaravelOnNginx
Normal file
@@ -0,0 +1,77 @@
|
||||
1. Install Nginx:
|
||||
- Update the package list: `sudo apt update`
|
||||
- Install Nginx: `sudo apt install nginx`
|
||||
|
||||
2. Configure Nginx:
|
||||
- Open the default Nginx configuration file: `sudo nano /etc/nginx/sites-available/default`
|
||||
- Replace the existing content with the following configuration:
|
||||
|
||||
```
|
||||
server {
|
||||
listen 80;
|
||||
server_name your_domain.com;
|
||||
root /var/www/html/your_laravel_project/public;
|
||||
|
||||
index index.php index.html index.htm;
|
||||
|
||||
location / {
|
||||
try_files $uri $uri/ /index.php?$query_string;
|
||||
}
|
||||
|
||||
location ~ \.php$ {
|
||||
include snippets/fastcgi-php.conf;
|
||||
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; # Adjust version if needed
|
||||
}
|
||||
|
||||
location ~ /\.ht {
|
||||
deny all;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
3. Save and close the file.
|
||||
|
||||
4. Test the Nginx configuration for syntax errors: `sudo nginx -t`
|
||||
|
||||
5. If there are no errors, restart Nginx to apply the changes: `sudo systemctl restart nginx`
|
||||
|
||||
6. Install PHP and required extensions:
|
||||
- Add the Ondřej Surý PPA repository: `sudo add-apt-repository ppa:ondrej/php`
|
||||
- Update the package list again: `sudo apt update`
|
||||
- Install PHP and required extensions (adjust version if needed):
|
||||
```
|
||||
sudo apt install php7.4-fpm php7.4-mbstring php7.4-xml php7.4-zip php7.4-mysql php7.4-curl php7.4-gd
|
||||
```
|
||||
|
||||
7. Install Composer:
|
||||
- Download and install Composer globally:
|
||||
```
|
||||
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
|
||||
```
|
||||
|
||||
8. Clone or upload your Laravel project to `/var/www/html/your_laravel_project` directory.
|
||||
|
||||
9. Set appropriate permissions for Laravel directories:
|
||||
```
|
||||
cd /var/www/html/your_laravel_project
|
||||
sudo chown -R www-data:www-data storage bootstrap/cache
|
||||
sudo chmod -R 775 storage bootstrap/cache
|
||||
```
|
||||
|
||||
10. Install project dependencies using Composer:
|
||||
```
|
||||
cd /var/www/html/your_laravel_project
|
||||
composer install --no-dev --optimize-autoloader
|
||||
```
|
||||
|
||||
11. Generate an application key for Laravel:
|
||||
```
|
||||
cd /var/www/html/your_laravel_project
|
||||
php artisan key:generate
|
||||
```
|
||||
|
||||
12. Restart PHP-FPM service to apply changes: `sudo systemctl restart php7.x-fpm` (replace x with your PHP version)
|
||||
|
||||
That's it! Your Laravel application should now be deployed on Nginx successfully.
|
||||
|
||||
Note: Make sure to replace "your_domain.com" with your actual domain name or IP address in step 2, and adjust any other configurations as per your specific requirements.
|
||||
Reference in New Issue
Block a user