Example #1
0
        public static List <AppsContainer> GetOneComputerData(string hostname)
        {
            var appsContainers = new List <AppsContainer>();

            using (var db = new ApplicationContext())
            {
                var computerId = GetComputerId(hostname);
                if (computerId == 0)
                {
                    return(appsContainers);
                }
                var computer      = db.Computers.Where(cc => cc.Id == computerId).ToList().FirstOrDefault();
                var appsContainer = new AppsContainer {
                    hostname = computer.Name, date = long.Parse(computer.UpdTime)
                };
                var programs = db.Programs.Where(p => p.IdC == computer.Id).ToList();
                foreach (var pr in programs)
                {
                    var app = new App(pr.Name, pr.Version);
                    appsContainer.apps.Add(app);
                }
                appsContainers.Add(appsContainer);
            }
            return(appsContainers);
        }
        public async Task <CreateChannelViewModel> Init()
        {
            var token   = AppsContainer.AccessToken();
            var channel = await ChannelService.CreateChannelAsync(await token(), "");

            return(channel);
        }
Example #3
0
 public AuthController(
     ServiceLocation serviceLocation,
     IConfiguration configuration,
     IHostingEnvironment env,
     AuthService <KahlaUser> authService,
     OAuthService oauthService,
     UserManager <KahlaUser> userManager,
     SignInManager <KahlaUser> signInManager,
     UserService userService,
     AppsContainer appsContainer,
     KahlaPushService pusher,
     ChannelService channelService,
     VersionChecker version,
     KahlaDbContext dbContext,
     IMemoryCache cache)
 {
     _serviceLocation = serviceLocation;
     _configuration   = configuration;
     _env             = env;
     _authService     = authService;
     _oauthService    = oauthService;
     _userManager     = userManager;
     _signInManager   = signInManager;
     _userService     = userService;
     _appsContainer   = appsContainer;
     _pusher          = pusher;
     _channelService  = channelService;
     _version         = version;
     _dbContext       = dbContext;
     _cache           = cache;
 }
Example #4
0
 public ApiController(
     UserManager <KahlaUser> userManager,
     SignInManager <KahlaUser> signInManager,
     KahlaDbContext dbContext,
     PushKahlaMessageService pushService,
     IConfiguration configuration,
     AuthService <KahlaUser> authService,
     ServiceLocation serviceLocation,
     OAuthService oauthService,
     ChannelService channelService,
     StorageService storageService,
     AppsContainer appsContainer,
     UserService userService)
 {
     _userManager     = userManager;
     _signInManager   = signInManager;
     _dbContext       = dbContext;
     _pusher          = pushService;
     _configuration   = configuration;
     _authService     = authService;
     _serviceLocation = serviceLocation;
     _oauthService    = oauthService;
     _channelService  = channelService;
     _storageService  = storageService;
     _appsContainer   = appsContainer;
     _userService     = userService;
 }
Example #5
0
 public AiurUploader(
     AppsContainer appsContainer,
     TokenService tokenService)
 {
     _appsContainer = appsContainer;
     _tokenService  = tokenService;
 }
Example #6
0
        public async Task <IActionResult> DeleteApp(DeleteAppViewModel model)
        {
            var cuser = await GetCurrentUserAsync();

            if (!ModelState.IsValid)
            {
                model.Recover(cuser, 1);
                return(View(model));
            }
            var target = await _dbContext.Apps.FindAsync(model.AppId);

            if (target == null)
            {
                return(NotFound());
            }
            else if (target.CreaterId != cuser.Id)
            {
                return(new UnauthorizedResult());
            }
            await ApiService.DeleteAppAsync(await AppsContainer.AccessToken(target.AppId, target.AppSecret)(), target.AppId);

            _dbContext.Apps.Remove(target);
            await _dbContext.SaveChangesAsync();

            return(RedirectToAction(nameof(AllApps)));
        }
