php-proxy-app
php-proxy-app copied to clipboard
Access by link only
Is it possible to make it so that the index.php file itself is password protected, but if a user is directed to index.php?q=VALUE, it is not blocked. I was thinking there would be some way through a .htaccess file, but I am not sure?
My website is: development.stech.software and we are using it so that teachers can give students access to blocked pages on the filter, but only through a link basis.
yes its possible . do you need passwords for each user or just a master password?. What should the q=value be?.. anyway heres a simple script you can add to the top of index.php
https://pastebin.com/WZ6Ki5dD
Yes! Thank you! The only thing is, the code you provided only works if the query string is “QUERY”. I need it so that it will work if there is ANY query string.
I just need a master password
Ill modify it shortly and send you it
try this. hope it can help the password is set to "MYPASS" but you can change this ofcourse https://pastebin.com/2vmiXkRF
Hey ash121121, when I add that to the top of my index.php, it gives me HTTP Error 500 and server couldn't handle request or something like that.
I added your code below <?php and above the first line of code in index.php
Send me the whole index.php with the added changes to pastebin
Here is my code. @ash121121
<?php
if ( isset ( $ _POST [ 'password' ] ) && $ _POST [ 'password' ] == 'MYPASS' ) { // We check here if the password entered matches 'MYPASS' and if so we set a cookie for 30 days .
setcookie ( "password" , 'MYPASS' , strtotime ( '+30 days' ) ) ;
header ( 'Location:' . $ _SERVER [ 'PHP_SELF' ] ) ;
exit ;
}
if ( empty ( $ _GET [ 'q' ] ) ) { // Here we check if 'index.php? q' has a value of 'VALUE' and if not we ask for password.
// Simple password protection
if ( ! isset ( $ _COOKIE [ 'password' ] ) || $ _COOKIE [ 'password' ] ! == 'MYPASS' ) {
echo '<html>
<head>
<title>
Password protected </ title>
</ head>
<body>
<div style = "text-align: center; margin-top: 50px;">
You must enter the password to view this content.
<form method = "POST">
<input type = "text" name = "password">
</ form>
</ div>
</ body>
</ html>' ;
exit ;
}
}
define('PROXY_START', microtime(true));
require("vendor/autoload.php");
use Proxy\Http\Request;
use Proxy\Http\Response;
use Proxy\Plugin\AbstractPlugin;
use Proxy\Event\FilterEvent;
use Proxy\Config;
use Proxy\Proxy;
use Proxy\plugin\YoutubePlugin;
// start the session
session_start();
// load config...
Config::load('./config.php');
// custom config file to be written to by a bash script or something
Config::load('./custom_config.php');
if(!Config::get('app_key')){
die("app_key inside config.php cannot be empty!");
}
if(!function_exists('curl_version')){
die("cURL extension is not loaded!");
}
// how are our URLs be generated from this point? this must be set here so the proxify_url function below can make use of it
if(Config::get('url_mode') == 2){
Config::set('encryption_key', md5(Config::get('app_key').$_SERVER['REMOTE_ADDR']));
} else if(Config::get('url_mode') == 3){
Config::set('encryption_key', md5(Config::get('app_key').session_id()));
}
// very important!!! otherwise requests are queued while waiting for session file to be unlocked
session_write_close();
// form submit in progress...
if(isset($_POST['url'])){
$url = $_POST['url'];
if (strpos ($url, '.') !== false){
$url = add_http($url);
header("HTTP/1.1 302 Found");
header('Location: '.proxify_url($url));
exit;
}
else {
$url = 'http://www.google.com/search?q=' . urlencode($url);
$url = add_http($url);
header("HTTP/1.1 302 Found");
header('Location: '.proxify_url($url));
exit;
}
} else if(!isset($_GET['q'])){
// must be at homepage - should we redirect somewhere else?
if(Config::get('index_redirect')){
// redirect to...
header("HTTP/1.1 302 Found");
header("Location: ".Config::get('index_redirect'));
} else {
echo render_template("./templates/main.php", array('version' => Proxy::VERSION));
}
exit;
}
// decode q parameter to get the real URL
$url = url_decrypt($_GET['q']);
$proxy = new Proxy();
// load plugins
foreach(Config::get('plugins', array()) as $plugin){
$plugin_class = $plugin.'Plugin';
if(file_exists('./plugins/'.$plugin_class.'.php')){
// use user plugin from /plugins/
require_once('./plugins/'.$plugin_class.'.php');
} else if(class_exists('\\Proxy\\Plugin\\'.$plugin_class)){
// does the native plugin from php-proxy package with such name exist?
$plugin_class = '\\Proxy\\Plugin\\'.$plugin_class;
}
// otherwise plugin_class better be loaded already through composer.json and match namespace exactly \\Vendor\\Plugin\\SuperPlugin
$proxy->getEventDispatcher()->addSubscriber(new $plugin_class());
}
try {
// request sent to index.php
$request = Request::createFromGlobals();
// remove all GET parameters such as ?q=
$request->get->clear();
// forward it to some other URL
$response = $proxy->forward($request, $url);
// if that was a streaming response, then everything was already sent and script will be killed before it even reaches this line
$response->send();
} catch (Exception $ex){
// if the site is on server2.proxy.com then you may wish to redirect it back to proxy.com
if(Config::get("error_redirect")){
$url = render_string(Config::get("error_redirect"), array(
'error_msg' => rawurlencode($ex->getMessage())
));
// Cannot modify header information - headers already sent
header("HTTP/1.1 302 Found");
header("Location: {$url}");
} else {
echo render_template("./templates/main.php", array(
'url' => $url,
'error_msg' => $ex->getMessage(),
'version' => Proxy::VERSION
));
}
}
?>
Please put it at pastebin.com
First issue im seeing is its added spaces in the code. Maybe github has done this so please upload to pastebin.com
https://pastebin.com/xpDBvJpM @ash121121
Do you have access to the error logs on the server or maybe can provide access to debug the issue? You can contact me at [email protected]
please replace index.php contents with this see if works. if not then ill need to see error logs
https://pastebin.com/raw/weJnEp9L
I just sent you an email; I just got on my lunch break, I will check it out in an hour.
Can you close this ? I believ we fixed it over email ?