fedipact.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #!/usr/bin/php
  2. <?php
  3. /*
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. define('N',"\n");
  16. require __DIR__.'/../lib/delinstbyid.php';
  17. $levs=['Debug', 'Info', 'Warning', 'Error'];
  18. $opts=[
  19. 'url'=>'https://fedipact.online/',
  20. 'ofpath'=>__DIR__.'/fedipact.list'
  21. ];
  22. $help='mustool.php
  23. DESCRIPTION
  24. fedipact.php downloads the list of Anti-Meta Fedi Pact signers from
  25. «'.$opts['url'].'», parses it, creates a machine readable signers list and
  26. saves it to «'.$opts['ofpath'].'».
  27. SYNOPSIS
  28. fedipact.php
  29. OPTIONS
  30. -h, --help
  31. Shows this help text and exits.
  32. This program comes with ABSOLUTELY NO WARRANTY; for details see the source.
  33. This is free software, and you are welcome to redistribute it under
  34. certain conditions; see <http://www.gnu.org/licenses/> for details.'.N;
  35. for ($i=1; $i<$argc; $i++) {
  36. if ($argv[$i]=='-h' || $argv[$i]=='--help') {
  37. echo($help);
  38. exit(0);
  39. } else {
  40. mexit('don’t know how to interpret «'.$argv[$i].'» (use «-h» to read help).'.N,1);
  41. }
  42. }
  43. $codoms=0;
  44. $ocont=@file($opts['ofpath'],FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES);
  45. if (is_array($ocont))
  46. $codoms=count($ocont);
  47. $cont=@file($opts['url'],FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES);
  48. if (is_array($cont)) {
  49. $doms=[];
  50. foreach ($cont as $line)
  51. // if (preg_match('#<li>\s*🖤\s*[a-z0-9\.\-\_]+@([a-z0-9\.\-\_]+)\s*</li>#iu',$line,$matches)===1)
  52. if (preg_match('#<li>\s*[a-z0-9\.\-\_]+@([a-z0-9\.\-\_]+)\s*</li>#iu',$line,$matches)===1)
  53. if (!in_array($matches[1],$doms))
  54. $doms[]=mb_strtolower($matches[1]);
  55. $cdoms=count($doms);
  56. if ($cdoms>0) {
  57. sort($doms);
  58. $doms=implode(N,$doms);
  59. if (@file_put_contents($opts['ofpath'],$doms.N)===false)
  60. mexit('couldn’t save domain list into «'.$opts['ofpath'].'» :-('.N,3);
  61. else
  62. eecho('done saving '.$cdoms.' entries into «'.$opts['ofpath'].'» :-)'.N,1);
  63. } else {
  64. mexit('couldn’t find any domain in «'.$opts['url'].'» :-('.N,2);
  65. }
  66. } else {
  67. mexit('couldn’t open «'.$opts['url'].'».'.N,3);
  68. }
  69. exit(0);
  70. // functions
  71. function mexit($msg,$code) {
  72. global $link;
  73. if (isset($link) && $link!==false) mysqli_close($link);
  74. if ($code==0)
  75. eecho($msg,1);
  76. else
  77. eecho($msg,3);
  78. exit($code);
  79. }
  80. function eecho($msg,$lev=1) {
  81. global $levs;
  82. $time=microtime(false);
  83. $time=explode(' ',$time);
  84. $time=date('Y-m-d H:i:s',$time[1]).'.'.substr($time[0],2);
  85. $msg=$time.' '.$levs[$lev].': '.$msg;
  86. if ($lev<2)
  87. echo($msg);
  88. else
  89. fwrite(STDERR,$msg);
  90. }
  91. ?>