-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclient.php
More file actions
132 lines (121 loc) · 5.11 KB
/
client.php
File metadata and controls
132 lines (121 loc) · 5.11 KB
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
<?php
include 'VarnishlogParser.class.php';
include 'kint/build/kint.php';
$FILEPATH = "";
$FILENAME = "";
$error = "";
$transactions_list = "";
$transactions_string = "";
$transactions_diagram_url = "";
try {
// Check requirements
if(!class_exists("VarnishlogParser\VarnishlogParser"))
throw new Exception("Please, include VarnishlogParser in this directory!");
if(!class_exists("\Kint"))
throw new Exception("Please, include Kint library.");
// Configure Kint
\Kint_Renderer_Rich::$access_paths = false;
\Kint::$display_called_from = false;
// Check input file
if(!empty($_FILES["fileselected"]['tmp_name']) && !$_FILES["fileselected"]['error']){
$FILEPATH = $_FILES["fileselected"]['tmp_name'];
$FILENAME = $_FILES["fileselected"]['name'];
}
elseif(!empty($_REQUEST["filepath"])){
$FILEPATH = $_REQUEST["filepath"]; // Obvious XSS flaw here
$FILENAME = $FILEPATH;
}
else {
throw new InvalidArgumentException("No filepath provided");
}
// Parse Varnishlog file
$transactions_list = VarnishlogParser\VarnishlogParser::parse($FILEPATH);
if(empty($transactions_list))
throw new Exception("Unable to parse the provided file: did you use <code>varnishlog -g raw</code> to generate this file?", 1);
// Output text representation of transactions
$transactions_string = VarnishlogParser\VarnishlogParser::simpleAnalysis($transactions_list,1);
// Reorder for future use
ksort($transactions_list);
// Get URL for sequence diagram
$transactions_diagram_url = VarnishlogParser\VarnishlogParser::getSequenceDiagram($transactions_string);
if(!$transactions_diagram_url)
throw new Exception("Error while generating image with websequencediagrams.com.");
}
catch(\InvalidArgumentException $e){
$error = "";
}
catch(\Exception $e){
$error = $e->getMessage();
}
?><!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<?php if(empty($FILENAME) && empty($FILEPATH)): ?>
<title>Varnishlog analysis</title>
<?php else: ?>
<title>Varnishlog analysis for : <?php echo $FILENAME ?></title>
<?php endif; ?>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div class="container">
<div class="jumbotron">
<h1>Varnishlog Analysis</h1>
<?php if($FILENAME): ?>
<p><em><?php echo $FILENAME // Obvious XSS flaw here ?></em></p>
<form method="get" action="<?php echo $_SERVER['PHP_SELF']?>">
<button type="submit" class="btn btn-primary">Try another file</button>
</form>
<?php endif; ?>
</div>
<?php if(empty($FILEPATH)) : ?>
<!-- No filepath provided -->
<form class="form-horizontal" method="post" action="<?php echo $_SERVER['PHP_SELF']?>" enctype="multipart/form-data">
<div class="form-group">
<label for="filepath" class="col-sm-4 control-label">Local path of varnishlog file...</label>
<div class="col-sm-8">
<input type="textfield" class="form-control" id="filepath" name="filepath" placeholder="./examples/vsltrans_gist.log">
</div>
<label for="fileselected" class="col-sm-4 control-label">...or upload a file</label>
<div class="col-sm-8">
<input type="file" id="fileselected" name="fileselected">
</div>
</div>
<div class="form-group">
<label for="show_debug" class="col-sm-4 control-label">Display debug data</label>
<div class="col-sm-8">
<input type="checkbox" id="show_debug" name="show_debug" value="1">
</div>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
<button type="button" class="btn" onclick="this.form.filepath.value='./examples/vsltrans_gist.log';this.form.submit();">See example</button>
</form>
<?php elseif($error):?>
<!-- An error occured -->
<div class="alert alert-danger" role="alert"><?php echo $error ?></div>
<?php else: ?>
<!-- Everything is fine -->
<div class="container">
<h2>Sequence diagram</h2>
<p>
<a href="<?php echo $transactions_diagram_url ?>" target="_black" title="See this image at full size"><img alt="Sequence diagram, explained below" src="<?php echo $transactions_diagram_url ?>" class="img-responsive center-block" /></a>
<p><strong>Note :</strong> this image will be destroyed in two minutes.</p>
</p>
</div>
<?php if(!empty($_REQUEST['show_debug']) && $_REQUEST['show_debug'] == "1"): ?>
<div class="container">
<h2>All transactions recorded</h2>
<?php \Kint::dump( $transactions_list, "Transaction list" ); ?>
</div>
<div class="container">
<h2>Simple representation</h2>
<pre class="pre-scrollable"><?php print $transactions_string ?></pre>
</div>
<?php endif; // end display debugs ?>
<?php endif; // end display results ?>
</div>
</body>
</html>