Initial Commit

This commit is contained in:
usmannasir
2017-10-24 19:16:36 +05:00
commit 11eae3f9fe
2124 changed files with 528735 additions and 0 deletions

0
serverLogs/__init__.py Normal file
View File

BIN
serverLogs/__init__.pyc Normal file

Binary file not shown.

6
serverLogs/admin.py Normal file
View File

@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.contrib import admin
# Register your models here.

BIN
serverLogs/admin.pyc Normal file

Binary file not shown.

8
serverLogs/apps.py Normal file
View File

@@ -0,0 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.apps import AppConfig
class ServerlogsConfig(AppConfig):
name = 'serverLogs'

View File

6
serverLogs/models.py Normal file
View File

@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models
# Create your models here.

BIN
serverLogs/models.pyc Normal file

Binary file not shown.

View File

@@ -0,0 +1,518 @@
/**
* Created by usman on 7/31/17.
*/
/* Java script code to read access log file */
app.controller('readAccessLogs', function($scope,$http) {
$scope.logFileLoading = false;
$scope.logsFeteched = true;
$scope.couldNotFetchLogs = true;
var url = "/serverlogs/getLogsFromFile";
var data = {
type:"access"
};
var config = {
headers : {
'X-CSRFToken': getCookie('csrftoken')
}
};
$http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas);
function ListInitialDatas(response) {
if(response.data.logstatus == 1){
$scope.logFileLoading = true;
$scope.logsFeteched = false;
$scope.couldNotFetchLogs = true;
$scope.logsData = response.data.logsdata;
}
else{
$scope.logFileLoading = true;
$scope.logsFeteched = true;
$scope.couldNotFetchLogs = false;
}
}
function cantLoadInitialDatas(response) {
$scope.logFileLoading = true;
$scope.logsFeteched = true;
$scope.couldNotFetchLogs = false;
}
$scope.fetchLogs = function(){
$scope.logFileLoading = false;
$scope.logsFeteched = true;
$scope.couldNotFetchLogs = true;
var url = "/serverlogs/getLogsFromFile";
var data = {
type:"access"
};
var config = {
headers : {
'X-CSRFToken': getCookie('csrftoken')
}
};
$http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas);
function ListInitialDatas(response) {
if(response.data.logstatus == 1){
$scope.logFileLoading = true;
$scope.logsFeteched = false;
$scope.couldNotFetchLogs = true;
$scope.logsData = response.data.logsdata;
}
else{
$scope.logFileLoading = true;
$scope.logsFeteched = true;
$scope.couldNotFetchLogs = false;
}
}
function cantLoadInitialDatas(response) {
$scope.logFileLoading = true;
$scope.logsFeteched = true;
$scope.couldNotFetchLogs = false;
}
};
});
/* Java script code to read log file ends here */
/* Java script code to read error log file */
app.controller('readErrorLogs', function($scope,$http) {
$scope.logFileLoading = false;
$scope.logsFeteched = true;
$scope.couldNotFetchLogs = true;
var url = "/serverlogs/getLogsFromFile";
var data = {
type:"error"
};
var config = {
headers : {
'X-CSRFToken': getCookie('csrftoken')
}
};
$http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas);
function ListInitialDatas(response) {
if(response.data.logstatus == 1){
$scope.logFileLoading = true;
$scope.logsFeteched = false;
$scope.couldNotFetchLogs = true;
$scope.logsData = response.data.logsdata;
}
else{
$scope.logFileLoading = true;
$scope.logsFeteched = true;
$scope.couldNotFetchLogs = false;
}
}
function cantLoadInitialDatas(response) {
$scope.logFileLoading = true;
$scope.logsFeteched = true;
$scope.couldNotFetchLogs = false;
}
$scope.fetchLogs = function(){
$scope.logFileLoading = false;
$scope.logsFeteched = true;
$scope.couldNotFetchLogs = true;
var url = "/serverlogs/getLogsFromFile";
var data = {
type:"error"
};
var config = {
headers : {
'X-CSRFToken': getCookie('csrftoken')
}
};
$http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas);
function ListInitialDatas(response) {
if(response.data.logstatus == 1){
$scope.logFileLoading = true;
$scope.logsFeteched = false;
$scope.couldNotFetchLogs = true;
$scope.logsData = response.data.logsdata;
}
else{
$scope.logFileLoading = true;
$scope.logsFeteched = true;
$scope.couldNotFetchLogs = false;
}
}
function cantLoadInitialDatas(response) {
$scope.logFileLoading = true;
$scope.logsFeteched = true;
$scope.couldNotFetchLogs = false;
}
};
});
/* Java script code to read log file ends here */
/* Java script code to read ftp log file */
app.controller('readFTPLogs', function($scope,$http) {
$scope.logFileLoading = false;
$scope.logsFeteched = true;
$scope.couldNotFetchLogs = true;
var url = "/serverlogs/getLogsFromFile";
var data = {
type:"ftp"
};
var config = {
headers : {
'X-CSRFToken': getCookie('csrftoken')
}
};
$http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas);
function ListInitialDatas(response) {
if(response.data.logstatus == 1){
$scope.logFileLoading = true;
$scope.logsFeteched = false;
$scope.couldNotFetchLogs = true;
$scope.logsData = response.data.logsdata;
}
else{
$scope.logFileLoading = true;
$scope.logsFeteched = true;
$scope.couldNotFetchLogs = false;
}
}
function cantLoadInitialDatas(response) {
$scope.logFileLoading = true;
$scope.logsFeteched = true;
$scope.couldNotFetchLogs = false;
}
$scope.fetchLogs = function(){
$scope.logFileLoading = false;
$scope.logsFeteched = true;
$scope.couldNotFetchLogs = true;
var url = "/serverlogs/getLogsFromFile";
var data = {
type:"ftp"
};
var config = {
headers : {
'X-CSRFToken': getCookie('csrftoken')
}
};
$http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas);
function ListInitialDatas(response) {
if(response.data.logstatus == 1){
$scope.logFileLoading = true;
$scope.logsFeteched = false;
$scope.couldNotFetchLogs = true;
$scope.logsData = response.data.logsdata;
}
else{
$scope.logFileLoading = true;
$scope.logsFeteched = true;
$scope.couldNotFetchLogs = false;
}
}
function cantLoadInitialDatas(response) {
$scope.logFileLoading = true;
$scope.logsFeteched = true;
$scope.couldNotFetchLogs = false;
}
};
});
/* Java script code to read log file ends here */
/* Java script code to read email log file */
app.controller('readEmailLogs', function($scope,$http) {
$scope.logFileLoading = false;
$scope.logsFeteched = true;
$scope.couldNotFetchLogs = true;
var url = "/serverlogs/getLogsFromFile";
var data = {
type:"email"
};
var config = {
headers : {
'X-CSRFToken': getCookie('csrftoken')
}
};
$http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas);
function ListInitialDatas(response) {
if(response.data.logstatus == 1){
$scope.logFileLoading = true;
$scope.logsFeteched = false;
$scope.couldNotFetchLogs = true;
$scope.logsData = response.data.logsdata;
}
else{
$scope.logFileLoading = true;
$scope.logsFeteched = true;
$scope.couldNotFetchLogs = false;
}
}
function cantLoadInitialDatas(response) {
$scope.logFileLoading = true;
$scope.logsFeteched = true;
$scope.couldNotFetchLogs = false;
}
$scope.fetchLogs = function(){
$scope.logFileLoading = false;
$scope.logsFeteched = true;
$scope.couldNotFetchLogs = true;
var url = "/serverlogs/getLogsFromFile";
var data = {
type:"email"
};
var config = {
headers : {
'X-CSRFToken': getCookie('csrftoken')
}
};
$http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas);
function ListInitialDatas(response) {
if(response.data.logstatus == 1){
$scope.logFileLoading = true;
$scope.logsFeteched = false;
$scope.couldNotFetchLogs = true;
$scope.logsData = response.data.logsdata;
}
else{
$scope.logFileLoading = true;
$scope.logsFeteched = true;
$scope.couldNotFetchLogs = false;
}
}
function cantLoadInitialDatas(response) {
$scope.logFileLoading = true;
$scope.logsFeteched = true;
$scope.couldNotFetchLogs = false;
}
};
});
/* Java script code to read log file ends here */

