public static function charge($token, $email, $amount) { $key = Config::get('stripeKey'); Stripe\Stripe::setApiKey($key); $customer = Stripe\Customer::create(array('email' => $email, 'card' => $token)); $charge = Stripe\Charge::create(array('customer' => $customer->id, 'amount' => $amount, 'currency' => 'USD')); return $charge; }
/** * Get a collection of programmes listed by letter, using a cached record if it exists * @param string $letter The letter for which to query the programmes * @return \Illuminate\Support\Collection */ public function getProgrammes($letter) { $page = Request::get('page', 1); return $this->cache->remember("bbc.programmes.{$letter}.page.{$page}", \Config::get('cache.remember_time'), function () use($letter) { return $this->bbc_api_client->getProgrammes($letter); }); }
public function debug($request, $response, $args) { $server = ["headers" => $request->getHeaders(), "content_type" => $request->getContentType()]; $res = ["server_info" => $server, "ip" => Http::getClientIP(), "version" => Config::get('version'), "reg_count" => Check::getIpRegCount(Http::getClientIP())]; Logger::debug(json_encode($res)); return $this->echoJson($response, $res); }
public function __construct() { $this->config = Config::get("mail")["mailgun"]; $this->mg = new MailgunService($this->config["key"]); $this->domain = $this->config["domain"]; $this->sender = $this->config["sender"]; }
public function testDebug() { $this->get('/debug'); $this->assertEquals('200', $this->response->getStatusCode()); $ary = json_decode($this->response->getBody(), true); // test version $this->assertEquals(Config::get('version'), $ary['version']); }
public static function checkPassword($hashedPassword, $password) { $method = Config::get('pwdMethod'); if ($hashedPassword == self::passwordHash($password)) { return true; } return false; }
/** * Deliver the email confirmation. * * @param User $user * @return void */ public function sendEmailConfirmationTo(User $user) { $this->to = $user->email; $this->view = 'emails.confirm'; $this->from = \Config::get('mail.from.address'); $this->name = \Config::get('mail.from.name'); $this->data = compact('user'); $this->deliver('🚗 애.카.프. 딜러회원 가입을 완료해주세요.'); }
public function isAbleToCheckin() { $last = $this->attributes['last_check_in_time']; $hour = Config::get('checkinTime'); if ($last + $hour * 3600 < time()) { return true; } return false; }
public static function createTokenStorage() { switch (Config::get('tokenDriver')) { case 'db': return new DB(); case 'dynamodb': return new Dynamodb(); default: return new DB(); } }
/** * @return Cache */ public static function newSessionCache() { switch (Config::get('session')) { case 'redis': return self::newRedisCache(); case 'file': return self::newFileCache(Config::getStoragePath('/framework/sessions')); default: return self::newFileCache(); } }
/** * @param string $message * @param string $type * @param array $attachment */ public function post($message, $type, $attachment = []) { $type = \Config::get('slack.types.' . strtolower($type), \Config::get('slack.default', [])); $webHookUrl = \Config::get('slack.webHookUrl'); $client = new Client($webHookUrl, ['username' => array_get($type, 'username', 'FamarryBot'), 'channel' => array_get($type, 'channel', '#random'), 'link_names' => true, 'icon' => array_get($type, 'icon', ':smile:')]); $messageObj = $client->createMessage(); if (!empty($attachment)) { $attachment = new Attachment(['fallback' => array_get($attachment, 'fallback', ''), 'text' => array_get($attachment, 'text', ''), 'pretext' => array_get($attachment, 'pretext', ''), 'color' => array_get($attachment, 'color', 'good'), 'fields' => array_get($attachment, 'fields', [])]); $messageObj->attach($attachment); } $messageObj->setText($message)->send(); }
public function registerJob($jobId, $jobInfo) { $queueData = ['key' => \Config::get('async.key'), 'jobs' => [['id' => $jobId, 'data' => $jobInfo]]]; if (\Config::get('async.enable', false) == true) { $auth = ["key" => \Config::get('aws.accounts.key'), "secret" => \Config::get('aws.accounts.secret'), "region" => \Config::get('aws.accounts.region')]; $sqs = new SqsClient($auth); $sqs->{$sqs}->sendMessage(['QueueUrl' => \Config::get('async.worker.queue'), 'MessageBody' => json_encode($queueData)]); // Log::info('Add Queue:' . json_encode($queueData)); } else { $this->executeJob($queueData); } }
private function setStatusName($todos) { foreach ($todos as $todo) { if ($todo->deleted_at) { $todo->status_name = 'DELETED'; } elseif ($todo->status == \Config::get('app.status.todo.incomplete')) { $todo->status_name = 'INCOMPLETE'; } elseif ($todo->status == \Config::get('app.status.todo.completed')) { $todo->status_name = 'COMPLETED'; } } return $todos; }
public static function getDriver() { $method = Config::get('authDriver'); switch ($method) { case 'cookie': return new Cookie(); break; case 'redis': return new Redis(); break; } return new Redis(); }
public static function createAuth() { $method = Config::get('authDriver'); switch ($method) { case 'cookie': return new Cookie(); case 'redis': return new Redis(); case 'jwt': return new JwtToken(); } return new Redis(); }
public static function sendDailyMail() { $users = User::all(); foreach ($users as $user) { echo "Send daily mail to user: "******"-每日流量报告"; $to = $user->email; try { Mail::send($to, $subject, 'news/daily-traffic-report.tpl', ["user" => $user], []); } catch (Exception $e) { echo $e->getMessage(); } } }
public static function send($to, $subject, $text) { $driver = Config::get("maildriver"); switch ($driver) { case "mailgun": $mail = new Mailgun(); $mail->send($to, $subject, $text); case "smtp": // @TODO smtp // @TODO smtp default: // @TODO default action } }
/** * @return Mailgun|Ses|Smtp|null */ public static function getClient() { $driver = Config::get("mailDriver"); switch ($driver) { case "mailgun": return new Mailgun(); case "ses": return new Ses(); case "smtp": return new Smtp(); default: // @TODO default action } return null; }
public static function getSmarty() { $smarty = new smarty(); //实例化smarty $smarty->settemplatedir(BASE_PATH . '/resources/views/' . Config::get('theme') . '/'); //设置模板文件存放目录 $smarty->setcompiledir(BASE_PATH . '/storage/framework/smarty/compile/'); //设置生成文件存放目录 $smarty->setcachedir(BASE_PATH . '/storage/framework/smarty/cache/'); //设置缓存文件存放目录 // add config $smarty->assign('config', Config::getPublicConfig()); $smarty->assign('user', Auth::getUser()); return $smarty; }
public static function send($to, $subject, $text) { $driver = Config::get("mailDriver"); switch ($driver) { case "mailgun": $mail = new Mailgun(); return $mail->send($to, $subject, $text); case "smtp": $mail = new Smtp(); return $mail->send($to, $subject, $text); default: // @TODO default action } return true; }
public function doCheckin($request, $response, $args) { $user = Auth::getUser(); //权限检查 if (!$user->isAbleToCheckin()) { $tranferToAdd = 0; $res['msg'] = "签到过了哦"; return $response->getBody()->write(json_encode($res)); } $tranferToAdd = rand(Config::get('checkinMin'), Config::get('checkinMax')); // Add transfer $user->addTraffic($tranferToAdd); $res['msg'] = "获得了" . $tranferToAdd . "MB流量"; return $response->getBody()->write(json_encode($res)); }
public function smarty() { //global $config; $smarty = new smarty(); //实例化smarty $smarty->settemplatedir(BASE_PATH . '/views/' . Config::get('theme') . '/'); //设置模板文件存放目录 $smarty->setcompiledir(BASE_PATH . '/storage/framework/smarty/compile/'); //设置生成文件存放目录 $smarty->setcachedir(BASE_PATH . '/storage/framework/smarty/cache/'); //设置缓存文件存放目录 // add config $smarty->assign('config', $_ENV); $smarty->assign('user', Auth::getUser()); $this->smarty = $smarty; return $smarty; }
/** * @param $email string * @return bool */ public static function sendResetEmail($email) { $pwdRst = new PasswordReset(); $pwdRst->email = $email; $pwdRst->init_time = time(); $pwdRst->expire_time = time() + 3600 * 24; // @todo $pwdRst->token = Tools::genRandomChar(64); if (!$pwdRst->save()) { return false; } $subject = Config::get('appName') . "重置密码"; $resetUrl = Config::get('baseUrl') . "/password/token/" . $pwdRst->token; try { Mail::send($email, $subject, 'password/reset.tpl', ["resetUrl" => $resetUrl], []); } catch (Exception $e) { return false; } return true; }
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, $next) { $key = Helper::getMuKeyFromReq($request); if ($key == null) { $res['ret'] = 0; $res['msg'] = "key is null"; $newResponse = $response->withStatus(401); $newResponse->getBody()->write(json_encode($res)); return $newResponse; } if ($key != Config::get('muKey')) { $res['ret'] = 0; $res['msg'] = "token is invalid"; $newResponse = $response->withStatus(401); $newResponse->getBody()->write(json_encode($res)); return $newResponse; } $response = $next($request, $response); return $response; }
public function addTraffic($request, $response, $args) { // $data = json_decode($request->getParsedBody(),true); $id = $args['id']; $u = $request->getParam('u'); $d = $request->getParam('d'); $nodeId = $request->getParam('node_id'); $node = Node::find($nodeId); $rate = $node->traffic_rate; $user = User::find($id); $user->t = time(); $user->u = $user->u + $u * $rate; $user->d = $user->d + $d * $rate; if (!$user->save()) { $res = ["msg" => "update failed"]; return $this->echoJson($response, $res, 400); } // log $totalTraffic = Tools::flowAutoShow(($u + $d) * $rate); $traffic = new TrafficLog(); $traffic->user_id = $id; $traffic->u = $u; $traffic->d = $d; $traffic->node_id = $nodeId; $traffic->rate = $rate; $traffic->traffic = $totalTraffic; $traffic->log_time = time(); $traffic->save(); $res = ["ret" => 1, "msg" => "ok"]; if (Config::get('log_traffic_dynamodb')) { try { $client = new DynamoTrafficLog(); $id = $client->store($u, $d, $nodeId, $id, $totalTraffic, $rate); $res["id"] = $id; } catch (\Exception $e) { $res["msg"] = $e->getMessage(); Logger::error($e->getMessage()); } } return $this->echoJson($response, $res); }
public function createAdmin() { echo "add admin/ 创建管理员帐号....."; // ask for input fwrite(STDOUT, "Enter your email/输入管理员邮箱: "); // get input $email = trim(fgets(STDIN)); // write input back fwrite(STDOUT, "Enter password for: {$email} / 为 {$email} 添加密码 "); $passwd = trim(fgets(STDIN)); echo "Email: {$email}, Password: {$passwd}! "; fwrite(STDOUT, "Press [Y] to create admin..... 按下[Y]确认来确认创建管理员账户..... "); $y = trim(fgets(STDIN)); if (strtolower($y) == "y") { echo "start create admin account"; // create admin user // do reg user $user = new User(); $user->user_name = "admin"; $user->email = $email; $user->pass = Hash::passwordHash($passwd); $user->passwd = Tools::genRandomChar(6); $user->port = Tools::getLastPort() + 1; $user->t = 0; $user->u = 0; $user->d = 0; $user->transfer_enable = Tools::toGB(Config::get('defaultTraffic')); $user->invite_num = Config::get('inviteNum'); $user->ref_by = 0; $user->is_admin = 1; if ($user->save()) { echo "Successful/添加成功!"; return true; } echo "添加失败"; return false; } echo "cancel"; return false; }
public function __construct() { $this->config = Config::get("mail")["smtp"]; $mail = new PHPMailer(); //$mail->SMTPDebug = 3; // Enable verbose debug output $mail->isSMTP(); // Set mailer to use SMTP $mail->Host = $this->config['host']; // Specify main and backup SMTP servers $mail->SMTPAuth = true; // Enable SMTP authentication $mail->Username = $this->config['username']; // SMTP username $mail->Password = '******'; // SMTP password $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted $mail->Port = $this->config['port']; // TCP port to connect to $mail->setFrom($this->config['sender'], $this->config['name']); $this->mail = $mail; }
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, $next) { if (Helper::isTesting()) { $response = $next($request, $response); return $response; } $key = Helper::getMuKeyFromReq($request); if ($key == null) { $res['ret'] = 0; $res['msg'] = "key is null"; $newResponse = $response->withJson($res, 401); return $newResponse; } if ($key != Config::get('muKey')) { $res['ret'] = 0; $res['msg'] = "token is invalid"; $newResponse = $response->withJson($res, 401); return $newResponse; } $response = $next($request, $response); return $response; }
/** * @param $email string * @return bool */ public static function sendVerification($email) { $ttl = Config::get('emailVerifyTTL'); $verification = EmailVerifyModel::where('email', '=', $email)->first(); if ($verification == null) { $verification = new EmailVerifyModel(); $verification->email = $email; } $verification->token = Tools::genRandomChar(Config::get('emailVerifyCodeLength')); $verification->expire_at = time() + $ttl * 60; if (!$verification->save()) { return false; } $appName = Config::get('appName'); $subject = $appName . ' 邮箱验证'; try { Mail::send($email, $subject, 'auth/verify.tpl', ['verification' => $verification, 'ttl' => $ttl], []); } catch (Exception $e) { return false; } return true; }
<?php /*** * ss-panel v3 Bootstrap * @author orvice * @email sspanel@orx.me * @url https://github.com/orvice/ss-panel */ use Illuminate\Database\Capsule\Manager as Capsule; use Dotenv\Dotenv; use App\Services\Config; // BASE_PATH define('BASE_PATH', __DIR__); // Vendor Autoload require BASE_PATH . '/vendor/autoload.php'; // Env $env = new Dotenv(__DIR__); $env->load(); // config time zone date_default_timezone_set($_ENV['timeZone']); // debug if ($_ENV['debug'] == "true") { define("DEBUG", true); } $_ENV['version'] = '3.0.2'; // db config $dbConfig = ['driver' => Config::get('db_driver'), 'host' => Config::get('db_host'), 'database' => Config::get('db_database'), 'username' => Config::get('db_username'), 'password' => Config::get('db_password'), 'charset' => Config::get('db_charset'), 'collation' => Config::get('db_collation'), 'prefix' => Config::get('db_prefix')]; // Init Eloquent ORM Connection $capsule = new Capsule(); $capsule->addConnection($dbConfig); $capsule->bootEloquent();