Make Offline Mirror of a Site using `wget`

Sometimes you want to create an offline copy of a site that you can take and view even without internet access. Using wget you can make such copy easily:

wget --mirror --convert-links --adjust-extension --page-requisites 
--no-parent http://example.org

Explanation of the various flags:

  • --mirror – Makes (among other things) the download recursive.
  • --convert-links – convert all the links (also to stuff like CSS stylesheets) to relative, so it will be suitable for offline viewing.
  • --adjust-extension – Adds suitable extensions to filenames (html or css) depending on their content-type.
  • --page-requisites – Download things like CSS style-sheets and images required to properly display the page offline.
  • --no-parent – When recursing do not ascend to the parent directory. It useful for restricting the download to only a portion of the site.

Alternatively, the command above may be shortened:

wget -mkEpnp http://example.org

Note: that the last p is part of np (--no-parent) and hence you see p twice in the flags.

Raspberry Pi NAS Samba Server

In acest articol va fi descris pasii care transorma raspberry pi in nas server. Ce este un nas server puteti citi aici.

Deci instalam mai intai samba. Acesta este o aplicatie care ofera posibilitatea de a partaja file-uri intre linux si windows in reteaua interna.

sudo apt-get install samba samba-common-bin

Editam fisierul de configurare samba:

sudo nano /etc/samba/smb.conf

Si adaugam la sfarsit:

[NAS]
comment = NAS Folder
path = /media/NASHDD1
valid users = @users
force group = users
create mask = 0660
directory mask = 0771
read only = no

Restartam samba:

sudo /etc/init.d/samba restart

In final adaugam utilizator local in lista de utilizatori samba:

sudo smbpasswd -a arvat

Acesta nu este un ghid complet. In articol lipseste montarea automata a hard-discului.

Cum se obține upgrade gratuit la Windows 10 [legal] dupa 29 iulie 2016

Oferta de upgrade Windows gratuit 10 s-a încheiat în mod oficial. Dar, în mod neoficial, copii gratuite Windows 10 sunt încă disponibile oficial.

Microsoft ofera in continuare upgrade pentru Windows 10 gratuit pentru persoanele care folosesc tehnologii de asistență. Tot ce trebuie să faceți este să accesați pagina și faceți clic pe butonul “Upgrade” pentru a începe.

Администрирование → Использование putty и ssh ключей в Windows

Так как приходиться уже не первый раз объяснять как это делается, решил оформить в виде How-To в картинках
Скачиваем архив putty отсюда putty.zip
1. Распаковываем и запускаем ssh-keygen

Выбираем ключ ssh-rsa и длину 2048 бит. Жмем «Generate».

Ключ готов, заполняем кодовую фразу и комментарий к нему. Сохраняем приватный ключ как mykey.ppk и публичный как id_rsa.pub

2. Далее необходимо скопировать наш публичный ключ на сервер. Для этого запускаем psftp.
psftp: no hostname specified; use «open host.name» to connect
psftp> open myserver
The server’s host key is not cached in the registry. You
have no guarantee that the server is the computer you
think it is.
The server’s rsa2 key fingerprint is:
ssh-rsa 2048 XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX
If you trust this host, enter «y» to add the key to
PuTTY’s cache and carry on connecting.
If you want to carry on connecting just once, without
adding the key to the cache, enter «n».
If you do not trust this host, press Return to abandon the
connection.
Store key in cache? (y/n) y
login as: root
[email protected]’s password:
Remote working directory is /root
psftp>put id_rsa.pub /tmp/id_rsa.pub
local:id_rsa.pub => remote:/tmp/id_rsa.pub
psftp>

3. Ключ скопировался, теперь нужно добавить его в /root/.ssh/authorized_keys
Для этого логинимся еще раз по паролю, через putty и выполняем
ssh-keygen -i -f /tmp/id_rsa.pub >> /root/.ssh/authorized_keys

Теперь осталось добавить наш ключ в ssh-agent’a. После запуска он сидит в трее, чтобы добавить ключ кликаем правой кнопкой на «Add Key»

Вводим кодовую фразу:

Теперь логинимся в putty:
login as: root
Authenticating with public key “rsa-key-20080908” from agent

Практически все, чтобы устранить проблемы с кодировками, с кривым отображением mc в путти, исправляем локаль в настроках:

Telegram PHP Bot

define('BOT_TOKEN', 'YOURBOT:TOKEN');
define('API_URL', 'https://api.telegram.org/bot'.BOT_TOKEN.'/');
	
// read incoming info and grab the chatID
$content = file_get_contents("php://input");
$update = json_decode($content, true);
$chatID = $update["message"]["chat"]["id"];
		