Example #7
0
        private static List <App> GetDifference(List <App> apps)
        {
            var result = new List <App>();

            if (!File.Exists(_config.CacheFileName))
            {
                return(apps);
            }
            var cachedApps = AppsContainer.FromBytes(File.ReadAllBytes(_config.CacheFileName)).apps;

            foreach (var app in apps)
            {
                var cachedApp = cachedApps.Find(a => a.name == app.name);
                if (cachedApp != null)
                {
                    cachedApps.Remove(cachedApp);
                    if (app.version == cachedApp.version)
                    {
                        continue;
                    }
                    app.status = AppStatus.Updated;
                }
                result.Add(app);
            }

            cachedApps.ForEach(app => app.status = AppStatus.Deleted);
            result.AddRange(cachedApps);
            return(result);
        }
Example #8
0
 public AuthController(
     ServiceLocation serviceLocation,
     IConfiguration configuration,
     IHostingEnvironment env,
     AuthService <ApplicationUser> authService,
     OAuthService oauthService,
     UserManager <ApplicationUser> userManager,
     SignInManager <ApplicationUser> signInManager,
     UserService userService,
     AppsContainer appsContainer,
     ChatPushService pusher,
     ChannelService channelService,
     VersionChecker version,
     ApplicationDbContext dbContext,
     ThirdPartyPushService thirdPartyPushService)
 {
     _serviceLocation       = serviceLocation;
     _configuration         = configuration;
     _env                   = env;
     _authService           = authService;
     _oauthService          = oauthService;
     _userManager           = userManager;
     _signInManager         = signInManager;
     _userService           = userService;
     _appsContainer         = appsContainer;
     _pusher                = pusher;
     _channelService        = channelService;
     _version               = version;
     _dbContext             = dbContext;
     _thirdPartyPushService = thirdPartyPushService;
 }
Example #9
0
        private static void SaveToCache(AppsContainer container)
        {
            var formatter = new BinaryFormatter();

            using (var fs = new FileStream(_config.CacheFileName, FileMode.OpenOrCreate))
                formatter.Serialize(fs, container);
        }
Example #10
0
 public AuthController(
     ServiceLocation serviceLocation,
     IWebHostEnvironment env,
     AuthService <KahlaUser> authService,
     UserManager <KahlaUser> userManager,
     SignInManager <KahlaUser> signInManager,
     UserService userService,
     AppsContainer appsContainer,
     KahlaPushService pusher,
     ChannelService channelService,
     VersionChecker version,
     KahlaDbContext dbContext,
     IOptions <List <DomainSettings> > optionsAccessor,
     AiurCache cache)
 {
     _serviceLocation = serviceLocation;
     _env             = env;
     _authService     = authService;
     _userManager     = userManager;
     _signInManager   = signInManager;
     _userService     = userService;
     _appsContainer   = appsContainer;
     _pusher          = pusher;
     _channelService  = channelService;
     _version         = version;
     _dbContext       = dbContext;
     _cache           = cache;
     _appDomains      = optionsAccessor.Value;
 }
Example #11
0
 public AuthController(
     StargateLocator serviceLocation,
     AuthService <KahlaUser> authService,
     UserManager <KahlaUser> userManager,
     SignInManager <KahlaUser> signInManager,
     UserService userService,
     AppsContainer appsContainer,
     KahlaPushService pusher,
     ChannelService channelService,
     KahlaDbContext dbContext,
     IOptions <List <DomainSettings> > optionsAccessor,
     EventService eventService,
     OnlineJudger onlineJudger,
     StargatePushService stargatePushService)
 {
     _stargateLocator     = serviceLocation;
     _authService         = authService;
     _userManager         = userManager;
     _signInManager       = signInManager;
     _userService         = userService;
     _appsContainer       = appsContainer;
     _pusher              = pusher;
     _channelService      = channelService;
     _dbContext           = dbContext;
     _eventService        = eventService;
     _onlineJudger        = onlineJudger;
     _stargatePushService = stargatePushService;
     _appDomains          = optionsAccessor.Value;
 }
