Qualcuno conosce il PHP?

Discuti dei problemi relativi alla programmazione nel tuo linguaggio preferito!

Moderatori: cb_123, thrantir, tonertemplum

Qualcuno conosce il PHP?

Messaggiodi Ibanez89 il 07 ago 2008, 22:47

Posto ciò k ho scritto anche su un'altro forum:

Raga ne capisco meno di 0 in programmazione, e quindi mi rivolgo a voi nella speranza di un'aniuto

1. Veniamo al dunque, uno script PHP ha la capacità di modificare un file in un sistema GNU/Linux?

Mi spiego meglio, è capace di editare un file di testo cancellando una frase e mettendo al suo posto una password random?

2. Uno script è capace, dopo aver ricevuto un'input "html" dall'esterno di chiudere, avviare o riavviare un processo di sistema?

vi spiego a cosa mi servirebbe:

In un'angolo remoto del metaverso una persona scatena un'evento A e tramite una richiesta tramite il protocollo http/https il server deve come prima cosa salvare i dati della persona che ha scatenato l'evento, e in secondo luogo modificare la password contenuta nel file di configurazione di un programma e avviare quest'ultimo.

Successivamente tramite un'altro evento B, lo script deve controllare in un database se la persona che ha scatenato l'evento è la stessa che ha scatenato quell'evento e in caso affermativo ordina al server di chiudere il processo, ricambiare password e ri avviare il processo "ad esempio se quella persona pensa che la password sia stata compromessa"

3. dopo tot tempo il server automaticamente chiude il processo avviato in precedenza...

Per la rete ho trovatyo sto script, ma non ho proprio idea se può esservi d'aiuto

<?

// SCPROXY+AUTH 0.1a tom@winamp.com 01.18.2002
// <a href="http://beta.shoutcast.com/~tpepper/scproxy.phps" target="_blank"><a href="http://beta.shoutcast.com/~tpepper/scproxy.phps" target="_blank">http://beta.shoutcast.com/~tpepper/scproxy.phps</a></a>
//
// requires: php 4.0.5+ compiled with --enable-sockets and --with-mysql
//
// this script will act as a liason between a private shoutcast server and
// a public listener, providing an auth mechanism for subscription-only
// services. This script is currently configured for a mysql database,
// but should be fairly trivial to convert to another db. It expects by
// default a database table with two entries, username and password, both
// in cleartext. If the incoming auth request matches these fields, the
// connection is put through. If not, byebye.
//
// the script also has a mechanism for disallowing concurrent logins, so only
// one authpair can proxy at a given moment. (only one person can listen to
// the stream per authentication pair is the intended effect)
//
// You will need some knowledge of mysql to create the database and
// table. An example, given the defaults, might be:
//
// mysqladmin create scproxy
// mysql scproxy
// mysql> CREATE TABLE auth(username VARCHAR(255) NOT NULL PRIMARY KEY,
// -> password VARCHAR(255) NOT NULL,
// -> timestamp INT NOT NULL);
// mysql> INSERT INTO auth VALUES ('test','password',0);
//
// then, configure the sc_host and sc_port below (and db_login/db_password
// if necessary,) then test by connecting winamp to this script via
// http://test<img%20src="images/smilies/tongue.gif"%20border="0"%20alt="">assword@php.server.ip.address/scriptname.php
//
// once you get it working, remove the test auth pair with:
// mysql> DELETE FROM auth WHERE username='test';



// BEGIN CONFIG BLOCK ////////////////////////////////////////////
$db_hostname="mysql.ip.address.here";
$db_login="dbusername";
$db_password="password";
$db_database="scproxy";
$db_tablename="auth";
$db_username_field="username";
$db_password_field="password";
$db_timefield="timestamp";
$sc_host="ip.of.shotucast.server";
$sc_port=8000;
// END CONFIG BLOCK //////////////////////////////////////////////

set_time_limit(0);
ignore_user_abort();
register_shutdown_function("byebye");

function byebye() {
global $shutdown_flag,$db_tablename,$db_timefield,$db_username_field,$PHP_AUTH_USER;
$shutdown_flag=1;
@mysql_query("UPDATE $db_tablename SET $db_timefield=0 WHERE $db_username_field='$PHP_AUTH_USER'");
@fclose($sp);
}

if (!isset($PHP_AUTH_USER)) {
header("WWW-Authenticate: Basic realm=\"SCProxy\"");
header("HTTP/1.0 401 Unauthorized");
echo "This service requires a valid login/password.\n";
exit;
}

$linkid=@mysql_connect($db_hostname, $db_login, $db_password) or die("Cannot connect to authentication database to verify login.");
@mysql_select_db($db_database) or die("Unable to select database $db_database.\n");

$query="SELECT $db_timefield AS lastupdate FROM $db_tablename WHERE $db_username_field='$PHP_AUTH_USER' AND $db_password_field='$PHP_AUTH_PW'";

$matches=0;
$lastupdate=0;
$res=@mysql_query($query);
if($obj=@mysql_fetch_object($res)) {
$lastupdate=$obj->lastupdate;
$matches=mysql_num_rows($res);
}

if(!$matches) {
header("WWW-Authenticate: Basic realm=\"SCProxy\"");
header("HTTP/1.0 401 Unauthorized");
echo "This service requires a valid login/password.\n";
exit;
}

if(time()-$lastupdate<600) {
header("ICY 404 The account is already in use. If account is inactive, wait 10 minutes and try again.");
exit("The account is already in use. If account is inactive, wait 10 minutes and try again.");
}

