Using phpseclib "write" in order to send Linux commands to a web server - phpseclib

I'm trying to use phpseclib in order to connect SSH to my Web Server through a WEB proxy.
The PHP file is very simple but it doesn't work, what is the problem?
After several seconds while the server seems to hang, the result I get is:
cd /home/web/sqladmin\nls -la\n
I tried also using \r\n and \r instead of \n.
The PHP filename is "ssh.php".
<?php
ini_set("display_errors",1);
include('Net/SSH2.php');
$ssh = new Net_SSH2('127.0.0.1');
if (!$ssh->login('username', 'password')) {
exit('Login Failed');
}
?>
<br>
<form action="ssh.php" method="get" name="salvarouting">
Comando: <input name="comando" type="text">
<br><input name="avanti" type="submit" value="OK">
</form>
<br>
<?php
$ssh->read('/.*#.*[$|#]/', NET_SSH2_READ_REGEX);
$ssh->write('cd /home/web/sqladmin\n');
if(isset($_GET['comando'])) {
$ssh->write($_GET['comando'].'\n');
$ssh->setTimeout(10);
echo '<pre>'.htmlspecialchars($ssh->read()).'</pre>';
}
?>

Related

Referer is insecure while host is secure

My site works fine locally, but on the staging server, I get the following error:
"Referer checking failed - Referer is insecure while host is secure."
Settings files are identical in both environments. Possibly should not be, but I'm not sure what needs to be tweaked.
The only other question I can find about this issue is CSRF verification Failed - Referer is insecure while host is secure, but that seems to have the opposite problem (works on production, but not locally).
I've looked at https://github.com/django/django/blob/master/django/middleware/csrf.py, but it's not immediately helpful to me.
This is where I make the POST request:
$(function() {
$(".submit-signin").on("click", function() {
var data = $("#signin-form").serialize();
$.post("/signin/", data, function(response) {
});
});
});
data contains the csrf token:
<form id="signin-form">
<input type="hidden" name="csrfmiddlewaretoken" value="{{ csrf_token }}"/>
{% include "signin_form.html" %}
<button type="button" class="small-button submit-signin">Sign in</button>
</form>
I don't know if the staging server is using HTTPS. How can I find this out?

ACF field content not retrieving in Wordpress Multisite

I am using ACF repeater field in Wordpress Multisite template. Fields showing in its admin panel and I can add content using back end. But those data not showing in front end. This is my code to retrieve data.
<?php if(get_field('history')): ?>
<?php while(has_sub_field('history')): ?>
<div class="col-lg-3 history">
<h3><?php the_sub_field('year'); ?></h3>
<div class="description"><p><?php the_sub_field('description'); ?></p></div>
</div>
<?php endwhile; ?>
I have 3 sites.
/xx
/xx
/xx
How can I show data in front end..?
I believe your if statement is incorrect. its should probably ready if(get_sub_field('history')):

Trying to validate one or more email extensions using regular expression

I'm getting a user to input their email address and trying to validate it using regular expressions and the preg match function. I'm unable to get the code to validate different email extensions (hotmail, gmail, blueyonder etc.) as I'm only able to get it to accept one and cannot use an OR function in the code. I'm not getting a specific error but as it is the user will have to be limted to just using the 'gmail.co.uk' extension. Any help?
Code:
<?php
$emailErr = "";
$email = "";
if(isset($_POST['submit'])){
if(empty($_POST["email"])) {
$emailErr = "Email is required";
}else{
$email = ($_POST["email"]);
if (!preg_match("/[a-zA-Z_-]+#[gmail]+.+[co]+.+[uk]/",$email)){
$emailErr = "Only letters and white space allowed";
}
}
}
?>
<html>
<head>
<title> symbol test</title>
<style>
.error {color: #FF0000;}
</style>
</head>
<body>
<form name = "testform" method="POST">
<p>Email:<input type="text" name="email" style="width:20%"/>
<span class="error">*<?php echo $emailErr;?></span>
<p><br><input type="submit" name="submit" value="Submit"/></br></p>
</form>
<?php
echo $email;
?>
</body>
</html>
[gmail] is not the actual way to go. This matches g or m or a or i or l.
[a-zA-Z_-]+#gmail\.co\.\uk
Add anchors if necessary.
if (!preg_match("~^[a-zA-Z_-]+#gmail\.co\.uk$~",$email)){
If you are looking for a generic regex to match all kind of valid email-ID then you can try
^(?![\W_])((?:([\w-]{2,})\.?){1,})(?<![\W_])#(?![\W_])(?=[\w.-]{5,})(?=.+\..+)(?1)(?<![\W_])$
Look at the regex demo for detailed overview.

How to upload image using rest web services in symfony

I am trying upload image using rest web service in my symfony application. I have tried the following code but it is throwing the error undefined index photo. I want to know what is the right way to do it.
I have followed how to send / get files via web-services in php but it didn't worked.
Here is the my html file with which am hitting the application url:
<form action="http://localhost/superbApp/web/app_dev.php/upload" enctype='multipart/form-data' method="POST">
<input type="file" name="photo" ></br>
<input type="submit" name="submit" value="Upload">
</form>
And my controller method is like:
public function uploadAction(){
$request = $this->getRequest(); /*** get the request method ****/
$RequestMethod = $request->getMethod();
$uploads_dir = '/uploads';
foreach ($_FILES["photo"]["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
$tmp_name = $_FILES["photo"]["tmp_name"][$key];
$name = $_FILES["photo"]["name"][$key];
move_uploaded_file($tmp_name, $uploads_dir."/".$name);
}
}
}
If you are using Symfony, you should use Symfony forms to do this. In your example, you put an URL which is pointing to app_dev.php, but that url doesn't work in production mode. In the Symfony cookbook there is an article explaining how upload files, which you should read:
http://symfony.com/doc/current/cookbook/doctrine/file_uploads.html
When you have done this, you can upload images via Rest WebService using the route specified for your action, specifying the Content-Type to multipart/form-data, and the name of the field which you add the image would be something like this package_yourbundle_yourformtype[file].

how to replace "opencart" word from back-end

i want to replace the "Opencart" word from my back-end by the name of my store. I mean the "Opencart" written before the "Administration" in back end and from its footer in Dashboard. Will please any one help me out?
Thank you..
I think "Opencart" not word but it's an image logo.
You can edit this line :
<div class="div2">
<img src="view/image/logo.png" title="<?php echo $heading_title; ?>" onclick="location = '<?php echo $home; ?>'" />
</div>
location file : admin/view/template/common/header.tpl