Example #12
0
 public WebSocketPusher(
     AppsContainer appsContainer,
     EventService eventService)
 {
     _appsContainer = appsContainer;
     _eventService  = eventService;
 }
Example #13
0
        public async Task <IActionResult> CreateBucket([FromForm] CreateBucketViewModel model)
        {
            var cuser = await GetCurrentUserAsync();

            if (!ModelState.IsValid)
            {
                model.ModelStateValid = false;
                model.Recover(this, cuser);
                return(View(model));
            }
            var app = await _dbContext.Apps.FindAsync(model.AppId);

            if (app == null)
            {
                return(NotFound());
            }
            try
            {
                var token  = AppsContainer.AccessToken(app.AppId, app.AppSecret);
                var result = await ApiService.CreateBucketAsync(await token(), model.NewBucketName, model.OpenToRead, model.OpenToUpload);

                return(RedirectToAction(nameof(AppsController.ViewApp), "Apps", new { id = app.AppId, JustHaveUpdated = true }));
            }
            catch (AiurUnexceptedResponse e)
            {
                ModelState.AddModelError(string.Empty, e.Response.message);
                model.ModelStateValid = false;
                model.Recover(this, cuser);
                return(View(model));
            }
        }
Example #14
0
        public async Task <IActionResult> EditBucket(EditBucketViewModel model)
        {
            var cuser = await GetCurrentUserAsync();

            if (!ModelState.IsValid)
            {
                model.ModelStateValid = false;
                model.Recover(cuser, 1);
                return(View(model));
            }
            try
            {
                var app = await _dbContext.Apps.FindAsync(model.AppId);

                var token  = AppsContainer.AccessToken(app.AppId, app.AppSecret);
                var bucket = await ApiService.ViewBucketDetailAsync(model.BucketId);

                if (bucket.BelongingAppId != app.AppId || app.CreaterId != cuser.Id)
                {
                    return(Unauthorized());
                }

                await ApiService.EditBucketAsync(await token(), model.BucketId, model.NewBucketName, model.OpenToRead, model.OpenToUpload);

                return(RedirectToAction(nameof(AppsController.ViewApp), "Apps", new { id = model.AppId, JustHaveUpdated = true }));
            }
            catch (AiurUnexceptedResponse e)
            {
                ModelState.AddModelError(string.Empty, e.Response.message);
                model.ModelStateValid = false;
                model.Recover(cuser, 1);
                return(View(model));
            }
        }
Example #15
0
        public async Task <IActionResult> DeleteFile(DeleteFileViewModel model)
        {
            var cuser = await GetCurrentUserAsync();

            if (!ModelState.IsValid)
            {
                model.Recover(cuser, 3);
                return(View(model));
            }
            var fileinfo = await ApiService.ViewOneFileAsync(model.FileId);

            var bucketInfo = await ApiService.ViewBucketDetailAsync(fileinfo.File.BucketId);

            var app = await _dbContext.Apps.FindAsync(bucketInfo.BelongingAppId);

            if (fileinfo == null || bucketInfo.BelongingAppId != app.AppId || fileinfo.File.BucketId != bucketInfo.BucketId)
            {
                return(Unauthorized());
            }
            await ApiService.DeleteFileAsync(await AppsContainer.AccessToken(app.AppId, app.AppSecret)(), model.FileId, bucketInfo.BucketId);

            return(RedirectToAction(nameof(ViewFiles), new
            {
                id = bucketInfo.BucketId
            }));
        }
 public DebugApiController(
     UserManager <KahlaUser> userManager,
     SignInManager <KahlaUser> signInManager,
     KahlaDbContext dbContext,
     PushKahlaMessageService pushService,
     IConfiguration configuration,
     AuthService <KahlaUser> authService,
     ServiceLocation serviceLocation,
     OAuthService oauthService,
     ChannelService channelService,
     StorageService storageService,
     AppsContainer appsContainer,
     UserService userService) : base(
         userManager,
         signInManager,
         dbContext,
         pushService,
         configuration,
         authService,
         serviceLocation,
         oauthService,
         channelService,
         storageService,
         appsContainer,
         userService)
 {
 }
