Archive

Archive for the ‘Windows’ Category

Send email when medical results appear on lam24.pl

24/09/2015 Leave a comment

Bellow php script will check every 15 min if medical results appear on lam24.pl and send email with notification.


<?php
$url = "https://lam24.pl/wyniki.aspx";
$zlecenie = "xxxxxxxxx";
$pesel = "xxxxxxxxxxx";

$f = "lam24.ini";
$size = filesize($f);
$fH = fopen($f,"r");
$data = fread($fH,$size);
fclose($fH);
if(strpos($data,'true') !== false) {
exit();
}

$ckfile = tempnam("/tmp", "CURLCOOKIE");
$useragent = 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.2 (KHTML, like Gecko) Chrome/5.0.342.3 Safari/533.2';

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_COOKIEJAR, $ckfile);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);

$html = curl_exec($ch);

curl_close($ch);

preg_match('~~', $html, $viewstate);
preg_match('~~', $html, $eventValidation);

$viewstate = $viewstate[1];
$eventValidation = $eventValidation[1];

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, $ckfile);
curl_setopt($ch, CURLOPT_COOKIEFILE, $ckfile);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_REFERER, $url);
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);

$postfields = array();
$postfields['__EVENTTARGET'] = "";
$postfields['__EVENTARGUMENT'] = "";
$postfields['__VIEWSTATE'] = $viewstate;
$postfields['__EVENTVALIDATION'] = $eventValidation;
$postfields['Login$UserName'] = $zlecenie;
$postfields['Login$Password'] = $pesel;
$postfields['Login$loginButton'] = 'Pokaż wyniki';

curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
$ret = curl_exec($ch);
if(strpos($ret,'Nie znaleziono wynik') !== true) {
$fp = fopen($f, 'w');
fwrite($fp, 'true');
fclose($fp);

$to = 'user@gmail.com';
$subject = 'Wyniki Lam24';
$message = 'Automatyczny skrypt, ktory sprawdza dostepnosc wynikow co 15 minut informuje za sa one juz dostepne:' . "\r\n" . 'https://lam24.pl/wyniki.aspx' . "\r\n" .
'Zlecenie: ' . $zlecenie . "\r\n" .
'Pesel: ' . $pesel;
$headers = 'From: user@domain.pl' . "\r\n" .
'Reply-To: user@domain.pl' . "\r\n" .
'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
}
curl_close($ch);
?>

crontab:
*/15 * * * * /usr/bin/php /home/n4p1/lam24/lam24.php

Categories: Bash, PHP + MySQL

Change the created/modified time of files

03/02/2013 Leave a comment

You can manually change created/modified/last accessed time of files using power shell and bellow command:

Get-ChildItem * | foreach { $_.CreationTime = get-date "3/2/2013 1:00 pm"; $_.LastWriteTime
 = get-date "3/2/2013 1:00 pm"; $_.LastAccessTime = get-date "3/2/2013 1:00 pm" }

Where * is a wildcard for all files in current directory. You can simply change it to file name etc.

Categories: Windows

Import XML data to MySQL tables

01/08/2012 1 comment

According to mysql documentation there is possibility to load data to mysql table from xml files. Hoverer after trying to execute below command:

napi@debian:/home/napi$ mysql -u root -p
mysql> use test;
Database changed
mysql> LOAD XML LOCAL INFILE '/var/www/SIMC.xml' INTO TABLE simc;
ERROR 1148 (42000): The used command is not allowed with this MySQL version

as a output I get this weird error. To fix that just add one parameter: ‘–local-infile’ to mysql command:

napi@debian:/home/napi$ mysql -u root -p --local-infile
mysql> use test;
Database changed
mysql>  LOAD XML LOCAL INFILE '/var/www/SIMC.xml' INTO TABLE simc;
Query OK, 4115 rows affected, 1580 warnings (0.85 sec)
Records: 4115  Deleted: 0  Skipped: 0  Warnings: 1580
Categories: PHP + MySQL

MCITP

08/11/2011 Leave a comment

Today I failed 70-640 exam…. Damn… I got 644/1000 points. 700 needed to pass.

Categories: Certification, Windows

How to parse lotto numbers from liczby.pl and put it to DB?

21/07/2011 Leave a comment