View File

@@ -0,0 +1,74 @@
{% extends "baseTemplate/index.html" %}
{% load i18n %}
{% block title %}{% trans "Access Logs - CyberPanel" %}{% endblock %}
{% block content %}
{% load static %}
{% get_current_language as LANGUAGE_CODE %}
<!-- Current language: {{ LANGUAGE_CODE }} -->
<div class="container">
<div id="page-title">
<h2>{% trans "Access Logs" %}</h2>
<p>{% trans "Access Logs for main web server." %}</p>
</div>
<div ng-controller="readAccessLogs" class="row">
<div class="panel">
<div class="panel-body">
<h3 class="title-hero">
{% trans "Last 50 Lines" %} <img ng-hide="logFileLoading" src="{% static 'images/loading.gif' %}">
</h3>
<div class="col-md-12">
<form class="form-horizontal bordered-row">
<div class="form-group">
<div class="col-sm-12">
<textarea ng-model="logsData" rows="30" class="form-control">{{ logs }}</textarea>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label"></label>
<div class="col-sm-4">
<button type="button" ng-click="fetchLogs()" class="btn btn-primary btn-lg btn-block">{% trans "Refresh" %}</button>
</div>
</div>
<div ng-hide="logsFeteched" class="alert alert-success">
<p>{% trans "Last 50 Lines Fetched" %}</p>
</div>
<div ng-hide="couldNotFetchLogs" class="alert alert-danger">
<p>{% trans "Could not fetch logs. Use the command line to view the log file." %}</p>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
{% endblock %}

