Advertisement
Guest User

active2

a guest
Aug 20th, 2012
14
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.25 KB | None | 0 0
  1. <?php
  2.  
  3. include "conf.php";
  4. $GLOBALS['file_codes'] = "/var/etc/proxy.codes";
  5. $GLOBALS['file_act'] = "/var/etc/proxy.act";
  6. $GLOBALS['file_user'] = "/var/etc/user.xml";
  7. $GLOBALS['file_cccam'] = "/var/etc/CCcam.cfg";
  8. $GLOBALS['USER_AG'] = "K_MERO_AGENT";
  9. $GLOBALS['http_path']="http://127.0.0.1:91/";
  10.  
  11. function plugin_src( $user, $pass, $msg, $code, $enddate=0 )
  12. {
  13. echo "grep -v \"#L\" /var/tuxbox/plugins/active_code.cfg > /tmp/actv.cfg";
  14. echo "\necho \"#LastName={$user}\" >> /tmp/actv.cfg";
  15. echo "\nmv /tmp/actv.cfg /var/tuxbox/plugins/active_code.cfg";
  16. echo "\ngrep -v \"#C\" /var/tuxbox/plugins/active_code.cfg > /tmp/actv.cfg";
  17. echo "\necho \"#Code={$code}\" >> /tmp/actv.cfg";
  18. echo "\nmv /tmp/actv.cfg /var/tuxbox/plugins/active_code.cfg";
  19. include "Lines.php";
  20. echo "\necho \"{$msg}\" > /var/tmp/msgS.tmp";
  21. echo "\nkillall -9 mgcamd_1.35";
  22. echo "\ncd /var/bin";
  23. echo "\./nmgcamd_1.35 start";
  24. }
  25.  
  26. function plugin_src2( $user, $pass, $msg )
  27. {
  28. include "Lines.php";
  29. echo "\nkillall -9 mgcamd_1.35";
  30. echo "\ncd /var/bin";
  31. echo "\./nmgcamd_1.35 start";
  32. }
  33.  
  34. function browser_src( $user=NULL, $pass=NULL, $msg=NULL )
  35. {
  36.  
  37. }
  38.  
  39. if ( $_SERVER["HTTP_USER_AGENT"] == $GLOBALS['USER_AG'] )
  40. {
  41. main();
  42. exit;
  43. }
  44. else
  45. {
  46. echo "hello !\n";
  47. exit;
  48. }
  49.  
  50. function main()
  51. {
  52. if ( !$_GET['code'] || empty( $_GET['code'] ) )
  53. {
  54. echo "1";
  55. return;
  56. }
  57. else
  58. {
  59. $code = trim( $_GET['code'] );
  60. }
  61.  
  62. if ( !is_numeric( $_GET['code'] ) )
  63. {
  64. echo "2";
  65. return;
  66. }
  67. $my_pass = gen_pass();
  68.  
  69. if ( !isset( $_GET['LastName'] ) || empty( $_GET['LastName'] ) )
  70. {
  71. $my_user = "abd" . time();
  72. }
  73. else
  74. {
  75. $my_user = trim( $_GET['LastName'] );
  76. }
  77. $days = file_codes_check( $code );
  78. if ( $days > 0 )
  79. {
  80. $text_msg = "{$GLOBALS['WELCOME']} votre compte est active avec succes! Expirera a " . date( "Y-m-d", time() + ($days * 24 * 60 * 60) );
  81. $enddate = time() + ($days * 24 * 60 * 60);
  82. $str_date = 0;
  83. $end_date = 0;
  84. if ( $_GET['LastName'] && is_array( $act = file_user_check( "name=\"{$_GET['LastName']}\"" ) ) )
  85. {
  86. if ( $act['End'] > time() )
  87. {
  88. $str_date = $act['Start'];
  89. $end_date = $act['End'] + ($days * 24 * 60 * 60);
  90. $text_msg = "Compte est etendue avec {$days} jours! Expirera a " . date( "Y-m-d", $end_date );
  91. $enddate = $end_date;
  92. }
  93. }
  94. file_act_add( $my_user, $my_pass, $code, $days, $str_date, $end_date );
  95. file_codes_del( $code );
  96. if ( $_SERVER["HTTP_USER_AGENT"] == $GLOBALS['USER_AG'] )
  97. plugin_src( $my_user, $my_pass, $text_msg, $code, $enddate );
  98. else
  99. browser_src( $my_user, $my_pass, $text_msg );
  100. }
  101. else
  102. {
  103. $code_wrong = 1;
  104. if ( $days == 0 )
  105. {
  106. $act = file_user_check( "code=\"{$code}\"" );
  107. if ( is_array( $act ) )
  108. {
  109. $code_wrong = 0;
  110. $my_user = $act['name'];
  111. if ( $act['End'] > time() )
  112. {
  113. file_act_add( $my_user, $my_pass, $code, $act['days'], $act['Start'], $act['End'] );
  114. if ( $_SERVER["HTTP_USER_AGENT"] == $GLOBALS['USER_AG'] )
  115. {
  116. plugin_src( $my_user, $my_pass, "Compte est reactif! Expirera a " . date( "Y-m-d", $act['End'] ), $code, $act['End'] );
  117. }
  118. else
  119. {
  120. browser_src( $my_user, $my_pass, $code, "Compte est reactif! Expirera a " . date( "Y-m-d", $act['End'] ) );
  121. }
  122. }
  123. else
  124. {
  125. if ( $_SERVER["HTTP_USER_AGENT"] == $GLOBALS['USER_AG'] && isset( $_GET['update'] ) && $_GET['update'] == "ok" )
  126. {
  127. $passwd = $act['password'];
  128. plugin_src2( $my_user, $passwd, "Votre compte a ete mise a jour avec succes!" );
  129. }
  130. else
  131. {
  132. echo "3";
  133. }
  134. }
  135. }
  136. }
  137. if ( $code_wrong )
  138. {
  139. echo "2";
  140. }
  141. }
  142. }
  143.  
  144. function gen_pass()
  145. {
  146. $str = md5( uniqid() * time() );
  147.  
  148. return $str = strtolower( substr( $str, -13 ) );
  149. }
  150.  
  151. function xml2array( $xml )
  152. {
  153. $xmlary = array( );
  154. $reels = '/<(\w+)\s*([^\/>]*)\s*(?:\/>|>(.*)<\/\s*\\1\s*>)/s';
  155. $reattrs = '/(\w+)=(?:"|\')([^"\']*)(:?"|\')/';
  156. preg_match_all( $reels, $xml, $elements );
  157. foreach ( $elements[1] as $ie => $xx )
  158. {
  159. $xmlary[$ie]["name"] = $elements[1][$ie];
  160. $attributes = trim( $elements[2][$ie] );
  161. if ( $attributes )
  162. {
  163. preg_match_all( $reattrs, $attributes, $att );
  164. foreach ( $att[1] as $ia => $xx )
  165. $xmlary[$ie]["attributes"][$att[1][$ia]] = $att[2][$ia];
  166. }
  167. $cdend = strpos( $elements[3][$ie], "<" );
  168. if ( $cdend > 0 )
  169. {
  170. $xmlary[$ie]["text"] = substr( $elements[3][$ie], 0, $cdend - 1 );
  171. }
  172. if ( preg_match( $reels, $elements[3][$ie] ) )
  173. {
  174. $xmlary[$ie]["elements"] = xml2array( $elements[3][$ie] );
  175. }
  176. else if ( $elements[3][$ie] )
  177. {
  178. $xmlary[$ie]["text"] = $elements[3][$ie];
  179. }
  180. }
  181. return $xmlary;
  182. }
  183.  
  184. function file_act_add( $user, $pass, $code, $days, $date_st=0, $date_end=0 )
  185. {
  186. $file_handle = fopen( $GLOBALS['file_act'], "a+" );
  187. if ( $file_handle )
  188. {
  189. if ( $date_st == 0 )
  190. {
  191. $date_st = time();
  192. }
  193. $txt_date_st = date( "Y/m/d", $date_st );
  194. if ( $date_end == 0 )
  195. {
  196. $date_end = time() + ($days * 24 * 60 * 60);
  197. }
  198. $txt_date_end = date( "Y/m/d", $date_end );
  199. fwrite( $file_handle, date( "[Y/m/d][H:i:s] " ) );
  200. fwrite( $file_handle, "Username = {$user} Password = {$pass} {$code}={$days} Start: {$txt_date_st} End: {$txt_date_end}\n" );
  201. fclose( $file_handle );
  202. if ( $GLOBALS['ACTION'] == "N" )
  203. {
  204. file_user_update( $user, $pass, $code, $days, date( "d-m-Y", $date_st ), date( "d-m-Y", $date_end ) );
  205. }
  206. elseif ( $GLOBALS['ACTION'] == "C" )
  207. {
  208. file_CCcam_update( $user, $pass, $code, date( "d-m-Y", $date_end ) );
  209. }
  210. elseif ( $GLOBALS['ACTION'] == "NC" )
  211. {
  212. file_user_update( $user, $pass, $code, $days, date( "d-m-Y", $date_st ), date( "d-m-Y", $date_end ) );
  213. file_CCcam_update( $user, $pass, $code, date( "d-m-Y", $date_end ) );
  214. }
  215. }
  216. }
  217.  
  218. function file_act_check( $code )
  219. {
  220. $lines = file( $GLOBALS['file_act'] );
  221. if ( is_array( $lines ) )
  222. {
  223. $code = " " . $code . "=";
  224. foreach ( $lines as $line )
  225. {
  226. if ( strstr( $line, $code ) )
  227. {
  228. $pieces = explode( " ", $line );
  229. $days = explode( "=", $pieces[3] );
  230. $date_st = explode( ": ", $pieces[4] );
  231. $date_end = explode( ": ", $pieces[5] );
  232. $days = $days[1];
  233. list($year, $month, $day) = split( '[/.-]', $date_st[1] );
  234. $date_st = mktime( 0, 0, 0, $month, $day, $year );
  235. list($year, $month, $day) = split( '[/.-]', $date_end[1] );
  236. $date_end = mktime( 0, 0, 0, $month, $day, $year );
  237. return array( "Days" => "{$days}", "Start" => "{$date_st}", "End" => "{$date_end}" );
  238. }
  239. }
  240. }
  241. return 0;
  242. }
  243.  
  244. function file_codes_check( $code )
  245. {
  246. $lines = file( $GLOBALS['file_codes'] );
  247. if ( is_array( $lines ) )
  248. {
  249. foreach ( $lines as $line )
  250. {
  251. list($cc, $day) = split( '=', $line );
  252. if ( strcmp( $cc, $code ) == 0 )
  253. {
  254. return trim( $day );
  255. }
  256. }
  257. }
  258. return 0;
  259. }
  260.  
  261. function file_codes_del( $code )
  262. {
  263. $lines = file( $GLOBALS['file_codes'] );
  264. if ( is_array( $lines ) )
  265. {
  266. $file_handle = fopen( $GLOBALS['file_codes'], "w" );
  267. if ( $file_handle )
  268. {
  269. $code = $code . "=";
  270. foreach ( $lines as $line )
  271. {
  272. if ( strstr( $line, $code ) === FALSE )
  273. {
  274. fwrite( $file_handle, $line );
  275. }
  276. }
  277. fclose( $file_handle );
  278. }
  279. }
  280. }
  281.  
  282. function file_user_write( $data )
  283. {
  284. $fp = fopen( $GLOBALS['file_user'], "w" );
  285. if ( $fp )
  286. {
  287. foreach ( $data as $value )
  288. {
  289. $value = trim( $value );
  290. if ( $value )
  291. {
  292. fwrite( $fp, $value . "\n" );
  293. }
  294. }
  295. fclose( $fp );
  296. }
  297. }
  298.  
  299. function file_CCcam_write( $data )
  300. {
  301. $fp = fopen( $GLOBALS['file_cccam'], "w" );
  302. if ( $fp )
  303. {
  304. foreach ( $data as $value )
  305. {
  306. $value - trim( $value );
  307. if ( $value )
  308. {
  309. fwrite( $fp, $value . "\n" );
  310. }
  311. }
  312. fclose( $fp );
  313. }
  314. }
  315.  
  316. function file_user_check( $find )
  317. {
  318. $lines = file( $GLOBALS['file_user'] );
  319. if ( is_array( $lines ) )
  320. {
  321. foreach ( $lines as $line )
  322. {
  323. if ( strstr( $line, $find ) )
  324. {
  325. $act = xml2array( $line );
  326. if ( $act[0]['name'] == "user" && is_array( $act[0]['attributes'] ) )
  327. {
  328. $act = $act[0]['attributes'];
  329. list($day, $month, $year) = split( '[/.-]', $act['startDate'] );
  330. $act['Start'] = mktime( 0, 0, 0, $month, $day, $year );
  331. list($day, $month, $year) = split( '[/.-]', $act['date'] );
  332. $act['End'] = mktime( 0, 0, 0, $month, $day, $year );
  333. return $act;
  334. }
  335. return 0;
  336. }
  337. }
  338. }
  339. return 0;
  340. }
  341.  
  342. function file_user_update( $user, $pass, $code, $days, $date_st, $date_end )
  343. {
  344. $lines = file( $GLOBALS['file_user'] );
  345. $newline = "<user name=\"{$user}\" password=\"{$pass}\" max-connections=\"1\" EcmRate=\"-1\" code=\"{$code}\" days=\"{$days}\" startDate=\"{$date_st}\" expire-date=\"{$date_end}\"/>";
  346. if ( is_array( $lines ) )
  347. {
  348. $code_str = "code=\"{$code}\"";
  349. if ( $_GET['LastName'] )
  350. {
  351. $code_str = "name=\"{$_GET['LastName']}\"";
  352. }
  353. $i = 0;
  354. foreach ( $lines as $line )
  355. {
  356. if ( strstr( $line, $code_str ) )
  357. {
  358. $lines[$i] = $newline;
  359. file_user_write( $lines );
  360. return 1;
  361. }
  362. $i++;
  363. }
  364. $frstel = $lines[0];
  365. $lines[0] = $newline;
  366. array_unshift( $lines, $frstel );
  367. file_user_write( $lines );
  368. }
  369. return 0;
  370. }
  371.  
  372. function file_cccam_update( $user, $pass, $code, $date_end )
  373. {
  374. $lines = file( $GLOBALS['file_cccam'], FILE_IGNORE_NEW_LINES );
  375. $newline = "F: {$user} {$pass} # {$date_end}";
  376. if ( is_array( $lines ) )
  377. {
  378. $code_str = "code=\"{$code}\"";
  379. if ( $_GET['LastName'] )
  380. {
  381. $code_str = "{$_GET['LastName']}";
  382. }
  383. $i = 0;
  384. foreach ( $lines as $line )
  385. {
  386. if ( strstr( $line, $code_str ) )
  387. {
  388. $lines[$i] = $newline;
  389. file_CCcam_write( $lines );
  390. return 1;
  391. }
  392. $i++;
  393. }
  394. $frstel = $lines[0];
  395. $lines[0] = $newline;
  396. array_unshift( $lines, $frstel );
  397. file_CCcam_write( $lines );
  398. }
  399. return 0;
  400. }
  401.  
  402. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement