1
0

inbounds.html 77 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617
  1. {{ template "page/head_start" .}}
  2. {{ template "page/head_end" .}}
  3. {{ template "page/body_start" .}}
  4. <a-layout id="app" v-cloak :class="themeSwitcher.currentTheme + ' inbounds-page'">
  5. <a-sidebar></a-sidebar>
  6. <a-layout id="content-layout">
  7. <a-layout-content>
  8. <a-spin :spinning="loadingStates.spinning" :delay="500" tip='{{ i18n "loading"}}'>
  9. <transition name="list" appear>
  10. <a-alert type="error" v-if="showAlert && loadingStates.fetched" :style="{ marginBottom: '10px' }"
  11. message='{{ i18n "secAlertTitle" }}' color="red" description='{{ i18n "secAlertSsl" }}' show-icon closable>
  12. </a-alert>
  13. </transition>
  14. <transition name="list" appear>
  15. <a-row v-if="!loadingStates.fetched">
  16. <a-card
  17. :style="{ textAlign: 'center', padding: '30px 0', marginTop: '10px', background: 'transparent', border: 'none' }">
  18. <a-spin tip='{{ i18n "loading" }}'></a-spin>
  19. </a-card>
  20. </a-row>
  21. <a-row :gutter="[isMobile ? 8 : 16, isMobile ? 0 : 12]" v-else>
  22. <a-col>
  23. <a-card size="small" :style="{ padding: '16px' }" hoverable>
  24. <a-row>
  25. <a-col :sm="12" :md="5">
  26. <a-custom-statistic title='{{ i18n "pages.inbounds.totalDownUp" }}'
  27. :value="`${SizeFormatter.sizeFormat(total.up)} / ${SizeFormatter.sizeFormat(total.down)}`">
  28. <template #prefix>
  29. <a-icon type="swap"></a-icon>
  30. </template>
  31. </a-custom-statistic>
  32. </a-col>
  33. <a-col :sm="12" :md="5">
  34. <a-custom-statistic title='{{ i18n "pages.inbounds.totalUsage" }}'
  35. :value="SizeFormatter.sizeFormat(total.up + total.down)"
  36. :style="{ marginTop: isMobile ? '10px' : 0 }">
  37. <template #prefix>
  38. <a-icon type="pie-chart"></a-icon>
  39. </template>
  40. </a-custom-statistic>
  41. </a-col>
  42. <a-col :sm="12" :md="5">
  43. <a-custom-statistic title='{{ i18n "pages.inbounds.allTimeTrafficUsage" }}'
  44. :value="SizeFormatter.sizeFormat(total.allTime)" :style="{ marginTop: isMobile ? '10px' : 0 }">
  45. <template #prefix>
  46. <a-icon type="history"></a-icon>
  47. </template>
  48. </a-custom-statistic>
  49. </a-col>
  50. <a-col :sm="12" :md="5">
  51. <a-custom-statistic title='{{ i18n "pages.inbounds.inboundCount" }}' :value="dbInbounds.length"
  52. :style="{ marginTop: isMobile ? '10px' : 0 }">
  53. <template #prefix>
  54. <a-icon type="bars"></a-icon>
  55. </template>
  56. </a-custom-statistic>
  57. </a-col>
  58. <a-col :sm="12" :md="4">
  59. <a-custom-statistic title='{{ i18n "clients" }}' value=" "
  60. :style="{ marginTop: isMobile ? '10px' : 0 }">
  61. <template #prefix>
  62. <a-space direction="horizontal">
  63. <a-icon type="team"></a-icon>
  64. <div>
  65. <a-back-top :target="() => document.getElementById('content-layout')"
  66. visibility-height="200"></a-back-top>
  67. <a-tag color="green">[[ total.clients ]]</a-tag>
  68. <a-popover title='{{ i18n "disabled" }}' :overlay-class-name="themeSwitcher.currentTheme">
  69. <template slot="content">
  70. <div v-for="clientEmail in total.deactive"><span>[[ clientEmail ]]</span></div>
  71. </template>
  72. <a-tag v-if="total.deactive.length">[[ total.deactive.length ]]</a-tag>
  73. </a-popover>
  74. <a-popover title='{{ i18n "depleted" }}' :overlay-class-name="themeSwitcher.currentTheme">
  75. <template slot="content">
  76. <div v-for="clientEmail in total.depleted"><span>[[ clientEmail ]]</span></div>
  77. </template>
  78. <a-tag color="red" v-if="total.depleted.length">[[ total.depleted.length ]]</a-tag>
  79. </a-popover>
  80. <a-popover title='{{ i18n "depletingSoon" }}'
  81. :overlay-class-name="themeSwitcher.currentTheme">
  82. <template slot="content">
  83. <div v-for="clientEmail in total.expiring"><span>[[ clientEmail ]]</span></div>
  84. </template>
  85. <a-tag color="orange" v-if="total.expiring.length">[[ total.expiring.length ]]</a-tag>
  86. </a-popover>
  87. <a-popover title='{{ i18n "online" }}' :overlay-class-name="themeSwitcher.currentTheme">
  88. <template slot="content">
  89. <div v-for="clientEmail in onlineClients"><span>[[ clientEmail ]]</span></div>
  90. </template>
  91. <a-tag color="blue" v-if="onlineClients.length">[[ onlineClients.length ]]</a-tag>
  92. </a-popover>
  93. </div>
  94. </a-space>
  95. </template>
  96. </a-custom-statistic>
  97. </a-col>
  98. </a-row>
  99. </a-card>
  100. </a-col>
  101. <a-col>
  102. <a-card hoverable>
  103. <template #title>
  104. <a-space direction="horizontal">
  105. <a-button type="primary" icon="plus" @click="openAddInbound">
  106. <template v-if="!isMobile">{{ i18n "pages.inbounds.addInbound" }}</template>
  107. </a-button>
  108. <a-dropdown :trigger="['click']">
  109. <a-button type="primary" icon="menu">
  110. <template v-if="!isMobile">{{ i18n "pages.inbounds.generalActions" }}</template>
  111. </a-button>
  112. <a-menu slot="overlay" @click="a => generalActions(a)" :theme="themeSwitcher.currentTheme">
  113. <a-menu-item key="import">
  114. <a-icon type="import"></a-icon>
  115. {{ i18n "pages.inbounds.importInbound" }}
  116. </a-menu-item>
  117. <a-menu-item key="export">
  118. <a-icon type="export"></a-icon>
  119. {{ i18n "pages.inbounds.export" }}
  120. </a-menu-item>
  121. <a-menu-item key="subs" v-if="subSettings.enable">
  122. <a-icon type="export"></a-icon>
  123. {{ i18n "pages.inbounds.export" }} - {{ i18n "pages.settings.subSettings" }}
  124. </a-menu-item>
  125. <a-menu-item key="resetInbounds">
  126. <a-icon type="reload"></a-icon>
  127. {{ i18n "pages.inbounds.resetAllTraffic" }}
  128. </a-menu-item>
  129. <a-menu-item key="resetClients">
  130. <a-icon type="file-done"></a-icon>
  131. {{ i18n "pages.inbounds.resetAllClientTraffics" }}
  132. </a-menu-item>
  133. <a-menu-item key="delDepletedClients" :style="{ color: '#FF4D4F' }">
  134. <a-icon type="rest"></a-icon>
  135. {{ i18n "pages.inbounds.delDepletedClients" }}
  136. </a-menu-item>
  137. </a-menu>
  138. </a-dropdown>
  139. </a-space>
  140. </template>
  141. <template #extra>
  142. <a-button-group>
  143. <a-button icon="sync" @click="manualRefresh" :loading="refreshing"></a-button>
  144. <a-popover placement="bottomRight" trigger="click" :overlay-class-name="themeSwitcher.currentTheme">
  145. <template #title>
  146. <div class="ant-custom-popover-title">
  147. <a-switch v-model="isRefreshEnabled" @change="toggleRefresh" size="small"></a-switch>
  148. <span>{{ i18n "pages.inbounds.autoRefresh" }}</span>
  149. </div>
  150. </template>
  151. <template #content>
  152. <a-space direction="vertical">
  153. <span>{{ i18n "pages.inbounds.autoRefreshInterval" }}</span>
  154. <a-select v-model="refreshInterval" :disabled="!isRefreshEnabled" :style="{ width: '100%' }"
  155. @change="changeRefreshInterval" :dropdown-class-name="themeSwitcher.currentTheme">
  156. <a-select-option v-for="key in [5,10,30,60]" :value="key*1000">[[ key ]]s</a-select-option>
  157. </a-select>
  158. </a-space>
  159. </template>
  160. <a-button icon="down"></a-button>
  161. </a-popover>
  162. </a-button-group>
  163. </template>
  164. <a-space direction="vertical">
  165. <div :style="isMobile ? {} : { display: 'flex', alignItems: 'center', justifyContent: 'flex-start' }">
  166. <a-switch v-model="enableFilter"
  167. :style="isMobile ? { marginBottom: '.5rem', display: 'flex' } : { marginRight: '.5rem' }"
  168. @change="toggleFilter">
  169. <a-icon slot="checkedChildren" type="search"></a-icon>
  170. <a-icon slot="unCheckedChildren" type="filter"></a-icon>
  171. </a-switch>
  172. <a-input v-if="!enableFilter" v-model.lazy="searchKey" placeholder='{{ i18n "search" }}' autofocus
  173. :style="{ maxWidth: '300px' }" :size="isMobile ? 'small' : ''"></a-input>
  174. <a-radio-group v-if="enableFilter" v-model="filterBy" @change="filterInbounds" button-style="solid"
  175. :size="isMobile ? 'small' : ''">
  176. <a-radio-button value="">{{ i18n "none" }}</a-radio-button>
  177. <a-radio-button value="deactive">{{ i18n "disabled" }}</a-radio-button>
  178. <a-radio-button value="depleted">{{ i18n "depleted" }}</a-radio-button>
  179. <a-radio-button value="expiring">{{ i18n "depletingSoon" }}</a-radio-button>
  180. <a-radio-button value="online">{{ i18n "online" }}</a-radio-button>
  181. </a-radio-group>
  182. </div>
  183. <a-table :columns="isMobile ? mobileColumns : columns" :row-key="dbInbound => dbInbound.id"
  184. :data-source="searchedInbounds" :scroll="isMobile ? {} : { x: 1000 }"
  185. :pagination=pagination(searchedInbounds) :expand-icon-as-cell="false" :expand-row-by-click="false"
  186. :expand-icon-column-index="0" :indent-size="0"
  187. :row-class-name="dbInbound => (dbInbound.isMultiUser() ? '' : 'hideExpandIcon')"
  188. :style="{ marginTop: '10px' }"
  189. :locale='{ filterConfirm: `{{ i18n "confirm" }}`, filterReset: `{{ i18n "reset" }}`, emptyText: `{{ i18n "noData" }}` }'>
  190. <template slot="action" slot-scope="text, dbInbound">
  191. <a-dropdown :trigger="['click']">
  192. <a-icon @click="e => e.preventDefault()" type="more"
  193. :style="{ fontSize: '20px', textDecoration: 'solid' }"></a-icon>
  194. <a-menu slot="overlay" @click="a => clickAction(a, dbInbound)"
  195. :theme="themeSwitcher.currentTheme">
  196. <a-menu-item key="edit">
  197. <a-icon type="edit"></a-icon>
  198. {{ i18n "edit" }}
  199. </a-menu-item>
  200. <a-menu-item key="qrcode"
  201. v-if="(dbInbound.isSS && !dbInbound.toInbound().isSSMultiUser) || dbInbound.isWireguard">
  202. <a-icon type="qrcode"></a-icon>
  203. {{ i18n "qrCode" }}
  204. </a-menu-item>
  205. <template v-if="dbInbound.isMultiUser()">
  206. <a-menu-item key="addClient">
  207. <a-icon type="user-add"></a-icon>
  208. {{ i18n "pages.client.add"}}
  209. </a-menu-item>
  210. <a-menu-item key="addBulkClient">
  211. <a-icon type="usergroup-add"></a-icon>
  212. {{ i18n "pages.client.bulk"}}
  213. </a-menu-item>
  214. <a-menu-item key="resetClients">
  215. <a-icon type="file-done"></a-icon>
  216. {{ i18n "pages.inbounds.resetInboundClientTraffics"}}
  217. </a-menu-item>
  218. <a-menu-item key="export">
  219. <a-icon type="export"></a-icon>
  220. {{ i18n "pages.inbounds.export"}}
  221. </a-menu-item>
  222. <a-menu-item key="subs" v-if="subSettings.enable">
  223. <a-icon type="export"></a-icon>
  224. {{ i18n "pages.inbounds.export"}} - {{ i18n "pages.settings.subSettings" }}
  225. </a-menu-item>
  226. <a-menu-item key="delDepletedClients" :style="{ color: '#FF4D4F' }">
  227. <a-icon type="rest"></a-icon>
  228. {{ i18n "pages.inbounds.delDepletedClients" }}
  229. </a-menu-item>
  230. </template>
  231. <template v-else>
  232. <a-menu-item key="showInfo">
  233. <a-icon type="info-circle"></a-icon>
  234. {{ i18n "info"}}
  235. </a-menu-item>
  236. </template>
  237. <a-menu-item key="clipboard">
  238. <a-icon type="copy"></a-icon>
  239. {{ i18n "pages.inbounds.exportInbound" }}
  240. </a-menu-item>
  241. <a-menu-item key="resetTraffic">
  242. <a-icon type="retweet"></a-icon> {{ i18n "pages.inbounds.resetTraffic" }}
  243. </a-menu-item>
  244. <a-menu-item key="clone">
  245. <a-icon type="block"></a-icon> {{ i18n "pages.inbounds.clone"}}
  246. </a-menu-item>
  247. <a-menu-item key="delete">
  248. <span :style="{ color: '#FF4D4F' }">
  249. <a-icon type="delete"></a-icon> {{ i18n "delete"}}
  250. </span>
  251. </a-menu-item>
  252. <a-menu-item v-if="isMobile">
  253. <a-switch size="small" v-model="dbInbound.enable"
  254. @change="switchEnable(dbInbound.id,dbInbound.enable)"></a-switch>
  255. {{ i18n "pages.inbounds.enable" }}
  256. </a-menu-item>
  257. </a-menu>
  258. </a-dropdown>
  259. </template>
  260. <template slot="protocol" slot-scope="text, dbInbound">
  261. <a-tag :style="{ margin: '0' }" color="purple">[[ dbInbound.protocol ]]</a-tag>
  262. <template v-if="dbInbound.isVMess || dbInbound.isVLess || dbInbound.isTrojan || dbInbound.isSS">
  263. <a-tag :style="{ margin: '0' }" color="green">[[ dbInbound.toInbound().stream.network ]]</a-tag>
  264. <a-tag :style="{ margin: '0' }" v-if="dbInbound.toInbound().stream.isTls"
  265. color="blue">TLS</a-tag>
  266. <a-tag :style="{ margin: '0' }" v-if="dbInbound.toInbound().stream.isReality"
  267. color="blue">Reality</a-tag>
  268. </template>
  269. </template>
  270. <template slot="clients" slot-scope="text, dbInbound">
  271. <template v-if="clientCount[dbInbound.id]">
  272. <a-tag :style="{ margin: '0' }" color="green">[[ clientCount[dbInbound.id].clients ]]</a-tag>
  273. <a-popover title='{{ i18n "disabled" }}' :overlay-class-name="themeSwitcher.currentTheme">
  274. <template slot="content">
  275. <div v-for="clientEmail in clientCount[dbInbound.id].deactive" :key="clientEmail"
  276. class="client-popup-item">
  277. <span>[[ clientEmail ]]</span>
  278. <a-tooltip :overlay-class-name="themeSwitcher.currentTheme">
  279. <template #title>
  280. [[ clientCount[dbInbound.id].comments.get(clientEmail) ]]
  281. </template>
  282. <a-icon type="message"
  283. v-if="clientCount[dbInbound.id].comments.get(clientEmail)"></a-icon>
  284. </a-tooltip>
  285. </div>
  286. </template>
  287. <a-tag :style="{ margin: '0', padding: '0 2px' }"
  288. v-if="clientCount[dbInbound.id].deactive.length">[[
  289. clientCount[dbInbound.id].deactive.length ]]</a-tag>
  290. </a-popover>
  291. <a-popover title='{{ i18n "depleted" }}' :overlay-class-name="themeSwitcher.currentTheme">
  292. <template slot="content">
  293. <div v-for="clientEmail in clientCount[dbInbound.id].depleted" :key="clientEmail"
  294. class="client-popup-item">
  295. <span>[[ clientEmail ]]</span>
  296. <a-tooltip :overlay-class-name="themeSwitcher.currentTheme">
  297. <template #title>
  298. [[ clientCount[dbInbound.id].comments.get(clientEmail) ]]
  299. </template>
  300. <a-icon type="message"
  301. v-if="clientCount[dbInbound.id].comments.get(clientEmail)"></a-icon>
  302. </a-tooltip>
  303. </div>
  304. </template>
  305. <a-tag :style="{ margin: '0', padding: '0 2px' }" color="red"
  306. v-if="clientCount[dbInbound.id].depleted.length">[[
  307. clientCount[dbInbound.id].depleted.length ]]</a-tag>
  308. </a-popover>
  309. <a-popover title='{{ i18n "depletingSoon" }}' :overlay-class-name="themeSwitcher.currentTheme">
  310. <template slot="content">
  311. <div v-for="clientEmail in clientCount[dbInbound.id].expiring" :key="clientEmail"
  312. class="client-popup-item">
  313. <span>[[ clientEmail ]]</span>
  314. <a-tooltip :overlay-class-name="themeSwitcher.currentTheme">
  315. <template #title>
  316. [[ clientCount[dbInbound.id].comments.get(clientEmail) ]]
  317. </template>
  318. <a-icon type="message"
  319. v-if="clientCount[dbInbound.id].comments.get(clientEmail)"></a-icon>
  320. </a-tooltip>
  321. </div>
  322. </template>
  323. <a-tag :style="{ margin: '0', padding: '0 2px' }" color="orange"
  324. v-if="clientCount[dbInbound.id].expiring.length">[[
  325. clientCount[dbInbound.id].expiring.length ]]</a-tag>
  326. </a-popover>
  327. <a-popover title='{{ i18n "online" }}' :overlay-class-name="themeSwitcher.currentTheme">
  328. <template slot="content">
  329. <div v-for="clientEmail in clientCount[dbInbound.id].online" :key="clientEmail"
  330. class="client-popup-item">
  331. <span>[[ clientEmail ]]</span>
  332. <a-tooltip :overlay-class-name="themeSwitcher.currentTheme">
  333. <template #title>
  334. [[ clientCount[dbInbound.id].comments.get(clientEmail) ]]
  335. </template>
  336. <a-icon type="message"
  337. v-if="clientCount[dbInbound.id].comments.get(clientEmail)"></a-icon>
  338. </a-tooltip>
  339. </div>
  340. </template>
  341. <a-tag :style="{ margin: '0', padding: '0 2px' }" color="blue"
  342. v-if="clientCount[dbInbound.id].online.length">[[ clientCount[dbInbound.id].online.length
  343. ]]</a-tag>
  344. </a-popover>
  345. </template>
  346. </template>
  347. <template slot="traffic" slot-scope="text, dbInbound">
  348. <a-popover :overlay-class-name="themeSwitcher.currentTheme">
  349. <template slot="content">
  350. <table cellpadding="2" width="100%">
  351. <tr>
  352. <td>↑[[ SizeFormatter.sizeFormat(dbInbound.up) ]]</td>
  353. <td>↓[[ SizeFormatter.sizeFormat(dbInbound.down) ]]</td>
  354. </tr>
  355. <tr v-if="dbInbound.total > 0 && dbInbound.up + dbInbound.down < dbInbound.total">
  356. <td>{{ i18n "remained" }}</td>
  357. <td>[[ SizeFormatter.sizeFormat(dbInbound.total - dbInbound.up - dbInbound.down) ]]</td>
  358. </tr>
  359. </table>
  360. </template>
  361. <a-tag
  362. :color="ColorUtils.usageColor(dbInbound.up + dbInbound.down, app.trafficDiff, dbInbound.total)">
  363. [[ SizeFormatter.sizeFormat(dbInbound.up + dbInbound.down) ]] /
  364. <template v-if="dbInbound.total > 0">
  365. [[ SizeFormatter.sizeFormat(dbInbound.total) ]]
  366. </template>
  367. <template v-else>
  368. <svg height="10px" width="14px" viewBox="0 0 640 512" fill="currentColor">
  369. <path
  370. d="M484.4 96C407 96 349.2 164.1 320 208.5C290.8 164.1 233 96 155.6 96C69.75 96 0 167.8 0 256s69.75 160 155.6 160C233.1 416 290.8 347.9 320 303.5C349.2 347.9 407 416 484.4 416C570.3 416 640 344.2 640 256S570.3 96 484.4 96zM155.6 368C96.25 368 48 317.8 48 256s48.25-112 107.6-112c67.75 0 120.5 82.25 137.1 112C276 285.8 223.4 368 155.6 368zM484.4 368c-67.75 0-120.5-82.25-137.1-112C364 226.2 416.6 144 484.4 144C543.8 144 592 194.2 592 256S543.8 368 484.4 368z"
  371. fill="currentColor"></path>
  372. </svg>
  373. </template>
  374. </a-tag>
  375. </a-popover>
  376. </template>
  377. <template slot="allTimeInbound" slot-scope="text, dbInbound">
  378. <a-tag>[[ SizeFormatter.sizeFormat(dbInbound.allTime || 0) ]]</a-tag>
  379. </template>
  380. <template slot="enable" slot-scope="text, dbInbound">
  381. <a-switch v-model="dbInbound.enable"
  382. @change="switchEnable(dbInbound.id,dbInbound.enable)"></a-switch>
  383. </template>
  384. <template slot="expiryTime" slot-scope="text, dbInbound">
  385. <a-popover v-if="dbInbound.expiryTime > 0" :overlay-class-name="themeSwitcher.currentTheme">
  386. <template slot="content" v-if="app.datepicker === 'gregorian'">
  387. [[ DateUtil.formatMillis(dbInbound.expiryTime) ]]
  388. </template>
  389. <template v-else slot="content">
  390. [[ DateUtil.convertToJalalian(moment(dbInbound.expiryTime)) ]]
  391. </template>
  392. <a-tag :style="{ minWidth: '50px' }"
  393. :color="ColorUtils.usageColor(new Date().getTime(), app.expireDiff, dbInbound._expiryTime)">
  394. [[ remainedDays(dbInbound._expiryTime) ]]
  395. </a-tag>
  396. </a-popover>
  397. <a-tag v-else color="purple" class="infinite-tag">
  398. <svg height="10px" width="14px" viewBox="0 0 640 512" fill="currentColor">
  399. <path
  400. d="M484.4 96C407 96 349.2 164.1 320 208.5C290.8 164.1 233 96 155.6 96C69.75 96 0 167.8 0 256s69.75 160 155.6 160C233.1 416 290.8 347.9 320 303.5C349.2 347.9 407 416 484.4 416C570.3 416 640 344.2 640 256S570.3 96 484.4 96zM155.6 368C96.25 368 48 317.8 48 256s48.25-112 107.6-112c67.75 0 120.5 82.25 137.1 112C276 285.8 223.4 368 155.6 368zM484.4 368c-67.75 0-120.5-82.25-137.1-112C364 226.2 416.6 144 484.4 144C543.8 144 592 194.2 592 256S543.8 368 484.4 368z"
  401. fill="currentColor"></path>
  402. </svg>
  403. </a-tag>
  404. </template>
  405. <template slot="info" slot-scope="text, dbInbound">
  406. <a-popover placement="bottomRight" :overlay-class-name="themeSwitcher.currentTheme"
  407. trigger="click">
  408. <template slot="content">
  409. <table cellpadding="2">
  410. <tr>
  411. <td>{{ i18n "pages.inbounds.protocol" }}</td>
  412. <td>
  413. <a-tag :style="{ margin: '0' }" color="purple">[[ dbInbound.protocol ]]</a-tag>
  414. <template
  415. v-if="dbInbound.isVMess || dbInbound.isVLess || dbInbound.isTrojan || dbInbound.isSS">
  416. <a-tag :style="{ margin: '0' }" color="blue">[[ dbInbound.toInbound().stream.network
  417. ]]</a-tag>
  418. <a-tag :style="{ margin: '0' }" v-if="dbInbound.toInbound().stream.isTls"
  419. color="green">tls</a-tag>
  420. <a-tag :style="{ margin: '0' }" v-if="dbInbound.toInbound().stream.isReality"
  421. color="green">reality</a-tag>
  422. </template>
  423. </td>
  424. </tr>
  425. <tr>
  426. <td>{{ i18n "pages.inbounds.port" }}</td>
  427. <td><a-tag>[[ dbInbound.port ]]</a-tag></td>
  428. </tr>
  429. <tr v-if="clientCount[dbInbound.id]">
  430. <td>{{ i18n "clients" }}</td>
  431. <td>
  432. <a-tag :style="{ margin: '0' }" color="blue">[[ clientCount[dbInbound.id].clients
  433. ]]</a-tag>
  434. <a-popover title='{{ i18n "disabled" }}'
  435. :overlay-class-name="themeSwitcher.currentTheme">
  436. <template slot="content">
  437. <div v-for="clientEmail in clientCount[dbInbound.id].deactive" :key="clientEmail"
  438. class="client-popup-item">
  439. <span>[[ clientEmail ]]</span>
  440. <a-tooltip :overlay-class-name="themeSwitcher.currentTheme">
  441. <template #title>
  442. [[ clientCount[dbInbound.id].comments.get(clientEmail) ]]
  443. </template>
  444. <a-icon type="message"
  445. v-if="clientCount[dbInbound.id].comments.get(clientEmail)"></a-icon>
  446. </a-tooltip>
  447. </div>
  448. </template>
  449. <a-tag :style="{ margin: '0', padding: '0 2px' }"
  450. v-if="clientCount[dbInbound.id].deactive.length">[[
  451. clientCount[dbInbound.id].deactive.length ]]</a-tag>
  452. </a-popover>
  453. <a-popover title='{{ i18n "depleted" }}'
  454. :overlay-class-name="themeSwitcher.currentTheme">
  455. <template slot="content">
  456. <div v-for="clientEmail in clientCount[dbInbound.id].depleted" :key="clientEmail"
  457. class="client-popup-item">
  458. <span>[[ clientEmail ]]</span>
  459. <a-tooltip :overlay-class-name="themeSwitcher.currentTheme">
  460. <template #title>
  461. [[ clientCount[dbInbound.id].comments.get(clientEmail) ]]
  462. </template>
  463. <a-icon type="message"
  464. v-if="clientCount[dbInbound.id].comments.get(clientEmail)"></a-icon>
  465. </a-tooltip>
  466. </div>
  467. </template>
  468. <a-tag :style="{ margin: '0', padding: '0 2px' }" color="red"
  469. v-if="clientCount[dbInbound.id].depleted.length">[[
  470. clientCount[dbInbound.id].depleted.length ]]</a-tag>
  471. </a-popover>
  472. <a-popover title='{{ i18n "depletingSoon" }}'
  473. :overlay-class-name="themeSwitcher.currentTheme">
  474. <template slot="content">
  475. <div v-for="clientEmail in clientCount[dbInbound.id].expiring" :key="clientEmail"
  476. class="client-popup-item">
  477. <span>[[ clientEmail ]]</span>
  478. <a-tooltip :overlay-class-name="themeSwitcher.currentTheme">
  479. <template #title>
  480. [[ clientCount[dbInbound.id].comments.get(clientEmail) ]]
  481. </template>
  482. <a-icon type="message"
  483. v-if="clientCount[dbInbound.id].comments.get(clientEmail)"></a-icon>
  484. </a-tooltip>
  485. </div>
  486. </template>
  487. <a-tag :style="{ margin: '0', padding: '0 2px' }" color="orange"
  488. v-if="clientCount[dbInbound.id].expiring.length">[[
  489. clientCount[dbInbound.id].expiring.length ]]</a-tag>
  490. </a-popover>
  491. <a-popover title='{{ i18n "online" }}' :overlay-class-name="themeSwitcher.currentTheme">
  492. <template slot="content">
  493. <div v-for="clientEmail in clientCount[dbInbound.id].online" :key="clientEmail"
  494. class="client-popup-item">
  495. <span>[[ clientEmail ]]</span>
  496. <a-tooltip :overlay-class-name="themeSwitcher.currentTheme">
  497. <template #title>
  498. [[ clientCount[dbInbound.id].comments.get(clientEmail) ]]
  499. </template>
  500. <a-icon type="message"
  501. v-if="clientCount[dbInbound.id].comments.get(clientEmail)"></a-icon>
  502. </a-tooltip>
  503. </div>
  504. </template>
  505. <a-tag :style="{ margin: '0', padding: '0 2px' }" color="green"
  506. v-if="clientCount[dbInbound.id].online.length">[[
  507. clientCount[dbInbound.id].online.length ]]</a-tag>
  508. </a-popover>
  509. </td>
  510. </tr>
  511. <tr>
  512. <td>{{ i18n "pages.inbounds.traffic" }}</td>
  513. <td>
  514. <a-popover :overlay-class-name="themeSwitcher.currentTheme">
  515. <template slot="content">
  516. <table cellpadding="2" width="100%">
  517. <tr>
  518. <td>↑[[ SizeFormatter.sizeFormat(dbInbound.up) ]]</td>
  519. <td>↓[[ SizeFormatter.sizeFormat(dbInbound.down) ]]</td>
  520. </tr>
  521. <tr
  522. v-if="dbInbound.total > 0 && dbInbound.up + dbInbound.down < dbInbound.total">
  523. <td>{{ i18n "remained" }}</td>
  524. <td>[[ SizeFormatter.sizeFormat(dbInbound.total - dbInbound.up - dbInbound.down)
  525. ]]</td>
  526. </tr>
  527. </table>
  528. </template>
  529. <a-tag
  530. :color="ColorUtils.usageColor(dbInbound.up + dbInbound.down, app.trafficDiff, dbInbound.total)">
  531. [[ SizeFormatter.sizeFormat(dbInbound.up + dbInbound.down) ]] /
  532. <template v-if="dbInbound.total > 0">
  533. [[ SizeFormatter.sizeFormat(dbInbound.total) ]]
  534. </template>
  535. <template v-else>
  536. <svg height="10px" width="14px" viewBox="0 0 640 512" fill="currentColor">
  537. <path
  538. d="M484.4 96C407 96 349.2 164.1 320 208.5C290.8 164.1 233 96 155.6 96C69.75 96 0 167.8 0 256s69.75 160 155.6 160C233.1 416 290.8 347.9 320 303.5C349.2 347.9 407 416 484.4 416C570.3 416 640 344.2 640 256S570.3 96 484.4 96zM155.6 368C96.25 368 48 317.8 48 256s48.25-112 107.6-112c67.75 0 120.5 82.25 137.1 112C276 285.8 223.4 368 155.6 368zM484.4 368c-67.75 0-120.5-82.25-137.1-112C364 226.2 416.6 144 484.4 144C543.8 144 592 194.2 592 256S543.8 368 484.4 368z"
  539. fill="currentColor"></path>
  540. </svg>
  541. </template>
  542. </a-tag>
  543. </a-popover>
  544. </td>
  545. </tr>
  546. <tr>
  547. <td>{{ i18n "pages.inbounds.expireDate" }}</td>
  548. <td>
  549. <a-tag :style="{ minWidth: '50px', textAlign: 'center' }"
  550. v-if="dbInbound.expiryTime > 0" :color="dbInbound.isExpiry? 'red': 'blue'">
  551. <template v-if="app.datepicker === 'gregorian'">
  552. [[ DateUtil.formatMillis(dbInbound.expiryTime) ]]
  553. </template>
  554. <template v-else>
  555. [[ DateUtil.convertToJalalian(moment(dbInbound.expiryTime)) ]]
  556. </template>
  557. </a-tag>
  558. <a-tag v-else :style="{ textAlign: 'center' }" color="purple" class="infinite-tag">
  559. <svg height="10px" width="14px" viewBox="0 0 640 512" fill="currentColor">
  560. <path
  561. d="M484.4 96C407 96 349.2 164.1 320 208.5C290.8 164.1 233 96 155.6 96C69.75 96 0 167.8 0 256s69.75 160 155.6 160C233.1 416 290.8 347.9 320 303.5C349.2 347.9 407 416 484.4 416C570.3 416 640 344.2 640 256S570.3 96 484.4 96zM155.6 368C96.25 368 48 317.8 48 256s48.25-112 107.6-112c67.75 0 120.5 82.25 137.1 112C276 285.8 223.4 368 155.6 368zM484.4 368c-67.75 0-120.5-82.25-137.1-112C364 226.2 416.6 144 484.4 144C543.8 144 592 194.2 592 256S543.8 368 484.4 368z"
  562. fill="currentColor"></path>
  563. </svg>
  564. </a-tag>
  565. </td>
  566. </tr>
  567. <tr>
  568. <td>{{ i18n "pages.inbounds.periodicTrafficResetTitle" }}</td>
  569. <td>
  570. <a-tag color="blue">[[ dbInbound.trafficReset ]]</a-tag>
  571. </td>
  572. </tr>
  573. </table>
  574. </template>
  575. <a-badge>
  576. <a-icon v-if="!dbInbound.enable" slot="count" type="pause-circle"
  577. :style="{ color: themeSwitcher.isDarkTheme ? '#2c3950' : '#bcbcbc' }"></a-icon>
  578. <a-button shape="round" size="small" :style="{ fontSize: '14px', padding: '0 10px' }">
  579. <a-icon type="info"></a-icon>
  580. </a-button>
  581. </a-badge>
  582. </a-popover>
  583. </template>
  584. <template slot="expandedRowRender" slot-scope="record">
  585. <a-table :row-key="client => client.id" :columns="isMobile ? innerMobileColumns : innerColumns"
  586. :data-source="getInboundClients(record)" :pagination=pagination(getInboundClients(record))
  587. :style="{ margin: `-10px ${isMobile ? '2px' : '22px'} -11px` }">
  588. {{template "component/aClientTable"}}
  589. </a-table>
  590. </template>
  591. </a-table>
  592. </a-space>
  593. </a-card>
  594. </a-col>
  595. </a-row>
  596. </transition>
  597. </a-spin>
  598. </a-layout-content>
  599. </a-layout>
  600. </a-layout>
  601. {{template "page/body_scripts" .}}
  602. <script src="{{ .base_path }}assets/qrcode/qrious2.min.js?{{ .cur_ver }}"></script>
  603. <script src="{{ .base_path }}assets/uri/URI.min.js?{{ .cur_ver }}"></script>
  604. <script src="{{ .base_path }}assets/js/model/inbound.js?{{ .cur_ver }}"></script>
  605. <script src="{{ .base_path }}assets/js/model/dbinbound.js?{{ .cur_ver }}"></script>
  606. {{template "component/aSidebar" .}}
  607. {{template "component/aThemeSwitch" .}}
  608. {{template "component/aCustomStatistic" .}}
  609. {{template "component/aPersianDatepicker" .}}
  610. {{template "modals/inboundModal"}}
  611. {{template "modals/promptModal"}}
  612. {{template "modals/qrcodeModal"}}
  613. {{template "modals/textModal"}}
  614. {{template "modals/inboundInfoModal"}}
  615. {{template "modals/clientsModal"}}
  616. {{template "modals/clientsBulkModal"}}
  617. <script>
  618. const columns = [{
  619. title: "ID",
  620. align: 'right',
  621. dataIndex: "id",
  622. width: 30,
  623. responsive: ["xs"],
  624. }, {
  625. title: '{{ i18n "pages.inbounds.operate" }}',
  626. align: 'center',
  627. width: 30,
  628. scopedSlots: { customRender: 'action' },
  629. }, {
  630. title: '{{ i18n "pages.inbounds.enable" }}',
  631. align: 'center',
  632. width: 35,
  633. scopedSlots: { customRender: 'enable' },
  634. }, {
  635. title: '{{ i18n "pages.inbounds.remark" }}',
  636. align: 'center',
  637. width: 60,
  638. dataIndex: "remark",
  639. }, {
  640. title: '{{ i18n "pages.inbounds.port" }}',
  641. align: 'center',
  642. dataIndex: "port",
  643. width: 40,
  644. }, {
  645. title: '{{ i18n "pages.inbounds.protocol" }}',
  646. align: 'left',
  647. width: 70,
  648. scopedSlots: { customRender: 'protocol' },
  649. }, {
  650. title: '{{ i18n "clients" }}',
  651. align: 'left',
  652. width: 50,
  653. scopedSlots: { customRender: 'clients' },
  654. }, {
  655. title: '{{ i18n "pages.inbounds.traffic" }}',
  656. align: 'center',
  657. width: 90,
  658. scopedSlots: { customRender: 'traffic' },
  659. }, {
  660. title: '{{ i18n "pages.inbounds.allTimeTraffic" }}',
  661. align: 'center',
  662. width: 70,
  663. scopedSlots: { customRender: 'allTimeInbound' },
  664. }, {
  665. title: '{{ i18n "pages.inbounds.expireDate" }}',
  666. align: 'center',
  667. width: 40,
  668. scopedSlots: { customRender: 'expiryTime' },
  669. }];
  670. const mobileColumns = [{
  671. title: "ID",
  672. align: 'right',
  673. dataIndex: "id",
  674. width: 10,
  675. responsive: ["s"],
  676. }, {
  677. title: '{{ i18n "pages.inbounds.operate" }}',
  678. align: 'center',
  679. width: 25,
  680. scopedSlots: { customRender: 'action' },
  681. }, {
  682. title: '{{ i18n "pages.inbounds.remark" }}',
  683. align: 'left',
  684. width: 70,
  685. dataIndex: "remark",
  686. }, {
  687. title: '{{ i18n "pages.inbounds.info" }}',
  688. align: 'center',
  689. width: 10,
  690. scopedSlots: { customRender: 'info' },
  691. }];
  692. const innerColumns = [
  693. { title: '{{ i18n "pages.inbounds.operate" }}', width: 65, scopedSlots: { customRender: 'actions' } },
  694. { title: '{{ i18n "pages.inbounds.enable" }}', width: 35, scopedSlots: { customRender: 'enable' } },
  695. { title: '{{ i18n "online" }}', width: 32, scopedSlots: { customRender: 'online' } },
  696. { title: '{{ i18n "pages.inbounds.client" }}', width: 80, scopedSlots: { customRender: 'client' } },
  697. { title: '{{ i18n "pages.inbounds.traffic" }}', width: 80, align: 'center', scopedSlots: { customRender: 'traffic' } },
  698. { title: '{{ i18n "pages.inbounds.allTimeTraffic" }}', width: 80, align: 'center', scopedSlots: { customRender: 'allTime' } },
  699. { title: '{{ i18n "pages.inbounds.expireDate" }}', width: 80, align: 'center', scopedSlots: { customRender: 'expiryTime' } },
  700. ];
  701. const innerMobileColumns = [
  702. { title: '{{ i18n "pages.inbounds.operate" }}', width: 10, align: 'center', scopedSlots: { customRender: 'actionMenu' } },
  703. { title: '{{ i18n "pages.inbounds.client" }}', width: 90, align: 'left', scopedSlots: { customRender: 'client' } },
  704. { title: '{{ i18n "pages.inbounds.info" }}', width: 10, align: 'center', scopedSlots: { customRender: 'info' } },
  705. ];
  706. const app = new Vue({
  707. delimiters: ['[[', ']]'],
  708. el: '#app',
  709. mixins: [MediaQueryMixin],
  710. data: {
  711. themeSwitcher,
  712. persianDatepicker,
  713. loadingStates: {
  714. fetched: false,
  715. spinning: false
  716. },
  717. inbounds: [],
  718. dbInbounds: [],
  719. searchKey: '',
  720. enableFilter: false,
  721. filterBy: '',
  722. searchedInbounds: [],
  723. expireDiff: 0,
  724. trafficDiff: 0,
  725. defaultCert: '',
  726. defaultKey: '',
  727. clientCount: [],
  728. onlineClients: [],
  729. lastOnlineMap: {},
  730. isRefreshEnabled: localStorage.getItem("isRefreshEnabled") === "true" ? true : false,
  731. refreshing: false,
  732. refreshInterval: Number(localStorage.getItem("refreshInterval")) || 5000,
  733. subSettings: {
  734. enable: false,
  735. subTitle: '',
  736. subURI: '',
  737. subJsonURI: '',
  738. },
  739. remarkModel: '-ieo',
  740. datepicker: 'gregorian',
  741. tgBotEnable: false,
  742. showAlert: false,
  743. ipLimitEnable: false,
  744. pageSize: 50,
  745. },
  746. methods: {
  747. loading(spinning = true) {
  748. this.loadingStates.spinning = spinning;
  749. },
  750. async getDBInbounds() {
  751. this.refreshing = true;
  752. const msg = await HttpUtil.get('/panel/api/inbounds/list');
  753. if (!msg.success) {
  754. this.refreshing = false;
  755. return;
  756. }
  757. await this.getLastOnlineMap();
  758. await this.getOnlineUsers();
  759. this.setInbounds(msg.obj);
  760. setTimeout(() => {
  761. this.refreshing = false;
  762. }, 500);
  763. },
  764. async getOnlineUsers() {
  765. const msg = await HttpUtil.post('/panel/api/inbounds/onlines');
  766. if (!msg.success) {
  767. return;
  768. }
  769. this.onlineClients = msg.obj != null ? msg.obj : [];
  770. },
  771. async getLastOnlineMap() {
  772. const msg = await HttpUtil.post('/panel/api/inbounds/lastOnline');
  773. if (!msg.success || !msg.obj) return;
  774. this.lastOnlineMap = msg.obj || {}
  775. },
  776. async getDefaultSettings() {
  777. const msg = await HttpUtil.post('/panel/setting/defaultSettings');
  778. if (!msg.success) {
  779. return;
  780. }
  781. with (msg.obj) {
  782. this.expireDiff = expireDiff * 86400000;
  783. this.trafficDiff = trafficDiff * 1073741824;
  784. this.defaultCert = defaultCert;
  785. this.defaultKey = defaultKey;
  786. this.tgBotEnable = tgBotEnable;
  787. this.subSettings = {
  788. enable: subEnable,
  789. subTitle: subTitle,
  790. subURI: subURI,
  791. subJsonURI: subJsonURI
  792. };
  793. this.pageSize = pageSize;
  794. this.remarkModel = remarkModel;
  795. this.datepicker = datepicker;
  796. this.ipLimitEnable = ipLimitEnable;
  797. }
  798. },
  799. setInbounds(dbInbounds) {
  800. this.inbounds.splice(0);
  801. this.dbInbounds.splice(0);
  802. this.clientCount.splice(0);
  803. for (const inbound of dbInbounds) {
  804. const dbInbound = new DBInbound(inbound);
  805. to_inbound = dbInbound.toInbound()
  806. this.inbounds.push(to_inbound);
  807. this.dbInbounds.push(dbInbound);
  808. if ([Protocols.VMESS, Protocols.VLESS, Protocols.TROJAN, Protocols.SHADOWSOCKS].includes(inbound.protocol)) {
  809. if (dbInbound.isSS && (!to_inbound.isSSMultiUser)) {
  810. continue;
  811. }
  812. this.clientCount[inbound.id] = this.getClientCounts(inbound, to_inbound);
  813. }
  814. }
  815. if (!this.loadingStates.fetched) {
  816. this.loadingStates.fetched = true
  817. }
  818. if (this.enableFilter) {
  819. this.filterInbounds();
  820. } else {
  821. this.searchInbounds(this.searchKey);
  822. }
  823. },
  824. getClientCounts(dbInbound, inbound) {
  825. let clientCount = 0, active = [], deactive = [], depleted = [], expiring = [], online = [], comments = new Map();
  826. clients = inbound.clients;
  827. clientStats = dbInbound.clientStats
  828. now = new Date().getTime()
  829. if (clients) {
  830. clientCount = clients.length;
  831. if (dbInbound.enable) {
  832. clients.forEach(client => {
  833. if (client.comment) {
  834. comments.set(client.email, client.comment)
  835. }
  836. if (client.enable) {
  837. active.push(client.email);
  838. if (this.isClientOnline(client.email)) online.push(client.email);
  839. } else {
  840. deactive.push(client.email);
  841. }
  842. });
  843. clientStats.forEach(stats => {
  844. const exhausted = stats.total > 0 && (stats.up + stats.down) >= stats.total;
  845. const expired = stats.expiryTime > 0 && stats.expiryTime <= now;
  846. if (expired || exhausted) {
  847. depleted.push(stats.email);
  848. } else {
  849. const expiringSoon = (stats.expiryTime > 0 && (stats.expiryTime - now < this.expireDiff)) ||
  850. (stats.total > 0 && (stats.total - (stats.up + stats.down) < this.trafficDiff));
  851. if (expiringSoon) expiring.push(stats.email);
  852. }
  853. });
  854. } else {
  855. clients.forEach(client => {
  856. deactive.push(client.email);
  857. });
  858. }
  859. }
  860. return {
  861. clients: clientCount,
  862. active: active,
  863. deactive: deactive,
  864. depleted: depleted,
  865. expiring: expiring,
  866. online: online,
  867. comments: comments,
  868. };
  869. },
  870. searchInbounds(key) {
  871. if (ObjectUtil.isEmpty(key)) {
  872. this.searchedInbounds = this.dbInbounds.slice();
  873. } else {
  874. this.searchedInbounds.splice(0, this.searchedInbounds.length);
  875. this.dbInbounds.forEach(inbound => {
  876. if (ObjectUtil.deepSearch(inbound, key)) {
  877. const newInbound = new DBInbound(inbound);
  878. const inboundSettings = JSON.parse(inbound.settings);
  879. if (inboundSettings.hasOwnProperty('clients')) {
  880. const searchedSettings = { "clients": [] };
  881. inboundSettings.clients.forEach(client => {
  882. if (ObjectUtil.deepSearch(client, key)) {
  883. searchedSettings.clients.push(client);
  884. }
  885. });
  886. newInbound.settings = Inbound.Settings.fromJson(inbound.protocol, searchedSettings);
  887. }
  888. this.searchedInbounds.push(newInbound);
  889. }
  890. });
  891. }
  892. },
  893. filterInbounds() {
  894. if (ObjectUtil.isEmpty(this.filterBy)) {
  895. this.searchedInbounds = this.dbInbounds.slice();
  896. } else {
  897. this.searchedInbounds.splice(0, this.searchedInbounds.length);
  898. this.dbInbounds.forEach(inbound => {
  899. const newInbound = new DBInbound(inbound);
  900. const inboundSettings = JSON.parse(inbound.settings);
  901. if (this.clientCount[inbound.id] && this.clientCount[inbound.id].hasOwnProperty(this.filterBy)) {
  902. const list = this.clientCount[inbound.id][this.filterBy];
  903. if (list.length > 0) {
  904. const filteredSettings = { "clients": [] };
  905. if (inboundSettings.clients) {
  906. inboundSettings.clients.forEach(client => {
  907. if (list.includes(client.email)) {
  908. filteredSettings.clients.push(client);
  909. }
  910. });
  911. }
  912. newInbound.settings = Inbound.Settings.fromJson(inbound.protocol, filteredSettings);
  913. this.searchedInbounds.push(newInbound);
  914. }
  915. }
  916. });
  917. }
  918. },
  919. toggleFilter() {
  920. if (this.enableFilter) {
  921. this.searchKey = '';
  922. } else {
  923. this.filterBy = '';
  924. this.searchedInbounds = this.dbInbounds.slice();
  925. }
  926. },
  927. generalActions(action) {
  928. switch (action.key) {
  929. case "import":
  930. this.importInbound();
  931. break;
  932. case "export":
  933. this.exportAllLinks();
  934. break;
  935. case "subs":
  936. this.exportAllSubs();
  937. break;
  938. case "resetInbounds":
  939. this.resetAllTraffic();
  940. break;
  941. case "resetClients":
  942. this.resetAllClientTraffics(-1);
  943. break;
  944. case "delDepletedClients":
  945. this.delDepletedClients(-1)
  946. break;
  947. }
  948. },
  949. clickAction(action, dbInbound) {
  950. switch (action.key) {
  951. case "qrcode":
  952. this.showQrcode(dbInbound.id);
  953. break;
  954. case "showInfo":
  955. this.showInfo(dbInbound.id);
  956. break;
  957. case "edit":
  958. this.openEditInbound(dbInbound.id);
  959. break;
  960. case "addClient":
  961. this.openAddClient(dbInbound.id)
  962. break;
  963. case "addBulkClient":
  964. this.openAddBulkClient(dbInbound.id)
  965. break;
  966. case "export":
  967. this.inboundLinks(dbInbound.id);
  968. break;
  969. case "subs":
  970. this.exportSubs(dbInbound.id);
  971. break;
  972. case "clipboard":
  973. this.copy(dbInbound.id);
  974. break;
  975. case "resetTraffic":
  976. this.resetTraffic(dbInbound.id);
  977. break;
  978. case "resetClients":
  979. this.resetAllClientTraffics(dbInbound.id);
  980. break;
  981. case "clone":
  982. this.openCloneInbound(dbInbound);
  983. break;
  984. case "delete":
  985. this.delInbound(dbInbound.id);
  986. break;
  987. case "delDepletedClients":
  988. this.delDepletedClients(dbInbound.id)
  989. break;
  990. }
  991. },
  992. openCloneInbound(dbInbound) {
  993. this.$confirm({
  994. title: '{{ i18n "pages.inbounds.cloneInbound"}} \"' + dbInbound.remark + '\"',
  995. content: '{{ i18n "pages.inbounds.cloneInboundContent"}}',
  996. okText: '{{ i18n "pages.inbounds.cloneInboundOk"}}',
  997. class: themeSwitcher.currentTheme,
  998. cancelText: '{{ i18n "cancel" }}',
  999. onOk: () => {
  1000. const baseInbound = dbInbound.toInbound();
  1001. dbInbound.up = 0;
  1002. dbInbound.down = 0;
  1003. this.cloneInbound(baseInbound, dbInbound);
  1004. },
  1005. });
  1006. },
  1007. async cloneInbound(baseInbound, dbInbound) {
  1008. const data = {
  1009. up: dbInbound.up,
  1010. down: dbInbound.down,
  1011. total: dbInbound.total,
  1012. remark: dbInbound.remark + " - Cloned",
  1013. enable: dbInbound.enable,
  1014. expiryTime: dbInbound.expiryTime,
  1015. trafficReset: dbInbound.trafficReset,
  1016. lastTrafficResetTime: dbInbound.lastTrafficResetTime,
  1017. listen: '',
  1018. port: RandomUtil.randomInteger(10000, 60000),
  1019. protocol: baseInbound.protocol,
  1020. settings: Inbound.Settings.getSettings(baseInbound.protocol).toString(),
  1021. streamSettings: baseInbound.stream.toString(),
  1022. sniffing: baseInbound.sniffing.toString(),
  1023. };
  1024. await this.submit('/panel/api/inbounds/add', data, inModal);
  1025. },
  1026. openAddInbound() {
  1027. inModal.show({
  1028. title: '{{ i18n "pages.inbounds.addInbound"}}',
  1029. okText: '{{ i18n "create"}}',
  1030. cancelText: '{{ i18n "close" }}',
  1031. confirm: async (inbound, dbInbound) => {
  1032. await this.addInbound(inbound, dbInbound, inModal);
  1033. },
  1034. isEdit: false
  1035. });
  1036. },
  1037. openEditInbound(dbInboundId) {
  1038. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1039. const inbound = dbInbound.toInbound();
  1040. inModal.show({
  1041. title: '{{ i18n "pages.inbounds.modifyInbound"}}',
  1042. okText: '{{ i18n "update"}}',
  1043. cancelText: '{{ i18n "close" }}',
  1044. inbound: inbound,
  1045. dbInbound: dbInbound,
  1046. confirm: async (inbound, dbInbound) => {
  1047. await this.updateInbound(inbound, dbInbound);
  1048. },
  1049. isEdit: true
  1050. });
  1051. },
  1052. async addInbound(inbound, dbInbound) {
  1053. const data = {
  1054. up: dbInbound.up,
  1055. down: dbInbound.down,
  1056. total: dbInbound.total,
  1057. remark: dbInbound.remark,
  1058. enable: dbInbound.enable,
  1059. expiryTime: dbInbound.expiryTime,
  1060. trafficReset: dbInbound.trafficReset,
  1061. lastTrafficResetTime: dbInbound.lastTrafficResetTime,
  1062. listen: inbound.listen,
  1063. port: inbound.port,
  1064. protocol: inbound.protocol,
  1065. settings: inbound.settings.toString(),
  1066. };
  1067. if (inbound.canEnableStream()) {
  1068. data.streamSettings = inbound.stream.toString();
  1069. } else if (inbound.stream?.sockopt) {
  1070. data.streamSettings = JSON.stringify({ sockopt: inbound.stream.sockopt.toJson() }, null, 2);
  1071. }
  1072. data.sniffing = inbound.sniffing.toString();
  1073. await this.submit('/panel/api/inbounds/add', data, inModal);
  1074. },
  1075. async updateInbound(inbound, dbInbound) {
  1076. const data = {
  1077. up: dbInbound.up,
  1078. down: dbInbound.down,
  1079. total: dbInbound.total,
  1080. remark: dbInbound.remark,
  1081. enable: dbInbound.enable,
  1082. expiryTime: dbInbound.expiryTime,
  1083. trafficReset: dbInbound.trafficReset,
  1084. lastTrafficResetTime: dbInbound.lastTrafficResetTime,
  1085. listen: inbound.listen,
  1086. port: inbound.port,
  1087. protocol: inbound.protocol,
  1088. settings: inbound.settings.toString(),
  1089. };
  1090. if (inbound.canEnableStream()) {
  1091. data.streamSettings = inbound.stream.toString();
  1092. } else if (inbound.stream?.sockopt) {
  1093. data.streamSettings = JSON.stringify({ sockopt: inbound.stream.sockopt.toJson() }, null, 2);
  1094. }
  1095. data.sniffing = inbound.sniffing.toString();
  1096. await this.submit(`/panel/api/inbounds/update/${dbInbound.id}`, data, inModal);
  1097. },
  1098. openAddClient(dbInboundId) {
  1099. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1100. clientModal.show({
  1101. title: '{{ i18n "pages.client.add"}}',
  1102. okText: '{{ i18n "pages.client.submitAdd"}}',
  1103. dbInbound: dbInbound,
  1104. confirm: async (clients, dbInboundId) => {
  1105. await this.addClient(clients, dbInboundId, clientModal);
  1106. },
  1107. isEdit: false
  1108. });
  1109. },
  1110. openAddBulkClient(dbInboundId) {
  1111. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1112. clientsBulkModal.show({
  1113. title: '{{ i18n "pages.client.bulk"}} ' + dbInbound.remark,
  1114. okText: '{{ i18n "pages.client.bulk"}}',
  1115. dbInbound: dbInbound,
  1116. confirm: async (clients, dbInboundId) => {
  1117. await this.addClient(clients, dbInboundId, clientsBulkModal);
  1118. },
  1119. });
  1120. },
  1121. openEditClient(dbInboundId, client) {
  1122. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1123. clients = this.getInboundClients(dbInbound);
  1124. index = this.findIndexOfClient(dbInbound.protocol, clients, client);
  1125. clientModal.show({
  1126. title: '{{ i18n "pages.client.edit"}}',
  1127. okText: '{{ i18n "pages.client.submitEdit"}}',
  1128. dbInbound: dbInbound,
  1129. index: index,
  1130. confirm: async (client, dbInboundId, clientId) => {
  1131. clientModal.loading();
  1132. await this.updateClient(client, dbInboundId, clientId);
  1133. clientModal.close();
  1134. },
  1135. isEdit: true
  1136. });
  1137. },
  1138. findIndexOfClient(protocol, clients, client) {
  1139. switch (protocol) {
  1140. case Protocols.TROJAN:
  1141. case Protocols.SHADOWSOCKS:
  1142. return clients.findIndex(item => item.password === client.password && item.email === client.email);
  1143. default: return clients.findIndex(item => item.id === client.id && item.email === client.email);
  1144. }
  1145. },
  1146. async addClient(clients, dbInboundId, modal) {
  1147. const data = {
  1148. id: dbInboundId,
  1149. settings: '{"clients": [' + clients.toString() + ']}',
  1150. };
  1151. await this.submit(`/panel/api/inbounds/addClient`, data, modal);
  1152. },
  1153. async updateClient(client, dbInboundId, clientId) {
  1154. const data = {
  1155. id: dbInboundId,
  1156. settings: '{"clients": [' + client.toString() + ']}',
  1157. };
  1158. await this.submit(`/panel/api/inbounds/updateClient/${clientId}`, data, clientModal);
  1159. },
  1160. resetTraffic(dbInboundId) {
  1161. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1162. this.$confirm({
  1163. title: '{{ i18n "pages.inbounds.resetTraffic"}}' + ' #' + dbInboundId,
  1164. content: '{{ i18n "pages.inbounds.resetTrafficContent"}}',
  1165. class: themeSwitcher.currentTheme,
  1166. okText: '{{ i18n "reset"}}',
  1167. cancelText: '{{ i18n "cancel"}}',
  1168. onOk: () => {
  1169. const inbound = dbInbound.toInbound();
  1170. dbInbound.up = 0;
  1171. dbInbound.down = 0;
  1172. this.updateInbound(inbound, dbInbound);
  1173. },
  1174. });
  1175. },
  1176. delInbound(dbInboundId) {
  1177. this.$confirm({
  1178. title: '{{ i18n "pages.inbounds.deleteInbound"}}' + ' #' + dbInboundId,
  1179. content: '{{ i18n "pages.inbounds.deleteInboundContent"}}',
  1180. class: themeSwitcher.currentTheme,
  1181. okText: '{{ i18n "delete"}}',
  1182. cancelText: '{{ i18n "cancel"}}',
  1183. onOk: () => this.submit('/panel/api/inbounds/del/' + dbInboundId),
  1184. });
  1185. },
  1186. delClient(dbInboundId, client, confirmation = true) {
  1187. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1188. clientId = this.getClientId(dbInbound.protocol, client);
  1189. if (confirmation) {
  1190. this.$confirm({
  1191. title: '{{ i18n "pages.inbounds.deleteClient"}}' + ' ' + client.email,
  1192. content: '{{ i18n "pages.inbounds.deleteClientContent"}}',
  1193. class: themeSwitcher.currentTheme,
  1194. okText: '{{ i18n "delete"}}',
  1195. cancelText: '{{ i18n "cancel"}}',
  1196. onOk: () => this.submit(`/panel/api/inbounds/${dbInboundId}/delClient/${clientId}`),
  1197. });
  1198. } else {
  1199. this.submit(`/panel/api/inbounds/${dbInboundId}/delClient/${clientId}`);
  1200. }
  1201. },
  1202. getSubGroupClients(dbInbounds, currentClient) {
  1203. const response = {
  1204. inbounds: [],
  1205. clients: [],
  1206. editIds: []
  1207. }
  1208. if (dbInbounds && dbInbounds.length > 0 && currentClient) {
  1209. dbInbounds.forEach((dbInboundItem) => {
  1210. const dbInbound = new DBInbound(dbInboundItem);
  1211. if (dbInbound) {
  1212. const inbound = dbInbound.toInbound();
  1213. if (inbound) {
  1214. const clients = inbound.clients;
  1215. if (clients.length > 0) {
  1216. clients.forEach((client) => {
  1217. if (client['subId'] === currentClient['subId']) {
  1218. client['inboundId'] = dbInboundItem.id
  1219. client['clientId'] = this.getClientId(dbInbound.protocol, client)
  1220. response.inbounds.push(dbInboundItem.id)
  1221. response.clients.push(client)
  1222. response.editIds.push(client['clientId'])
  1223. }
  1224. })
  1225. }
  1226. }
  1227. }
  1228. })
  1229. }
  1230. return response;
  1231. },
  1232. getClientId(protocol, client) {
  1233. switch (protocol) {
  1234. case Protocols.TROJAN: return client.password;
  1235. case Protocols.SHADOWSOCKS: return client.email;
  1236. default: return client.id;
  1237. }
  1238. },
  1239. checkFallback(dbInbound) {
  1240. newDbInbound = new DBInbound(dbInbound);
  1241. if (dbInbound.listen.startsWith("@")) {
  1242. rootInbound = this.inbounds.find((i) =>
  1243. i.isTcp &&
  1244. ['trojan', 'vless'].includes(i.protocol) &&
  1245. i.settings.fallbacks.find(f => f.dest === dbInbound.listen)
  1246. );
  1247. if (rootInbound) {
  1248. newDbInbound.listen = rootInbound.listen;
  1249. newDbInbound.port = rootInbound.port;
  1250. newInbound = newDbInbound.toInbound();
  1251. newInbound.stream.security = rootInbound.stream.security;
  1252. newInbound.stream.tls = rootInbound.stream.tls;
  1253. newInbound.stream.externalProxy = rootInbound.stream.externalProxy;
  1254. newDbInbound.streamSettings = newInbound.stream.toString();
  1255. }
  1256. }
  1257. return newDbInbound;
  1258. },
  1259. showQrcode(dbInboundId, client) {
  1260. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1261. newDbInbound = this.checkFallback(dbInbound);
  1262. qrModal.show('{{ i18n "qrCode"}}', newDbInbound, client);
  1263. },
  1264. showInfo(dbInboundId, client) {
  1265. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1266. index = 0;
  1267. if (dbInbound.isMultiUser()) {
  1268. inbound = dbInbound.toInbound();
  1269. clients = inbound.clients;
  1270. index = this.findIndexOfClient(dbInbound.protocol, clients, client);
  1271. }
  1272. newDbInbound = this.checkFallback(dbInbound);
  1273. infoModal.show(newDbInbound, index);
  1274. },
  1275. switchEnable(dbInboundId, state) {
  1276. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1277. dbInbound.enable = state;
  1278. this.submit(`/panel/api/inbounds/update/${dbInboundId}`, dbInbound);
  1279. },
  1280. async switchEnableClient(dbInboundId, client) {
  1281. this.loading()
  1282. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1283. inbound = dbInbound.toInbound();
  1284. clients = inbound.clients;
  1285. index = this.findIndexOfClient(dbInbound.protocol, clients, client);
  1286. clients[index].enable = !clients[index].enable;
  1287. clientId = this.getClientId(dbInbound.protocol, clients[index]);
  1288. await this.updateClient(clients[index], dbInboundId, clientId);
  1289. this.loading(false);
  1290. },
  1291. async submit(url, data, modal) {
  1292. const msg = await HttpUtil.postWithModal(url, data, modal);
  1293. if (msg.success) {
  1294. await this.getDBInbounds();
  1295. }
  1296. },
  1297. getInboundClients(dbInbound) {
  1298. return dbInbound.toInbound().clients;
  1299. },
  1300. resetClientTraffic(client, dbInboundId, confirmation = true) {
  1301. if (confirmation) {
  1302. this.$confirm({
  1303. title: '{{ i18n "pages.inbounds.resetTraffic"}}' + ' ' + client.email,
  1304. content: '{{ i18n "pages.inbounds.resetTrafficContent"}}',
  1305. class: themeSwitcher.currentTheme,
  1306. okText: '{{ i18n "reset"}}',
  1307. cancelText: '{{ i18n "cancel"}}',
  1308. onOk: () => this.submit('/panel/api/inbounds/' + dbInboundId + '/resetClientTraffic/' + client.email),
  1309. })
  1310. } else {
  1311. this.submit('/panel/api/inbounds/' + dbInboundId + '/resetClientTraffic/' + client.email);
  1312. }
  1313. },
  1314. resetAllTraffic() {
  1315. this.$confirm({
  1316. title: '{{ i18n "pages.inbounds.resetAllTrafficTitle"}}',
  1317. content: '{{ i18n "pages.inbounds.resetAllTrafficContent"}}',
  1318. class: themeSwitcher.currentTheme,
  1319. okText: '{{ i18n "reset"}}',
  1320. cancelText: '{{ i18n "cancel"}}',
  1321. onOk: () => this.submit('/panel/api/inbounds/resetAllTraffics'),
  1322. });
  1323. },
  1324. resetAllClientTraffics(dbInboundId) {
  1325. this.$confirm({
  1326. title: dbInboundId > 0 ? '{{ i18n "pages.inbounds.resetInboundClientTrafficTitle"}}' : '{{ i18n "pages.inbounds.resetAllClientTrafficTitle"}}',
  1327. content: dbInboundId > 0 ? '{{ i18n "pages.inbounds.resetInboundClientTrafficContent"}}' : '{{ i18n "pages.inbounds.resetAllClientTrafficContent"}}',
  1328. class: themeSwitcher.currentTheme,
  1329. okText: '{{ i18n "reset"}}',
  1330. cancelText: '{{ i18n "cancel"}}',
  1331. onOk: () => this.submit('/panel/api/inbounds/resetAllClientTraffics/' + dbInboundId),
  1332. })
  1333. },
  1334. delDepletedClients(dbInboundId) {
  1335. this.$confirm({
  1336. title: '{{ i18n "pages.inbounds.delDepletedClientsTitle"}}',
  1337. content: '{{ i18n "pages.inbounds.delDepletedClientsContent"}}',
  1338. class: themeSwitcher.currentTheme,
  1339. okText: '{{ i18n "delete"}}',
  1340. cancelText: '{{ i18n "cancel"}}',
  1341. onOk: () => this.submit('/panel/api/inbounds/delDepletedClients/' + dbInboundId),
  1342. })
  1343. },
  1344. isExpiry(dbInbound, index) {
  1345. return dbInbound.toInbound().isExpiry(index);
  1346. },
  1347. getUpStats(dbInbound, email) {
  1348. if (email.length == 0) return 0;
  1349. clientStats = dbInbound.clientStats.find(stats => stats.email === email);
  1350. return clientStats ? clientStats.up : 0;
  1351. },
  1352. getDownStats(dbInbound, email) {
  1353. if (email.length == 0) return 0;
  1354. clientStats = dbInbound.clientStats.find(stats => stats.email === email);
  1355. return clientStats ? clientStats.down : 0;
  1356. },
  1357. getSumStats(dbInbound, email) {
  1358. if (email.length == 0) return 0;
  1359. clientStats = dbInbound.clientStats.find(stats => stats.email === email);
  1360. return clientStats ? clientStats.up + clientStats.down : 0;
  1361. },
  1362. getAllTimeClient(dbInbound, email) {
  1363. if (email.length == 0) return 0;
  1364. clientStats = dbInbound.clientStats.find(stats => stats.email === email);
  1365. if (!clientStats) return 0;
  1366. return clientStats.allTime || (clientStats.up + clientStats.down);
  1367. },
  1368. getRemStats(dbInbound, email) {
  1369. if (email.length == 0) return 0;
  1370. clientStats = dbInbound.clientStats.find(stats => stats.email === email);
  1371. if (!clientStats) return 0;
  1372. remained = clientStats.total - (clientStats.up + clientStats.down);
  1373. return remained > 0 ? remained : 0;
  1374. },
  1375. clientStatsColor(dbInbound, email) {
  1376. if (email.length == 0) return ColorUtils.clientUsageColor();
  1377. clientStats = dbInbound.clientStats.find(stats => stats.email === email);
  1378. return ColorUtils.clientUsageColor(clientStats, app.trafficDiff)
  1379. },
  1380. statsProgress(dbInbound, email) {
  1381. if (email.length == 0) return 100;
  1382. clientStats = dbInbound.clientStats.find(stats => stats.email === email);
  1383. if (!clientStats) return 0;
  1384. if (clientStats.total == 0) return 100;
  1385. return 100 * (clientStats.down + clientStats.up) / clientStats.total;
  1386. },
  1387. expireProgress(expTime, reset) {
  1388. now = new Date().getTime();
  1389. remainedSeconds = expTime < 0 ? -expTime / 1000 : (expTime - now) / 1000;
  1390. resetSeconds = reset * 86400;
  1391. if (remainedSeconds >= resetSeconds) return 0;
  1392. return 100 * (1 - (remainedSeconds / resetSeconds));
  1393. },
  1394. remainedDays(expTime) {
  1395. if (expTime == 0) return null;
  1396. if (expTime < 0) return TimeFormatter.formatSecond(expTime / -1000);
  1397. now = new Date().getTime();
  1398. if (expTime < now) return '{{ i18n "depleted" }}';
  1399. return TimeFormatter.formatSecond((expTime - now) / 1000);
  1400. },
  1401. statsExpColor(dbInbound, email) {
  1402. if (email.length == 0) return '#7a316f';
  1403. clientStats = dbInbound.clientStats.find(stats => stats.email === email);
  1404. if (!clientStats) return '#7a316f';
  1405. statsColor = ColorUtils.usageColor(clientStats.down + clientStats.up, this.trafficDiff, clientStats.total);
  1406. expColor = ColorUtils.usageColor(new Date().getTime(), this.expireDiff, clientStats.expiryTime);
  1407. switch (true) {
  1408. case statsColor == "red" || expColor == "red":
  1409. return "#cf3c3c"; // Red
  1410. case statsColor == "orange" || expColor == "orange":
  1411. return "#f37b24"; // Orange
  1412. case statsColor == "green" || expColor == "green":
  1413. return "#008771"; // Green
  1414. default:
  1415. return "#7a316f"; // purple
  1416. }
  1417. },
  1418. isClientEnabled(dbInbound, email) {
  1419. clientStats = dbInbound.clientStats ? dbInbound.clientStats.find(stats => stats.email === email) : null;
  1420. return clientStats ? clientStats['enable'] : true;
  1421. },
  1422. // Returns true when client's traffic is exhausted or expiry time is passed
  1423. isClientDepleted(dbInbound, email) {
  1424. if (!email || !dbInbound || !dbInbound.clientStats) return false;
  1425. const stats = dbInbound.clientStats.find(s => s.email === email);
  1426. if (!stats) return false;
  1427. const now = new Date().getTime();
  1428. const exhausted = stats.total > 0 && (stats.up + stats.down) >= stats.total;
  1429. const expired = stats.expiryTime > 0 && now >= stats.expiryTime;
  1430. return exhausted || expired;
  1431. },
  1432. isClientOnline(email) {
  1433. return this.onlineClients.includes(email);
  1434. },
  1435. getLastOnline(email) {
  1436. return this.lastOnlineMap[email] || null
  1437. },
  1438. formatLastOnline(email) {
  1439. const ts = this.getLastOnline(email)
  1440. if (!ts) return '-'
  1441. if (this.datepicker === 'gregorian') {
  1442. return DateUtil.formatMillis(ts)
  1443. }
  1444. return DateUtil.convertToJalalian(moment(ts))
  1445. },
  1446. isRemovable(dbInboundId) {
  1447. return this.getInboundClients(this.dbInbounds.find(row => row.id === dbInboundId)).length > 1;
  1448. },
  1449. inboundLinks(dbInboundId) {
  1450. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1451. newDbInbound = this.checkFallback(dbInbound);
  1452. txtModal.show('{{ i18n "pages.inbounds.export"}}', newDbInbound.genInboundLinks(this.remarkModel), newDbInbound.remark);
  1453. },
  1454. exportSubs(dbInboundId) {
  1455. const dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1456. const clients = this.getInboundClients(dbInbound);
  1457. let subLinks = []
  1458. if (clients != null) {
  1459. clients.forEach(c => {
  1460. if (c.subId && c.subId.length > 0) {
  1461. subLinks.push(this.subSettings.subURI + c.subId)
  1462. }
  1463. })
  1464. }
  1465. txtModal.show(
  1466. '{{ i18n "pages.inbounds.export"}} - {{ i18n "pages.settings.subSettings" }}',
  1467. [...new Set(subLinks)].join('\n'),
  1468. dbInbound.remark + "-Subs");
  1469. },
  1470. importInbound() {
  1471. promptModal.open({
  1472. title: '{{ i18n "pages.inbounds.importInbound" }}',
  1473. type: 'textarea',
  1474. value: '',
  1475. okText: '{{ i18n "pages.inbounds.import" }}',
  1476. confirm: async (dbInboundText) => {
  1477. await this.submit('/panel/api/inbounds/import', { data: dbInboundText }, promptModal);
  1478. },
  1479. });
  1480. },
  1481. exportAllSubs() {
  1482. let subLinks = []
  1483. for (const dbInbound of this.dbInbounds) {
  1484. const clients = this.getInboundClients(dbInbound);
  1485. if (clients != null) {
  1486. clients.forEach(c => {
  1487. if (c.subId && c.subId.length > 0) {
  1488. subLinks.push(this.subSettings.subURI + c.subId)
  1489. }
  1490. })
  1491. }
  1492. }
  1493. txtModal.show(
  1494. '{{ i18n "pages.inbounds.export"}} - {{ i18n "pages.settings.subSettings" }}',
  1495. [...new Set(subLinks)].join('\r\n'),
  1496. 'All-Inbounds-Subs');
  1497. },
  1498. exportAllLinks() {
  1499. let copyText = [];
  1500. for (const dbInbound of this.dbInbounds) {
  1501. copyText.push(dbInbound.genInboundLinks(this.remarkModel));
  1502. }
  1503. txtModal.show('{{ i18n "pages.inbounds.export"}}', copyText.join('\r\n'), 'All-Inbounds');
  1504. },
  1505. copy(dbInboundId) {
  1506. dbInbound = this.dbInbounds.find(row => row.id === dbInboundId);
  1507. txtModal.show('{{ i18n "pages.inbounds.inboundData" }}', JSON.stringify(dbInbound, null, 2));
  1508. },
  1509. async startDataRefreshLoop() {
  1510. while (this.isRefreshEnabled) {
  1511. try {
  1512. await this.getDBInbounds();
  1513. } catch (e) {
  1514. console.error(e);
  1515. }
  1516. await PromiseUtil.sleep(this.refreshInterval);
  1517. }
  1518. },
  1519. toggleRefresh() {
  1520. localStorage.setItem("isRefreshEnabled", this.isRefreshEnabled);
  1521. if (this.isRefreshEnabled) {
  1522. this.startDataRefreshLoop();
  1523. }
  1524. },
  1525. changeRefreshInterval() {
  1526. localStorage.setItem("refreshInterval", this.refreshInterval);
  1527. },
  1528. async manualRefresh() {
  1529. if (!this.refreshing) {
  1530. this.loadingStates.spinning = true;
  1531. await this.getDBInbounds();
  1532. this.loadingStates.spinning = false;
  1533. }
  1534. },
  1535. pagination(obj) {
  1536. if (this.pageSize > 0 && obj.length > this.pageSize) {
  1537. // Set page options based on object size
  1538. sizeOptions = [];
  1539. for (i = this.pageSize; i <= obj.length; i = i + this.pageSize) {
  1540. sizeOptions.push(i.toString());
  1541. }
  1542. // Add option to see all in one page
  1543. sizeOptions.push(i.toString());
  1544. p = {
  1545. showSizeChanger: true,
  1546. size: 'small',
  1547. position: 'bottom',
  1548. pageSize: this.pageSize,
  1549. pageSizeOptions: sizeOptions
  1550. };
  1551. return p;
  1552. }
  1553. return false
  1554. }
  1555. },
  1556. watch: {
  1557. searchKey: Utils.debounce(function (newVal) {
  1558. this.searchInbounds(newVal);
  1559. }, 500)
  1560. },
  1561. mounted() {
  1562. if (window.location.protocol !== "https:") {
  1563. this.showAlert = true;
  1564. }
  1565. this.loading();
  1566. this.getDefaultSettings();
  1567. if (this.isRefreshEnabled) {
  1568. this.startDataRefreshLoop();
  1569. }
  1570. else {
  1571. this.getDBInbounds();
  1572. }
  1573. this.loading(false);
  1574. },
  1575. computed: {
  1576. total() {
  1577. let down = 0, up = 0, allTime = 0;
  1578. let clients = 0, deactive = [], depleted = [], expiring = [];
  1579. this.dbInbounds.forEach(dbInbound => {
  1580. down += dbInbound.down;
  1581. up += dbInbound.up;
  1582. allTime += (dbInbound.allTime || (dbInbound.up + dbInbound.down));
  1583. if (this.clientCount[dbInbound.id]) {
  1584. clients += this.clientCount[dbInbound.id].clients;
  1585. deactive = deactive.concat(this.clientCount[dbInbound.id].deactive);
  1586. depleted = depleted.concat(this.clientCount[dbInbound.id].depleted);
  1587. expiring = expiring.concat(this.clientCount[dbInbound.id].expiring);
  1588. }
  1589. });
  1590. return {
  1591. down: down,
  1592. up: up,
  1593. allTime: allTime,
  1594. clients: clients,
  1595. deactive: deactive,
  1596. depleted: depleted,
  1597. expiring: expiring,
  1598. };
  1599. }
  1600. },
  1601. });
  1602. </script>
  1603. {{ template "page/body_end" .}}