View File

@@ -0,0 +1,71 @@
{% extends "baseTemplate/index.html" %}
{% load i18n %}
{% block title %}{% trans "Error Logs - CyberPanel" %}{% endblock %}
{% block content %}
{% load static %}
{% get_current_language as LANGUAGE_CODE %}
<!-- Current language: {{ LANGUAGE_CODE }} -->
<div class="container">
<div id="page-title">
<h2>{% trans "Email Logs" %}</h2>
<p>{% trans "Email Logs for main web server." %}</p>
</div>
<div ng-controller="readEmailLogs" class="row">
<div class="panel">
<div class="panel-body">
<h3 class="title-hero">
{% trans "Last 50 Lines" %} <img ng-hide="logFileLoading" src="{% static 'images/loading.gif' %}">
</h3>
<div class="col-md-12">
<form class="form-horizontal bordered-row">
<div class="form-group">
<div class="col-sm-12">
<textarea ng-model="logsData" rows="30" class="form-control">{{ logs }}</textarea>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label"></label>
<div class="col-sm-4">
<button type="button" ng-click="fetchLogs()" class="btn btn-primary btn-lg btn-block">{% trans "Refresh" %}</button>
</div>
</div>
<div ng-hide="logsFeteched" class="alert alert-success">
<p>{% trans "Last 50 Lines Fetched" %}</p>
</div>
<div ng-hide="couldNotFetchLogs" class="alert alert-danger">
<p>{% trans "Could not fetch logs. Use the command line to view the log file." %}</p>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
{% endblock %}

View File

