123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- <?php
- // by 请勿倒卖,已申请软著,否则追究法律责任
- require_once "deplist/CFPropertyList.php";
- include "../../system/db.class.php";
- include "../../system/user.php";
- Chk_authkey();
- $GLOBALS["userlogined"] || reJSON(-1);
- $id = SafeRequest("id", "post") ? bees_decrypt(SafeRequest("id", "post")) : 0;
- $time = SafeRequest("time", "post");
- $filename = SafeRequest("filename", "post");
- preg_match("/^(\\d+\\-\\d+)\$/", $time) || reJSON(-2);
- $tmp = IN_ROOT . "data/tmp/" . $time . "/app.ipa";
- is_file($tmp) || reJSON(-2);
- $in_size = intval(filesize($tmp));
- $explode = explode("-", $time);
- $icontime = md5($explode[0] . "-" . $explode[1] . "-" . rand(2, pow(2, 24))) . ".png";
- $in_app = md5($explode[1] . "-" . $explode[0] . "-" . rand(2, pow(2, 24))) . ".ipa";
- is_file(IN_ROOT . "data/attachment/" . $in_app) && reJSON(-2);
- IN_VERIFY > 0 && $GLOBALS["xfcms_in_verify"] != 1 && reJSON(-3);
- $dir = IN_ROOT . "data/tmp/" . $time . "/";
- include_once "../zip/zip.php";
- $zip = new PclZip($tmp);
- $zip->extract(PCLZIP_OPT_PATH, $dir, PCLZIP_OPT_BY_PREG, "/^Payload\\/.*.app\\/Info.plist\$/");
- $zip->extract(PCLZIP_OPT_PATH, $dir, PCLZIP_OPT_BY_PREG, "/^Payload\\/.*.app\\/embedded.mobileprovision\$/");
- $zip->extract(PCLZIP_OPT_PATH, $dir, PCLZIP_OPT_BY_PREG, "/^Payload\\/.*.app\\/(?!.*\\/).*.png\$/");
- $icon = SafeRequest("icon", "post");
- if (strpos($icon, "data:image/png;base64") === false) {
- $icon = pack("H*", $icon);
- }
- $payloaddir = $dir . "/Payload/";
- if (is_dir($payloaddir)) {
- $d = NULL;
- $h = opendir($payloaddir);
- while ($f = readdir($h)) {
- if ($f != "." && $f != ".." && is_dir($payloaddir . "/" . $f)) {
- $d = $payloaddir . "/" . $f;
- }
- }
- closedir($h);
- $info = file_get_contents($d . "/Info.plist");
- $plist = new \CFPropertyList\CFPropertyList();
- $plist->parse($info);
- $plist = $plist->toArray();
- $in_size + $GLOBALS["xfcms_in_spaceuse"] > $GLOBALS["xfcms_in_spacetotal"] && reJSON(-4);
- $in_name = detect_encoding(isset($plist["CFBundleDisplayName"]) ? $plist["CFBundleDisplayName"] : $plist["CFBundleName"]);
- $in_mnvs = $plist["MinimumOSVersion"];
- $in_bid = $plist["CFBundleIdentifier"];
- $in_bsvs = $plist["CFBundleShortVersionString"];
- $in_bvs = $plist["CFBundleVersion"];
- $in_bexe = $plist["CFBundleExecutable"];
- rename($tmp, IN_ROOT . "data/attachment/" . $in_app);
- $basedir = IN_ROOT . "data/image/app";
- $imgdir = date("Y/m/d");
- creatdir($basedir . "/" . $imgdir);
- $in_icon = $imgdir . "/" . $icontime;
- if (preg_match("/^(data:\\s*image\\/(\\w+);base64,)/", $icon, $result)) {
- $img_base64 = str_replace($result[1], "", $icon);
- $img_base64 = base64_decode($img_base64);
- $fileext = $result[2];
- if (in_array(strtolower($fileext), array("pjpeg", "jpeg", "jpg", "gif", "bmp", "png"))) {
- $basedir = IN_ROOT . "data/image/app";
- $imgdir = date("Y/m/d");
- creatdir($basedir . "/" . $imgdir);
- $filepath = $basedir . "/" . $imgdir . "/" . $icontime;
- $in_icon = $imgdir . "/" . $icontime;
- file_put_contents($filepath, $img_base64);
- }
- }
- $embedded = $d . "/embedded.mobileprovision";
- if (!file_exists($embedded)) {
- $in_nick = "*";
- $in_type = "1";
- $in_team = "*";
- $in_udids = "*";
- } else {
- $em = file_get_contents($embedded);
- $emfile = str_replace(".ipa", ".mobileprovision", "../../../data/attachment/" . $in_app);
- rename($embedded, $emfile);
- $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")) : "*";
- $in_type = preg_match("/^iOS Team Provisioning Profile:/", $in_nick) ? 0 : 1;
- $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")) : "*";
- $in_udids = preg_match("/<key>UUID<\\/key>([\\s\\S]+?)<string>([\\s\\S]+?)<\\/string>/", $em, $m) ? mb_convert_encoding($m[2], set_chars(), "HTML-ENTITIES") : "*";
- }
- $in_form = "iOS";
- $deduct = getDeduct($in_size);
- $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);
- $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();
- if ($app) {
- $id = $app["in_id"];
- @unlink(IN_PATH . "data/image/app/" . $app["in_icon"]);
- db("appid")->where("in_id", $id)->update($data);
- db("app")->where("in_appid", $id)->update(array("in_release" => 0));
- } else {
- $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));
- $id = db("appid")->insertGetId($data);
- }
- $logData = db("appid")->where("in_id", $id)->find();
- $logData["in_appid"] = $logData["in_id"];
- unset($logData["in_id"]);
- $logData["in_addtime"] = time();
- db("app")->strict(false)->insert($logData);
- db("user")->where("in_userid", $GLOBALS["xfcms_in_userid"])->inc("in_spaceuse", $in_size)->update();
- reJSON(array("id" => bees_encrypt($id)), 1);
- }
|