rscriptd.drv 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php if ( !defined('ENVIRONMENT') ) exit('Only STG can run script!' . "\n");
  2. class Executer {
  3. // Recived data from `ubilling.cls`:
  4. private $log;
  5. private $config;
  6. private $database;
  7. // Constructor:
  8. public function __construct($data) {
  9. // Put all recived data to specified vars:
  10. foreach ($data as $key => $value) {
  11. $this->$key = $value;
  12. }
  13. // Write log message, that class is loaded:
  14. $this->log->message(__CLASS__, "RScriptD driver loaded", 'debug');
  15. // Run:
  16. switch ( ENVIRONMENT ) {
  17. case OnConnect:
  18. case OnDisconnect:
  19. $script = constant('ENVIRONMENT');
  20. $this->$script();
  21. break;
  22. }
  23. }
  24. // 1. OnConnect:
  25. public function OnConnect() {
  26. // User's TX & RX:
  27. $rate = $this->database->get_user_rate();
  28. // ARP:
  29. shell_exec($this->config['arpcmd'] . ' -S ' . IP . ' ' . $this->database->get_user_mac());
  30. // Speed control:
  31. shell_exec($this->config['fwcmd'] . " pipe " . (ID + 101) . " config bw " . $rate['tx'] . $this->config['rate_val'] . " queue 32Kbytes");
  32. shell_exec($this->config['fwcmd'] . " pipe " . (ID + 18101) . " config bw " . $rate['rx'] . $this->config['rate_val'] . " queue 32Kbytes");
  33. // Shaper:
  34. shell_exec($this->config['fwcmd'] . " table 3 add " . IP . " " . (ID + 101));
  35. shell_exec($this->config['fwcmd'] . " table 4 add " . IP . " " . (ID + 18101));
  36. shell_exec($this->config['fwcmd'] . " table 47 delete " . IP);
  37. // Day/Night switcher:
  38. file_put_contents(BASEPATH . "dn/" . LOGIN, $rate['rx'] . ":" . (ID + 18101), LOCK_EX);
  39. shell_exec("/bin/chmod 777 " . BASEPATH . "dn/" . LOGIN);
  40. $this->log->message(__CLASS__, "Creation of firewall rules done", 'success');
  41. }
  42. // 2. OnDisconnect:
  43. public function OnDisconnect() {
  44. // Delete old pipes:
  45. shell_exec($this->config['fwcmd'] . " pipe " . (ID + 101) . " delete");
  46. shell_exec($this->config['fwcmd'] . " pipe " . (ID + 18101) . " delete");
  47. // Delete from shaper:
  48. shell_exec($this->config['fwcmd'] . " table 3 delete " . IP . " " . (ID + 101));
  49. shell_exec($this->config['fwcmd'] . " table 4 delete " . IP . " " . (ID + 18101));
  50. shell_exec($this->config['fwcmd'] . " table 47 add " . IP);
  51. // Day/Night switcher:
  52. shell_exec("/bin/rm " . BASEPATH . "dn/" . LOGIN);
  53. $this->log->message(__CLASS__, "Removing of firewall rules done", 'success');
  54. }
  55. }
  56. ?>