Example #17
0
 public AppsController(
     UserManager <DeveloperUser> userManager,
     SignInManager <DeveloperUser> signInManager,
     ILoggerFactory loggerFactory,
     DeveloperDbContext dbContext,
     ServiceLocation serviceLocation,
     StorageService storageService,
     OSSApiService ossApiService,
     AppsContainer appsContainer,
     CoreApiService coreApiService,
     IConfiguration configuration,
     SitesService siteService)
 {
     _userManager     = userManager;
     _signInManager   = signInManager;
     _logger          = loggerFactory.CreateLogger <AppsController>();
     _dbContext       = dbContext;
     _serviceLocation = serviceLocation;
     _storageService  = storageService;
     _ossApiService   = ossApiService;
     _appsContainer   = appsContainer;
     _coreApiService  = coreApiService;
     _configuration   = configuration;
     _siteService     = siteService;
 }
Example #18
0
        public async Task Recover(
            DeveloperUser user,
            DeveloperApp appInDb,
            CoreApiService coreApiService,
            AppsContainer appsContainer,
            SitesService sitesService,
            EventService eventService,
            ChannelService channelService,
            RecordsService recordsService,
            int pageNumber)
        {
            RootRecover(user);
            var token = await appsContainer.AccessToken(appInDb.AppId, appInDb.AppSecret);

            Grants = await coreApiService.AllUserGrantedAsync(token, pageNumber, 15);

            var sites = await sitesService.ViewMySitesAsync(token);

            Sites = sites.Sites;

            var errorLogs = await eventService.ViewAsync(token);

            ErrorLogs = errorLogs.Logs;

            var channels = await channelService.ViewMyChannelsAsync(token);

            Channels = channels.Channels;

            var records = await recordsService.ViewMyRecordsAsync(token, Array.Empty <string>());

            Records = records.Records;

            Trusted = appInDb.TrustedApp;
        }
Example #19
0
        public async Task <IActionResult> GenerateLink(int id)
        {
            var cuser = await GetCurrentUserAsync();

            var fileinfo = await ApiService.ViewOneFileAsync(id);

            if (fileinfo.File == null)
            {
                return(NotFound());
            }
            var bucketInfo = await ApiService.ViewBucketDetailAsync(fileinfo.File.BucketId);

            var app = await _dbContext.Apps.FindAsync(bucketInfo.BelongingAppId);

            if (bucketInfo.BelongingAppId != app.AppId)
            {
                return(Unauthorized());
            }
            var secret = await SecretService.GenerateAsync(id, await AppsContainer.AccessToken(app.AppId, app.AppSecret)());

            var model = new GenerateLinkViewModel(cuser)
            {
                Address  = secret.Value,
                BucketId = bucketInfo.BucketId
            };

            return(View(model));
        }
Example #20
0
        public async Task <IActionResult> ViewFiles(int id)//Bucket Id
        {
            var cuser = await GetCurrentUserAsync();

            var bucketInfo = await ApiService.ViewBucketDetailAsync(id);

            if (bucketInfo.BelongingAppId == null)
            {
                return(NotFound());
            }
            var app = await _dbContext.Apps.FindAsync(bucketInfo.BelongingAppId);

            var files = await ApiService.ViewAllFilesAsync(await AppsContainer.AccessToken(app.AppId, app.AppSecret)(), id);

            var model = new ViewFilesViewModel(cuser)
            {
                BucketId   = files.BucketId,
                AllFiles   = files.AllFiles,
                AppId      = app.AppId,
                OpenToRead = bucketInfo.OpenToRead,
                BucketName = bucketInfo.BucketName
            };

            return(View(model));
        }