Answers is:


<?php
$hostname = "localhost";
$username = "lotto";
$password = "";

try {
$db = new PDO("mysql:host=$hostname;dbname=lotto", $username, $password);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);

$n = 1;
while ($n <= 126) {
$html = file_get_contents("http://www.liczby.pl/index.php?d=l&dl_d=wyniki_duzego_lotka&dl_w=plansza&w_dl_strona=$n");
preg_match_all("#(<td nowrap>(.*?)</td>)|(<td align=\"center\"  class=\"(.*?)\" title=\"(.*?)\">(.*?)</td>)#", $html, $match);
$i=0;

$match2 = array_mesh($match[2], $match[6]);

foreach ($match2 as $record){
if($i==7 or $i==0){
$time = strtotime($record);
$db->query("INSERT INTO losowania (id, data) VALUES ('', $time)");
$id = $db->lastInsertId();
if($i==7){
$i=0;
}
}
else {
$db->query("INSERT INTO liczby (id, losowania_id, liczby) VALUES ('', $id, $record)");
}
$i++;
}
$n++;
}
$db = null; // close the database connection
}
catch(PDOException $e) {
echo $e->getMessage();
}

function array_mesh() {
// Combine multiple associative arrays and sum the values for any common keys
// The function can accept any number of arrays as arguments
// The values must be numeric or the summed value will be 0

// Get the number of arguments being passed
$numargs = func_num_args();

// Save the arguments to an array
$arg_list = func_get_args();

// Create an array to hold the combined data
$out = array();

// Loop through each of the arguments
for ($i = 0; $i < $numargs; $i++) {
$in = $arg_list[$i]; // This will be equal to each array passed as an argument

// Loop through each of the arrays passed as arguments
foreach($in as $key => $value) {
// If the same key exists in the $out array
if(array_key_exists($key, $out)) {
// Sum the values of the common key
$sum = $in[$key].$out[$key];
// Add the key => value pair to array $out
$out[$key] = $sum;
}else{
// Add to $out any key => value pairs in the $in array that did not have a match in $out
$out[$key] = $in[$key];
}
}
}

return $out;
}
?>

Categories: PHP + MySQL, Programming

Log In to an Expired Windows XP

26/06/2011 Leave a comment

We need reset XP trial.

In Safe mode type:

rundll32.exe syssetup,SetupOobeBnk

This can be done 4 times.

Categories: Windows

Linux commands in Windows command-line

01/12/2010 2 comments

How often you are working on windows and linux (eg. via putty) at the same time? Would you like use wget, ls, grep, mkdir commands in windows cmd.exe? Would not it be nicer to have linux commands in windows?  If yes, you should install GnuWin inside your Windows OS.

There is o two ways to do that. You can install all packages or install only that what you need. There is a packages list available to manual install.

Categories: Windows

HOWTO: Import NTUSER.DAT and other registry files to temp key.

23/07/2010 2 comments

How to view registry from another pc? Its easy. Just copy DAT files from Windows\System32\Config or NTUSER.DAT from Documents and Settings\username and use that command:

reg.exe load HKLM\TmpHive c:\dir\NTUSER.DAT

Now you are able to view loaded DAT file via regedit.

To unload do:

reg.exe unload HKLM\TmpHive

Categories: Windows

First steps… Looking for perfect IDE

19/07/2010 2 comments

Some time ago I need to write application that will run every 15 min and get information about how many pages was printed on network printers (OKI B6250 and Konica Minolta 7333). I had experience in Delphi but i wanna do this in free IDE. Obviously Lazarus is not enough for me…

So i decided to use NetBeans with C++. Unfortunately my experience and knowledge in C was very poor… So after using google, trying to do something alone, I decided write it in well known for me – PHP… It’s not perfect choice but acceptable for that project.  Also I don’t wanna waste my time with project in C without basic knowledge of that language. So I decide, that C++ need wait for better time.

Hurray! Now Im starting learn C++ also I had a books (never use it before – so this is quite new for me :))

The first question was, “what IDE?”. I know Borland had sometime his C++ IDE but this was not free. Im looking for free, user-friendly environment. As I said before I choice NetBeans with C++ (MinGW) and I hope its a good choice.

Categories: C++