@@ -0,0 +1,71 @@
{% extends "baseTemplate/index.html" %}
{% load i18n %}
{% block title %}{% trans "Error Logs - CyberPanel" %}{% endblock %}
{% block content %}
{% load static %}
{% get_current_language as LANGUAGE_CODE %}
<!-- Current language: {{ LANGUAGE_CODE }} -->
<div class="container">
<div id="page-title">
<h2>{% trans "Error Logs" %}</h2>
<p>{% trans "Error Logs for main web server." %}</p>
</div>
<div ng-controller="readErrorLogs" class="row">
<div class="panel">
<div class="panel-body">
<h3 class="title-hero">
{% trans "Last 50 Lines" %} <img ng-hide="logFileLoading" src="{% static 'images/loading.gif' %}">
</h3>
<div class="col-md-12">
<form class="form-horizontal bordered-row">
<div class="form-group">
<div class="col-sm-12">
<textarea ng-model="logsData" rows="30" class="form-control">{{ logs }}</textarea>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label"></label>
<div class="col-sm-4">
<button type="button" ng-click="fetchLogs()" class="btn btn-primary btn-lg btn-block">{% trans "Refresh" %}</button>
</div>
</div>
<div ng-hide="logsFeteched" class="alert alert-success">
<p>{% trans "Last 50 Lines Fetched" %}</p>
</div>
<div ng-hide="couldNotFetchLogs" class="alert alert-danger">
<p>{% trans "Could not fetch logs. Use the command line to view the log file." %}</p>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
{% endblock %}

View File

@@ -0,0 +1,68 @@
{% extends "baseTemplate/index.html" %}
{% load i18n %}
{% block title %}{% trans "FTP Logs - CyberPanel" %}{% endblock %}
{% block content %}
{% load static %}
{% get_current_language as LANGUAGE_CODE %}
<!-- Current language: {{ LANGUAGE_CODE }} -->
<div class="container">
<div id="page-title">
<h2>{% trans "FTP Logs" %}</h2>
<p>{% trans "FTP Logs for main web server." %}</p>
</div>
<div ng-controller="readFTPLogs" class="row">
<div class="panel">
<div class="panel-body">
<h3 class="title-hero">
{% trans "Last 50 Lines" %} <img ng-hide="logFileLoading" src="{% static 'images/loading.gif' %}">
</h3>
<div class="col-md-12">
<form class="form-horizontal bordered-row">
<div class="form-group">
<div class="col-sm-12">
<textarea ng-model="logsData" rows="30" class="form-control">{{ logs }}</textarea>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label"></label>
<div class="col-sm-4">
<button type="button" ng-click="fetchLogs()" class="btn btn-primary btn-lg btn-block">{% trans "Refresh" %}</button>
</div>
</div>
<div ng-hide="logsFeteched" class="alert alert-success">
<p>{% trans "Last 50 Lines Fetched" %}</p>
</div>
<div ng-hide="couldNotFetchLogs" class="alert alert-danger">
<p>{% trans "Could not fetch logs. Use the command line to view the log file." %}</p>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
{% endblock %}

View File

@@ -0,0 +1,82 @@
{% extends "baseTemplate/index.html" %}
{% load i18n %}
{% block title %}{% trans "Server Logs - CyberPanel" %}{% endblock %}
{% block content %}
{% load static %}
{% get_current_language as LANGUAGE_CODE %}
<!-- Current language: {{ LANGUAGE_CODE }} -->
<div class="container">
<div id="page-title">
<h2>{% trans "Server Logs" %}</h2>
<p>{% trans "These are the logs from main server, to see logs for your website navigate to: Websites -> List Websites -> Select Website -> View Logs." %}</p>
</div>
<div class="panel">
<div class="panel-body">
<h3 class="title-hero">
{% trans "Available Functions" %}
</h3>
<div class="example-box-wrapper">
<div class="row">
<div class="col-md-6">
<a href="{% url 'accessLogs' %}" title="{% trans 'Access Logs' %}" class="tile-box tile-box-shortcut btn-primary">
<div class="tile-header">
{% trans "Access Logs" %}
</div>
<div class="tile-content-wrapper">
<i class="glyph-icon icon-dashboard"></i>
</div>
</a>
</div>
<div class="col-md-6">
<a href="{% url 'errorLogs' %}" title="{% trans 'Error Logs' %}" class="tile-box tile-box-shortcut btn-primary">
<div class="tile-header">
{% trans "Error Logs" %}
</div>
<div class="tile-content-wrapper">
<i class="glyph-icon icon-dashboard"></i>
</div>
</a>
</div>
</div>
<div class="row">
<div class="col-md-6">
<a href="{% url 'emaillogs' %}" title="{% trans 'Email Logs' %}" class="tile-box tile-box-shortcut btn-primary">
<div class="tile-header">
{% trans "Email Logs" %}
</div>
<div class="tile-content-wrapper">
<i class="glyph-icon icon-dashboard"></i>
</div>
</a>
</div>
<div class="col-md-6">
<a href="{% url 'ftplogs' %}" title="{% trans 'FTP Logs' %}" class="tile-box tile-box-shortcut btn-primary">
<div class="tile-header">
{% trans "FTP Logs" %}
</div>
<div class="tile-content-wrapper">
<i class="glyph-icon icon-dashboard"></i>
</div>
</a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
{% endblock %}