Example #21
0
        public async Task <IActionResult> EnterCode(EnterCodeViewModel model)
        {
            var user = await GetCurrentUserAsync();

            if (!ModelState.IsValid)
            {
                model.Recover(user);
                model.ModelStateValid = ModelState.IsValid;
                return(View(model));
            }
            var correctToken = await _userManager.VerifyChangePhoneNumberTokenAsync(user, model.Code, model.NewPhoneNumber);

            if (correctToken)
            {
                var result = await UserService.SetPhoneNumberAsync(user.Id, await AppsContainer.AccessToken()(), model.NewPhoneNumber);

                if (result.Code == ErrorType.Success)
                {
                    user.PhoneNumber = model.NewPhoneNumber;
                    await _userManager.UpdateAsync(user);

                    return(RedirectToAction(nameof(Phone), new { JustHaveUpdated = true }));
                }
                throw new InvalidOperationException();
            }
            else
            {
                model.ModelStateValid = false;
                model.Recover(user);
                ModelState.AddModelError("", "Your token is invalid!");
                return(View(model));
            }
        }
Example #22
0
        public async Task Recover(
            DeveloperUser user,
            App thisApp,
            CoreApiService coreApiService,
            AppsContainer appsContainer,
            SitesService sitesService,
            EventService eventService,
            ChannelService channelService,
            int pageNumber)
        {
            RootRecover(user);
            var token = await appsContainer.AccessToken(thisApp.AppId, thisApp.AppSecret);

            Grants = await coreApiService.AllUserGrantedAsync(token, pageNumber, 15);

            var sites = await sitesService.ViewMySitesAsync(token);

            Sites = sites.Sites;

            var errorLogs = await eventService.ViewAsync(token);

            ErrorLogs = errorLogs.Logs;

            var channels = await channelService.ViewMyChannelsAsync(token);

            Channels = channels.Channels;
        }
Example #23
0
 public BucketController(
     DeveloperDbContext dbContext,
     AppsContainer appsContainer,
     OSSApiService ossApiService)
 {
     _dbContext     = dbContext;
     _appsContainer = appsContainer;
     _ossApiService = ossApiService;
 }
Example #24
0
 public KahlaPushService(
     AppsContainer appsContainer,
     ChannelService channelService,
     CannonService cannonService)
 {
     _appsContainer  = appsContainer;
     _channelService = channelService;
     _cannonService  = cannonService;
 }
Example #25
0
 public EmailNotifier(
     ILogger <EmailNotifier> logger,
     IServiceScopeFactory scopeFactory,
     AppsContainer appsContainer)
 {
     _logger        = logger;
     _scopeFactory  = scopeFactory;
     _appsContainer = appsContainer;
 }
 public DashboardController(
     AppsContainer appsContainer,
     RecordsService recordsService,
     UserManager <WrapUser> userManager)
 {
     _appsContainer  = appsContainer;
     _recordsService = recordsService;
     _userManager    = userManager;
 }
Example #27
0
 public RecordsController(
     DeveloperDbContext dbContext,
     AppsContainer appsContainer,
     RecordsService recordsService)
 {
     _dbContext      = dbContext;
     _appsContainer  = appsContainer;
     _recordsService = recordsService;
 }
Example #28
0
 public KahlaPushService(
     AppsContainer appsContainer,
     CannonService cannonService,
     EventService eventService)
 {
     _appsContainer = appsContainer;
     _cannonService = cannonService;
     _eventService  = eventService;
 }
 public APIFriendlyServerExceptionMiddleware(
     RequestDelegate next,
     ILogger <APIFriendlyServerExceptionMiddleware> logger,
     AppsContainer appsContainer,
     EventService eventService)
 {
     _next          = next;
     _logger        = logger;
     _appsContainer = appsContainer;
     _eventService  = eventService;
 }
Example #30
0
 public FilesCleaner(
     ILogger <FilesCleaner> logger,
     IServiceScopeFactory scopeFactory,
     AppsContainer appsContainer,
     IConfiguration configuration)
 {
     _logger        = logger;
     _scopeFactory  = scopeFactory;
     _appsContainer = appsContainer;
     _configuration = configuration;
 }