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
serverStatus/__init__.py Normal file
View File

BIN
serverStatus/__init__.pyc Normal file

Binary file not shown.

6
serverStatus/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
serverStatus/admin.pyc Normal file

Binary file not shown.

8
serverStatus/apps.py Normal file
View File

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

View File

6
serverStatus/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
serverStatus/models.pyc Normal file

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 933 B

View File

@@ -0,0 +1,279 @@
/**
* Created by usman on 7/31/17.
*/
/* Java script code to start/stop litespeed */
app.controller('litespeedStatus', function($scope,$http) {
$scope.restartorStopLoading = true;
$scope.actionResult = true;
$scope.actionResultBad = true;
$scope.serverStatusCouldNotConnect = true;
$scope.restartLitespeed = function(){
$scope.disableReboot = true;
$scope.disableStop = true;
$scope.restartorStopLoading = false;
var url = "/serverstatus/startorstopLitespeed";
var data = {
reboot:1,
};
var config = {
headers : {
'X-CSRFToken': getCookie('csrftoken')
}
};
$http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas);
function ListInitialDatas(response) {
$scope.restartorStopLoading = true;
$scope.disableReboot = false;
$scope.disableStop = false;
if(response.data.reboot == 1){
$scope.restartorStopLoading = true;
$scope.actionResult = false;
$scope.actionResultBad = true;
$scope.serverStatusCouldNotConnect = true;
}
else{
$scope.restartorStopLoading = true;
$scope.actionResult = true;
$scope.actionResultBad = false;
$scope.serverStatusCouldNotConnect = true;
}
}
function cantLoadInitialDatas(response) {
$scope.restartorStopLoading = true;
$scope.actionResult = true;
$scope.actionResultBad = true;
$scope.serverStatusCouldNotConnect = false;
$scope.disableReboot = false;
$scope.disableStop = false;
}
};
$scope.stopLitespeed = function(){
$scope.disableReboot = true;
$scope.disableStop = true;
$scope.restartorStopLoading = false;
var url = "/serverstatus/startorstopLitespeed";
var data = {
reboot:0,
};
var config = {
headers : {
'X-CSRFToken': getCookie('csrftoken')
}
};
$http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas);
function ListInitialDatas(response) {
$scope.restartorStopLoading = true;
$scope.disableReboot = false;
$scope.disableStop = false;
if(response.data.shutdown == 1){
$scope.restartorStopLoading = true;
$scope.actionResult = false;
$scope.actionResultBad = true;
$scope.serverStatusCouldNotConnect = true;
}
else{
$scope.restartorStopLoading = true;
$scope.actionResult = true;
$scope.actionResultBad = false;
$scope.serverStatusCouldNotConnect = true;
}
}
function cantLoadInitialDatas(response) {
$scope.restartorStopLoading = true;
$scope.actionResult = true;
$scope.actionResultBad = true;
$scope.serverStatusCouldNotConnect = false;
$scope.disableReboot = false;
$scope.disableStop = false;
}
};
});
/* Java script code to start/stop litespeed */
/* Java script code to read log file */
app.controller('readCyberCPLogFile', function($scope,$http) {
$scope.logFileLoading = false;
$scope.logsFeteched = true;
$scope.couldNotFetchLogs = true;
var url = "/serverstatus/getFurtherDataFromLogFile";
var data = {};
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 = "/serverstatus/getFurtherDataFromLogFile";
var data = {};
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,72 @@
{% extends "baseTemplate/index.html" %}
{% load i18n %}
{% block title %}{% trans "CyberPanel Main Log File - 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 "CyberPanel Main Log File" %}</h2>
<p>{% trans "This log file corresponds to errors generated by CyberPanel for your domain errors log you can look into /home/domain/logs." %}</p>
</div>
<div ng-controller="readCyberCPLogFile" 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,57 @@
{% extends "baseTemplate/index.html" %}
{% load i18n %}
{% block title %}{% trans "Server Status - 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 Status" %}</h2>
<p>{% trans "View LiteSpeed status and log files." %}</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-4">
<a href="{% url 'litespeedStatus' %}" title="{% trans 'LiteSpeed Status' %}" class="tile-box tile-box-shortcut btn-primary">
<div class="tile-header">
{% trans "LiteSpeed Status" %}
</div>
<div class="tile-content-wrapper">
<i class="glyph-icon icon-dashboard"></i>
</div>
</a>
</div>
<div class="col-md-4">
<a href="{% url 'cyberCPMainLogFile' %}" title="{% trans 'CyberPanel Main Log File' %}" class="tile-box tile-box-shortcut btn-primary">
<div class="tile-header">
{% trans "CyberPanel Main Log File" %}
</div>
<div class="tile-content-wrapper">
<i class="glyph-icon icon-dashboard"></i>
</div>
</a>
</div>
</div>
</div>
</div>
</div>
</div>
{% endblock %}

View File

@@ -0,0 +1,140 @@
{% extends "baseTemplate/index.html" %}
{% load i18n %}
{% block title %}{% trans "LiteSpeed Status - 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 "LiteSpeed Status:" %} <img src="{% static 'images/lsON.png' %}"></h2>
<p>{% trans "On this page you can get information regarding your LiteSpeed processes." %}</p>
</div>
<div class="row">
<div class="panel">
<div class="panel-body">
<div ng-controller="litespeedStatus" class="col-md-6">
<div class="example-box-wrapper">
{% if processList %}
<h3 class="content-box-header bg-black">
{% trans "LiteSpeed Processes" %}
</h3>
<table class="table">
<thead>
<tr>
<th>#</th>
<th>{% trans "Process ID" %}</th>
<th>{% trans "Name" %}</th>
</tr>
</thead>
<tbody>
{% for items in processList %}
<tr>
<td>{{ forloop.counter }}</td>
<td> {{ items }}</td>
{% if forloop.counter == 1 %}
<td>{% trans "Main Process" %}</td>
{% elif forloop.counter == 2 %}
<td>{% trans "lscgid Process" %}</td>
{% else %}
<td>{% trans "Worker Process" %}</td>
{% endif %}
{% endfor %}
</tr>
</tbody>
</table>
{% else %}
<div class="alert alert-danger">
<p>{% trans "Could not fetch details, either LiteSpeed is not running or some error occurred, please see CyberPanel Main log file." %}</p>
</div>
{% endif %}
<button ng-click="restartLitespeed()" ng-disabled="disableReboot" class="btn btn-alt btn-hover btn-blue-alt">
<span>{% trans "Reboot Litespeed" %}</span>
<i class="glyph-icon icon-arrow-right"></i>
</button>
<button ng-click="stopLitespeed()" ng-disable="disableStop" class="btn btn-alt btn-hover btn-danger">
<span>{% trans "Stop LiteSpeed" %}</span>
<i class="glyph-icon icon-arrow-right"></i>
</button>
<img ng-hide="restartorStopLoading" src="{% static 'images/loading.gif' %}">
<div ng-hide="actionResult" class="alert alert-success">
<p>{% trans "Action successful." %}</p>
</div>
<div ng-hide="actionResultBad" class="alert alert-danger">
<p>{% trans "Error Occurred. See CyberPanel main log file." %}</p>
</div>
<div ng-hide="serverStatusCouldNotConnect" class="alert alert-danger">
<p>{% trans "Could not connect to server." %}</p>
</div>
</div>
</div>
<div class="col-md-6">
<div class="example-box-wrapper">
<h3 class="content-box-header bg-black">
Version: {{ lsversion }}
</h3>
<div class="content-box-wrapper">
<table class="table">
<thead>
<tr>
<th>{{ modules }}</th>
</tr>
</thead>
<tbody>
{% for items in loadedModules %}
<tr>
<td>{{ items }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
{% endblock %}

6
serverStatus/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.

13
serverStatus/urls.py Normal file
View File

@@ -0,0 +1,13 @@
from django.conf.urls import url
import views
urlpatterns = [
url(r'^$', views.serverStatusHome, name='serverStatusHome'),
url(r'^litespeedStatus', views.litespeedStatus, name='litespeedStatus'),
url(r'^startorstopLitespeed', views.stopOrRestartLitespeed, name='startorstopLitespeed'),
url(r'^cyberCPMainLogFile', views.cyberCPMainLogFile, name='cyberCPMainLogFile'),
url(r'^getFurtherDataFromLogFile',views.getFurtherDataFromLogFile,name='getFurtherDataFromLogFile'),
]

153
serverStatus/views.py Normal file
View File

@@ -0,0 +1,153 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.shortcuts import render,redirect
from django.http import HttpResponse
from plogical.processUtilities import ProcessUtilities
import plogical.CyberCPLogFileWriter as logging
from loginSystem.views import loadLoginPage
import json
import subprocess
from loginSystem.models import Administrator
# Create your views here.
def serverStatusHome(request):
try:
userID = request.session['userID']
admin = Administrator.objects.get(pk=userID)
if admin.type == 3:
return HttpResponse("You don't have enough priviliges to access this page.")
return render(request,'serverStatus/index.html')
except KeyError:
return redirect(loadLoginPage)
def litespeedStatus(request):
try:
userID = request.session['userID']
admin = Administrator.objects.get(pk=userID)
if admin.type == 3:
return HttpResponse("You don't have enough priviliges to access this page.")
processList = ProcessUtilities.getLitespeedProcessNumber()
try:
versionInformation = subprocess.check_output(["/usr/local/lsws/bin/lshttpd", "-v"]).split("\n")
lsversion = versionInformation[0]
modules = versionInformation[1]
counter = 0
loadedModules = []
for items in versionInformation:
if counter == 0 or counter == 1:
counter = counter + 1
continue
else:
loadedModules.append(items)
except subprocess.CalledProcessError,msg:
logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[litespeedStatus]")
return render(request,"serverStatus/litespeedStatus.html",{"processList":processList,"liteSpeedVersionStatus":"For some reaons not able to load version details, see CyberCP main log file."})
if(processList!=0):
dataForHtml = {"processList": processList, "lsversion": lsversion, "modules": modules,
"loadedModules": loadedModules}
return render(request,"serverStatus/litespeedStatus.html",dataForHtml)
else:
dataForHtml = {"lsversion": lsversion, "modules": modules,
"loadedModules": loadedModules}
return render(request, "serverStatus/litespeedStatus.html",dataForHtml)
except KeyError,msg:
logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[litespeedStatus]")
return redirect(loadLoginPage)
def stopOrRestartLitespeed(request):
try:
userID = request.session['userID']
admin = Administrator.objects.get(pk=userID)
if admin.type == 3:
return HttpResponse("You don't have enough priviliges to access this page.")
data = json.loads(request.body)
reboot = data['reboot']
if reboot==1:
if ProcessUtilities.restartLitespeed() == 1:
status = {"reboot":1,"shutdown":0}
else:
status = {"reboot": 0, "shutdown": 0, "error_message":"Please see CyberCP main log file."}
else:
if ProcessUtilities.stopLitespeed() == 1:
status = {"reboot":0,"shutdown":1}
else:
status = {"reboot": 0, "shutdown": 0, "error_message":"Please see CyberCP main log file."}
final_json = json.dumps(status)
return HttpResponse(final_json)
except KeyError, msg:
status = {"reboot": 0, "shutdown": 0, "error_message": "Not logged in as admin"}
logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[stopOrRestartLitespeed]")
return HttpResponse("Not Logged in as admin")
def cyberCPMainLogFile(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,'serverStatus/cybercpmainlogfile.html')
except KeyError,msg:
logging.CyberCPLogFileWriter.writeToFile(str(msg) + "[cyberCPMainLogFile]")
return redirect(loadLoginPage)
def getFurtherDataFromLogFile(request):
try:
val = request.session['userID']
fewLinesOfLogFile = logging.CyberCPLogFileWriter.readLastNFiles(50,logging.CyberCPLogFileWriter.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) + "[getFurtherDataFromLogFile]")
return HttpResponse("Not Logged in as admin")