admin-ipa.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. // by 请勿倒卖,已申请软著,否则追究法律责任
  3. namespace PngFile;
  4. require_once "depng/pngCompote.php";
  5. namespace CFPropertyList;
  6. require_once "deplist/CFPropertyList.php";
  7. include "../../system/db.class.php";
  8. error_reporting(0);
  9. if (empty($_COOKIE["in_adminid"]) || empty($_COOKIE["in_adminname"]) || empty($_COOKIE["in_adminpassword"]) || empty($_COOKIE["in_permission"]) || empty($_COOKIE["in_adminexpire"]) || !db("admin")->where("in_adminid", intval($_COOKIE["in_adminid"]))->value("in_adminid") || md5(db("admin")->where("in_adminid", intval($_COOKIE["in_adminid"]))->value("in_adminpassword")) !== $_COOKIE["in_adminpassword"]) {
  10. exit("-1");
  11. }
  12. $time = $_GET["time"];
  13. $tmp = IN_ROOT . "data/tmp/" . $time . ".ipa";
  14. $explode = explode("_", $time);
  15. $icontime = md5($explode[0] . "_" . $explode[1] . "_" . rand(2, pow(2, 24))) . ".png";
  16. $apptime = md5($explode[1] . "_" . $explode[0] . "_" . rand(2, pow(2, 24))) . ".ipa";
  17. $dir = IN_ROOT . "data/tmp/" . $time . "/Payload";
  18. if (is_dir($dir)) {
  19. rename($tmp, IN_ROOT . "data/attachment/" . $apptime);
  20. $d = NULL;
  21. $h = opendir($dir);
  22. while ($f = readdir($h)) {
  23. if ($f != "." && $f != ".." && is_dir($dir . "/" . $f)) {
  24. $d = $dir . "/" . $f;
  25. }
  26. }
  27. closedir($h);
  28. $info = file_get_contents($d . "/Info.plist");
  29. $plist = new CFPropertyList();
  30. $plist->parse($info);
  31. $plist = $plist->toArray();
  32. $xml_size = $_GET["size"];
  33. $xml_name = detect_encoding(isset($plist["CFBundleDisplayName"]) ? $plist["CFBundleDisplayName"] : $plist["CFBundleName"]);
  34. $xml_mnvs = $plist["MinimumOSVersion"];
  35. $xml_bid = $plist["CFBundleIdentifier"];
  36. $xml_bsvs = $plist["CFBundleShortVersionString"];
  37. $xml_bvs = $plist["CFBundleVersion"];
  38. $newfile = IN_ROOT . "data/attachment/" . $icontime;
  39. $icon = $plist["CFBundleIcons"]["CFBundlePrimaryIcon"]["CFBundleIconFiles"];
  40. if (!$icon) {
  41. $icon = $plist["CFBundleIconFiles"];
  42. if (!$icon) {
  43. $icon = $plist["CFBundleIconFiles~ipad"];
  44. }
  45. }
  46. if (preg_match("/\\./", $icon[0])) {
  47. $cvt = is_file($d . "/" . $icon[0]) ? "trim" : "strtolower";
  48. for ($i = 0; $i < count($icon); $i++) {
  49. if (is_file($d . "/" . $cvt($icon[$i]))) {
  50. $big[] = filesize($d . "/" . $cvt($icon[$i]));
  51. $small[] = filesize($d . "/" . $cvt($icon[$i]));
  52. }
  53. }
  54. rsort($big);
  55. sort($small);
  56. for ($p = 0; $p < count($icon); $p++) {
  57. if ($big[0] == filesize($d . "/" . $cvt($icon[$p]))) {
  58. $bigfile = $d . "/" . $cvt($icon[$p]);
  59. }
  60. if ($small[0] == filesize($d . "/" . $cvt($icon[$p]))) {
  61. $smallfile = $d . "/" . $cvt($icon[$p]);
  62. }
  63. }
  64. } else {
  65. $ext = is_file($d . "/" . $icon[0] . ".png") ? ".png" : "@2x.png";
  66. for ($i = 0; $i < count($icon); $i++) {
  67. if (is_file($d . "/" . $icon[$i] . $ext)) {
  68. $big[] = filesize($d . "/" . $icon[$i] . $ext);
  69. $small[] = filesize($d . "/" . $icon[$i] . $ext);
  70. }
  71. }
  72. rsort($big);
  73. sort($small);
  74. for ($p = 0; $p < count($icon); $p++) {
  75. if ($big[0] == filesize($d . "/" . $icon[$p] . $ext)) {
  76. $bigfile = is_file($d . "/" . $icon[$p] . "@3x.png") ? $d . "/" . $icon[$p] . "@3x.png" : $d . "/" . $icon[$p] . $ext;
  77. }
  78. if ($small[0] == filesize($d . "/" . $icon[$p] . $ext)) {
  79. $smallfile = preg_match("/AppIcon20x20/", $icon[$p]) ? $d . "/" . $icon[$p] . "@3x.png" : $d . "/" . $icon[$p] . $ext;
  80. }
  81. }
  82. }
  83. $png = new \PngFile\PngFile($smallfile);
  84. if (!$png->revertIphone($newfile)) {
  85. if (!rename($bigfile, $newfile)) {
  86. if ($plist["CFBundleIconFile"]) {
  87. if (preg_match("/\\./", $plist["CFBundleIconFile"])) {
  88. rename($d . "/" . $plist["CFBundleIconFile"], $newfile);
  89. } else {
  90. rename($d . "/" . $plist["CFBundleIconFile"] . ".png", $newfile);
  91. }
  92. } else {
  93. copy(IN_ROOT . "static/index/image/iOS.png", $newfile);
  94. }
  95. }
  96. }
  97. $em = file_get_contents($d . "/embedded.mobileprovision");
  98. rename($d . "/embedded.mobileprovision", str_replace(".png", ".mobileprovision", $newfile));
  99. $xml_nick = preg_match("/<key>Name<\\/key>\r\n([\\s\\S]+?)<string>([\\s\\S]+?)<\\/string>/", $em, $m) ? mb_convert_encoding($m[2], set_chars(), "HTML-ENTITIES") : "*";
  100. $xml_type = preg_match("/^iOS Team Provisioning Profile:/", $xml_nick) ? 0 : 1;
  101. $xml_team = preg_match("/<key>TeamName<\\/key>\r\n([\\s\\S]+?)<string>([\\s\\S]+?)<\\/string>/", $em, $m) ? mb_convert_encoding($m[2], set_chars(), "HTML-ENTITIES") : "*";
  102. echo "{'name':'" . $xml_name . "','mnvs':'" . $xml_mnvs . "','bid':'" . $xml_bid . "','bsvs':'" . $xml_bsvs . "','bvs':'" . $xml_bvs . "','form':'iOS','nick':'" . $xml_nick . "','type':'" . $xml_type . "','team':'" . $xml_team . "','icon':'" . $icontime . "','app':'" . $apptime . "','size':'" . $xml_size . "'}";
  103. }