Loading...
Change root password of Muse X-Duo Raid Thermaltake

Firmware 1.7.1

Thermaltake not provides root password for this NAS.
It is possible to change it.

You need to change /etc/passwd file where passwords (encrypted) are stored.

Download Sancho to control Mldonkey server. Install it.
Go to your admin interface of NAS. Login as admin. Go to section Advanced and start your DownaloadStation (mldonkey).

Now run Sancho to connect to mldonkey server. Put ip of your NAS and admin password.
On Sancho search for a button named Console. Click it and now you can send commands to server with the last one row at bottom.
Mldonkey run as root ad you can lunch commands as a shell.
Unlikely if you write “passwd” you can’t change root password because the console not support remote prompt.
But you can run che command “/bin/chmod 777 /etc/passwd”. So anyone can write on password file.

Now you need an access thru telnet or ssh.
On Sancho, write the command “/bin/chsh -s /bin/bash admin.
Now open your putty or a Prompt-command and write “telnet 192.168.X.Y” (192.168.X.Y is ip of your NAS).
Enter admin as login and your password.
You are in.

Now you can run “vi /etc/passwd”.
first line is similar to:
root:75hv0xCjznz1U75hv0xCjznz1U:500:600,700,701,702:…..

and other lines, one is similar to
admin:7asd5hasdv0xCjznz1U75hv0xCjznz1U:500:600,700,701,702:…..

copy the string of the second field (separated from “:”) (es:7asd5hasdv0xCjznz1U75hv0xCjznz1U) in the second field of the”root line”.

Example:
root:7asd5hasdv0xCjznz1U75hv0xCjznz1U:500:600,700,701,702:…..

So your root password is the same of admin password.
Save /etc/passwd and now you know root password.

If you prefer you can login as root and run passwd to change root password.
Reset permissions of /etc/passwd file with “/bin/chmod 755 /etc/passwd”

Richiesta conferma nell’invio di una form
function confirmSubmit() {
var agree=confirm("Confermi ?");
if (agree)
return true ;
else
return false ;
}
<form action="" onsubmit="return confirmSubmit()">...
Troncare una stringa dopo ‘tot’ parole

In sostituzione del testo elimnato è possible inserire $terminal_string. Per esempio potrebbe essere un ‘[..]’ per far capire che il testo contina.

function trunc($phrase, $max_words, $terminal_string){
       $phrase_array = explode(' ',$phrase);
       if(count($phrase_array) > $max_words && $max_words > 0)
          $phrase = implode(' ',array_slice($phrase_array, 0, $max_words)) . $terminal_string;
       return $phrase;
}
Conoscere l’estensione dal nome di un file
function getExtension($file){
        $dots = explode(".", $file);
        return strtolower($dots[count($dots)-1]);
}
Stripslashes ricorsiva su un array

A volte può essere utile fare uno stripslashes su ogni elemento dell’array.

function stripslashes_deep($value)
{
$value = is_array($value) ?
array_map('stripslashes_deep', $value) :
stripslashes($value);

return $value;
}
Elminare da una stringa caratteri non validi

In realtà è molto potente, ma per capire come funziona bisogna iniziare con gli esempi facile :)
Questa riga di codice permette di levare da $originaltext” i caratteri che non siano cifre, lettere minuscole, punto, underscore e meno.

$strippedtext = preg_replace('/[^0-9a-z._-]/i','',$originaltext);
Paginazione in php, con aggiunta di un filtro alla query

Creare una semplicissima paginazione da una query sql.
In aggiunta c’e’ la possibilità di passare un filtro (in questo caso sul campo ‘colore’ della tabella del database).
La variabile $filtro impostata a ‘any’ impedisce al filtro di eseguire la sua azione; può essere utile nel caso volessimo utilizzare anche un filtro con il campo ‘colore’ uguale a stringa vuota.


$elems_per_page = 10; // Elementi per ogni pagina
$page = $_GET[page];
if(!($page)) {
$page = 1;
}
$primo = ($page-1) * $elems_per_page ;

$sql = "";
if($filtro && $filtro != "any") {
$sql = " AND colore = '$filtro'";
}
$query = "SELECT * FROM matite_colorate WHERE 1 $sql";
$result = mysql_query($query) or die("Select last failed $query");
$num_rows = mysql_num_rows($result);

$tot_pagine = ceil($num_rows / $elems_per_page);
$prev_page = $page - 1;
$next_page = $page + 1;

if($prev_page > 0)
echo "<a href='?filtro=$filtro&page=$prev_page'>pagina precedente</a>  ";
if($tot_pagine > 0)
echo "pagina $page di $tot_pagine   ";
if($next_page <= $tot_pagine)
echo "<a href='?filtro=$filtro&page=$next_page'> pagina successiva</a>";

$query .= " ORDER BY id LIMIT $primo, $elems_per_page";
$result = mysql_query($query) or die("Select last failed $query");
$num_rows = mysql_num_rows($result);

// ora è possibile utilizzare $result per listare solo gli elementi della pagina corrente

while ($line = mysql_fetch_assoc($result))  {
........
}
Arrotondamento

Funzioni offerte da php per arrotondare un numero.

round($bla, $cifredecimali);

ceil($bla / $blu); // arrotondamento per eccesso

floor($bla / $bli); // arrotondamento per difetto
Errori di php direttamente nella pagina

Solitamente le impostazioni del php.ini disabilitano la scrittura degli errori di php direttamente nelle pagine.
Questo comando permette invece di sovrascrivere tali impostazioni. Molto utile in caso vogliamo avere la dicitura degli errori di php direttamente nella pagina, soprattutto in fase di debug.
Con questa dicitura verranno scritti tutti gli errori tranne i NOTICE che non sono veri e propri errori ma che php scrive a tonnellare.
Da riportare all’inizio della pagina php.

error_reporting(E_ALL ^ E_NOTICE);

Per altre info.

Creare un backup di mysql senza phpmyadmin

Ecco come fare il backup di un database se non si dispone di phpmyadmin e non si ha accesso al server per eseguire un mysqldump.
Il codice php restituisce un file di testo contenente un mysqldump.

header('Content-type: application/txt');
header('Content-Disposition: attachment; filename="'.date("Ymd").'_netsonsdump.sql"');

$server = "mysql5.netsons.org"; /* in genere localhost */
$user = "celoria"; /* utente di mysql */
$pass = "password";
$db = "celoria";

mysql_connect($server, $user, $pass);
mysql_select_db($db);
$tables = mysql_list_tables($db);
while ($td = mysql_fetch_array($tables))
{
	$table = $td[0];
	$r = mysql_query("SHOW CREATE TABLE `$table`");
	if ($r)	{
		$insert_sql = "";
		$d = mysql_fetch_array($r);
		$d[1] .= ";";
		$SQL[] = str_replace("\n", "", $d[1]);
		$table_query = mysql_query("SELECT * FROM `$table`");
		$num_fields = mysql_num_fields($table_query);
		while ($fetch_row = mysql_fetch_array($table_query)) {
			$insert_sql .= "INSERT INTO $table VALUES(";
			for ($n=1;$n<=$num_fields;$n++)	{
				$m = $n - 1;
				$insert_sql .= "'".mysql_real_escape_string($fetch_row[$m])."', ";
			}
			$insert_sql = substr($insert_sql,0,-2);
			$insert_sql .= ");\n";
		}
		if ($insert_sql!= "") {
			$SQL[] = $insert_sql;
		}
	}
}

echo implode("\r", $SQL);