|
1 | 1 | <?php
|
| 2 | + |
2 | 3 | //TODO: protect page with authentication
|
3 | 4 | $valid_users = array("admin" => "password2014");
|
4 | 5 |
|
5 | 6 | $auth = false;
|
6 | 7 | //AUTH
|
7 | 8 | if (isset($_COOKIE["copy_remote_file"]) && $_COOKIE["copy_remote_file"] == true) {
|
8 |
| - $auth = true; |
| 9 | + $auth = true; |
9 | 10 | }
|
10 | 11 | if (isset($_POST) && isset($_POST["login_username"]) && $_POST["login_username"] != "" && isset($_POST["login_password"]) && $_POST["login_password"] != "") {
|
11 |
| - foreach ($valid_users as $username => $pwd) { |
12 |
| - if ($username == $_POST["login_username"] && $pwd == $_POST["login_password"]) { |
13 |
| - $auth = true; |
14 |
| - setcookie("copy_remote_file", true, time() + 3600); |
15 |
| - } |
16 |
| - } |
| 12 | + foreach ($valid_users as $username => $pwd) { |
| 13 | + if ($username == $_POST["login_username"] && $pwd == $_POST["login_password"]) { |
| 14 | + $auth = true; |
| 15 | + setcookie("copy_remote_file", true, time() + 3600); |
| 16 | + } |
| 17 | + } |
17 | 18 | }
|
18 | 19 |
|
19 | 20 |
|
|
23 | 24 | $remote_file_url = "";
|
24 | 25 | $copy_action = false;
|
25 | 26 | if (isset($_POST) && isset($_POST["remote_file_url"]) && $_POST["remote_file_url"] != "") {
|
26 |
| - $copy_action = true; |
27 |
| - set_time_limit(0); |
28 |
| - ini_set('max_execution_time', 300000000); |
29 |
| - |
30 |
| - try { |
31 |
| - $remote_file_url = $_POST["remote_file_url"]; |
32 |
| - $file_name = basename($remote_file_url); |
33 |
| - $filePath = dirname(__FILE__) . DIRECTORY_SEPARATOR . $file_name; |
34 |
| - if(file_exists($filePath )){ |
35 |
| - $error_message = "Local file '" . $filePath . "' already exist!"; |
36 |
| - } |
37 |
| - |
38 |
| - if (filter_var($remote_file_url, FILTER_VALIDATE_URL) === FALSE) { |
39 |
| - $error_message = "Url '" . $remote_file_url . "' not valid!"; |
40 |
| - } else { |
41 |
| - $fh = fopen($file_name, "wb"); |
42 |
| - $curl = curl_init($remote_file_url); |
43 |
| - |
44 |
| - curl_setopt($curl, CURLOPT_FILE, $fh); |
45 |
| - curl_setopt($curl, CURLOPT_NOBODY, true); |
46 |
| - |
47 |
| - $exec_result = curl_exec($curl); |
48 |
| - |
49 |
| - if ($exec_result !== false) { |
50 |
| - $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); |
51 |
| - |
52 |
| - if ($statusCode == 404) { |
53 |
| - $error_message = "Remote file '" . $remote_file_url . "' responded with 404!"; |
54 |
| - } |
55 |
| - if ($statusCode == 200) { |
56 |
| - $errors = false; |
57 |
| - } |
58 |
| - } |
59 |
| - |
60 |
| - curl_close($curl); |
61 |
| - |
62 |
| - |
63 |
| - } |
64 |
| - |
65 |
| - } catch (Exception $e) { |
66 |
| - $error_message = $e->getMessage(); |
67 |
| - } |
| 27 | + $copy_action = true; |
| 28 | + set_time_limit(0); |
| 29 | + ini_set('max_execution_time', 300000000); |
| 30 | + ini_set('memory_limit', '-1'); |
| 31 | + |
| 32 | + try { |
| 33 | + $remote_file_url = $_POST["remote_file_url"]; |
| 34 | + $file_name = basename($remote_file_url); |
| 35 | + $filePath = dirname(__FILE__) . DIRECTORY_SEPARATOR . $file_name; |
| 36 | + if (file_exists($filePath)) { |
| 37 | + $error_message = "Local file '" . $filePath . "' already exist!"; |
| 38 | + } |
| 39 | + |
| 40 | + if (filter_var($remote_file_url, FILTER_VALIDATE_URL) === false) { |
| 41 | + $error_message = "Url '" . $remote_file_url . "' not valid!"; |
| 42 | + } else { |
| 43 | + |
| 44 | + $error_message = shell_exec("wget " . $filePath . " " . $remote_file_url); |
| 45 | + |
| 46 | + $errors = false; |
| 47 | + } |
| 48 | + |
| 49 | + } catch (Exception $e) { |
| 50 | + $error_message = $e->getMessage(); |
| 51 | + } |
68 | 52 | }
|
69 | 53 | ?>
|
70 | 54 |
|
71 | 55 | <!DOCTYPE html>
|
72 | 56 | <html>
|
73 |
| -<head> |
74 |
| - <meta charset="utf-8"> |
75 |
| - <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet"> |
76 |
| -</head> |
77 |
| -<body> |
78 |
| -<div class="container"> |
79 |
| - <div class="row"> |
80 |
| - |
81 |
| - <?php |
82 |
| - if (!$auth){ |
83 |
| - ?> |
84 |
| - <div class="col-md-6 col-md-offset-3 login"> |
85 |
| - <br> |
86 |
| - <br> |
87 |
| - |
88 |
| - <div class="jumbotron"> |
89 |
| - <h1 style="text-align:center;">Login</h1> |
90 |
| - <br> |
91 |
| - |
92 |
| - <form name="form-login" method="POST" class="form-horizontal"> |
93 |
| - <fieldset> |
94 |
| - <div class="form-group"> |
95 |
| - <label class="control-label col-sm-3" for="username">Email</label> |
96 |
| - |
97 |
| - <div class="col-sm-9"> |
98 |
| - <div class="input-group"> |
| 57 | + <head> |
| 58 | + <meta charset="utf-8"> |
| 59 | + <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet"> |
| 60 | + </head> |
| 61 | + <body> |
| 62 | + <div class="container"> |
| 63 | + <div class="row"> |
| 64 | + |
| 65 | + <?php |
| 66 | + if (!$auth){ |
| 67 | + ?> |
| 68 | + <div class="col-md-6 col-md-offset-3 login"> |
| 69 | + <br> <br> |
| 70 | + |
| 71 | + <div class="jumbotron"> |
| 72 | + <h1 style="text-align:center;">Login</h1> |
| 73 | + <br> |
| 74 | + |
| 75 | + <form name="form-login" method="POST" class="form-horizontal"> |
| 76 | + <fieldset> |
| 77 | + <div class="form-group"> |
| 78 | + <label class="control-label col-sm-3" for="username">Email</label> |
| 79 | + |
| 80 | + <div class="col-sm-9"> |
| 81 | + <div class="input-group"> |
99 | 82 | <span class="input-group-addon">
|
100 | 83 | <span class="glyphicon glyphicon-user"></span>
|
101 | 84 | </span>
|
102 |
| - <input type="text" id="login_username" name="login_username" class="form-control" placeholder="Insert here the username"> |
103 |
| - </div> |
104 |
| - </div> |
105 |
| - </div> |
| 85 | + <input type="text" id="login_username" name="login_username" class="form-control" placeholder="Insert here the username"> |
| 86 | + </div> |
| 87 | + </div> |
| 88 | + </div> |
106 | 89 |
|
107 |
| - <div class="form-group"> |
108 |
| - <label class="control-label col-sm-3" for="password">Password</label> |
| 90 | + <div class="form-group"> |
| 91 | + <label class="control-label col-sm-3" for="password">Password</label> |
109 | 92 |
|
110 |
| - <div class="col-sm-9"> |
111 |
| - <div class="input-group"> |
| 93 | + <div class="col-sm-9"> |
| 94 | + <div class="input-group"> |
112 | 95 | <span class="input-group-addon">
|
113 | 96 | <span class="glyphicon glyphicon-lock"></span>
|
114 | 97 | </span>
|
115 |
| - <input type="password" id="login_password" name="login_password" class="form-control" placeholder="Insert here the password"> |
116 |
| - </div> |
117 |
| - </div> |
118 |
| - </div> |
119 |
| - |
120 |
| - <div class="form-group"> |
121 |
| - <div class="col-sm-9 col-sm-offset-3"> |
122 |
| - <button type="submit" class="btn btn-primary"> |
123 |
| - <span class="glyphicon glyphicon-log-in"></span> Login |
124 |
| - </button> |
125 |
| - </div> |
126 |
| - </div> |
127 |
| - </fieldset> |
128 |
| - </form> |
129 |
| - </div> |
130 |
| - </div> |
131 |
| - |
132 |
| - <?php |
133 |
| - } |
134 |
| - else{ |
135 |
| - ?> |
136 |
| - <div class="col-xs-12"> |
137 |
| - <br> |
138 |
| - <br> |
139 |
| - |
140 |
| - <div class="jumbotron"> |
141 |
| - <h1>Copy remote file to local</h1> |
142 |
| - |
143 |
| - <p> |
144 |
| - Copy remote file to local inserting remote url of file only! |
145 |
| - </p> |
146 |
| - |
147 |
| - |
148 |
| - <form role="form" method="post"> |
149 |
| - <div class="form-group"> |
150 |
| - <label for="remote_file_url">Remote file url</label> |
151 |
| - <input |
152 |
| - name="remote_file_url" |
153 |
| - class="form-control" |
154 |
| - placeholder="File url like https://github.com/twbs/bootstrap/archive/v3.2.0.zip" |
155 |
| - value="<?php echo $remote_file_url; ?>"> |
156 |
| - </div> |
157 |
| - <button type="submit" class="btn btn-primary">Submit</button> |
158 |
| - </form> |
159 |
| - <div> |
160 |
| - <br> |
161 |
| - <br> |
162 |
| - <?php |
163 |
| - if ($copy_action) { |
164 |
| - if ($errors) { |
165 |
| - ?> |
166 |
| - <div class="alert alert-danger" role="alert"><span class="glyphicon glyphicon-remove"></span> File not copied. Errors: <b><?php echo $error_message; ?></b></div> |
167 |
| - <?php |
168 |
| - } else { |
169 |
| - ?> |
170 |
| - <div class="alert alert-success" role="alert"><span class="glyphicon glyphicon-ok"></span> File copied in <b><?php echo $filePath; ?></b></div> |
171 |
| - <?php |
172 |
| - } |
173 |
| - } |
174 |
| - ?> |
175 |
| - </div> |
176 |
| - </div> |
177 |
| - <?php |
178 |
| - } |
179 |
| - ?> |
180 |
| - |
181 |
| - |
182 |
| - </div> |
183 |
| - </div> |
184 |
| -</div> |
185 |
| - |
186 |
| -<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script> |
187 |
| -</body> |
| 98 | + <input type="password" id="login_password" name="login_password" class="form-control" placeholder="Insert here the password"> |
| 99 | + </div> |
| 100 | + </div> |
| 101 | + </div> |
| 102 | + |
| 103 | + <div class="form-group"> |
| 104 | + <div class="col-sm-9 col-sm-offset-3"> |
| 105 | + <button type="submit" class="btn btn-primary"> |
| 106 | + <span class="glyphicon glyphicon-log-in"></span> |
| 107 | + Login |
| 108 | + </button> |
| 109 | + </div> |
| 110 | + </div> |
| 111 | + </fieldset> |
| 112 | + </form> |
| 113 | + </div> |
| 114 | + </div> |
| 115 | + |
| 116 | + <?php |
| 117 | + } |
| 118 | + else{ |
| 119 | + ?> |
| 120 | + <div class="col-xs-12"> |
| 121 | + <br> <br> |
| 122 | + |
| 123 | + <div class="jumbotron"> |
| 124 | + <h1>Copy remote file to local</h1> |
| 125 | + |
| 126 | + <p> |
| 127 | + Copy remote file to local inserting remote url of file only! |
| 128 | + </p> |
| 129 | + |
| 130 | + |
| 131 | + <form role="form" method="post"> |
| 132 | + <div class="form-group"> |
| 133 | + <label for="remote_file_url">Remote file url</label> |
| 134 | + <input |
| 135 | + name="remote_file_url" |
| 136 | + class="form-control" |
| 137 | + placeholder="File url like https://github.com/twbs/bootstrap/archive/v3.2.0.zip" |
| 138 | + value="<?php echo $remote_file_url; ?>"> |
| 139 | + </div> |
| 140 | + <button type="submit" class="btn btn-primary">Submit</button> |
| 141 | + </form> |
| 142 | + <div> |
| 143 | + <br> <br> |
| 144 | + <?php |
| 145 | + if ($copy_action) { |
| 146 | + if ($errors) { |
| 147 | + ?> |
| 148 | + <div class="alert alert-danger" role="alert"> |
| 149 | + <span class="glyphicon glyphicon-remove"></span> |
| 150 | + File not copied. Errors: <b><?php echo $error_message; ?></b></div> |
| 151 | + <?php |
| 152 | + } else { |
| 153 | + ?> |
| 154 | + <div class="alert alert-success" role="alert"> |
| 155 | + <span class="glyphicon glyphicon-ok"></span> |
| 156 | + File copied in <b><?php echo $filePath; ?></b></div> |
| 157 | + <?php |
| 158 | + } |
| 159 | + } |
| 160 | + ?> |
| 161 | + </div> |
| 162 | + </div> |
| 163 | + <?php |
| 164 | + } |
| 165 | + ?> |
| 166 | + |
| 167 | + |
| 168 | + </div> |
| 169 | + </div> |
| 170 | + </div> |
| 171 | + |
| 172 | + <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script> |
| 173 | + </body> |
188 | 174 | </html>
|
189 | 175 |
|
0 commit comments