php To change this template choose Tools Templates and open the templa

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
* Description of letitbit_net
*
* @author Valery Sizov
*/
class letitbit_net {
public function upload($task) {
$data = ORM::factory('storage_service')->getAuthDataByTask($task);
$client = new Browser('http://letitbit.net/tmpl/login.php','POST');
$client->addPostParameter(array(
'log' => $data->login,
'pas' => $data->password,
));
$response = $client->ssend();
$upload_id = text::random('numeric', 12);
$client->setUrl('http://letitbit.net/');
$client->setMethod('GET');
$response = $client->send();
$body = $response->getBody();
$pattern = '#<form name="F1Upload" enctype="multipart/form-data" action="(.*?)" method="post"';
$pattern .= '.* name="xmode" value="(\d*?)"';
$pattern .= '.*name="pbmode" value="(.*?)"';
$pattern .= '.*name="owner" type="hidden" id="owner" value="(.*?)"';
$pattern .= '.*name="pin" type="hidden" id="owner" value="(.*?)"';
$pattern .= '.*name="base" type="hidden" id="owner" value="(.*?)"';
$pattern .= '.*name="host" type="hidden" id="owner" value="(.*?)"';
$pattern .= '.*name="css_name" value="(.*?)"';
$pattern .= '.*name="tmpl_name" value="(.*?)"#s';
if(!preg_match($pattern, $body,$m)){
throw new Exception('Немогу прочитать форму отправки');
}
$server = $m[1].$upload_id.'&js_on=1&xpass=1B2M2Y8AsgTpgAmY7PhCfg&xmode='.$m[2];
$client->setUrl($server);
$client->setMethod('POST');
$client->addPostParameter(array(
'xmode'=>$m[2],
'pbmode' => $m[3],
'owner' => $m[4],
'pin' => $m[5],
'base' => $m[6],
'host' => $m[7],
'css_name' => $m[8],
'tmpl_name' => $m[9],
));
$client->addUpload('file_0', $task->files->path, $task->files->name);
$request = $client->send();
$body = $request->getBody();
$pattern = "#action='(.*?)' target='_parent'";
$pattern .= ".*<textarea name='file_name\[\]'>(.*?)</textarea>";
$pattern .= ".*<textarea name='file_name_orig\[\]'>(.*?)</textarea>";
$pattern .= ".*<textarea name='file_status\[\]'>(.*?)</textarea>";
$pattern .= ".*<textarea name='file_size\[\]'>(.*?)</textarea>";
$pattern .= ".*<textarea name='file_descr\[\]'>(.*?)</textarea>";
$pattern .= ".*<textarea name='file_mime\[\]'>(.*?)</textarea>";
$pattern .= ".*<textarea name='number_of_files'>(.*?)</textarea>";
$pattern .= ".*<textarea name='ip'>(.*?)</textarea>";
$pattern .= ".*<textarea name='host'>(.*?)</textarea>";
$pattern .= ".*<textarea name='duration'>(.*?)</textarea>";
$pattern .= ".*<textarea name='target_dir'>(.*?)</textarea>";
$pattern .= ".*<textarea name='owner'>(.*?)</textarea>";
$pattern .= ".*<textarea name='pin'>(.*?)</textarea>";
$pattern .= ".*<textarea name='base'>(.*?)</textarea>";
$pattern .= ".*<textarea name='host'>(.*?)</textarea>#s";
if(!preg_match($pattern, $body, $o)){
throw new Exception('Не удается распарсить форму №2');
}
$client->setUrl($o[1]);
$client->setMethod('POST');
$client->addPostParameter(array(
'file_name[]'=>$o[2],
'file_name_orig[]'=>$o[3],
'file_status[]'=>$o[4],
'file_size[]'=>$o[5],
'file_descr[]'=>$o[6],
'file_mime[]'=>$o[7],
'number_of_files'=>$o[8],
'ip'=>$o[9],
'host'=>$o[10],
'duration'=>$o[11],
'target_dir'=>$o[12],
'owner'=>$o[13],
'pin'=>$o[14],
'base'=>$o[15],
'host'=>$o[16],
));
$end_url = $client->send()->getHeader('LOCATION');
$client->setUrl($end_url);
$client->setMethod('GET');
$body = $client->send()->getBody();
$pattern = '#<h1>.*</h1>\s*<textarea cols=65 rows=15>(.*?)\s</textarea>#s';
if(!preg_match($pattern, $body,$k)){
throw new Exception('Немогу распарсить страницу с сылками на файл');
}
$task->status_upload = 1;
$task->link = $k[1];
$task->save();
return TRUE;
}
}
?>