summaryrefslogtreecommitdiffstats
path: root/utility
diff options
context:
space:
mode:
authorBernhard Posselt <dev@bernhard-posselt.com>2014-04-10 19:38:52 +0200
committerBernhard Posselt <dev@bernhard-posselt.com>2014-04-10 19:38:52 +0200
commit836dfebf723afc264868da69021c89221d02aa18 (patch)
treeae5274151345a13f65488bb6562fe1db0da41244 /utility
parent5befce51ef9f38609b713cfbc6095a3b60b1d574 (diff)
build http basic auth rather than requiring it from the user to write the correct auth string into the config
Diffstat (limited to 'utility')
-rw-r--r--utility/config.php31
1 files changed, 25 insertions, 6 deletions
diff --git a/utility/config.php b/utility/config.php
index 0fa636ea8..d415595b7 100644
--- a/utility/config.php
+++ b/utility/config.php
@@ -41,7 +41,8 @@ class Config {
private $useCronUpdates; // turn off updates run by owncloud cronjob
private $proxyHost;
private $proxyPort;
- private $proxyAuth;
+ private $proxyUser;
+ private $proxyPassword;
private $api;
@@ -55,7 +56,8 @@ class Config {
$this->api = $api;
$this->proxyHost = '';
$this->proxyPort = 8080;
- $this->proxyAuth = '';
+ $this->proxyUser = '';
+ $this->proxyPassword = '';
}
public function getProxyPort() {
@@ -67,7 +69,19 @@ class Config {
}
public function getProxyAuth() {
- return $this->proxyAuth;
+ if($this->proxyUser === '') {
+ return null;
+ } else {
+ return $this->proxyUser . ':' . $this->proxyPassword;
+ }
+ }
+
+ public function getProxyUser() {
+ return $this->proxyUser;
+ }
+
+ public function getProxyPassword() {
+ return $this->proxyPassword;
}
public function getAutoPurgeMinimumInterval() {
@@ -128,8 +142,12 @@ class Config {
$this->proxyHost = $value;
}
- public function setProxyAuth($value) {
- $this->proxyAuth = $value;
+ public function setProxyUser($value) {
+ $this->proxyUser = $value;
+ }
+
+ public function setProxyPassword($value) {
+ $this->proxyPassword = $value;
}
@@ -172,7 +190,8 @@ class Config {
"useCronUpdates = " . var_export($this->useCronUpdates, true) . "\n" .
"proxyHost = " . $this->proxyHost . "\n" .
"proxyPort = " . $this->proxyPort . "\n" .
- "proxyAuth = " . $this->proxyAuth;
+ "proxyUser = " . $this->proxyUser . "\n" .
+ "proxyPassword = " . $this->proxyPassword;
;
$this->fileSystem->file_put_contents($configPath, $ini);
t .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
import { wsUri } from '../env';
import { LoginForm, RegisterForm, UserOperation, CommunityForm, PostForm, SavePostForm, CommentForm, SaveCommentForm, CommentLikeForm, GetPostsForm, CreatePostLikeForm, FollowCommunityForm, GetUserDetailsForm, ListCommunitiesForm, GetModlogForm, BanFromCommunityForm, AddModToCommunityForm, AddAdminForm, BanUserForm, SiteForm, Site, UserView, GetRepliesForm, SearchForm } from '../interfaces';
import { webSocket } from 'rxjs/webSocket';
import { Subject } from 'rxjs';
import { retryWhen, delay, take } from 'rxjs/operators';
import { UserService } from './';
import { i18n } from '../i18next';

export class WebSocketService {
  private static _instance: WebSocketService;
  public subject: Subject<any>;

  public site: Site;
  public admins: Array<UserView>;
  public banned: Array<UserView>;

  private constructor() {
    this.subject = webSocket(wsUri);

    // Necessary to not keep reconnecting
    this.subject
      .pipe(retryWhen(errors => errors.pipe(delay(60000), take(999))))
      .subscribe();

      console.log(`Connected to ${wsUri}`);
  }

  public static get Instance(){
    return this._instance || (this._instance = new this());
  }
   
  public login(loginForm: LoginForm) {
    this.subject.next(this.wsSendWrapper(UserOperation.Login, loginForm));
  }

  public register(registerForm: RegisterForm) {
    this.subject.next(this.wsSendWrapper(UserOperation.Register, registerForm));
  }

  public createCommunity(communityForm: CommunityForm) {
    this.setAuth(communityForm);
    this.subject.next(this.wsSendWrapper(UserOperation.CreateCommunity, communityForm));
  }

  public editCommunity(communityForm: CommunityForm) {
    this.setAuth(communityForm);
    this.subject.next(this.wsSendWrapper(UserOperation.EditCommunity, communityForm));
  }

  public followCommunity(followCommunityForm: FollowCommunityForm) {
    this.setAuth(followCommunityForm);
    this.subject.next(this.wsSendWrapper(UserOperation.FollowCommunity, followCommunityForm));
  }

  public listCommunities(form: ListCommunitiesForm) {
    this.setAuth(form, false);
    this.subject.next(this.wsSendWrapper(UserOperation.ListCommunities, form));
  }

  public getFollowedCommunities() {
    let data = {auth: UserService.Instance.auth };
    this.subject.next(this.wsSendWrapper(UserOperation.GetFollowedCommunities, data));
  }

  public listCategories() {
    this.subject.next(this.wsSendWrapper(UserOperation.ListCategories, undefined));
  }

  public createPost(postForm: PostForm) {
    this.setAuth(postForm);
    this.subject.next(this.wsSendWrapper(UserOperation.CreatePost, postForm));
  }

  public getPost(postId: number) {
    let data = {id: postId, auth: UserService.Instance.auth };
    this.subject.next(this.wsSendWrapper(UserOperation.GetPost, data));
  }

  public getCommunity(communityId: number) {
    let data = {id: communityId, auth: UserService.Instance.auth };
    this.subject.next(this.wsSendWrapper(UserOperation.GetCommunity, data));
  }

  public getCommunityByName(name: string) {
    let data = {name: name, auth: UserService.Instance.auth };
    this.subject.next(this.wsSendWrapper(UserOperation.GetCommunity, data));
  }

  public createComment(commentForm: CommentForm) {
    this.setAuth(commentForm);
    this.subject.next(this.wsSendWrapper(UserOperation.CreateComment, commentForm));
  }

  public editComment(commentForm: CommentForm) {
    this.setAuth(commentForm);
    this.subject.next(this.wsSendWrapper(UserOperation.EditComment, commentForm));
  }

  public likeComment(form: CommentLikeForm) {
    this.setAuth(form);
    this.subject.next(this.wsSendWrapper(UserOperation.CreateCommentLike, form));
  }

  public saveComment(form: SaveCommentForm) {
    this.setAuth(form);
    this.subject.next(this.wsSendWrapper(UserOperation.SaveComment, form));
  }

  public getPosts(form: GetPostsForm) {
    this.setAuth(form, false);
    this.subject.next(this.wsSendWrapper(UserOperation.GetPosts, form));
  }

  public likePost(form: CreatePostLikeForm) {
    this.setAuth(form);
    this.subject.next(this.wsSendWrapper(UserOperation.CreatePostLike, form));
  }

  public editPost(postForm: PostForm) {
    this.setAuth(postForm);
    this.subject.next(this.wsSendWrapper(UserOperation.EditPost, postForm));
  }

  public savePost(form: SavePostForm) {
    this.setAuth(form);
    this.subject.next(this.wsSendWrapper(UserOperation.SavePost, form));
  }

  public banFromCommunity(form: BanFromCommunityForm) {
    this.setAuth(form);
    this.subject.next(this.wsSendWrapper(UserOperation.BanFromCommunity, form));
  }

  public addModToCommunity(form: AddModToCommunityForm) {
    this.setAuth(form);
    this.subject.next(this.wsSendWrapper(UserOperation.AddModToCommunity, form));
  }

  public banUser(form: BanUserForm) {
    this.setAuth(form);
    this.subject.next(this.wsSendWrapper(UserOperation.BanUser, form));
  }

  public addAdmin(form: AddAdminForm) {
    this.setAuth(form);
    this.subject.next(this.wsSendWrapper(UserOperation.AddAdmin, form));
  }

  public getUserDetails(form: GetUserDetailsForm) {
    this.setAuth(form, false);
    this.subject.next(this.wsSendWrapper(UserOperation.GetUserDetails, form));
  }

  public getReplies(form: GetRepliesForm) {
    this.setAuth(form);
    this.subject.next(this.wsSendWrapper(UserOperation.GetReplies, form));
  }

  public getModlog(form: GetModlogForm) {
    this.subject.next(this.wsSendWrapper(UserOperation.GetModlog, form));
  }

  public createSite(siteForm: SiteForm) {
    this.setAuth(siteForm);
    this.subject.next(this.wsSendWrapper(UserOperation.CreateSite, siteForm));
  }

  public editSite(siteForm: SiteForm) {
    this.setAuth(siteForm);
    this.subject.next(this.wsSendWrapper(UserOperation.EditSite, siteForm));
  }

  public getSite() {
    this.subject.next(this.wsSendWrapper(UserOperation.GetSite, undefined));
  }

  public search(form: SearchForm) {
    this.subject.next(this.wsSendWrapper(UserOperation.Search, form));
  }

  public markAllAsRead() {
    let form = {};
    this.setAuth(form);
    this.subject.next(this.wsSendWrapper(UserOperation.MarkAllAsRead, form));
  }

  private wsSendWrapper(op: UserOperation, data: any) {
    let send = { op: UserOperation[op], data: data };
    console.log(send);
    return send;
  }

  private setAuth(obj: any, throwErr: boolean = true) {
    obj.auth = UserService.Instance.auth;
    if (obj.auth == null && throwErr) {
      alert(i18n.t('not_logged_in'));
      throw "Not logged in";
    }
  }
}

window.onbeforeunload = (() => {
  WebSocketService.Instance.subject.unsubscribe();
  WebSocketService.Instance.subject = null;
});