6
serverLogs/tests.py Normal file
View File

@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.test import TestCase
# Create your tests here.

12
serverLogs/urls.py Normal file
View File

@@ -0,0 +1,12 @@
from django.conf.urls import url
import views
urlpatterns = [
url(r'^$', views.logsHome, name='logsHome'),
url(r'^accessLogs', views.accessLogs, name='accessLogs'),
url(r'^errorLogs', views.errorLogs, name='errorLogs'),
url(r'^emaillogs', views.emailLogs, name='emaillogs'),
url(r'^ftplogs', views.ftplogs, name='ftplogs'),
url(r'^getLogsFromFile',views.getLogsFromFile, name="getLogsFromFile"),
]

122
serverLogs/views.py Normal file
View File

@@ -0,0 +1,122 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.shortcuts import render,redirect
from loginSystem.views import loadLoginPage
from django.http import HttpResponse
import json
import plogical.CyberCPLogFileWriter as logging
from plogical.installUtilities import installUtilities
from loginSystem.models import Administrator
# Create your views here.
def logsHome(request):
try:
val = request.session['userID']
except KeyError:
return redirect(loadLoginPage)
return render(request,'serverLogs/index.html')
def accessLogs(request):
try:
val = request.session['userID']
admin = Administrator.objects.get(pk=val)
if admin.type == 3:
return HttpResponse("You don't have enough priviliges to access this page.")
return render(request,'serverLogs/accessLogs.html')
except KeyError,msg:
logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[accessLogs]")
return redirect(loadLoginPage)
def errorLogs(request):
try:
val = request.session['userID']
admin = Administrator.objects.get(pk=val)
if admin.type == 3:
return HttpResponse("You don't have enough priviliges to access this page.")
return render(request,'serverLogs/errorLogs.html')
except KeyError,msg:
logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[accessLogs]")
return redirect(loadLoginPage)
def ftplogs(request):
try:
val = request.session['userID']
admin = Administrator.objects.get(pk=val)
if admin.type == 3:
return HttpResponse("You don't have enough priviliges to access this page.")
return render(request,'serverLogs/ftplogs.html')
except KeyError,msg:
logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[accessLogs]")
return redirect(loadLoginPage)
def emailLogs(request):
try:
val = request.session['userID']
admin = Administrator.objects.get(pk=val)
if admin.type == 3:
return HttpResponse("You don't have enough priviliges to access this page.")
return render(request,'serverLogs/emailLogs.html')
except KeyError,msg:
logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[accessLogs]")
return redirect(loadLoginPage)
def getLogsFromFile(request):
try:
val = request.session['userID']
data = json.loads(request.body)
type = data['type']
if type=="access":
fileName = installUtilities.Server_root_path+"/logs/access.log"
elif type=="error":
fileName = installUtilities.Server_root_path + "/logs/error.log"
elif type=="email":
fileName="/var/log/maillog"
elif type=="ftp":
fileName="/var/log/messages"
fewLinesOfLogFile = logging.CyberCPLogFileWriter.readLastNFiles(50,fileName)
fewLinesOfLogFile = str(fewLinesOfLogFile)
status = {"logstatus":1,"logsdata":fewLinesOfLogFile}
final_json = json.dumps(status)
return HttpResponse(final_json)
except KeyError, msg:
status = {"logstatus":0,"error":"Could not fetch data from log file, please see CyberCP main log file through command line."}
logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[getLogsFromFile]")
return HttpResponse("Not Logged in as admin")