mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2026-05-07 03:36:05 +02:00
Minor bug fixes to Cron.
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
websiteFunctions/static/images/icons/repeat.png
Normal file
BIN
websiteFunctions/static/images/icons/repeat.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.8 KiB |
@@ -2074,7 +2074,8 @@ app.controller('suspendWebsiteControl', function($scope,$http) {
|
||||
/* Java script code to suspend/un-suspend ends here */
|
||||
|
||||
|
||||
/* Java script code to manage cron ends here */
|
||||
|
||||
/* Java script code to manage cron */
|
||||
|
||||
app.controller('manageCronController', function($scope,$http) {
|
||||
$("#manageCronLoading").hide();
|
||||
@@ -2082,11 +2083,11 @@ app.controller('manageCronController', function($scope,$http) {
|
||||
$("#cronTable").hide();
|
||||
$("#saveCronButton").hide();
|
||||
$("#addCronButton").hide();
|
||||
|
||||
|
||||
$("#addCronFailure").hide();
|
||||
$("#cronEditSuccess").hide();
|
||||
$("#fetchCronFailure").hide();
|
||||
|
||||
|
||||
$scope.fetchWebsites = function(){
|
||||
|
||||
$("#manageCronLoading").show();
|
||||
@@ -2109,7 +2110,7 @@ app.controller('manageCronController', function($scope,$http) {
|
||||
$http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas);
|
||||
|
||||
function ListInitialDatas(response) {
|
||||
if (response.data.getWebsiteCron == 0)
|
||||
if (response.data.getWebsiteCron === 0)
|
||||
{
|
||||
console.log(response.data);
|
||||
$scope.errorMessage = response.data.error_message;
|
||||
@@ -2138,7 +2139,7 @@ app.controller('manageCronController', function($scope,$http) {
|
||||
$("#cronEditSuccess").hide();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
$scope.fetchCron = function(cronLine){
|
||||
|
||||
$("#cronTable").show();
|
||||
@@ -2146,14 +2147,14 @@ app.controller('manageCronController', function($scope,$http) {
|
||||
$("#modifyCronForm").show();
|
||||
$("#saveCronButton").show();
|
||||
$("#addCronButton").hide();
|
||||
|
||||
|
||||
$("#addCronFailure").hide();
|
||||
$("#cronEditSuccess").hide();
|
||||
$("#fetchCronFailure").hide();
|
||||
|
||||
|
||||
$scope.line = cronLine;
|
||||
console.log($scope.line);
|
||||
|
||||
|
||||
var websiteToBeModified = $scope.websiteToBeModified;
|
||||
url = "/websites/getCronbyLine";
|
||||
var data = {
|
||||
@@ -2171,7 +2172,7 @@ app.controller('manageCronController', function($scope,$http) {
|
||||
function ListInitialDatas(response) {
|
||||
console.log(response);
|
||||
|
||||
if (response.data.getWebsiteCron == 0)
|
||||
if (response.data.getWebsiteCron === 0)
|
||||
{
|
||||
console.log(response.data);
|
||||
$scope.errorMessage = response.data.error_message;
|
||||
@@ -2207,7 +2208,7 @@ app.controller('manageCronController', function($scope,$http) {
|
||||
$("#cronEditSuccess").hide();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
$scope.populate = function(){
|
||||
splitTime = $scope.defined.split(" ");
|
||||
$scope.minute = splitTime[0];
|
||||
@@ -2216,9 +2217,9 @@ app.controller('manageCronController', function($scope,$http) {
|
||||
$scope.month = splitTime[3];
|
||||
$scope.weekday = splitTime[4];
|
||||
}
|
||||
|
||||
|
||||
$scope.addCronForm = function(){
|
||||
|
||||
|
||||
$("#addCronFailure").hide();
|
||||
$("#cronEditSuccess").hide();
|
||||
$("#fetchCronFailure").hide();
|
||||
@@ -2226,10 +2227,10 @@ app.controller('manageCronController', function($scope,$http) {
|
||||
if (!$scope.websiteToBeModified) {
|
||||
alert("Please select a domain first");
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
$scope.minute = $scope.hour = $scope.monthday = $scope.month = $scope.weekday = $scope.command = $scope.line = "";
|
||||
|
||||
|
||||
$("#cronTable").hide();
|
||||
$("#manageCronLoading").hide();
|
||||
$("#modifyCronForm").show();
|
||||
@@ -2237,17 +2238,16 @@ app.controller('manageCronController', function($scope,$http) {
|
||||
$("#addCronButton").show();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
$scope.addCronFunc = function(){
|
||||
|
||||
$("#manageCronLoading").show();
|
||||
$scope.errorMessage = "test1";
|
||||
$("#addCronFailure").hide();
|
||||
$("#cronEditSuccess").hide();
|
||||
$("#fetchCronFailure").hide();
|
||||
|
||||
|
||||
var websiteToBeModified = $scope.websiteToBeModified;
|
||||
|
||||
|
||||
url = "/websites/addNewCron";
|
||||
var data = {
|
||||
domain : websiteToBeModified,
|
||||
@@ -2269,20 +2269,15 @@ app.controller('manageCronController', function($scope,$http) {
|
||||
function ListInitialDatas(response) {
|
||||
console.log(response);
|
||||
|
||||
if (response.data.addNewCron == 0)
|
||||
if (response.data.addNewCron === 0)
|
||||
{
|
||||
console.log(response.data)
|
||||
$scope.errorMessage = response.data.error_message;
|
||||
console.log($scope.errorMessage)
|
||||
$scope.errorMessage = "test2";
|
||||
console.log(response.data.error_message)
|
||||
$scope.errorMessage = response.data.error_message
|
||||
$("#manageCronLoading").hide();
|
||||
$("#cronEditSuccess").hide();
|
||||
$("#fetchCronFailure").hide();
|
||||
$("#addCronFailure").show();
|
||||
}
|
||||
else{
|
||||
console.log(response.data);
|
||||
$("#cronTable").hide();
|
||||
$("#manageCronLoading").hide();
|
||||
$("#cronEditSuccess").show();
|
||||
@@ -2298,16 +2293,16 @@ app.controller('manageCronController', function($scope,$http) {
|
||||
$("#fetchCronFailure").hide();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
$scope.removeCron = function(line){
|
||||
|
||||
$("#manageCronLoading").show();
|
||||
|
||||
|
||||
$("#addCronFailure").hide();
|
||||
$("#cronEditSuccess").hide();
|
||||
$("#fetchCronFailure").hide();
|
||||
|
||||
|
||||
url = "/websites/remCronbyLine";
|
||||
var data = {
|
||||
domain : $scope.websiteToBeModified,
|
||||
@@ -2324,9 +2319,8 @@ app.controller('manageCronController', function($scope,$http) {
|
||||
function ListInitialDatas(response) {
|
||||
console.log(response);
|
||||
|
||||
if (response.data.remCronbyLine == 0)
|
||||
if (response.data.remCronbyLine === 0)
|
||||
{
|
||||
console.log(response.data)
|
||||
$scope.errorMessage = response.data.error_message;
|
||||
$("#manageCronLoading").hide();
|
||||
$("#cronEditSuccess").hide();
|
||||
@@ -2334,7 +2328,6 @@ app.controller('manageCronController', function($scope,$http) {
|
||||
$("#addCronFailure").show();
|
||||
}
|
||||
else{
|
||||
console.log(response.data);
|
||||
$("#cronTable").hide();
|
||||
$("#manageCronLoading").hide();
|
||||
$("#cronEditSuccess").show();
|
||||
@@ -2350,16 +2343,16 @@ app.controller('manageCronController', function($scope,$http) {
|
||||
$("#fetchCronFailure").hide();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
$scope.modifyCronFunc = function(){
|
||||
|
||||
$("#manageCronLoading").show();
|
||||
$("#addCronFailure").hide();
|
||||
$("#cronEditSuccess").hide();
|
||||
$("#fetchCronFailure").hide();
|
||||
|
||||
|
||||
var websiteToBeModified = $scope.websiteToBeModified;
|
||||
|
||||
|
||||
url = "/websites/saveCronChanges";
|
||||
var data = {
|
||||
domain : websiteToBeModified,
|
||||
@@ -2380,11 +2373,10 @@ app.controller('manageCronController', function($scope,$http) {
|
||||
|
||||
$http.post(url, data,config).then(ListInitialDatas, cantLoadInitialDatas);
|
||||
function ListInitialDatas(response) {
|
||||
console.log(response);
|
||||
|
||||
if (response.data.addNewCron == 0)
|
||||
if (response.data.addNewCron === 0)
|
||||
{
|
||||
console.log(response.data)
|
||||
|
||||
$scope.errorMessage = response.data.error_message;
|
||||
$("#manageCronLoading").hide();
|
||||
$("#cronEditSuccess").hide();
|
||||
@@ -2408,7 +2400,7 @@ app.controller('manageCronController', function($scope,$http) {
|
||||
$("#fetchCronFailure").hide();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
@@ -7,10 +7,10 @@
|
||||
{% get_current_language as LANGUAGE_CODE %}
|
||||
<!-- Current language: {{ LANGUAGE_CODE }} -->
|
||||
|
||||
<div class="container">
|
||||
<div ng-controller="manageCronController" class="container">
|
||||
<div id="page-title">
|
||||
<h2>{% trans "Cron Management" %}</h2>
|
||||
<p>{% trans "Create, edit or delete your cron from this page." %}</p>
|
||||
<p>{% trans "Create, edit or delete your cron jobs from this page." %}</p>
|
||||
</div>
|
||||
|
||||
<div class="panel">
|
||||
@@ -21,7 +21,7 @@
|
||||
<div class="example-box-wrapper">
|
||||
|
||||
|
||||
<form ng-controller="manageCronController" action="/" class="form-horizontal bordered-row">
|
||||
<form action="/" class="form-horizontal bordered-row">
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
@@ -149,20 +149,18 @@
|
||||
{{ messger }}
|
||||
<div class="col-sm-4">
|
||||
<div id="fetchCronFailure" class="alert alert-danger">
|
||||
<p>{% trans "Cannot fetch website details. Error message:" %} {{ errorMessage }}</p>
|
||||
<p>{% trans "Cannot fetch website details. Error message:" %} {$ errorMessage $}</p>
|
||||
</div>
|
||||
|
||||
<div id="addCronFailure" class="alert alert-danger">
|
||||
<p>{% trans "Unable to add/save Cron. Error message:" %} {{ errorMessage }}</p>
|
||||
<p>{% trans "Unable to add/save Cron. Error message:" %} {$ errorMessage $}</p>
|
||||
</div>
|
||||
<div id="cronEditSuccess" class="alert alert-success">
|
||||
<p>{% trans "Cron job saved" %}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</form>
|
||||
|
||||
@@ -16,13 +16,18 @@
|
||||
|
||||
{% if not error %}
|
||||
|
||||
<div class="panel">
|
||||
<div class="panel-body">
|
||||
<h3 class="title-hero">
|
||||
{% trans "Resource Usage" %}
|
||||
</h3>
|
||||
<div class="example-box-wrapper">
|
||||
<div class="row">
|
||||
|
||||
<div class="example-box-wrapper">
|
||||
|
||||
<div style="border-radius: 25px;border-color:#3498db" class="content-box">
|
||||
|
||||
<h3 class="content-box-header bg-blue">
|
||||
{% trans "Resource Usage" %} <img ng-hide="domainLoading" src="/static/images/loading.gif">
|
||||
</h3>
|
||||
|
||||
|
||||
<div class="content-box-wrapper">
|
||||
<div class="row">
|
||||
|
||||
<div class="col-md-6">
|
||||
<table class="table table-bordered">
|
||||
@@ -97,9 +102,11 @@
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
@@ -250,7 +257,7 @@
|
||||
<div class="content-box-wrapper">
|
||||
<div class="row">
|
||||
|
||||
<div class="col-md-6" style="margin-bottom: 2%;">
|
||||
<div class="col-md-4" style="margin-bottom: 2%;">
|
||||
<a href="" ng-click="showCreateDomainForm()" title="{% trans 'Add Domains' %}" href="" >
|
||||
<img src="{% static 'images/icons/domains.png' %}">
|
||||
</a>
|
||||
@@ -261,7 +268,7 @@
|
||||
</div>
|
||||
|
||||
|
||||
<div class="col-md-6" style="margin-bottom: 2%;">
|
||||
<div class="col-md-4" style="margin-bottom: 2%;">
|
||||
<a href="" ng-click="showListDomains()" title="{% trans 'List Domains' %}" href="" title="{% trans 'List Domains' %}">
|
||||
<img src="{% static 'images/icons/sort.png' %}">
|
||||
</a>
|
||||
@@ -272,6 +279,17 @@
|
||||
</div>
|
||||
|
||||
|
||||
<div class="col-md-4" style="margin-bottom: 2%;">
|
||||
<a href="{% url 'listCron' %}" target="_blank" title="{% trans 'Add new Cron Job' %}" href="" title="{% trans 'List Domains' %}">
|
||||
<img src="{% static 'images/icons/repeat.png' %}">
|
||||
</a>
|
||||
<a href="{% url 'listCron' %}" target="_blank" title="{% trans 'List Domains' %}" title="{% trans 'Add new Cron Job' %}">
|
||||
<span style='font-size: 21px;font-family: "Times New Roman", Times, serif; padding-left: 2%'>{% trans "Cron Job" %}</span>
|
||||
</a>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -56,8 +56,9 @@ urlpatterns = [
|
||||
url(r'^fetchDomains', views.fetchDomains, name='submitDomainCreation'),
|
||||
url(r'^changePHP', views.changePHP, name='changePHP'),
|
||||
url(r'^submitDomainDeletion', views.submitDomainDeletion, name='submitDomainDeletion'),
|
||||
|
||||
|
||||
# crons
|
||||
|
||||
url(r'^listCron',views.listCron,name="listCron"),
|
||||
url(r'^getWebsiteCron',views.getWebsiteCron,name="getWebsiteCron"),
|
||||
url(r'^getCronbyLine',views.getCronbyLine,name="getCronbyLine"),
|
||||
|
||||
Binary file not shown.
@@ -37,480 +37,7 @@ def loadWebsitesHome(request):
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
def listCron(request):
|
||||
try:
|
||||
val = request.session['userID']
|
||||
try:
|
||||
admin = Administrator.objects.get(pk=request.session['userID'])
|
||||
|
||||
if admin.type == 1:
|
||||
websites = Websites.objects.all()
|
||||
websitesName = []
|
||||
|
||||
for items in websites:
|
||||
websitesName.append(items.domain)
|
||||
else:
|
||||
if admin.type == 2:
|
||||
websites = admin.websites_set.all()
|
||||
admins = Administrator.objects.filter(owner=admin.pk)
|
||||
websitesName = []
|
||||
|
||||
for items in websites:
|
||||
websitesName.append(items.domain)
|
||||
|
||||
for items in admins:
|
||||
webs = items.websites_set.all()
|
||||
|
||||
for web in webs:
|
||||
websitesName.append(web.domain)
|
||||
else:
|
||||
websitesName = []
|
||||
websites = Websites.objects.filter(admin=admin)
|
||||
for items in websites:
|
||||
websitesName.append(items.domain)
|
||||
|
||||
return render(request, 'websiteFunctions/listCron.html', {'websiteList':websitesName})
|
||||
except BaseException, msg:
|
||||
logging.CyberCPLogFileWriter.writeToFile(str(msg))
|
||||
return HttpResponse(str(msg))
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
|
||||
|
||||
def getWebsiteCron(request):
|
||||
try:
|
||||
val = request.session['userID']
|
||||
if request.method == 'POST':
|
||||
try:
|
||||
|
||||
data = json.loads(request.body)
|
||||
domain = data['domain']
|
||||
|
||||
admin = Administrator.objects.get(pk=request.session['userID'])
|
||||
website = Websites.objects.get(domain=domain)
|
||||
|
||||
if Websites.objects.filter(domain=domain).exists():
|
||||
pass
|
||||
else:
|
||||
dic = {'getWebsiteCron': 0, 'error_message': 'You do not own this domain'}
|
||||
json_data = json.dumps(dic)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
if admin.type != 1:
|
||||
website = Websites.objects.get(domain=domain)
|
||||
if website.admin != admin:
|
||||
dic = {'getWebsiteCron': 0, 'error_message': 'You do not own this domain'}
|
||||
json_data = json.dumps(dic)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
cronPath = "/var/spool/cron/" + website.externalApp
|
||||
cmd = 'sudo test -e '+cronPath+' && echo Exists'
|
||||
output = os.popen(cmd).read()
|
||||
|
||||
if "Exists" not in output:
|
||||
data_ret = {'getWebsiteCron': 1, "user": website.externalApp, "crons":{}}
|
||||
final_json = json.dumps(data_ret)
|
||||
return HttpResponse(final_json)
|
||||
|
||||
cronPath = "/var/spool/cron/" + website.externalApp
|
||||
crons = []
|
||||
|
||||
try:
|
||||
f = subprocess.check_output(["sudo","cat",cronPath])
|
||||
print f
|
||||
except subprocess.CalledProcessError as error:
|
||||
dic = {'getWebsiteCron': 0, 'error_message': 'Unable to access Cron file'}
|
||||
json_data = json.dumps(dic)
|
||||
return HttpResponse(json_data)
|
||||
counter = 0
|
||||
for line in f.split("\n"):
|
||||
if line:
|
||||
split = line.split(" ", 5)
|
||||
print line
|
||||
print split
|
||||
if len(split) == 6:
|
||||
counter += 1
|
||||
crons.append({"line" : counter,
|
||||
"minute" : split[0],
|
||||
"hour" : split[1],
|
||||
"monthday": split[2],
|
||||
"month" : split[3],
|
||||
"weekday" : split[4],
|
||||
"command" : split[5]})
|
||||
|
||||
print json.dumps(crons)
|
||||
|
||||
data_ret = {'getWebsiteCron': 1, "user": website.externalApp, "crons":crons}
|
||||
final_json = json.dumps(data_ret)
|
||||
return HttpResponse(final_json)
|
||||
except BaseException,msg:
|
||||
print msg
|
||||
dic = {'getWebsiteCron': 0, 'error_message': str(msg)}
|
||||
json_data = json.dumps(dic)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
except KeyError, msg:
|
||||
status = {"getWebsiteCron":0,"error":"Not Logged in as admin"}
|
||||
final_json = json.dumps(status)
|
||||
return HttpResponse(final_json)
|
||||
|
||||
def getCronbyLine(request):
|
||||
try:
|
||||
val = request.session['userID']
|
||||
if request.method == 'POST':
|
||||
try:
|
||||
|
||||
data = json.loads(request.body)
|
||||
domain = data['domain']
|
||||
line = data['line']
|
||||
|
||||
line -= 1
|
||||
admin = Administrator.objects.get(pk=request.session['userID'])
|
||||
website = Websites.objects.get(domain=domain)
|
||||
|
||||
if Websites.objects.filter(domain=domain).exists():
|
||||
pass
|
||||
else:
|
||||
dic = {'getWebsiteCron': 0, 'error_message': 'You do not own this domain'}
|
||||
json_data = json.dumps(dic)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
if admin.type == 1:
|
||||
pass
|
||||
else:
|
||||
website = Websites.objects.get(domain=domain)
|
||||
if website.admin == admin:
|
||||
pass
|
||||
else:
|
||||
dic = {'getWebsiteCron': 0, 'error_message': 'You do not own this domain'}
|
||||
json_data = json.dumps(dic)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
cronPath = "/var/spool/cron/" + website.externalApp
|
||||
crons = []
|
||||
|
||||
try:
|
||||
f = subprocess.check_output(["sudo","cat",cronPath])
|
||||
print f
|
||||
except subprocess.CalledProcessError as error:
|
||||
dic = {'getWebsiteCron': 0, 'error_message': 'Unable to access Cron file'}
|
||||
json_data = json.dumps(dic)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
f = f.split("\n")
|
||||
cron = f[line]
|
||||
|
||||
if not cron:
|
||||
dic = {'getWebsiteCron': 0, 'error_message':'Cron line empty'}
|
||||
json_data = json.dumps(dic)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
cron = cron.split(" ", 5)
|
||||
if len(cron) != 6:
|
||||
dic = {'getWebsiteCron': 0, 'error_message':'Cron line incorrect'}
|
||||
json_data = json.dumps(dic)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
|
||||
data_ret = {"getWebsiteCron": 1,
|
||||
"user": website.externalApp,
|
||||
"cron":{
|
||||
"minute":cron[0],
|
||||
"hour":cron[1],
|
||||
"monthday":cron[2],
|
||||
"month":cron[3],
|
||||
"weekday":cron[4],
|
||||
"command":cron[5],
|
||||
},
|
||||
"line":line}
|
||||
final_json = json.dumps(data_ret)
|
||||
return HttpResponse(final_json)
|
||||
except BaseException,msg:
|
||||
print msg
|
||||
dic = {'getWebsiteCron': 0, 'error_message': str(msg)}
|
||||
json_data = json.dumps(dic)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
except KeyError, msg:
|
||||
status = {"getWebsiteCron":0,"error":"Not Logged in"}
|
||||
final_json = json.dumps(status)
|
||||
return HttpResponse(final_json)
|
||||
|
||||
def saveCronChanges(request):
|
||||
try:
|
||||
val = request.session['userID']
|
||||
if request.method == 'POST':
|
||||
try:
|
||||
|
||||
data = json.loads(request.body)
|
||||
domain = data['domain']
|
||||
line = data['line']
|
||||
|
||||
minute = data['minute']
|
||||
hour = data['hour']
|
||||
monthday = data['monthday']
|
||||
month = data['month']
|
||||
weekday = data['weekday']
|
||||
command = data['command']
|
||||
|
||||
admin = Administrator.objects.get(pk=request.session['userID'])
|
||||
website = Websites.objects.get(domain=domain)
|
||||
|
||||
if Websites.objects.filter(domain=domain).exists():
|
||||
pass
|
||||
else:
|
||||
dic = {'getWebsiteCron': 0, 'error_message': 'You do not own this domain'}
|
||||
json_data = json.dumps(dic)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
if admin.type == 1:
|
||||
pass
|
||||
else:
|
||||
website = Websites.objects.get(domain=domain)
|
||||
if website.admin == admin:
|
||||
pass
|
||||
else:
|
||||
dic = {'getWebsiteCron': 0, 'error_message': 'You do not own this domain'}
|
||||
json_data = json.dumps(dic)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
cronPath = "/var/spool/cron/" + website.externalApp
|
||||
tempPath = "/home/cyberpanel/" + website.externalApp + str(randint(10000,99999)) + ".cron.tmp"
|
||||
|
||||
finalCron = "%s %s %s %s %s %s" % (minute, hour, monthday, month, weekday, command)
|
||||
|
||||
o = subprocess.call(['sudo','cp',cronPath,tempPath])
|
||||
if o is not 0:
|
||||
data_ret = {'addNewCron': 0, 'error_message': 'Unable to copy to temporary files'}
|
||||
final_json = json.dumps(data_ret)
|
||||
return HttpResponse(final_json)
|
||||
|
||||
# Confirming that directory is read/writable
|
||||
o = subprocess.call(['sudo','chown','cyberpanel:cyberpanel',tempPath])
|
||||
if o is not 0:
|
||||
data_ret = {'addNewCron': 0, 'error_message': 'Error Changing Permissions'}
|
||||
final_json = json.dumps(data_ret)
|
||||
return HttpResponse(final_json)
|
||||
|
||||
with open(tempPath, 'r') as file:
|
||||
data = file.readlines()
|
||||
|
||||
data[line] = finalCron+'\n'
|
||||
|
||||
with open(tempPath, 'w') as file:
|
||||
file.writelines( data )
|
||||
print 'test'
|
||||
|
||||
output = subprocess.call(["sudo","/usr/bin/crontab", "-u", website.externalApp, tempPath])
|
||||
|
||||
os.remove(tempPath)
|
||||
if output != 0:
|
||||
data_ret = {'addNewCron': 0, 'error_message': 'Incorrect Syntax cannot be accepted'}
|
||||
final_json = json.dumps(data_ret)
|
||||
return HttpResponse(final_json)
|
||||
|
||||
data_ret = {"getWebsiteCron": 1,
|
||||
"user": website.externalApp,
|
||||
"cron": finalCron,
|
||||
"line":line}
|
||||
final_json = json.dumps(data_ret)
|
||||
return HttpResponse(final_json)
|
||||
except BaseException,msg:
|
||||
print msg
|
||||
dic = {'getWebsiteCron': 0, 'error_message': str(msg)}
|
||||
json_data = json.dumps(dic)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
except KeyError, msg:
|
||||
status = {"getWebsiteCron":0,"error":"Not Logged in"}
|
||||
final_json = json.dumps(status)
|
||||
return HttpResponse(final_json)
|
||||
|
||||
def remCronbyLine(request):
|
||||
try:
|
||||
val = request.session['userID']
|
||||
if request.method == 'POST':
|
||||
try:
|
||||
|
||||
data = json.loads(request.body)
|
||||
domain = data['domain']
|
||||
line = data['line']
|
||||
|
||||
line -= 1
|
||||
|
||||
admin = Administrator.objects.get(pk=request.session['userID'])
|
||||
website = Websites.objects.get(domain=domain)
|
||||
|
||||
if Websites.objects.filter(domain=domain).exists():
|
||||
pass
|
||||
else:
|
||||
dic = {'remCronbyLine': 0, 'error_message': 'You do not own this domain'}
|
||||
json_data = json.dumps(dic)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
if admin.type == 1:
|
||||
pass
|
||||
else:
|
||||
website = Websites.objects.get(domain=domain)
|
||||
if website.admin == admin:
|
||||
pass
|
||||
else:
|
||||
dic = {'remCronbyLine': 0, 'error_message': 'You do not own this domain'}
|
||||
json_data = json.dumps(dic)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
cronPath = "/var/spool/cron/" + website.externalApp
|
||||
cmd = 'sudo test -e '+cronPath+' && echo Exists'
|
||||
output = os.popen(cmd).read()
|
||||
|
||||
if "Exists" not in output:
|
||||
data_ret = {'remCronbyLine': 0, 'error_message': 'No Cron exists for this user'}
|
||||
final_json = json.dumps(data_ret)
|
||||
return HttpResponse(final_json)
|
||||
|
||||
cronPath = "/var/spool/cron/" + website.externalApp
|
||||
tempPath = "/home/cyberpanel/" + website.externalApp + str(randint(10000,99999)) + ".cron.tmp"
|
||||
|
||||
o = subprocess.call(['sudo','cp',cronPath,tempPath])
|
||||
if o is not 0:
|
||||
data_ret = {'addNewCron': 0, 'error_message': 'Unable to copy to temporary files'}
|
||||
final_json = json.dumps(data_ret)
|
||||
return HttpResponse(final_json)
|
||||
|
||||
# Confirming that directory is read/writable
|
||||
o = subprocess.call(['sudo','chown','cyberpanel:cyberpanel',tempPath])
|
||||
if o is not 0:
|
||||
data_ret = {'addNewCron': 0, 'error_message': 'Error Changing Permissions'}
|
||||
final_json = json.dumps(data_ret)
|
||||
return HttpResponse(final_json)
|
||||
|
||||
with open(tempPath, 'r') as file:
|
||||
data = file.readlines()
|
||||
|
||||
removedLine = data.pop(line)
|
||||
|
||||
with open(tempPath, 'w') as file:
|
||||
file.writelines( data )
|
||||
|
||||
output = subprocess.call(["sudo","/usr/bin/crontab", "-u", website.externalApp, tempPath])
|
||||
|
||||
os.remove(tempPath)
|
||||
if output != 0:
|
||||
data_ret = {'addNewCron': 0, 'error_message': 'Incorrect Syntax cannot be accepted'}
|
||||
final_json = json.dumps(data_ret)
|
||||
return HttpResponse(final_json)
|
||||
|
||||
data_ret = {"remCronbyLine": 1,
|
||||
"user": website.externalApp,
|
||||
"removeLine": removedLine,
|
||||
"line":line}
|
||||
final_json = json.dumps(data_ret)
|
||||
return HttpResponse(final_json)
|
||||
except BaseException,msg:
|
||||
print msg
|
||||
dic = {'remCronbyLine': 0, 'error_message': str(msg)}
|
||||
json_data = json.dumps(dic)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
except KeyError, msg:
|
||||
status = {"remCronbyLine":0,"error":"Not Logged in"}
|
||||
final_json = json.dumps(status)
|
||||
return HttpResponse(final_json)
|
||||
|
||||
def addNewCron(request):
|
||||
try:
|
||||
val = request.session['userID']
|
||||
if request.method == 'POST':
|
||||
try:
|
||||
|
||||
data = json.loads(request.body)
|
||||
domain = data['domain']
|
||||
|
||||
minute = data['minute']
|
||||
hour = data['hour']
|
||||
monthday = data['monthday']
|
||||
month = data['month']
|
||||
weekday = data['weekday']
|
||||
command = data['command']
|
||||
|
||||
admin = Administrator.objects.get(pk=request.session['userID'])
|
||||
website = Websites.objects.get(domain=domain)
|
||||
|
||||
if Websites.objects.filter(domain=domain).exists():
|
||||
pass
|
||||
else:
|
||||
dic = {'addNewCron': 0, 'error_message': 'You do not own this domain'}
|
||||
json_data = json.dumps(dic)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
if admin.type != 1:
|
||||
website = Websites.objects.get(domain=domain)
|
||||
if website.admin == admin:
|
||||
pass
|
||||
else:
|
||||
dic = {'addNewCron': 0, 'error_message': 'You do not own this domain'}
|
||||
json_data = json.dumps(dic)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
cronPath = "/var/spool/cron/" + website.externalApp
|
||||
cmd = 'sudo test -e '+cronPath+' && echo Exists'
|
||||
output = os.popen(cmd).read()
|
||||
|
||||
if "Exists" not in output:
|
||||
echo = subprocess.Popen(('echo'), stdout=subprocess.PIPE)
|
||||
output = subprocess.call(('sudo', 'crontab', '-u', website.externalApp, '-'), stdin=echo.stdout)
|
||||
echo.wait()
|
||||
echo.stdout.close()
|
||||
# Confirmation
|
||||
o = subprocess.call(["sudo","cp","/dev/null",cronPath])
|
||||
|
||||
cronPath = "/var/spool/cron/" + website.externalApp
|
||||
tempPath = "/home/cyberpanel/" + website.externalApp + str(randint(10000,99999)) + ".cron.tmp"
|
||||
|
||||
finalCron = "%s %s %s %s %s %s" % (minute, hour, monthday, month, weekday, command)
|
||||
|
||||
o = subprocess.call(['sudo','cp',cronPath,tempPath])
|
||||
if o is not 0:
|
||||
data_ret = {'addNewCron': 0, 'error_message': 'Unable to copy to temporary files'}
|
||||
final_json = json.dumps(data_ret)
|
||||
return HttpResponse(final_json)
|
||||
|
||||
# Confirming that directory is read/writable
|
||||
o = subprocess.call(['sudo','chown','cyberpanel:cyberpanel',tempPath])
|
||||
if o is not 0:
|
||||
data_ret = {'addNewCron': 0, 'error_message': 'Error Changing Permissions'}
|
||||
final_json = json.dumps(data_ret)
|
||||
return HttpResponse(final_json)
|
||||
|
||||
with open(tempPath, "a") as file:
|
||||
file.write(finalCron+"\n")
|
||||
|
||||
output = subprocess.call(["sudo","/usr/bin/crontab", "-u", website.externalApp, tempPath])
|
||||
|
||||
os.remove(tempPath)
|
||||
if output != 0:
|
||||
data_ret = {'addNewCron': 0, 'error_message': 'Incorrect Syntax cannot be accepted'}
|
||||
final_json = json.dumps(data_ret)
|
||||
return HttpResponse(final_json)
|
||||
|
||||
data_ret = {"addNewCron": 1,
|
||||
"user": website.externalApp,
|
||||
"cron": finalCron}
|
||||
final_json = json.dumps(data_ret)
|
||||
return HttpResponse(final_json)
|
||||
except BaseException,msg:
|
||||
print msg
|
||||
dic = {'addNewCron': 0, 'error_message': str(msg)}
|
||||
json_data = json.dumps(dic)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
except KeyError, msg:
|
||||
status = {"addNewCron":0,"error":"Not Logged in"}
|
||||
final_json = json.dumps(status)
|
||||
return HttpResponse(final_json)
|
||||
|
||||
|
||||
def createWebsite(request):
|
||||
try:
|
||||
val = request.session['userID']
|
||||
@@ -2356,4 +1883,480 @@ def CreateWebsiteFromBackup(request):
|
||||
except BaseException, msg:
|
||||
data_ret = {'createWebSiteStatus': 0, 'error_message': str(msg), "existsStatus": 0}
|
||||
json_data = json.dumps(data_ret)
|
||||
return HttpResponse(json_data)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
|
||||
def listCron(request):
|
||||
try:
|
||||
val = request.session['userID']
|
||||
try:
|
||||
admin = Administrator.objects.get(pk=request.session['userID'])
|
||||
|
||||
if admin.type == 1:
|
||||
websites = Websites.objects.all()
|
||||
websitesName = []
|
||||
|
||||
for items in websites:
|
||||
websitesName.append(items.domain)
|
||||
else:
|
||||
if admin.type == 2:
|
||||
websites = admin.websites_set.all()
|
||||
admins = Administrator.objects.filter(owner=admin.pk)
|
||||
websitesName = []
|
||||
|
||||
for items in websites:
|
||||
websitesName.append(items.domain)
|
||||
|
||||
for items in admins:
|
||||
webs = items.websites_set.all()
|
||||
|
||||
for web in webs:
|
||||
websitesName.append(web.domain)
|
||||
else:
|
||||
websitesName = []
|
||||
websites = Websites.objects.filter(admin=admin)
|
||||
for items in websites:
|
||||
websitesName.append(items.domain)
|
||||
|
||||
return render(request, 'websiteFunctions/listCron.html', {'websiteList': websitesName})
|
||||
except BaseException, msg:
|
||||
logging.CyberCPLogFileWriter.writeToFile(str(msg))
|
||||
return HttpResponse(str(msg))
|
||||
except KeyError:
|
||||
return redirect(loadLoginPage)
|
||||
|
||||
|
||||
def getWebsiteCron(request):
|
||||
try:
|
||||
val = request.session['userID']
|
||||
if request.method == 'POST':
|
||||
try:
|
||||
|
||||
data = json.loads(request.body)
|
||||
domain = data['domain']
|
||||
|
||||
admin = Administrator.objects.get(pk=request.session['userID'])
|
||||
website = Websites.objects.get(domain=domain)
|
||||
|
||||
if Websites.objects.filter(domain=domain).exists():
|
||||
pass
|
||||
else:
|
||||
dic = {'getWebsiteCron': 0, 'error_message': 'You do not own this domain'}
|
||||
json_data = json.dumps(dic)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
if admin.type != 1:
|
||||
website = Websites.objects.get(domain=domain)
|
||||
if website.admin != admin:
|
||||
dic = {'getWebsiteCron': 0, 'error_message': 'You do not own this domain'}
|
||||
json_data = json.dumps(dic)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
cronPath = "/var/spool/cron/" + website.externalApp
|
||||
cmd = 'sudo test -e ' + cronPath + ' && echo Exists'
|
||||
output = os.popen(cmd).read()
|
||||
|
||||
if "Exists" not in output:
|
||||
data_ret = {'getWebsiteCron': 1, "user": website.externalApp, "crons": {}}
|
||||
final_json = json.dumps(data_ret)
|
||||
return HttpResponse(final_json)
|
||||
|
||||
cronPath = "/var/spool/cron/" + website.externalApp
|
||||
crons = []
|
||||
|
||||
try:
|
||||
f = subprocess.check_output(["sudo", "cat", cronPath])
|
||||
print f
|
||||
except subprocess.CalledProcessError as error:
|
||||
dic = {'getWebsiteCron': 0, 'error_message': 'Unable to access Cron file'}
|
||||
json_data = json.dumps(dic)
|
||||
return HttpResponse(json_data)
|
||||
counter = 0
|
||||
for line in f.split("\n"):
|
||||
if line:
|
||||
split = line.split(" ", 5)
|
||||
print line
|
||||
print split
|
||||
if len(split) == 6:
|
||||
counter += 1
|
||||
crons.append({"line": counter,
|
||||
"minute": split[0],
|
||||
"hour": split[1],
|
||||
"monthday": split[2],
|
||||
"month": split[3],
|
||||
"weekday": split[4],
|
||||
"command": split[5]})
|
||||
|
||||
print json.dumps(crons)
|
||||
|
||||
data_ret = {'getWebsiteCron': 1, "user": website.externalApp, "crons": crons}
|
||||
final_json = json.dumps(data_ret)
|
||||
return HttpResponse(final_json)
|
||||
except BaseException, msg:
|
||||
print msg
|
||||
dic = {'getWebsiteCron': 0, 'error_message': str(msg)}
|
||||
json_data = json.dumps(dic)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
except KeyError, msg:
|
||||
status = {"getWebsiteCron": 0, "error": "Not Logged in as admin"}
|
||||
final_json = json.dumps(status)
|
||||
return HttpResponse(final_json)
|
||||
|
||||
|
||||
def getCronbyLine(request):
|
||||
try:
|
||||
val = request.session['userID']
|
||||
if request.method == 'POST':
|
||||
try:
|
||||
|
||||
data = json.loads(request.body)
|
||||
domain = data['domain']
|
||||
line = data['line']
|
||||
|
||||
line -= 1
|
||||
admin = Administrator.objects.get(pk=request.session['userID'])
|
||||
website = Websites.objects.get(domain=domain)
|
||||
|
||||
if Websites.objects.filter(domain=domain).exists():
|
||||
pass
|
||||
else:
|
||||
dic = {'getWebsiteCron': 0, 'error_message': 'You do not own this domain'}
|
||||
json_data = json.dumps(dic)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
if admin.type == 1:
|
||||
pass
|
||||
else:
|
||||
website = Websites.objects.get(domain=domain)
|
||||
if website.admin == admin:
|
||||
pass
|
||||
else:
|
||||
dic = {'getWebsiteCron': 0, 'error_message': 'You do not own this domain'}
|
||||
json_data = json.dumps(dic)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
cronPath = "/var/spool/cron/" + website.externalApp
|
||||
crons = []
|
||||
|
||||
try:
|
||||
f = subprocess.check_output(["sudo", "cat", cronPath])
|
||||
print f
|
||||
except subprocess.CalledProcessError as error:
|
||||
dic = {'getWebsiteCron': 0, 'error_message': 'Unable to access Cron file'}
|
||||
json_data = json.dumps(dic)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
f = f.split("\n")
|
||||
cron = f[line]
|
||||
|
||||
if not cron:
|
||||
dic = {'getWebsiteCron': 0, 'error_message': 'Cron line empty'}
|
||||
json_data = json.dumps(dic)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
cron = cron.split(" ", 5)
|
||||
if len(cron) != 6:
|
||||
dic = {'getWebsiteCron': 0, 'error_message': 'Cron line incorrect'}
|
||||
json_data = json.dumps(dic)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
data_ret = {"getWebsiteCron": 1,
|
||||
"user": website.externalApp,
|
||||
"cron": {
|
||||
"minute": cron[0],
|
||||
"hour": cron[1],
|
||||
"monthday": cron[2],
|
||||
"month": cron[3],
|
||||
"weekday": cron[4],
|
||||
"command": cron[5],
|
||||
},
|
||||
"line": line}
|
||||
final_json = json.dumps(data_ret)
|
||||
return HttpResponse(final_json)
|
||||
except BaseException, msg:
|
||||
print msg
|
||||
dic = {'getWebsiteCron': 0, 'error_message': str(msg)}
|
||||
json_data = json.dumps(dic)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
except KeyError, msg:
|
||||
status = {"getWebsiteCron": 0, "error": "Not Logged in"}
|
||||
final_json = json.dumps(status)
|
||||
return HttpResponse(final_json)
|
||||
|
||||
|
||||
def saveCronChanges(request):
|
||||
try:
|
||||
val = request.session['userID']
|
||||
if request.method == 'POST':
|
||||
try:
|
||||
|
||||
data = json.loads(request.body)
|
||||
domain = data['domain']
|
||||
line = data['line']
|
||||
|
||||
minute = data['minute']
|
||||
hour = data['hour']
|
||||
monthday = data['monthday']
|
||||
month = data['month']
|
||||
weekday = data['weekday']
|
||||
command = data['command']
|
||||
|
||||
admin = Administrator.objects.get(pk=request.session['userID'])
|
||||
website = Websites.objects.get(domain=domain)
|
||||
|
||||
if Websites.objects.filter(domain=domain).exists():
|
||||
pass
|
||||
else:
|
||||
dic = {'getWebsiteCron': 0, 'error_message': 'You do not own this domain'}
|
||||
json_data = json.dumps(dic)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
if admin.type == 1:
|
||||
pass
|
||||
else:
|
||||
website = Websites.objects.get(domain=domain)
|
||||
if website.admin == admin:
|
||||
pass
|
||||
else:
|
||||
dic = {'getWebsiteCron': 0, 'error_message': 'You do not own this domain'}
|
||||
json_data = json.dumps(dic)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
cronPath = "/var/spool/cron/" + website.externalApp
|
||||
tempPath = "/home/cyberpanel/" + website.externalApp + str(randint(10000, 99999)) + ".cron.tmp"
|
||||
|
||||
finalCron = "%s %s %s %s %s %s" % (minute, hour, monthday, month, weekday, command)
|
||||
|
||||
o = subprocess.call(['sudo', 'cp', cronPath, tempPath])
|
||||
if o is not 0:
|
||||
data_ret = {'addNewCron': 0, 'error_message': 'Unable to copy to temporary files'}
|
||||
final_json = json.dumps(data_ret)
|
||||
return HttpResponse(final_json)
|
||||
|
||||
# Confirming that directory is read/writable
|
||||
o = subprocess.call(['sudo', 'chown', 'cyberpanel:cyberpanel', tempPath])
|
||||
if o is not 0:
|
||||
data_ret = {'addNewCron': 0, 'error_message': 'Error Changing Permissions'}
|
||||
final_json = json.dumps(data_ret)
|
||||
return HttpResponse(final_json)
|
||||
|
||||
with open(tempPath, 'r') as file:
|
||||
data = file.readlines()
|
||||
|
||||
data[line] = finalCron + '\n'
|
||||
|
||||
with open(tempPath, 'w') as file:
|
||||
file.writelines(data)
|
||||
print 'test'
|
||||
|
||||
output = subprocess.call(["sudo", "/usr/bin/crontab", "-u", website.externalApp, tempPath])
|
||||
|
||||
os.remove(tempPath)
|
||||
if output != 0:
|
||||
data_ret = {'addNewCron': 0, 'error_message': 'Incorrect Syntax cannot be accepted.'}
|
||||
final_json = json.dumps(data_ret)
|
||||
return HttpResponse(final_json)
|
||||
|
||||
data_ret = {"getWebsiteCron": 1,
|
||||
"user": website.externalApp,
|
||||
"cron": finalCron,
|
||||
"line": line}
|
||||
final_json = json.dumps(data_ret)
|
||||
return HttpResponse(final_json)
|
||||
except BaseException, msg:
|
||||
print msg
|
||||
dic = {'getWebsiteCron': 0, 'error_message': str(msg)}
|
||||
json_data = json.dumps(dic)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
except KeyError, msg:
|
||||
status = {"getWebsiteCron": 0, "error": "Not Logged in"}
|
||||
final_json = json.dumps(status)
|
||||
return HttpResponse(final_json)
|
||||
|
||||
|
||||
def remCronbyLine(request):
|
||||
try:
|
||||
val = request.session['userID']
|
||||
if request.method == 'POST':
|
||||
try:
|
||||
|
||||
data = json.loads(request.body)
|
||||
domain = data['domain']
|
||||
line = data['line']
|
||||
|
||||
line -= 1
|
||||
|
||||
admin = Administrator.objects.get(pk=request.session['userID'])
|
||||
website = Websites.objects.get(domain=domain)
|
||||
|
||||
if Websites.objects.filter(domain=domain).exists():
|
||||
pass
|
||||
else:
|
||||
dic = {'remCronbyLine': 0, 'error_message': 'You do not own this domain'}
|
||||
json_data = json.dumps(dic)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
if admin.type == 1:
|
||||
pass
|
||||
else:
|
||||
website = Websites.objects.get(domain=domain)
|
||||
if website.admin == admin:
|
||||
pass
|
||||
else:
|
||||
dic = {'remCronbyLine': 0, 'error_message': 'You do not own this domain'}
|
||||
json_data = json.dumps(dic)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
cronPath = "/var/spool/cron/" + website.externalApp
|
||||
cmd = 'sudo test -e ' + cronPath + ' && echo Exists'
|
||||
output = os.popen(cmd).read()
|
||||
|
||||
if "Exists" not in output:
|
||||
data_ret = {'remCronbyLine': 0, 'error_message': 'No Cron exists for this user'}
|
||||
final_json = json.dumps(data_ret)
|
||||
return HttpResponse(final_json)
|
||||
|
||||
cronPath = "/var/spool/cron/" + website.externalApp
|
||||
tempPath = "/home/cyberpanel/" + website.externalApp + str(randint(10000, 99999)) + ".cron.tmp"
|
||||
|
||||
o = subprocess.call(['sudo', 'cp', cronPath, tempPath])
|
||||
if o is not 0:
|
||||
data_ret = {'addNewCron': 0, 'error_message': 'Unable to copy to temporary files'}
|
||||
final_json = json.dumps(data_ret)
|
||||
return HttpResponse(final_json)
|
||||
|
||||
# Confirming that directory is read/writable
|
||||
o = subprocess.call(['sudo', 'chown', 'cyberpanel:cyberpanel', tempPath])
|
||||
if o is not 0:
|
||||
data_ret = {'addNewCron': 0, 'error_message': 'Error Changing Permissions'}
|
||||
final_json = json.dumps(data_ret)
|
||||
return HttpResponse(final_json)
|
||||
|
||||
with open(tempPath, 'r') as file:
|
||||
data = file.readlines()
|
||||
|
||||
removedLine = data.pop(line)
|
||||
|
||||
with open(tempPath, 'w') as file:
|
||||
file.writelines(data)
|
||||
|
||||
output = subprocess.call(["sudo", "/usr/bin/crontab", "-u", website.externalApp, tempPath])
|
||||
|
||||
os.remove(tempPath)
|
||||
if output != 0:
|
||||
data_ret = {'addNewCron': 0, 'error_message': 'Incorrect Syntax cannot be accepted'}
|
||||
final_json = json.dumps(data_ret)
|
||||
return HttpResponse(final_json)
|
||||
|
||||
data_ret = {"remCronbyLine": 1,
|
||||
"user": website.externalApp,
|
||||
"removeLine": removedLine,
|
||||
"line": line}
|
||||
final_json = json.dumps(data_ret)
|
||||
return HttpResponse(final_json)
|
||||
except BaseException, msg:
|
||||
print msg
|
||||
dic = {'remCronbyLine': 0, 'error_message': str(msg)}
|
||||
json_data = json.dumps(dic)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
except KeyError, msg:
|
||||
status = {"remCronbyLine": 0, "error": "Not Logged in"}
|
||||
final_json = json.dumps(status)
|
||||
return HttpResponse(final_json)
|
||||
|
||||
|
||||
def addNewCron(request):
|
||||
try:
|
||||
val = request.session['userID']
|
||||
if request.method == 'POST':
|
||||
try:
|
||||
|
||||
data = json.loads(request.body)
|
||||
domain = data['domain']
|
||||
|
||||
minute = data['minute']
|
||||
hour = data['hour']
|
||||
monthday = data['monthday']
|
||||
month = data['month']
|
||||
weekday = data['weekday']
|
||||
command = data['command']
|
||||
|
||||
admin = Administrator.objects.get(pk=request.session['userID'])
|
||||
website = Websites.objects.get(domain=domain)
|
||||
|
||||
if Websites.objects.filter(domain=domain).exists():
|
||||
pass
|
||||
else:
|
||||
dic = {'addNewCron': 0, 'error_message': 'You do not own this domain'}
|
||||
json_data = json.dumps(dic)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
if admin.type != 1:
|
||||
website = Websites.objects.get(domain=domain)
|
||||
if website.admin == admin:
|
||||
pass
|
||||
else:
|
||||
dic = {'addNewCron': 0, 'error_message': 'You do not own this domain'}
|
||||
json_data = json.dumps(dic)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
cronPath = "/var/spool/cron/" + website.externalApp
|
||||
cmd = 'sudo test -e ' + cronPath + ' && echo Exists'
|
||||
output = os.popen(cmd).read()
|
||||
|
||||
if "Exists" not in output:
|
||||
echo = subprocess.Popen(('echo'), stdout=subprocess.PIPE)
|
||||
output = subprocess.call(('sudo', 'crontab', '-u', website.externalApp, '-'), stdin=echo.stdout)
|
||||
echo.wait()
|
||||
echo.stdout.close()
|
||||
# Confirmation
|
||||
o = subprocess.call(["sudo", "cp", "/dev/null", cronPath])
|
||||
|
||||
cronPath = "/var/spool/cron/" + website.externalApp
|
||||
tempPath = "/home/cyberpanel/" + website.externalApp + str(randint(10000, 99999)) + ".cron.tmp"
|
||||
|
||||
finalCron = "%s %s %s %s %s %s" % (minute, hour, monthday, month, weekday, command)
|
||||
|
||||
o = subprocess.call(['sudo', 'cp', cronPath, tempPath])
|
||||
if o is not 0:
|
||||
data_ret = {'addNewCron': 0, 'error_message': 'Unable to copy to temporary files'}
|
||||
final_json = json.dumps(data_ret)
|
||||
return HttpResponse(final_json)
|
||||
|
||||
# Confirming that directory is read/writable
|
||||
o = subprocess.call(['sudo', 'chown', 'cyberpanel:cyberpanel', tempPath])
|
||||
if o is not 0:
|
||||
data_ret = {'addNewCron': 0, 'error_message': 'Error Changing Permissions'}
|
||||
final_json = json.dumps(data_ret)
|
||||
return HttpResponse(final_json)
|
||||
|
||||
with open(tempPath, "a") as file:
|
||||
file.write(finalCron + "\n")
|
||||
|
||||
output = subprocess.call(["sudo", "/usr/bin/crontab", "-u", website.externalApp, tempPath])
|
||||
|
||||
os.remove(tempPath)
|
||||
if output != 0:
|
||||
data_ret = {'addNewCron': 0, 'error_message': 'Incorrect Syntax cannot be accepted'}
|
||||
final_json = json.dumps(data_ret)
|
||||
return HttpResponse(final_json)
|
||||
|
||||
data_ret = {"addNewCron": 1,
|
||||
"user": website.externalApp,
|
||||
"cron": finalCron}
|
||||
final_json = json.dumps(data_ret)
|
||||
return HttpResponse(final_json)
|
||||
except BaseException, msg:
|
||||
print msg
|
||||
dic = {'addNewCron': 0, 'error_message': str(msg)}
|
||||
json_data = json.dumps(dic)
|
||||
return HttpResponse(json_data)
|
||||
|
||||
except KeyError, msg:
|
||||
status = {"addNewCron": 0, "error": "Not Logged in"}
|
||||
final_json = json.dumps(status)
|
||||
return HttpResponse(final_json)
|
||||
Binary file not shown.
Reference in New Issue
Block a user