forked from freuds/nconf
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathgenerate_config.php
147 lines (121 loc) · 5.27 KB
/
generate_config.php
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
<?php
require_once 'include/head.php';
echo '<img src="img/loader.gif" width="30" height="auto" />';
$lock_file = 'temp/generate.lock';
$status = check_file('file_exists', $lock_file, TRUE, "File/Directory still exists, please remove it: ");
if ( $status ){
# lock file exists
$lock_file_age = ( time() - filemtime($lock_file) );
NConf_DEBUG::set($lock_file_age.' seconds', '', "lock file last set since");
NConf_DEBUG::set(" should be available in " . (600-$lock_file_age) . " seconds", '', 'Next execution');
NConf_DEBUG::set("Remove the 'generate.lock' in the 'temp' directory", '', 'Force remove lock?');
# check if file is older than 10min(600sec) so replace it (should not be, because file will be removed)
# but this will prevent lock file to stay there
if ( $lock_file_age < 600 ){
# some one other is generating the config
NConf_DEBUG::set('Someone else is already generating the configuration. If you believe this is in error, run: sudo nems-quickfix', 'ERROR');
# close page and cancel action
if ( NConf_DEBUG::status('ERROR') ) {
echo NConf_HTML::exit_error();
}
}else{
# remove lock file
$unlink_status = unlink($lock_file);
if (!$unlink_status){
NConf_DEBUG::set('removing old lock failed', 'ERROR');
}
}
# if file is older, script will continue, and try to get lock again
}
# create lock
$generate_lock_handle = fopen($lock_file, 'w');
$status = flock($generate_lock_handle, LOCK_EX | LOCK_NB); //lock the file
?>
<!-- jQuery part -->
<script type="text/javascript">
// jQuery execute generate
$(document).ready(function(){
// disable interaction until page is loaded
var dialog_loading = $('<div class="center"></div>')
.html('<br><img src="img/working.gif"><h2>Please stand by...</h2><br><br><div id="progressbar"></div>')
.dialog({
autoOpen: true,
title: "Generating config",
closeOnEscape: false,
open: function(event, ui) { $(".ui-dialog-titlebar-close").hide(); },
modal: true,
draggable: false,
resizable: false,
height: 161
});
// accordion style enhanced to handle all items
$(".accordion_title").on("click hover", function(event) {
$(this).nconf_accordion_list(event);
});
// set the duration of one progress animation
var progress_step_animation_duration = 5000;
var current_percent = 0;
// progressbar
var refreshId = setInterval(function() {
$.ajax({
url: "temp/generate.lock",
cache: false,
dataType: "text",
type: "POST",
success: function(data){
// create bar if not exist
$( "#progressbar" ).not(".ui-progressbar").progressbar({
value: 0
});
// move bar
var percent = parseInt( $.trim(data) );
//alert("current: "+ current_percent + " -> read from file: " + percent);
if (current_percent >= percent){
// progress each interval, even if no feedback
// progress status from file must be smaller or match the current value
// otherwise the status should be taken on else
current_percent += 1;
}else{
// progress status is biger, go to that current state
if ( percent > 100 ){
// max size is 100 %
percent = 100;
}else if( !(percent > 0 ) ){
// set percent to 0 if not between 0-100
percent = 0;
}
// save current percent for next interval check
current_percent = percent;
}
var percent_width = current_percent + "%";
$( "#progressbar > .ui-progressbar-value" ).animate({width: percent_width}, progress_step_animation_duration, 'linear', function(){
if ( percent == 100 ){
dialog_loading.dialog('close');
clearInterval (refreshId);
}
});
}
});
}, 5000);
$("#maincontent").load("call_file.php", {
'ajax_file': "exec_generate_config.php" ,
'debug': "yes",
'username': "<?php echo $_SESSION['userinfos']['username'];?>"
}, function(data){
// generate finished, so close progress bar
clearInterval (refreshId);
if ( $("#progressbar").is(".ui-progressbar") ){
$( "#progressbar > .ui-progressbar-value" ).stop(true).animate({width: "100%"}, "slow", 'linear', function(){
dialog_loading.dialog('close');
});
}else{
dialog_loading.dialog('close');
}
});
});
</script>
<!-- END of jQuery part -->
<?php
//mysqli_close($dbh);
require_once 'include/foot.php';
?>