$sp = fsockopen($sc_host, $sc_port, &$errno, &$errstr, 10);
if (!$sp) exit("Could not connect to SHOUTcast server.\n");

set_socket_blocking($sp,false);

fwrite($sp,"GET / HTTP/1.0\nUser-Agent:SHOUTcast PHP Proxy 0.1\nicy-metadata:1\n\n");

$sockack=0;

for ($i=0; $i<120; $i++) {
if (feof($sp)) break;
$str.=fread($sp,4096);
usleep(200000);
if (strpos($str,"\r\n\r\n")) break;
}


if(strpos($str,"\r\n\r\n")===false) exit("Unable to establish stream with SHOUTcast server.\n");
else {
$head=substr($str,0,strpos($str,"\r\n\r\n"));
$head=eregi_replace("ICY 200 OK\r\n","",$head);
header($head);
}

flush();
echo substr($str,strpos($str,"\r\n\r\n")+4);
flush();
while(!$shutdown_flag) {
$buf=fread($sp,4096);
if (feof($sp)) $shutdown_flag=1;
echo $buf;
flush();
usleep(75000);
if(time()-$lasttime>300) {
@mysql_query("UPDATE $db_tablename SET $db_timefield=".time()." WHERE $db_username_field='$PHP_AUTH_USER'");
$lasttime=time();
}
}

?>

2.
Create a PLS file that points to your PHP script.
When folks click the PLS, it'll load in Winamp and ask for authorization.

Listeners provide their username and password in the form (the popup displays this example):
username<img src="images/smilies/tongue.gif" border="0" alt="">assword

Generic PLS Example:
[playlist]
NumberOfEntries=1
File1=http://YOUR-PHP-SCRIPT
Title1=YOUR-STATION-NAME
Length1=-1
Version=2

Pseudo PLS Example:
[playlist]
NumberOfEntries=1
File1=http://www.myhost.com/myscript.php
Title1=My Station
Length1=-1
Version=2

3.
I have modified my PHP script to authorize against my phpBB PHP bulletin board.
Change the database values to point to your phpBB users table and users columns.
Change the initial query to:
$query="SELECT $db_timefield AS lastupdate FROM $db_tablename WHERE $db_username_field='$PHP_AUTH_USER' AND $db_password_field='" . md5($PHP_AUTH_PW) . "'";


Dite che una cosa simile è fattibile? Ho visto un sistema simile in azione ed è fenomenale, mi farebbe risparmiare un sacco di tempo e d+
CiAo DanIele...

Immagine
Pentium4 Northwood HT 2.6@3000 "230*13" vcore def [RIP] King Value 512*2 200@230 cas2@3 Ati x800gto2@x850pe powered by Arctic Cooler [RIP] Mother ASRock P4VM900-SATA2 [RIP]
insomma poco alla volta mi si sta bruciando tutto :asd:

Immagine
Avatar utente
Ibanez89
AmdPlanet Guru
AmdPlanet Guru
 
Messaggi: 5563
Iscritto il: 15 apr 2006, 17:31
Località: Corato (BA)

 

Re: Qualcuno conosce il PHP?

Messaggiodi paperina il 08 ago 2008, 09:56

si', si puo' fare di certo. Appena ho tempo magari do un'occhiata al codice che hai postato, ma ti posso dire gia' ora che il php viene usato spesso per simili cose.
Spero di poterti essere presto di aiuto
Muore lentamente chi evita una passione...
Avatar utente
paperina
Saggio del pianeta
Saggio del pianeta
 
Messaggi: 526
Iscritto il: 20 set 2006, 17:55
Località: pisa

Re: Qualcuno conosce il PHP?

Messaggiodi thrantir il 08 ago 2008, 11:10

quoto paperina.

considera che php può essere utilizzato come linguagio di scripting in sostituzione a bash :wink:

tieni presente che lo script viene invocato da un utente particolare, che è quello che manda in esecuzione il web server (immagino apache), quindi quell'utente deve anche avere tutti i diritti necessari per fae le operazioni che ti occorrono
Fletto i muscoli e sono nel vuoto
Principi di architettura degli eleboratori
X postare immagini
-----BEGIN GEEK CODE BLOCK-----
GCS/IT/L/MU d- s: a C++$>+++ UL+>++ P L+++>++++ E--- W++ N++>+++ o+>++ K? w O-- M- VMS? V- PS++ Y+ PGP+ t 5? X+ R++>+++ tv+ b+++>++++ DI+++ D++ G e++ h- r++ y++
------END GEEK CODE BLOCK------
Addio Dani, sono più ricco perchè ti ho conosciuto
Avatar utente
thrantir
Moderatore
Moderatore
 
Messaggi: 8897
Iscritto il: 27 mag 2003, 13:32
Località: Pisa

Re: Qualcuno conosce il PHP?

Messaggiodi Ibanez89 il 08 ago 2008, 13:30

perfetto, grazie mille, do anche qualche lettura a guide ecc
CiAo DanIele...

Immagine
Pentium4 Northwood HT 2.6@3000 "230*13" vcore def [RIP] King Value 512*2 200@230 cas2@3 Ati x800gto2@x850pe powered by Arctic Cooler [RIP] Mother ASRock P4VM900-SATA2 [RIP]
insomma poco alla volta mi si sta bruciando tutto :asd:

Immagine
Avatar utente
Ibanez89
AmdPlanet Guru
AmdPlanet Guru
 
Messaggi: 5563
Iscritto il: 15 apr 2006, 17:31
Località: Corato (BA)


Torna a Programmare

Chi c’è in linea

Visitano il forum: Nessuno e 1 ospite

cron