PHP / Python Check if firewall is turned off - php

is it possible to write a PHP script that checks if the PC's firewall is disabled and then output yes/no into a checkbox on the webpage? (Hosting my own web server using WAMP)
Currently what i have in mind is create a .bat file that checks if firewall is turned off
using:
netsh advfirewall show public
then check if the State shown on CMD is On / OFF and return results to the web-page's checkbox.
Thing is i have no idea how do i go about doing the check state and return results.
Please advise. Also open to other ideas / solutions that could provide similar results.
PS: Am a beginner at PHP scripting and only started learning python today and project is due in 3 weeks. Also would be nice if you could link full code solutions if you know of any. I learn faster through referencing.

You can use this command to get only the status of the public profile :
"netsh advfirewall show public state"
This command can be used in a python script with the subprocess module :
result = subprocess.check_output(["netsh", "advfirewall", "show ", "allprofiles", "state"].decode('utf-8')
The result will be a string, using regex you will be able to get the value from it.
https://docs.python.org/3/library/re.html
Example of regex :
status = re.search('state[ ]*([A-Za-z])*', result).group(1)

Related

Script selenium python always detected as bot on flashseats :(

my script always detected why ?!!!!
most of time i use python selenium for scraping website but this time i'am always detected by "https://www.flashseats.com"
Can you help me please!!
here's part of my selenium code , i even try to use different proxies but :( same result,
please propose me a solution either in python or PHP.
chrome_options = webdriver.ChromeOptions()
options = webdriver.ChromeOptions()
options.add_argument('--disable-infobars')
options.add_argument('--disable-extensions')
options.add_argument('--profile-directory=Default')
options.add_argument('--incognito')
options.add_argument('--disable-plugins-discovery')
options.add_argument('--start-maximized')
#_chrome_options = Options()
#_chrome_options.add_argument('disable-infobars')
driver = webdriver.Chrome(r'C:\browser\chromedriver.exe', chrome_options=chrome_options)
time.sleep(10)
driver.get("https://www.flashseats.com/")
I know that might be a late answer, but you can try using Selenium-Profiles or undetected-chromedriver for that.
To answer your question: You're most likely getting detected because of values in javascript like navigator.webdriver, which might be different than in a normal browser.

Scala Lift - Run PHP file from within scala runtime

I'm not entirely sure the wording for the title is correct, but what I'm attempting to do is run and execute PHP files from within the Lift framework.
I'm not after any url queries to a PHP file residing on a server, more interested in somehow getting the PHP runtime working through my Scala/Lift app.
Use case: I have my app packaged into a .war file, I host this via a cloud provider. I upload code snippets to said app which then runs the php file and does whatever necessary.
I've seen various posts regarding Bianca but am hoping to keep this setup light and require only the PHP binary itself and a little code to get it flying.
Thanks in advance, please let me know if you need me to elaborate :)
“Never say never, because limits, like fears, are often just an
illusion.”
― Michael Jordan
What you really need is an open source (GPL), embeddable, full PHP 5 implementation, written entirely in Java!
Caucho's Quercus PHP Java runtime is just that, and it will let you run PHP within a Java app without external libraries or native code.
Below is a Quercus-PHP-in-Java code sample I found in this answer
import javax.script.ScriptEngine;
import com.caucho.quercus.script.QuercusScriptEngineFactory;
QuercusScriptEngineFactory factory = new QuercusScriptEngineFactory();
ScriptEngine engine = factory.getScriptEngine();
String phpCode = "<?php $foo = strlen('abc'); print $foo; return 'yikes'; ?>"; //PHP Code as String
Object o = engine.eval(phpCode);
System.out.println(o);
It should be little effort to convert this code to idiomatic Scala. Obviously, the 'phpCode' variable could be constructed from external PHP file contents etc.
Let us know how you get on ;-)
That's a bit of an odd requirement, but if it's what you need to do, you can use a ProcessBuilder to execute and interact with your PHP script from the command line.

Get windows title using php doesn't work on browser call

