-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.php
216 lines (204 loc) · 6.79 KB
/
test.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
<?
/*
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%#
# _ ___ _ #
# (_)__ \ | | #
# ___ ___ _ ) |_ _____| |__ #
#/ __|/ __| | / /\ \ /\ / / _ \ '_ \ #
#\__ \ (__| |/ /_ \ V V / __/ |_) | #
#|___/\___|_|____| \_/\_/ \___|_.__/ #
#JORGE ZULUAGA (C) 2011 #
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#TEST PAGE
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
*/
//////////////////////////////////////////////////////////////////////////////////
//LOAD PACKAGE
//////////////////////////////////////////////////////////////////////////////////
$nerror=0;
$report="";
$RELATIVE=".";
$PAGETITLE="Test Page";
$LIBFILE="$RELATIVE/lib/sci2web.php";
$report.="<p class='testsession'>Library</p>";
if(file_exists($LIBFILE)){
$report.="<p class='testsuccess'>File '$LIBFILE' load.</p>";
include($LIBFILE);
}else{
echo "<p>Library file '$LIBFILE' is not accesible</p>";
phpinfo();
return 1;
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//CHECK CONFIGURATION
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
$report.="<p class='testsession'>Configuration files test</p>";
foreach(array("sci2web.conf","sci2web.db") as $confile){
systemCmd("ls $PROJ[PROJPATH]/lib/$confile");
if($PHP["?"]){
$report.="<p class='testerror'>Configuration file $confile does not exist</p>";
$nerror++;
}else{
$report.="<p class='testsuccess'>Configuration file $confile checked</p>";
}
systemCmd("chmod og-rwx $PROJ[PROJPATH]/lib/$confile");
if($PHP["?"]){
$report.="<p class='testerror'>Permissions for configuration file $confile not set properly</p>";
$nerror++;
}else{
$report.="<p class='testsuccess'>Permissions of file $confile checked</p>";
}
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//CHECK VARIABLES
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
$report.="<p class='testsession'>Variables test</p>";
if(!isset($PROJ) or !isset($PHP)){
$report.=<<<REPORT
<p class="testerror">Critical variables not load</p>
REPORT;
$nerror++;
goto report;
}else{
$proj_critvars=array("PROJBASE","PROJNAME","ENTRYPAGE");
$php_critvars=array("DEBUG","WEBUSER","WEBGROUP");
$vars="";
foreach($proj_critvars as $var){
$vars.="<li>PROJECT VAR '$var' = $PROJ[$var]</li>";
}
foreach($php_critvars as $var){
$vars.="<li>PHP VARS '$var' = $PHP[$var]</li>";
}
$report.=<<<REPORT
<p class="testsuccess">
Critical variables:
<ul>
$vars
</ul>
</p>
REPORT;
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//CHECK STYLES
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
$report.="<p class='testsession'>Styles load</p>";
$cssfile="$PROJ[PROJPATH]/lib/sci2web.css";
if(file_exists($cssfile)){
$report.="<p class='testsuccess'>File '$cssfile' load.</p>";
require_once("$PROJ[PROJPATH]/lib/sci2web.css");
}else{
echo "<p>Styles file '$cssfile' is not accesible</p>";
phpinfo();
return 1;
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//CHECK DATABASE
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
$resmat=mysqlCmd("show tables;");
$database=print_r($resmat,true);
$report.="<p class='testsession'>Database test</p>";
if(1 or !$PHP[DB]){
$report.=<<<REPORT
<p class="testsuccess">Database:$PHP[DB]</p>
<p class="testsuccess">List of tables:$database</p>
REPORT;
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//CHECK SCI2WEB USER AND PERMISSION
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
$report.="<p class='testsession'>Testing Sci2Web User</p>";
$out=systemCmd("id sci2web");
if($PHP["?"]){
$report.="<p class='testerror'>User 'sci2web' not found</p>";
$nerror++;
}else{
$report.="<p class='testsuccess'>User sci2web found: $out</p>";
}
sci2webCmd("pwd");
if($PHP["?"]){
$report.="<p class='testerror'>Error executing command as 'sci2web' user. Please check if you have already created the account, configured the sudoers file and assigned the right password to the accound</p>";
$nerror++;
}else{
$report.="<p class='testsuccess'>Success executing command</p>";
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//CHECK PERMISSIONS
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
$report.="<p class='testsession'>Permissions test</p>";
$dirs=array("$PROJ[TMPPATH]/test",
"$PROJ[APPSPATH]/template/application-desc.html",
"$PROJ[RUNSPATH]/test",
"$PROJ[PAGESPATH]/main",
"$PROJ[PAGESPATH]/main/content");
foreach($dirs as $dir){
systemCmd("touch $dir");
if($PHP["?"]){
$report.="<p class='testerror'>Error accessing '$dir'</p>";
$nerror++;
}else{
$report.="<p class='testsuccess'>Success accessing '$dir'</p>";
systemCmd("rm $dir");
}
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//CHECK APPLICATION
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
$report.="<p class='testsession'>Sample Application</p>";
$sampleapp="MercuPy";
foreach(array("1.0-2B","1.0-3B","1.0-4B","2.0-FB") as $version){
systemCmd("ls $PROJ[APPSPATH]/$sampleapp/$version/bin/elem2state");
if($PHP["?"]){
$report.="<p class='testerror'>Version '$version' of the sample application not compiled yet</p>";
$nerror++;
}else{
$report.="<p class='testsuccess'>Version '$version' of the sample application compiled</p>";
}
$dbname="${sampleapp}_${version}";
mysqlCmd("describe `$dbname`");
if($PHP["?"]){
$report.="<p class='testerror'>Database for results of version '$version' of the sample application not created</p>";
$nerror++;
}else{
$report.="<p class='testsuccess'>Database $dbname found</p>";
}
}
report:
$classerr="testsuccess";
if($nerror) $classerr="testerror";
echo<<<CONTENT
<html>
<head>
$PROJ[STYLES]
<style type="text/css">
p.testsession{
font-size:18px;
font-weight:bold;
color:blue;
}
p.testerror{
color:red;
}
p.testsuccess{
color:green;
}
</style>
<script type="text/javascript" src="$PROJ[PROJDIR]/js/jquery/jquery-1.7.js"></script>
<script type="text/javascript" src="$PROJ[PROJDIR]/js/domwindow/jquery.DOMWindow.js"></script>
<script type="text/javascript" src="$PROJ[PROJDIR]/js/ckeditor/ckeditor.js"></script>
<script type="text/javascript" src="$PROJ[PROJDIR]/js/tabber/tabber.js"></script>
<script type="text/javascript" src="$PROJ[PROJDIR]/js/sci2web.js"></script>
</head>
<body>
<div class="tabber" id=0>
<div class="tabbertab">
<h2>Test $PROJ[PROJNAME]</h2>
<div style="background-color:$COLORS[text];padding:20px">
<p class="$classerr">Number of errors: $nerror<p>
</div>
$report
</div>
</div>
</body>
</html>
CONTENT;
?>