// compose reply
$reply =  sendMessage();
		
// send reply
$sendto =API_URL."sendmessage?chat_id=".$chatID."&text=".$reply;
file_get_contents($sendto);

function sendMessage(){
$message = "I am a baby bot.";
return $message;
}

crtmpserver

Crtmpserver este o aplicatie similara adobe media server. Contine mai putine functii decat AMS, totusi este o aplicatie destul de buna pentru functii streaming de baza.

# cd /usr/ports/net/crtmpserver
# make install clean

adaugam in /etc/rc.conf pentru pornire automata

crtmpserver_enable="YES"
crtmpserver_config="/usr/local/etc/crtmpserver.lua"

Pentru pornire manuala:

/usr/local/etc/rc.d/crtmpserver start

Pentru transmitere video catre crtmpserver folosim același Adobe Flash media encoder.

Comenzi utile SSH

SSH reverse port forwarding

ssh -i /root/id_rsa -N -T -R 80:localhost:80 [email protected]

Un tunel SSH prin mai multe puncte

ssh -A -t [email protected] -p xxx ssh -A -t [email protected] -p xxx

Interogare de bază MySQL în PHP

<?php
### Default TIMEZONE ###
date_default_timezone_set('Europe/Chisinau');
    
### ENABLE DEBUGING MODE ###
error_reporting(E_ALL);
ini_set('display_errors','On');

### MYSQL MAIN CONFIG ###
define("MYSQL_USER", "user");
define("MYSQL_PASS", "pass");
define("MYSQL_URL", "localhost");
define("MYSQL_DB", "db_title");

$mysqli = new mysqli(MYSQL_URL, MYSQL_USER, MYSQL_PASS, MYSQL_DB);
$mysqli->set_charset("UTF8");

$stmt = $mysqli->prepare("SELECT * FROM `TABLE` WHERE `id`=?");
$stmt->bind_param('i', $item);
$stmt->execute();
$result = $stmt->get_result();
    
if ($result->num_rows > 0) {
     while ($row = $result->fetch_assoc()) {
          ...
     }
}

$mysqli->close();

?>

Un simplu irc bot

<?php
set_time_limit(0);
error_reporting(E_ALL);
ini_set('display_errors','On');

$ircServer = "irc.domain.com";
$ircPort = "6667";
$ircChannel = "#bot";

define("MYSQL_USER", "user");
define("MYSQL_PASS", "pass");
define("MYSQL_URL", "localhost");
define("MYSQL_DB", "db_name");

$mysqli = new mysqli(MYSQL_URL, MYSQL_USER, MYSQL_PASS, MYSQL_DB);
$mysqli->set_charset("UTF8");

$ircSocket = fsockopen($ircServer, $ircPort, $eN, $eS);

if ($ircSocket) {
    fwrite($ircSocket, "USER Lost rawr.test lol :code\n");
    fwrite($ircSocket, "NICK PHP_BOT".rand(0,400)."\n");
    fwrite($ircSocket, "JOIN ".$ircChannel."\n");

    while(1) {
        while($data = fgets($ircSocket, 128)) {
            $array = explode(' ', $data);
            //read
            if ('PRIVMSG' == substr($array[1], 0, 7)) {
                $array = explode(':', $data);
                $q = trim(preg_replace('/\s\s+/', ' ', $array[2]));
                $q = $mysqli->real_escape_string($q);
 
                $results = $mysqli->query("SELECT * FROM `ANSWERS` WHERE `question`='".$q."'");
                while ($row = $results->fetch_assoc()) {
                    //answer
                    fwrite($ircSocket, "PRIVMSG ".$ircChannel." :".$row['answer']." \n");
                }
            }
 
             // Separate all data
             $exData = explode(' ', $data);

             // Send PONG back to the server
             if($exData[0] == "PING") {
                fwrite($ircSocket, "PONG ".$exData[1]."\n");
            }
        }
    }
}
else {
    echo $eS . ": " . $eN;
}

?>

Înlăturarea dependențelor neutilizate în FreeBSD

De exemplu … am instalat mc … dar am ramas dezamagit, deaceea am facut

cd /usr/ports/misc/mc/
make deinstall clean

Si am scapat de el.
Totusi, probabil ca am deinstalat doar mc, nu si toate dependentele.
Solutia este o aplicatie simpla pentru a face u[pgrade a porturilor instalate. Pentru a instala aceasta aplicatie scriem:

# cd /usr/ports/ports-mgmt/portmaster
# make install clean
# portmaster -s

Foloseste -s pentru a deinstala dependente neutilizate.