My problem is I need to fetch FOOBAR2000's title because that including information of playing file, so I create a execute file via Win32 API(GetWindowText(), EnumWindows()) and it's working good.
TCHAR SearchText[MAX_LOADSTRING] = _T("foobar2000");
BOOL CALLBACK WorkerProc(HWND hwnd, LPARAM lParam)
{
TCHAR buffer[MAX_TITLESTRING];
GetWindowText(hwnd, buffer, MAX_TITLESTRING);
if(_tcsstr(buffer, SearchText))
{
// find it output something
}
return TRUE;
}
EnumWindows(WorkerProc, NULL);
Output would look like "album artis title .... [foobar2000 v1.1.5]"
I created a php file like test.php, and use exec() to execute it.
exec("foobar.exe");
then in console(cmd) I use command to execute it
php test.php
It's working good too, same output like before.
Now I use browser(firefox) to call this php file(test.php), strange things happened.
The output only foobar2000 v1.1.5, others information gone ...
I think maybe is exec() problem? priority or some limitation, so I use C# to create a COM Object and register it, and rewrite php code
$mydll = new COM("FOOBAR_COMObject.FOOBAR_Class");
echo $mydll->GetFooBarTitle();
still same result, command line OK, but browser Fail.
My question is
Why have 2 different output between command line and browser. I can't figure it out.
How can I get correct output via browser.
or there is a easy way to fetch FOOBAR2000's title?
Does anyone have experience on this problem?
== 2012/11/28 edited ==
follow Enno's opinion, I modify http_control plug-in to add filename info, original json info is "track title".
modify as following
state.cpp line 380 add 1 line
+pb_helper1 = pfc::string_filename(pb_item_ptr->get_path());
pb_helper1x = xml_friendly_string(pb_helper1);
# 1: when firefox opens the php and it gets executed, it the context depends on the user which runs the php-container (apache), this is quite different from the commandline call which gets executed in your context
# 2 and 3: there seems to be more than one way for getting the title: use the foobar-sdk and create a module which simply reads the current title per api, then write your result in an static-html-document inside your http-root-folder OR use the http-client inside the sdk, with it, you do not need a wabserver, even better use a already implemented module: for instance foo_upnp or foo-httpcontrol
Good luck!
If your webserver runs as a service, in windows you need to enable "allow desktop interaction" for the service. Your php script runs as a child of the webserver process when requested via browser.

Security through command line: is it a good idea? (PHP)

Is it OK to give full authorization to any request coming from the command line?
My idea was to make this check:
if(isset($_SERVER['argc']) AND $_SERVER['argc']>=2) {
// it must be the admin, give him full authorization, no further checks needed.
} else {
// normal web request, authentication needed.
}
Does this make sense?
Anything else I should know before I start using the command line to execute my php scripts?
It's only safe if the server has only one user. Otherwise you need to either:
Check for the correct user ID in the script
Make the script only executable for that user
(This is assuming a Linux server)
The command line is not a very good place from which to control your web application: your app displays HTML output, which is not much good to a human looking at a console (not to mention the JavaScript that won't work etc).
You could arrange for different output to be generated when running from the command line, but as a practical matter: why bother with all this? Why not have the administrator be authenticated from the web just like any other user?
If you want to have a special backdoor built into your app anyway though, I would suggest something like this (which is web-based):
define('ADMIN_BACKDOOR', true); // comment out to disable
$is_admin = defined('ADMIN_BACKDOOR') && $_SERVER['REMOTE_ADDR'] == '127.0.0.1';
This is IMO next to impossible to exploit, and it allows you admin access from a natural environment (the browser).

Communication, Passing Info between PHP App and Ruby App

I primarily work in PHP and prefer to do so since there seem to be more jobs in this language, at least in my area (and I'm still fairly new to it so I want to continue to learn the language better).. but for some things I want to do I need to use the WWW Mechanize library that doesn't work with PHP but does with Ruby (yes I know PHP has some alternatives but I have tried them and they don't work for me so I need to do this), so I'd like to write most of my app in PHP and then just call Ruby when I need to use this library, then pass the info back to PHP, yes I know this would be "slow" but thats not an issue in this case as this isn't a public web app, its just for business use..
I'm wondering what the best way would be to pass info between the 2 languages.. I have thought of using http POST (like with Curl in PHP) to do this but not sure if this is the most efficient way any.. any info is appreciated, thanks
There are two different ways that I would do this:
\1. In ruby, set up a non-HTTP server that only listens on '::' (or 127.0.0.1 if you don't like ipv6). Then, every time your PHP script needs to do something, it can connect to the server and pass data to it. This would be the fastest solution because the ruby script doesn't need to start up every time PHP needs to do something.
Example Ruby:
require 'mechanize'
require 'socket'
def do_mechanize_stuff(command, *args)
case command
when 'search_google'
# search google with args.join(' ')
when 'answer_questions_on_stackoverflow'
# answer questions on stackoverflow
# with mechanize
end
'the result to pass to PHP'
end
srv = TCPServer.new '::', 3000
loop do
Thread.new(srv.accept) do |sock|
sock.write(
do_mechanize_stuff *sock.gets.split(' ')
)
sock.close
end
end
Example Ruby client: (you will need to translate this to PHP)
require 'socket'
# This is a script that searches google
# and writes the results to stdout.
s = TCPSocket.new 'localhost', 3000
s.puts 'search_google how to use a keyboard'
until (r = s.gets).nil?
print r # a search result.
end
You could use process watching tools like http://god.rubyforge.org/ to keep the server running.
\2. Make the ruby script a command line utility, and use exec in PHP to call it.
An example command line script:
require 'mechanize'
def do_mechanize_stuff(command, *args)
# ... from previous example
end
do_mechanize_stuff ARGV.shift, ARGV
I would suggest following a Software as a Service Architectire (SOA) and running a Ruby/Rails application as a separate process. You'll have to develop an API between the two (a very simple one will work): using POST/GET as you first thought is a right way to go here.

Categories