index-ipa.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. // by 请勿倒卖,已申请软著,否则追究法律责任
  3. require_once "deplist/CFPropertyList.php";
  4. include "../../system/db.class.php";
  5. include "../../system/user.php";
  6. Chk_authkey();
  7. $GLOBALS["userlogined"] || reJSON(-1);
  8. $id = SafeRequest("id", "post") ? bees_decrypt(SafeRequest("id", "post")) : 0;
  9. $time = SafeRequest("time", "post");
  10. $filename = SafeRequest("filename", "post");
  11. preg_match("/^(\\d+\\-\\d+)\$/", $time) || reJSON(-2);
  12. $tmp = IN_ROOT . "data/tmp/" . $time . "/app.ipa";
  13. is_file($tmp) || reJSON(-2);
  14. $in_size = intval(filesize($tmp));
  15. $explode = explode("-", $time);
  16. $icontime = md5($explode[0] . "-" . $explode[1] . "-" . rand(2, pow(2, 24))) . ".png";
  17. $in_app = md5($explode[1] . "-" . $explode[0] . "-" . rand(2, pow(2, 24))) . ".ipa";
  18. is_file(IN_ROOT . "data/attachment/" . $in_app) && reJSON(-2);
  19. IN_VERIFY > 0 && $GLOBALS["xfcms_in_verify"] != 1 && reJSON(-3);
  20. $dir = IN_ROOT . "data/tmp/" . $time . "/";
  21. include_once "../zip/zip.php";
  22. $zip = new PclZip($tmp);
  23. $zip->extract(PCLZIP_OPT_PATH, $dir, PCLZIP_OPT_BY_PREG, "/^Payload\\/.*.app\\/Info.plist\$/");
  24. $zip->extract(PCLZIP_OPT_PATH, $dir, PCLZIP_OPT_BY_PREG, "/^Payload\\/.*.app\\/embedded.mobileprovision\$/");
  25. $zip->extract(PCLZIP_OPT_PATH, $dir, PCLZIP_OPT_BY_PREG, "/^Payload\\/.*.app\\/(?!.*\\/).*.png\$/");
  26. $icon = SafeRequest("icon", "post");
  27. if (strpos($icon, "data:image/png;base64") === false) {
  28. $icon = pack("H*", $icon);
  29. }
  30. $payloaddir = $dir . "/Payload/";
  31. if (is_dir($payloaddir)) {
  32. $d = NULL;
  33. $h = opendir($payloaddir);
  34. while ($f = readdir($h)) {
  35. if ($f != "." && $f != ".." && is_dir($payloaddir . "/" . $f)) {
  36. $d = $payloaddir . "/" . $f;
  37. }
  38. }
  39. closedir($h);
  40. $info = file_get_contents($d . "/Info.plist");
  41. $plist = new \CFPropertyList\CFPropertyList();
  42. $plist->parse($info);
  43. $plist = $plist->toArray();
  44. $in_size + $GLOBALS["xfcms_in_spaceuse"] > $GLOBALS["xfcms_in_spacetotal"] && reJSON(-4);
  45. $in_name = detect_encoding(isset($plist["CFBundleDisplayName"]) ? $plist["CFBundleDisplayName"] : $plist["CFBundleName"]);
  46. $in_mnvs = $plist["MinimumOSVersion"];
  47. $in_bid = $plist["CFBundleIdentifier"];
  48. $in_bsvs = $plist["CFBundleShortVersionString"];
  49. $in_bvs = $plist["CFBundleVersion"];
  50. $in_bexe = $plist["CFBundleExecutable"];
  51. rename($tmp, IN_ROOT . "data/attachment/" . $in_app);
  52. $basedir = IN_ROOT . "data/image/app";
  53. $imgdir = date("Y/m/d");
  54. creatdir($basedir . "/" . $imgdir);
  55. $in_icon = $imgdir . "/" . $icontime;
  56. if (preg_match("/^(data:\\s*image\\/(\\w+);base64,)/", $icon, $result)) {
  57. $img_base64 = str_replace($result[1], "", $icon);
  58. $img_base64 = base64_decode($img_base64);
  59. $fileext = $result[2];
  60. if (in_array(strtolower($fileext), array("pjpeg", "jpeg", "jpg", "gif", "bmp", "png"))) {
  61. $basedir = IN_ROOT . "data/image/app";
  62. $imgdir = date("Y/m/d");
  63. creatdir($basedir . "/" . $imgdir);
  64. $filepath = $basedir . "/" . $imgdir . "/" . $icontime;
  65. $in_icon = $imgdir . "/" . $icontime;
  66. file_put_contents($filepath, $img_base64);
  67. }
  68. }
  69. $embedded = $d . "/embedded.mobileprovision";
  70. if (!file_exists($embedded)) {
  71. $in_nick = "*";
  72. $in_type = "1";
  73. $in_team = "*";
  74. $in_udids = "*";
  75. } else {
  76. $em = file_get_contents($embedded);
  77. $emfile = str_replace(".ipa", ".mobileprovision", "../../../data/attachment/" . $in_app);
  78. rename($embedded, $emfile);
  79. $in_nick = preg_match("/<key>Name<\\/key>([\\s\\S]+?)<string>([\\s\\S]+?)<\\/string>/", $em, $m) ? SafeSql(mb_convert_encoding($m[2], set_chars(), "HTML-ENTITIES")) : "*";
  80. $in_type = preg_match("/^iOS Team Provisioning Profile:/", $in_nick) ? 0 : 1;
  81. $in_team = preg_match("/<key>TeamName<\\/key>([\\s\\S]+?)<string>([\\s\\S]+?)<\\/string>/", $em, $m) ? SafeSql(mb_convert_encoding($m[2], set_chars(), "HTML-ENTITIES")) : "*";
  82. $in_udids = preg_match("/<key>UUID<\\/key>([\\s\\S]+?)<string>([\\s\\S]+?)<\\/string>/", $em, $m) ? mb_convert_encoding($m[2], set_chars(), "HTML-ENTITIES") : "*";
  83. }
  84. $in_form = "iOS";
  85. $deduct = getDeduct($in_size);
  86. $data = array("in_name" => $in_name, "in_type" => $in_type, "in_size" => $in_size, "in_form" => $in_form, "in_mnvs" => $in_mnvs, "in_bid" => $in_bid, "in_bsvs" => $in_bsvs, "in_bvs" => $in_bvs, "in_nick" => $in_nick, "in_team" => $in_team, "in_udids" => $in_udids, "in_deduct" => $deduct, "in_icon" => $in_icon, "in_app" => $in_app, "in_originalName" => $filename, "in_updatetime" => time(), "remote" => 0, "in_bexe" => $in_bexe);
  87. $app = db("appid")->where("in_uid", $GLOBALS["xfcms_in_userid"])->where("in_form", $in_form)->where("in_bid", $in_bid)->where("in_name", $in_name)->find();
  88. if ($app) {
  89. $id = $app["in_id"];
  90. @unlink(IN_PATH . "data/image/app/" . $app["in_icon"]);
  91. db("appid")->where("in_id", $id)->update($data);
  92. db("app")->where("in_appid", $id)->update(array("in_release" => 0));
  93. } else {
  94. $data = array_merge($data, array("in_uid" => $GLOBALS["xfcms_in_userid"], "in_uname" => $GLOBALS["xfcms_in_username"], "in_udids" => $in_udids, "in_link" => creatLink(), "in_addtime" => time(), "in_downloads" => 0));
  95. $id = db("appid")->insertGetId($data);
  96. }
  97. $logData = db("appid")->where("in_id", $id)->find();
  98. $logData["in_appid"] = $logData["in_id"];
  99. unset($logData["in_id"]);
  100. $logData["in_addtime"] = time();
  101. db("app")->strict(false)->insert($logData);
  102. db("user")->where("in_userid", $GLOBALS["xfcms_in_userid"])->inc("in_spaceuse", $in_size)->update();
  103. reJSON(array("id" => bees_encrypt($id)), 1);
  104. }